From 903d4ff7d01362da3afc32475dc3a049d8059e42 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Wed, 8 Dec 2021 13:39:17 -0500 Subject: [PATCH] Make sure we don't warn when fields are used https://github.com/rust-lang/rust/pull/85200 changed rust to emit more unused warnings if fields in a struct are ultimately never read. This adds a test to make sure that we don't experience these warnings. --- argh/tests/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/argh/tests/lib.rs b/argh/tests/lib.rs index 5c4ace6..fe8c858 100644 --- a/argh/tests/lib.rs +++ b/argh/tests/lib.rs @@ -1288,3 +1288,21 @@ fn redact_arg_values_produces_errors_with_bad_arguments() { }), ); } + +#[test] +fn redact_arg_values_does_not_warn_if_used() { + #[forbid(unused)] + #[derive(FromArgs, Debug)] + /// Short description + struct Cmd { + #[argh(positional)] + /// speed of cmd + speed: u8, + } + + let cmd = Cmd::from_args(&["program-name"], &["5"]).unwrap(); + assert_eq!(cmd.speed, 5); + + let actual = Cmd::redact_arg_values(&["program-name"], &["5"]).unwrap(); + assert_eq!(actual, &["program-name", "speed"]); +}