diff options
Diffstat (limited to 'vendor/clap_builder/src/parser')
-rw-r--r-- | vendor/clap_builder/src/parser/arg_matcher.rs | 6 | ||||
-rw-r--r-- | vendor/clap_builder/src/parser/error.rs | 6 | ||||
-rw-r--r-- | vendor/clap_builder/src/parser/matches/any_value.rs | 112 | ||||
-rw-r--r-- | vendor/clap_builder/src/parser/matches/arg_matches.rs | 4 | ||||
-rw-r--r-- | vendor/clap_builder/src/parser/matches/matched_arg.rs | 4 | ||||
-rw-r--r-- | vendor/clap_builder/src/parser/matches/mod.rs | 3 | ||||
-rw-r--r-- | vendor/clap_builder/src/parser/mod.rs | 2 | ||||
-rw-r--r-- | vendor/clap_builder/src/parser/parser.rs | 27 | ||||
-rw-r--r-- | vendor/clap_builder/src/parser/validator.rs | 10 |
9 files changed, 34 insertions, 140 deletions
diff --git a/vendor/clap_builder/src/parser/arg_matcher.rs b/vendor/clap_builder/src/parser/arg_matcher.rs index d584689cd..124d46f5f 100644 --- a/vendor/clap_builder/src/parser/arg_matcher.rs +++ b/vendor/clap_builder/src/parser/arg_matcher.rs @@ -5,10 +5,10 @@ use std::ops::Deref; // Internal use crate::builder::{Arg, ArgPredicate, Command}; -use crate::parser::AnyValue; use crate::parser::Identifier; use crate::parser::PendingArg; use crate::parser::{ArgMatches, MatchedArg, SubCommand, ValueSource}; +use crate::util::AnyValue; use crate::util::FlatMap; use crate::util::Id; use crate::INTERNAL_ERROR_MSG; @@ -130,7 +130,9 @@ impl ArgMatcher { } pub(crate) fn check_explicit(&self, arg: &Id, predicate: &ArgPredicate) -> bool { - self.get(arg).map_or(false, |a| a.check_explicit(predicate)) + self.get(arg) + .map(|a| a.check_explicit(predicate)) + .unwrap_or_default() } pub(crate) fn start_custom_arg(&mut self, arg: &Arg, source: ValueSource) { diff --git a/vendor/clap_builder/src/parser/error.rs b/vendor/clap_builder/src/parser/error.rs index 66b2bc79e..77b0bb0fc 100644 --- a/vendor/clap_builder/src/parser/error.rs +++ b/vendor/clap_builder/src/parser/error.rs @@ -1,3 +1,5 @@ +use crate::util::AnyValueId; + /// Violation of [`ArgMatches`][crate::ArgMatches] assumptions #[derive(Clone, Debug)] #[allow(missing_copy_implementations)] // We might add non-Copy types in the future @@ -7,9 +9,9 @@ pub enum MatchesError { #[non_exhaustive] Downcast { /// Type for value stored in [`ArgMatches`][crate::ArgMatches] - actual: super::AnyValueId, + actual: AnyValueId, /// The target type to downcast to - expected: super::AnyValueId, + expected: AnyValueId, }, /// Argument not defined in [`Command`][crate::Command] #[non_exhaustive] diff --git a/vendor/clap_builder/src/parser/matches/any_value.rs b/vendor/clap_builder/src/parser/matches/any_value.rs deleted file mode 100644 index dc7a3e953..000000000 --- a/vendor/clap_builder/src/parser/matches/any_value.rs +++ /dev/null @@ -1,112 +0,0 @@ -#[derive(Clone)] -pub(crate) struct AnyValue { - inner: std::sync::Arc<dyn std::any::Any + Send + Sync + 'static>, - // While we can extract `TypeId` from `inner`, the debug repr is of a number, so let's track - // the type_name in debug builds. - id: AnyValueId, -} - -impl AnyValue { - pub(crate) fn new<V: std::any::Any + Clone + Send + Sync + 'static>(inner: V) -> Self { - let id = AnyValueId::of::<V>(); - let inner = std::sync::Arc::new(inner); - Self { inner, id } - } - - pub(crate) fn downcast_ref<T: std::any::Any + Clone + Send + Sync + 'static>( - &self, - ) -> Option<&T> { - self.inner.downcast_ref::<T>() - } - - pub(crate) fn downcast_into<T: std::any::Any + Clone + Send + Sync>(self) -> Result<T, Self> { - let id = self.id; - let value = - ok!(std::sync::Arc::downcast::<T>(self.inner).map_err(|inner| Self { inner, id })); - let value = std::sync::Arc::try_unwrap(value).unwrap_or_else(|arc| (*arc).clone()); - Ok(value) - } - - pub(crate) fn type_id(&self) -> AnyValueId { - self.id - } -} - -impl std::fmt::Debug for AnyValue { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { - f.debug_struct("AnyValue").field("inner", &self.id).finish() - } -} - -#[derive(Copy, Clone)] -pub struct AnyValueId { - type_id: std::any::TypeId, - #[cfg(debug_assertions)] - type_name: &'static str, -} - -impl AnyValueId { - pub(crate) fn of<A: ?Sized + 'static>() -> Self { - Self { - type_id: std::any::TypeId::of::<A>(), - #[cfg(debug_assertions)] - type_name: std::any::type_name::<A>(), - } - } -} - -impl PartialEq for AnyValueId { - fn eq(&self, other: &Self) -> bool { - self.type_id == other.type_id - } -} - -impl Eq for AnyValueId {} - -impl PartialOrd for AnyValueId { - fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { - self.type_id.partial_cmp(&other.type_id) - } -} - -impl Ord for AnyValueId { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { - self.type_id.cmp(&other.type_id) - } -} - -impl std::hash::Hash for AnyValueId { - fn hash<H: std::hash::Hasher>(&self, state: &mut H) { - self.type_id.hash(state); - } -} - -impl std::fmt::Debug for AnyValueId { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { - #[cfg(not(debug_assertions))] - { - self.type_id.fmt(f) - } - #[cfg(debug_assertions)] - { - f.debug_struct(self.type_name).finish() - } - } -} - -impl<'a, A: ?Sized + 'static> From<&'a A> for AnyValueId { - fn from(_: &'a A) -> Self { - Self::of::<A>() - } -} - -#[cfg(test)] -mod test { - #[test] - #[cfg(debug_assertions)] - fn debug_impl() { - use super::*; - - assert_eq!(format!("{:?}", AnyValue::new(5)), "AnyValue { inner: i32 }"); - } -} diff --git a/vendor/clap_builder/src/parser/matches/arg_matches.rs b/vendor/clap_builder/src/parser/matches/arg_matches.rs index 306ce9ed2..da8a34783 100644 --- a/vendor/clap_builder/src/parser/matches/arg_matches.rs +++ b/vendor/clap_builder/src/parser/matches/arg_matches.rs @@ -8,11 +8,11 @@ use std::slice::Iter; // Internal #[cfg(debug_assertions)] use crate::builder::Str; -use crate::parser::AnyValue; -use crate::parser::AnyValueId; use crate::parser::MatchedArg; use crate::parser::MatchesError; use crate::parser::ValueSource; +use crate::util::AnyValue; +use crate::util::AnyValueId; use crate::util::FlatMap; use crate::util::Id; use crate::INTERNAL_ERROR_MSG; diff --git a/vendor/clap_builder/src/parser/matches/matched_arg.rs b/vendor/clap_builder/src/parser/matches/matched_arg.rs index 901990cfb..24df8b160 100644 --- a/vendor/clap_builder/src/parser/matches/matched_arg.rs +++ b/vendor/clap_builder/src/parser/matches/matched_arg.rs @@ -6,10 +6,10 @@ use std::{ }; use crate::builder::ArgPredicate; -use crate::parser::AnyValue; -use crate::parser::AnyValueId; use crate::parser::ValueSource; use crate::util::eq_ignore_case; +use crate::util::AnyValue; +use crate::util::AnyValueId; use crate::INTERNAL_ERROR_MSG; #[derive(Debug, Clone)] diff --git a/vendor/clap_builder/src/parser/matches/mod.rs b/vendor/clap_builder/src/parser/matches/mod.rs index 0e3474fb3..eb865853c 100644 --- a/vendor/clap_builder/src/parser/matches/mod.rs +++ b/vendor/clap_builder/src/parser/matches/mod.rs @@ -1,9 +1,7 @@ -mod any_value; mod arg_matches; mod matched_arg; mod value_source; -pub use any_value::AnyValueId; pub use arg_matches::IdsRef; pub use arg_matches::RawValues; pub use arg_matches::Values; @@ -11,6 +9,5 @@ pub use arg_matches::ValuesRef; pub use arg_matches::{ArgMatches, Indices}; pub use value_source::ValueSource; -pub(crate) use any_value::AnyValue; pub(crate) use arg_matches::SubCommand; pub(crate) use matched_arg::MatchedArg; diff --git a/vendor/clap_builder/src/parser/mod.rs b/vendor/clap_builder/src/parser/mod.rs index c99e74f95..3e73544d5 100644 --- a/vendor/clap_builder/src/parser/mod.rs +++ b/vendor/clap_builder/src/parser/mod.rs @@ -10,8 +10,6 @@ mod validator; pub(crate) mod features; pub(crate) use self::arg_matcher::ArgMatcher; -pub(crate) use self::matches::AnyValue; -pub(crate) use self::matches::AnyValueId; pub(crate) use self::matches::{MatchedArg, SubCommand}; pub(crate) use self::parser::Identifier; pub(crate) use self::parser::PendingArg; diff --git a/vendor/clap_builder/src/parser/parser.rs b/vendor/clap_builder/src/parser/parser.rs index c29100485..723e1cd69 100644 --- a/vendor/clap_builder/src/parser/parser.rs +++ b/vendor/clap_builder/src/parser/parser.rs @@ -13,9 +13,9 @@ use crate::error::Result as ClapResult; use crate::mkeymap::KeyType; use crate::output::Usage; use crate::parser::features::suggestions; -use crate::parser::AnyValue; use crate::parser::{ArgMatcher, SubCommand}; use crate::parser::{Validator, ValueSource}; +use crate::util::AnyValue; use crate::util::Id; use crate::ArgAction; use crate::INTERNAL_ERROR_MSG; @@ -305,7 +305,8 @@ impl<'cmd> Parser<'cmd> { .cmd .get_positionals() .last() - .map_or(false, |p_name| !p_name.is_last_set()); + .map(|p_name| !p_name.is_last_set()) + .unwrap_or_default(); let missing_pos = self.cmd.is_allow_missing_positional_set() && is_second_to_last @@ -779,9 +780,10 @@ impl<'cmd> Parser<'cmd> { matcher.check_explicit(arg_id, &crate::builder::ArgPredicate::IsPresent) }) .filter(|&n| { - self.cmd.find(n).map_or(true, |a| { - !(a.is_hide_set() || required.contains(a.get_id())) - }) + self.cmd + .find(n) + .map(|a| !(a.is_hide_set() || required.contains(a.get_id()))) + .unwrap_or(true) }) .cloned() .collect(); @@ -810,9 +812,8 @@ impl<'cmd> Parser<'cmd> { .cmd .get_keymap() .get(&pos_counter) - .map_or(false, |arg| { - arg.is_allow_hyphen_values_set() && !arg.is_last_set() - }) + .map(|arg| arg.is_allow_hyphen_values_set() && !arg.is_last_set()) + .unwrap_or_default() { debug!( "Parser::parse_long_args: positional at {} allows hyphens", @@ -847,7 +848,8 @@ impl<'cmd> Parser<'cmd> { .cmd .get_keymap() .get(&pos_counter) - .map_or(false, |arg| arg.is_allow_negative_numbers_set()) + .map(|arg| arg.is_allow_negative_numbers_set()) + .unwrap_or_default() && short_arg.is_number() { debug!("Parser::parse_short_arg: negative number"); @@ -856,9 +858,8 @@ impl<'cmd> Parser<'cmd> { .cmd .get_keymap() .get(&pos_counter) - .map_or(false, |arg| { - arg.is_allow_hyphen_values_set() && !arg.is_last_set() - }) + .map(|arg| arg.is_allow_hyphen_values_set() && !arg.is_last_set()) + .unwrap_or_default() && short_arg .clone() .any(|c| !c.map(|c| self.cmd.contains_short(c)).unwrap_or_default()) @@ -1536,7 +1537,7 @@ impl<'cmd> Parser<'cmd> { .filter(|arg_id| { matcher.check_explicit(arg_id, &crate::builder::ArgPredicate::IsPresent) }) - .filter(|n| self.cmd.find(n).map_or(true, |a| !a.is_hide_set())) + .filter(|n| self.cmd.find(n).map(|a| !a.is_hide_set()).unwrap_or(true)) .cloned() .collect(); diff --git a/vendor/clap_builder/src/parser/validator.rs b/vendor/clap_builder/src/parser/validator.rs index 49d28a34f..5c3d34643 100644 --- a/vendor/clap_builder/src/parser/validator.rs +++ b/vendor/clap_builder/src/parser/validator.rs @@ -199,7 +199,10 @@ impl<'cmd> Validator<'cmd> { .map(|(n, _)| n) .filter(|n| { // Filter out the args we don't want to specify. - self.cmd.find(n).map_or(false, |a| !a.is_hide_set()) + self.cmd + .find(n) + .map(|a| !a.is_hide_set()) + .unwrap_or_default() }) .filter(|key| !conflicting_keys.contains(key)) .cloned() @@ -445,7 +448,10 @@ impl<'cmd> Validator<'cmd> { .map(|(n, _)| n) .filter(|n| { // Filter out the args we don't want to specify. - self.cmd.find(n).map_or(false, |a| !a.is_hide_set()) + self.cmd + .find(n) + .map(|a| !a.is_hide_set()) + .unwrap_or_default() }) .cloned() .chain(raw_req_args) |