Skip to content

Commit 9619a2e

Browse files
committed
Avoid unnecessary cloning in Parser::get_ident_from_generic_arg.
1 parent 3e04fed commit 9619a2e

File tree

1 file changed

+5
-9
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+5
-9
lines changed

compiler/rustc_parse/src/parser/path.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ impl<'a> Parser<'a> {
527527
Ok(ident_gen_args) => ident_gen_args,
528528
Err(()) => return Ok(Some(AngleBracketedArg::Arg(arg))),
529529
};
530-
if binder.is_some() {
530+
if binder {
531531
// FIXME(compiler-errors): this could be improved by suggesting lifting
532532
// this up to the trait, at least before this becomes real syntax.
533533
// e.g. `Trait<for<'a> Assoc = Ty>` -> `for<'a> Trait<Assoc = Ty>`
@@ -720,28 +720,24 @@ impl<'a> Parser<'a> {
720720

721721
/// Given a arg inside of generics, we try to destructure it as if it were the LHS in
722722
/// `LHS = ...`, i.e. an associated type binding.
723-
/// This returns (optionally, if they are present) any `for<'a, 'b>` binder args, the
723+
/// This returns a bool indicating if there are any `for<'a, 'b>` binder args, the
724724
/// identifier, and any GAT arguments.
725725
fn get_ident_from_generic_arg(
726726
&self,
727727
gen_arg: &GenericArg,
728-
) -> Result<(Option<Vec<ast::GenericParam>>, Ident, Option<GenericArgs>), ()> {
728+
) -> Result<(bool, Ident, Option<GenericArgs>), ()> {
729729
if let GenericArg::Type(ty) = gen_arg {
730730
if let ast::TyKind::Path(qself, path) = &ty.kind
731731
&& qself.is_none()
732732
&& let [seg] = path.segments.as_slice()
733733
{
734-
return Ok((None, seg.ident, seg.args.as_deref().cloned()));
734+
return Ok((false, seg.ident, seg.args.as_deref().cloned()));
735735
} else if let ast::TyKind::TraitObject(bounds, ast::TraitObjectSyntax::None) = &ty.kind
736736
&& let [ast::GenericBound::Trait(trait_ref, ast::TraitBoundModifier::None)] =
737737
bounds.as_slice()
738738
&& let [seg] = trait_ref.trait_ref.path.segments.as_slice()
739739
{
740-
return Ok((
741-
Some(trait_ref.bound_generic_params.clone()),
742-
seg.ident,
743-
seg.args.as_deref().cloned(),
744-
));
740+
return Ok((true, seg.ident, seg.args.as_deref().cloned()));
745741
}
746742
}
747743
Err(())

0 commit comments

Comments
 (0)