Skip to content

Commit

Permalink
Fix compilation with #[deny(warnings)] with the ! type
Browse files Browse the repository at this point in the history
  • Loading branch information
TeXitoi committed Mar 27, 2018
1 parent ce62bca commit 71e2c05
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 8 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ rust:
matrix:
include:
- rust: nightly
env: FEATURES="--features testing_only_proc_macro2_nightly"
allow_failures:
- rust: nightly
env: FEATURES="--features nightly"

script:
- cargo test $FEATURES
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# v0.2.5 (2018-XX-XX)
# v0.2.6 (2018-XX-XX)

* Fix compilation with `#[deny(warnings)]` with the `!` type (https://github.com/rust-lang/rust/pull/49039#issuecomment-376420816) by [@TeXitoi](https://github.com/TeXitoi)

* Improve first example in the documentation ([#82](https://github.com/TeXitoi/structopt/issues/82)) by [@TeXitoi](https://github.com/TeXitoi)

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ readme = "README.md"

[features]
default = ["clap/default"]
testing_only_proc_macro2_nightly = ["structopt-derive/testing_only_proc_macro2_nightly"]
nightly = ["structopt-derive/nightly"]

[badges]
travis-ci = { repository = "TeXitoi/structopt" }
Expand Down
2 changes: 1 addition & 1 deletion structopt-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ quote = "0.4"
proc-macro2 = "0.2"

[features]
testing_only_proc_macro2_nightly = ["proc-macro2/nightly"]
nightly = ["proc-macro2/nightly"]

[lib]
proc-macro = true
4 changes: 2 additions & 2 deletions structopt-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ fn impl_structopt_for_struct(
#from_clap
}

#[allow(dead_code)]
#[allow(dead_code, unreachable_code)]
#[doc(hidden)]
impl #name {
#augment_clap
Expand All @@ -406,7 +406,7 @@ fn impl_structopt_for_enum(
#from_clap
}

#[allow(unused_variables, dead_code)]
#[allow(unused_variables, dead_code, unreachable_code)]
#[doc(hidden)]
impl #name {
#augment_clap
Expand Down
46 changes: 46 additions & 0 deletions tests/deny-warnings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2018 Guillaume Pinot (@TeXitoi) <texitoi@texitoi.eu>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![deny(warnings)]
#![cfg(feature = "nightly")]// TODO: remove that when never is stable

#[macro_use]
extern crate structopt;

use structopt::StructOpt;

fn try_str(s: &str) -> Result<String, !> {
Ok(s.into())
}

#[test]
fn warning_never_struct() {
#[derive(Debug, PartialEq, StructOpt)]
struct Opt {
#[structopt(parse(try_from_str = "try_str"))]
s: String,
}
assert_eq!(Opt { s: "foo".to_string() },
Opt::from_iter(&["test", "foo"]));

}

#[test]
fn warning_never_enum() {
#[derive(Debug, PartialEq, StructOpt)]
enum Opt {
Foo {
#[structopt(parse(try_from_str = "try_str"))]
s: String,
}
}
assert_eq!(Opt::Foo { s: "foo".to_string() },
Opt::from_iter(&["test", "Foo", "foo"]));

}

1 comment on commit 71e2c05

@scottmcm
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, that was fast! Thanks!

Please sign in to comment.