From 6ceb865c9533dfef948e414a94f5fc48a2d978fa Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 6 May 2022 14:15:28 -0500 Subject: [PATCH] fix(assert): Detect conflicting arguments (unstable) Fixes #3660 --- src/build/debug_asserts.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/build/debug_asserts.rs b/src/build/debug_asserts.rs index cf27de12230..76bc0a96f09 100644 --- a/src/build/debug_asserts.rs +++ b/src/build/debug_asserts.rs @@ -155,6 +155,14 @@ pub(crate) fn assert_app(cmd: &Command) { } for req in &arg.r_ifs { + #[cfg(feature = "unstable-v4")] + { + assert!( + !arg.is_required_set(), + "Argument {}: `required` conflicts with `required_if_eq*`", + arg.name + ); + } assert!( cmd.id_exists(&req.0), "Command {}: Argument or group '{:?}' specified in 'required_if_eq*' for '{}' does not exist", @@ -165,6 +173,14 @@ pub(crate) fn assert_app(cmd: &Command) { } for req in &arg.r_ifs_all { + #[cfg(feature = "unstable-v4")] + { + assert!( + !arg.is_required_set(), + "Argument {}: `required` conflicts with `required_if_eq_all`", + arg.name + ); + } assert!( cmd.id_exists(&req.0), "Command {}: Argument or group '{:?}' specified in 'required_if_eq_all' for '{}' does not exist", @@ -175,6 +191,14 @@ pub(crate) fn assert_app(cmd: &Command) { } for req in &arg.r_unless { + #[cfg(feature = "unstable-v4")] + { + assert!( + !arg.is_required_set(), + "Argument {}: `required` conflicts with `required_unless*`", + arg.name + ); + } assert!( cmd.id_exists(req), "Command {}: Argument or group '{:?}' specified in 'required_unless*' for '{}' does not exist", @@ -185,6 +209,14 @@ pub(crate) fn assert_app(cmd: &Command) { } for req in &arg.r_unless_all { + #[cfg(feature = "unstable-v4")] + { + assert!( + !arg.is_required_set(), + "Argument {}: `required` conflicts with `required_unless*`", + arg.name + ); + } assert!( cmd.id_exists(req), "Command {}: Argument or group '{:?}' specified in 'required_unless*' for '{}' does not exist",