Skip to content

Commit ddd5cb2

Browse files
committed
more helpful error messages for repeat or flatten in wrong position
1 parent 80e959f commit ddd5cb2

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-0
lines changed

conf_derive/src/proc_macro_options/field_item/parameter_item.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ impl ParameterItem {
302302
set_once(&path, &mut result.test, Some(ParameterTestItem::new(meta)?))
303303
} else if path.is_ident("pos") {
304304
set_once(&path, &mut result.is_positional, Some(path.span()))
305+
} else if path.is_ident("repeat") {
306+
Err(meta.error("`repeat` must be the first conf attribute on this field"))
307+
} else if path.is_ident("flatten") {
308+
Err(meta.error("`flatten` must be the first conf attribute on this field"))
305309
} else {
306310
Err(meta.error("unrecognized conf parameter option"))
307311
}

tests/ui/flatten_not_first.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use conf::Conf;
2+
3+
#[derive(Conf, Debug)]
4+
pub struct Inner {
5+
#[arg(long)]
6+
pub value: String,
7+
}
8+
9+
#[derive(Conf, Debug)]
10+
pub struct BadConfig {
11+
#[conf(long, flatten)]
12+
pub inner: Inner,
13+
}
14+
15+
fn main() {}

tests/ui/flatten_not_first.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: `flatten` must be the first conf attribute on this field
2+
--> tests/ui/flatten_not_first.rs:11:18
3+
|
4+
11 | #[conf(long, flatten)]
5+
| ^^^^^^^

tests/ui/repeat_not_first.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use conf::Conf;
2+
3+
#[derive(Conf, Debug)]
4+
pub struct BadConfig {
5+
#[conf(long, repeat)]
6+
pub values: Vec<String>,
7+
}
8+
9+
fn main() {}

tests/ui/repeat_not_first.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: `repeat` must be the first conf attribute on this field
2+
--> tests/ui/repeat_not_first.rs:5:18
3+
|
4+
5 | #[conf(long, repeat)]
5+
| ^^^^^^

0 commit comments

Comments
 (0)