From: Noah Lev Date: Fri, 27 Aug 2021 00:36:48 +0000 (-0700) Subject: Remove unnecessary `Box` in `Type::QPath` X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=e20bb157a2b2f413c187ab33ddc626a3e69adff8;p=rust.git Remove unnecessary `Box` in `Type::QPath` --- diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index cbc010698c7..20fb91eba39 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -545,7 +545,7 @@ fn param_env_to_generics( match lhs { Type::QPath { name: left_name, ref self_type, ref trait_, .. } => { let ty = &*self_type; - let mut new_trait = *trait_.clone(); + let mut new_trait = trait_.clone(); if self.is_fn_trait(trait_) && left_name == sym::Output { ty_to_fn @@ -592,12 +592,12 @@ fn param_env_to_generics( // duplicate bound like `T: Iterator + Iterator` // on the docs page. bounds.remove(&GenericBound::TraitBound( - PolyTrait { trait_: *trait_.clone(), generic_params: Vec::new() }, + PolyTrait { trait_: trait_.clone(), generic_params: Vec::new() }, hir::TraitBoundModifier::None, )); // Avoid creating any new duplicate bounds later in the outer // loop - ty_to_traits.entry(*ty.clone()).or_default().insert(*trait_.clone()); + ty_to_traits.entry(*ty.clone()).or_default().insert(trait_.clone()); } _ => panic!("Unexpected LHS {:?} for {:?}", lhs, item_def_id), } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 3c10fadeff3..73e56a610fb 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -387,7 +387,7 @@ fn clean(&self, cx: &mut DocContext<'_>) -> Type { name: cx.tcx.associated_item(self.item_def_id).ident.name, self_def_id: self_type.def_id(), self_type: box self_type, - trait_: box trait_, + trait_, } } } @@ -1277,16 +1277,16 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type { let segments = if p.is_global() { &p.segments[1..] } else { &p.segments }; let trait_segments = &segments[..segments.len() - 1]; let trait_def = cx.tcx.associated_item(p.res.def_id()).container.id(); - let trait_path = self::Path { + let trait_ = self::Path { res: Res::Def(DefKind::Trait, trait_def), segments: trait_segments.clean(cx), }; - register_res(cx, trait_path.res); + register_res(cx, trait_.res); Type::QPath { name: p.segments.last().expect("segments were empty").ident.name, self_def_id: Some(DefId::local(qself.hir_id.owner.local_def_index)), self_type: box qself.clean(cx), - trait_: box trait_path, + trait_, } } hir::QPath::TypeRelative(ref qself, ref segment) => { @@ -1297,13 +1297,13 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type { ty::Error(_) => return Type::Infer, _ => bug!("clean: expected associated type, found `{:?}`", ty), }; - let trait_path = hir::Path { span, res, segments: &[] }.clean(cx); - register_res(cx, trait_path.res); + let trait_ = hir::Path { span, res, segments: &[] }.clean(cx); + register_res(cx, trait_.res); Type::QPath { name: segment.ident.name, self_def_id: res.opt_def_id(), self_type: box qself.clean(cx), - trait_: box trait_path, + trait_, } } hir::QPath::LangItem(..) => bug!("clean: requiring documentation of lang item"), diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index da06737394d..b57e8a0ed2a 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1408,8 +1408,7 @@ fn def_id_full(&self, cache: &Cache) -> Option { name: Symbol, self_type: Box, self_def_id: Option, - // FIXME: remove this `Box`; it's unnecessary - trait_: Box, + trait_: Path, }, // `_` diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 10320baaf93..fda540aa186 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -436,7 +436,7 @@ fn from_tcx(ty: clean::Type, tcx: TyCtxt<'_>) -> Self { }, QPath { name, self_type, trait_, .. } => { // FIXME: should `trait_` be a clean::Path equivalent in JSON? - let trait_ = ResolvedPath { did: trait_.res.def_id(), path: *trait_ }.into_tcx(tcx); + let trait_ = ResolvedPath { did: trait_.res.def_id(), path: trait_ }.into_tcx(tcx); Type::QualifiedPath { name: name.to_string(), self_type: Box::new((*self_type).into_tcx(tcx)),