diff --git a/clap_derive/src/attrs.rs b/clap_derive/src/attrs.rs index 2561294f..b40da9a1 100644 --- a/clap_derive/src/attrs.rs +++ b/clap_derive/src/attrs.rs @@ -481,12 +481,15 @@ impl Attrs { "parse attribute is not allowed for flattened entry" ); } - if res.has_explicit_methods() || res.has_doc_methods() { + if res.has_explicit_methods() { abort!( res.kind.span(), - "methods and doc comments are not allowed for flattened entry" + "methods are not allowed for flattened entry" ); } + + // ignore doc comments + res.doc_comment = vec![]; } Kind::ExternalSubcommand => { @@ -695,14 +698,6 @@ impl Attrs { .iter() .any(|m| m.name != "about" && m.name != "long_about") } - - pub fn has_doc_methods(&self) -> bool { - !self.doc_comment.is_empty() - || self - .methods - .iter() - .any(|m| m.name == "about" || m.name == "long_about") - } } /// replace all `:` with `, ` when not inside the `<>` diff --git a/clap_derive/tests/flatten.rs b/clap_derive/tests/flatten.rs index 77f99add..702f1ae9 100644 --- a/clap_derive/tests/flatten.rs +++ b/clap_derive/tests/flatten.rs @@ -132,3 +132,22 @@ fn merge_subcommands_with_flatten() { Opt::parse_from(&["test", "command2", "43"]) ); } + +#[test] +fn flatten_with_doc_comment() { + #[derive(Clap, Debug)] + struct DaemonOpts { + #[clap(short)] + user: String, + #[clap(short)] + group: String, + } + + #[derive(Clap, Debug)] + #[clap(name = "basic")] + struct Opt { + /// A very important doc comment I just can't leave out! + #[clap(flatten)] + opts: DaemonOpts, + } +} diff --git a/clap_derive/tests/ui/flatten_and_doc.rs b/clap_derive/tests/ui/flatten_and_doc.rs deleted file mode 100644 index dea35c23..00000000 --- a/clap_derive/tests/ui/flatten_and_doc.rs +++ /dev/null @@ -1,30 +0,0 @@ -// 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. - -use clap::Clap; - -#[derive(Clap, Debug)] -struct DaemonOpts { - #[clap(short)] - user: String, - #[clap(short)] - group: String, -} - -#[derive(Clap, Debug)] -#[clap(name = "basic")] -struct Opt { - /// Opts. - #[clap(flatten)] - opts: DaemonOpts, -} - -fn main() { - let opt = Opt::parse(); - println!("{:?}", opt); -} diff --git a/clap_derive/tests/ui/flatten_and_doc.stderr b/clap_derive/tests/ui/flatten_and_doc.stderr deleted file mode 100644 index fec9a79b..00000000 --- a/clap_derive/tests/ui/flatten_and_doc.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: methods and doc comments are not allowed for flattened entry - --> $DIR/flatten_and_doc.rs:23:12 - | -23 | #[clap(flatten)] - | ^^^^^^^ diff --git a/clap_derive/tests/ui/flatten_and_methods.stderr b/clap_derive/tests/ui/flatten_and_methods.stderr index 0b86ceed..772f2df8 100644 --- a/clap_derive/tests/ui/flatten_and_methods.stderr +++ b/clap_derive/tests/ui/flatten_and_methods.stderr @@ -1,4 +1,4 @@ -error: methods and doc comments are not allowed for flattened entry +error: methods are not allowed for flattened entry --> $DIR/flatten_and_methods.rs:22:19 | 22 | #[clap(short, flatten)]