don't alloc Path and mutate it inplace

This commit is contained in:
klensy 2021-12-12 20:16:18 +03:00
parent 58457bbfd3
commit 8869dbc2a0
2 changed files with 6 additions and 11 deletions

View File

@ -505,7 +505,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
.and_then(|trait_| { .and_then(|trait_| {
ty_to_traits ty_to_traits
.get(&ty) .get(&ty)
.map(|bounds| bounds.contains(&strip_path_generics(trait_.clone()))) .map(|bounds| bounds.contains(&strip_path_generics(trait_)))
}) })
.unwrap_or(false) .unwrap_or(false)
{ {

View File

@ -141,17 +141,12 @@ pub(super) fn external_path(
} }
/// Remove the generic arguments from a path. /// Remove the generic arguments from a path.
crate fn strip_path_generics(path: Path) -> Path { crate fn strip_path_generics(mut path: Path) -> Path {
let segments = path for ps in path.segments.iter_mut() {
.segments ps.args = GenericArgs::AngleBracketed { args: vec![], bindings: vec![] }
.iter() }
.map(|s| PathSegment {
name: s.name,
args: GenericArgs::AngleBracketed { args: vec![], bindings: vec![] },
})
.collect();
Path { res: path.res, segments } path
} }
crate fn qpath_to_string(p: &hir::QPath<'_>) -> String { crate fn qpath_to_string(p: &hir::QPath<'_>) -> String {