-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2805 from epage/validate_default
fix(derive): Type check `default_value_t`
- Loading branch information
Showing
3 changed files
with
41 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// 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. | ||
|
||
use clap::Clap; | ||
|
||
#[derive(Clap, Debug)] | ||
#[clap(name = "basic")] | ||
struct Opt { | ||
#[clap(default_value_t = -10)] | ||
value: u32, | ||
} | ||
|
||
fn main() { | ||
let opt = Opt::parse(); | ||
println!("{:?}", opt); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
error[E0600]: cannot apply unary operator `-` to type `u32` | ||
--> $DIR/default_value_t_invalid.rs:14:30 | ||
| | ||
14 | #[clap(default_value_t = -10)] | ||
| ^^^ cannot apply unary operator `-` | ||
| | ||
= note: unsigned values cannot be negated |