Skip to content

Commit

Permalink
Disallow default_value and required for Option (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops authored and TeXitoi committed Apr 6, 2018
1 parent 5b883fc commit 6a39e59
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v0.2.7 (unreleased)

* Fail compilation when using `default_value` and `required` with `Option` ([#88](https://github.com/TeXitoi/structopt/pull/88)) by [@Kerollmops](https://github.com/Kerollmops)

# v0.2.6 (2018-03-31)

* Fail compilation when using `default_value` or `required` with `bool` ([#80](https://github.com/TeXitoi/structopt/issues/80)) by [@TeXitoi](https://github.com/TeXitoi)
Expand Down
25 changes: 18 additions & 7 deletions structopt-derive/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,24 @@ impl Attrs {
}
}

if res.ty == Ty::Bool {
if res.has_method("default_value") {
panic!("default_value is meaningless for bool")
}
if res.has_method("required") {
panic!("required is meaningless for bool")
}
match res.ty {
Ty::Bool => {
if res.has_method("default_value") {
panic!("default_value is meaningless for bool")
}
if res.has_method("required") {
panic!("required is meaningless for bool")
}
},
Ty::Option => {
if res.has_method("default_value") {
panic!("default_value is meaningless for Option")
}
if res.has_method("required") {
panic!("required is meaningless for Option")
}
},
_ => (),
}

res
Expand Down

0 comments on commit 6a39e59

Please sign in to comment.