From 8869dbc2a096c03414a2b872465ca2b0bbe65bbc Mon Sep 17 00:00:00 2001 From: klensy Date: Sun, 12 Dec 2021 20:16:18 +0300 Subject: [PATCH] don't alloc Path and mutate it inplace --- src/librustdoc/clean/auto_trait.rs | 2 +- src/librustdoc/clean/utils.rs | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 7b66ff7d41136..09692d27e8fbe 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -505,7 +505,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { .and_then(|trait_| { ty_to_traits .get(&ty) - .map(|bounds| bounds.contains(&strip_path_generics(trait_.clone()))) + .map(|bounds| bounds.contains(&strip_path_generics(trait_))) }) .unwrap_or(false) { diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 19b309d6a30c8..7f7be246367aa 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -141,17 +141,12 @@ pub(super) fn external_path( } /// Remove the generic arguments from a path. -crate fn strip_path_generics(path: Path) -> Path { - let segments = path - .segments - .iter() - .map(|s| PathSegment { - name: s.name, - args: GenericArgs::AngleBracketed { args: vec![], bindings: vec![] }, - }) - .collect(); +crate fn strip_path_generics(mut path: Path) -> Path { + for ps in path.segments.iter_mut() { + ps.args = GenericArgs::AngleBracketed { args: vec![], bindings: vec![] } + } - Path { res: path.res, segments } + path } crate fn qpath_to_string(p: &hir::QPath<'_>) -> String {