From 71e2c05adec185d2a592d0733a133124cf37e83c Mon Sep 17 00:00:00 2001 From: Guillaume Pinot Date: Tue, 27 Mar 2018 09:44:36 +0200 Subject: [PATCH] Fix compilation with `#[deny(warnings)]` with the `!` type https://github.com/rust-lang/rust/pull/49039#issuecomment-376420816 --- .travis.yml | 4 +--- CHANGELOG.md | 4 +++- Cargo.toml | 2 +- structopt-derive/Cargo.toml | 2 +- structopt-derive/src/lib.rs | 4 ++-- tests/deny-warnings.rs | 46 +++++++++++++++++++++++++++++++++++++ 6 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 tests/deny-warnings.rs diff --git a/.travis.yml b/.travis.yml index 11a38d41..982b0bb6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index b98fc16f..fba7fe89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/Cargo.toml b/Cargo.toml index 2fe0abf3..adb8d5c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/structopt-derive/Cargo.toml b/structopt-derive/Cargo.toml index da134629..7bc3fb33 100644 --- a/structopt-derive/Cargo.toml +++ b/structopt-derive/Cargo.toml @@ -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 diff --git a/structopt-derive/src/lib.rs b/structopt-derive/src/lib.rs index fb7bce25..b38c4c0a 100644 --- a/structopt-derive/src/lib.rs +++ b/structopt-derive/src/lib.rs @@ -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 @@ -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 diff --git a/tests/deny-warnings.rs b/tests/deny-warnings.rs new file mode 100644 index 00000000..2dde87da --- /dev/null +++ b/tests/deny-warnings.rs @@ -0,0 +1,46 @@ +// Copyright 2018 Guillaume Pinot (@TeXitoi) +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , 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 { + 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"])); + +} +