Skip to content

Commit

Permalink
Merge pull request #5468 from klensy/clone-me
Browse files Browse the repository at this point in the history
chore(derive): remove useless clones
  • Loading branch information
epage committed Apr 22, 2024
2 parents 0cd10d1 + 1a35888 commit 5ba6714
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions clap_derive/src/item.rs
Expand Up @@ -360,7 +360,7 @@ impl Item {
.ty()
.cloned()
.unwrap_or_else(|| Sp::new(Ty::Other, self.kind.span()));
let kind = Sp::new(Kind::FromGlobal(ty), attr.name.clone().span());
let kind = Sp::new(Kind::FromGlobal(ty), attr.name.span());
Some(kind)
}
Some(MagicAttrName::Subcommand) if attr.value.is_none() => {
Expand All @@ -373,15 +373,15 @@ impl Item {
.ty()
.cloned()
.unwrap_or_else(|| Sp::new(Ty::Other, self.kind.span()));
let kind = Sp::new(Kind::Subcommand(ty), attr.name.clone().span());
let kind = Sp::new(Kind::Subcommand(ty), attr.name.span());
Some(kind)
}
Some(MagicAttrName::ExternalSubcommand) if attr.value.is_none() => {
if attr.value.is_some() {
let expr = attr.value_or_abort()?;
abort!(expr, "attribute `{}` does not accept a value", attr.name);
}
let kind = Sp::new(Kind::ExternalSubcommand, attr.name.clone().span());
let kind = Sp::new(Kind::ExternalSubcommand, attr.name.span());
Some(kind)
}
Some(MagicAttrName::Flatten) if attr.value.is_none() => {
Expand All @@ -394,15 +394,12 @@ impl Item {
.ty()
.cloned()
.unwrap_or_else(|| Sp::new(Ty::Other, self.kind.span()));
let kind = Sp::new(Kind::Flatten(ty), attr.name.clone().span());
let kind = Sp::new(Kind::Flatten(ty), attr.name.span());
Some(kind)
}
Some(MagicAttrName::Skip) if actual_attr_kind != AttrKind::Group => {
let expr = attr.value.clone();
let kind = Sp::new(
Kind::Skip(expr, self.kind.attr_kind()),
attr.name.clone().span(),
);
let kind = Sp::new(Kind::Skip(expr, self.kind.attr_kind()), attr.name.span());
Some(kind)
}
_ => None,
Expand Down Expand Up @@ -574,7 +571,7 @@ impl Item {
.iter()
.any(|a| a.magic == Some(MagicAttrName::ValueEnum))
{
quote_spanned!(attr.name.clone().span()=> {
quote_spanned!(attr.name.span()=> {
static DEFAULT_VALUE: ::std::sync::OnceLock<String> = ::std::sync::OnceLock::new();
let s = DEFAULT_VALUE.get_or_init(|| {
let val: #ty = #val;
Expand All @@ -584,7 +581,7 @@ impl Item {
s
})
} else {
quote_spanned!(attr.name.clone().span()=> {
quote_spanned!(attr.name.span()=> {
static DEFAULT_VALUE: ::std::sync::OnceLock<String> = ::std::sync::OnceLock::new();
let s = DEFAULT_VALUE.get_or_init(|| {
let val: #ty = #val;
Expand All @@ -595,7 +592,7 @@ impl Item {
})
};

let raw_ident = Ident::new("default_value", attr.name.clone().span());
let raw_ident = Ident::new("default_value", attr.name.span());
self.methods.push(Method::new(raw_ident, val));
}

Expand Down Expand Up @@ -632,7 +629,7 @@ impl Item {
.iter()
.any(|a| a.magic == Some(MagicAttrName::ValueEnum))
{
quote_spanned!(attr.name.clone().span()=> {
quote_spanned!(attr.name.span()=> {
{
fn iter_to_vals<T>(iterable: impl IntoIterator<Item = T>) -> impl Iterator<Item=String>
where
Expand All @@ -653,7 +650,7 @@ impl Item {
}
})
} else {
quote_spanned!(attr.name.clone().span()=> {
quote_spanned!(attr.name.span()=> {
{
fn iter_to_vals<T>(iterable: impl IntoIterator<Item = T>) -> impl Iterator<Item=String>
where
Expand All @@ -672,7 +669,7 @@ impl Item {
};

self.methods.push(Method::new(
Ident::new("default_values", attr.name.clone().span()),
Ident::new("default_values", attr.name.span()),
val,
));
}
Expand Down Expand Up @@ -702,7 +699,7 @@ impl Item {
.iter()
.any(|a| a.magic == Some(MagicAttrName::ValueEnum))
{
quote_spanned!(attr.name.clone().span()=> {
quote_spanned!(attr.name.span()=> {
static DEFAULT_VALUE: ::std::sync::OnceLock<String> = ::std::sync::OnceLock::new();
let s = DEFAULT_VALUE.get_or_init(|| {
let val: #ty = #val;
Expand All @@ -712,7 +709,7 @@ impl Item {
s
})
} else {
quote_spanned!(attr.name.clone().span()=> {
quote_spanned!(attr.name.span()=> {
static DEFAULT_VALUE: ::std::sync::OnceLock<::std::ffi::OsString> = ::std::sync::OnceLock::new();
let s = DEFAULT_VALUE.get_or_init(|| {
let val: #ty = #val;
Expand All @@ -723,7 +720,7 @@ impl Item {
})
};

let raw_ident = Ident::new("default_value", attr.name.clone().span());
let raw_ident = Ident::new("default_value", attr.name.span());
self.methods.push(Method::new(raw_ident, val));
}

Expand Down Expand Up @@ -760,7 +757,7 @@ impl Item {
.iter()
.any(|a| a.magic == Some(MagicAttrName::ValueEnum))
{
quote_spanned!(attr.name.clone().span()=> {
quote_spanned!(attr.name.span()=> {
{
fn iter_to_vals<T>(iterable: impl IntoIterator<Item = T>) -> impl Iterator<Item=::std::ffi::OsString>
where
Expand All @@ -781,7 +778,7 @@ impl Item {
}
})
} else {
quote_spanned!(attr.name.clone().span()=> {
quote_spanned!(attr.name.span()=> {
{
fn iter_to_vals<T>(iterable: impl IntoIterator<Item = T>) -> impl Iterator<Item=::std::ffi::OsString>
where
Expand All @@ -800,7 +797,7 @@ impl Item {
};

self.methods.push(Method::new(
Ident::new("default_values", attr.name.clone().span()),
Ident::new("default_values", attr.name.span()),
val,
));
}
Expand Down

0 comments on commit 5ba6714

Please sign in to comment.