Skip to content

Commit

Permalink
refactor: removes unused imports on nightly via cfg directive
Browse files Browse the repository at this point in the history
If one is using a nightly Rust compiler they should compile clap
with the `nightly` feature.

```toml
[dependencies]
clap = { version = "2.27", features = ["nightly"] }
```

This isn't required for compilation to succeed, only to take
advantage of any nightly features used by clap.

If one is compiling with `#[deny(warnings)]` this commit will cause
compilation to fail if one *does not* compile with the `nightly`
since `std::ascii::AsciiExt` is no longer required in in multiple
files as of the latest Rust nightly (Nov 6th, 2017).

Closes #1095
  • Loading branch information
kbknapp committed Nov 7, 2017
1 parent 284d01b commit fb08bb5
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/app/settings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Std
#[cfg(not(feature = "nightly"))]
use std::ascii::AsciiExt;
use std::str::FromStr;
use std::ops::BitOr;
Expand Down
1 change: 1 addition & 0 deletions src/args/settings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Std
#[cfg(not(feature = "nightly"))]
use std::ascii::AsciiExt;
use std::str::FromStr;

Expand Down
1 change: 1 addition & 0 deletions src/completions/shell.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(not(feature = "nightly"))]
use std::ascii::AsciiExt;
use std::str::FromStr;
use std::fmt;
Expand Down
1 change: 1 addition & 0 deletions src/completions/zsh.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

// Std
use std::io::Write;
#[cfg(not(feature = "nightly"))]
use std::ascii::AsciiExt;

// Internal
Expand Down
1 change: 1 addition & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ macro_rules! arg_enum {
type Err = String;

fn from_str(s: &str) -> ::std::result::Result<Self,Self::Err> {
#[cfg(not(feature = "nightly"))]
use ::std::ascii::AsciiExt;
match s {
$(stringify!($v) |
Expand Down
12 changes: 12 additions & 0 deletions tests/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,15 @@ fn quoted_arg_name() {
.expect("Expected to successfully match the given args.");
assert!(matches.is_present("option2"));
}

#[test]
fn arg_enum() {
arg_enum!{
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum Greek {
Alpha,
Bravo
}
}
assert_eq!("Alpha".parse::<Greek>(), Ok(Greek::Alpha));
}

0 comments on commit fb08bb5

Please sign in to comment.