GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(derive): reject optional positional values · jdx/usage@2b1fb98

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • derive/src
    • model.rs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎derive/src/model.rs‎

Copy file name to clipboardExpand all lines: derive/src/model.rs
+21-1Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,14 @@ impl Field {
13911391
return Err(syn::Error::new(
13921392
span,
13931393
"a field is either a flag or a positional argument, not both: it has \
1394-
`long` or `short` as well as `arg`",
1394+
`long` or `short` as well as `arg`",
1395+
));
1396+
}
1397+
if value_optional && !is_flag {
1398+
return Err(syn::Error::new(
1399+
span,
1400+
"`value_optional` describes a flag whose value may be left off, so the field \
1401+
needs a `long` or a `short`",
13951402
));
13961403
}
13971404
if !is_flag && count {
@@ -2570,6 +2577,19 @@ mod tests {
25702577
);
25712578
}
25722579

2580+
#[test]
2581+
fn value_optional_is_refused_on_a_positional() {
2582+
let err = rejection(
2583+
r#"
2584+
struct Ex {
2585+
#[usage(arg, value_optional)]
2586+
out: Option<String>,
2587+
}
2588+
"#,
2589+
);
2590+
assert!(err.contains("needs a `long` or a `short`"), "{err}");
2591+
}
2592+
25732593
#[test]
25742594
fn a_selector_naming_nothing_is_a_compile_error() {
25752595
let err = rejection(

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.