Skip to content

Commit 71e2c05

Browse files
committed
Fix compilation with #[deny(warnings)] with the ! type
rust-lang/rust#49039 (comment)
1 parent ce62bca commit 71e2c05

File tree

6 files changed

+54
-8
lines changed

6 files changed

+54
-8
lines changed

.travis.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ rust:
77
matrix:
88
include:
99
- rust: nightly
10-
env: FEATURES="--features testing_only_proc_macro2_nightly"
11-
allow_failures:
12-
- rust: nightly
10+
env: FEATURES="--features nightly"
1311

1412
script:
1513
- cargo test $FEATURES

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# v0.2.5 (2018-XX-XX)
1+
# v0.2.6 (2018-XX-XX)
2+
3+
* Fix compilation with `#[deny(warnings)]` with the `!` type (https://github.com/rust-lang/rust/pull/49039#issuecomment-376420816) by [@TeXitoi](https://github.com/TeXitoi)
24

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

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ readme = "README.md"
1212

1313
[features]
1414
default = ["clap/default"]
15-
testing_only_proc_macro2_nightly = ["structopt-derive/testing_only_proc_macro2_nightly"]
15+
nightly = ["structopt-derive/nightly"]
1616

1717
[badges]
1818
travis-ci = { repository = "TeXitoi/structopt" }

structopt-derive/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ quote = "0.4"
1818
proc-macro2 = "0.2"
1919

2020
[features]
21-
testing_only_proc_macro2_nightly = ["proc-macro2/nightly"]
21+
nightly = ["proc-macro2/nightly"]
2222

2323
[lib]
2424
proc-macro = true

structopt-derive/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ fn impl_structopt_for_struct(
381381
#from_clap
382382
}
383383

384-
#[allow(dead_code)]
384+
#[allow(dead_code, unreachable_code)]
385385
#[doc(hidden)]
386386
impl #name {
387387
#augment_clap
@@ -406,7 +406,7 @@ fn impl_structopt_for_enum(
406406
#from_clap
407407
}
408408

409-
#[allow(unused_variables, dead_code)]
409+
#[allow(unused_variables, dead_code, unreachable_code)]
410410
#[doc(hidden)]
411411
impl #name {
412412
#augment_clap

tests/deny-warnings.rs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2018 Guillaume Pinot (@TeXitoi) <[email protected]>
2+
//
3+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6+
// option. This file may not be copied, modified, or distributed
7+
// except according to those terms.
8+
9+
#![deny(warnings)]
10+
#![cfg(feature = "nightly")]// TODO: remove that when never is stable
11+
12+
#[macro_use]
13+
extern crate structopt;
14+
15+
use structopt::StructOpt;
16+
17+
fn try_str(s: &str) -> Result<String, !> {
18+
Ok(s.into())
19+
}
20+
21+
#[test]
22+
fn warning_never_struct() {
23+
#[derive(Debug, PartialEq, StructOpt)]
24+
struct Opt {
25+
#[structopt(parse(try_from_str = "try_str"))]
26+
s: String,
27+
}
28+
assert_eq!(Opt { s: "foo".to_string() },
29+
Opt::from_iter(&["test", "foo"]));
30+
31+
}
32+
33+
#[test]
34+
fn warning_never_enum() {
35+
#[derive(Debug, PartialEq, StructOpt)]
36+
enum Opt {
37+
Foo {
38+
#[structopt(parse(try_from_str = "try_str"))]
39+
s: String,
40+
}
41+
}
42+
assert_eq!(Opt::Foo { s: "foo".to_string() },
43+
Opt::from_iter(&["test", "Foo", "foo"]));
44+
45+
}
46+

0 commit comments

Comments
 (0)