diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-12-13 11:18:58 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-12-14 15:36:39 +0000 |
| commit | 6af36387095b5578711fb9bc75f45140d3c77410 (patch) | |
| tree | daa3220f28c54d55f7fa3ce65e1a32acb9b22879 /compiler/rustc_privacy/src | |
| parent | a5cd3bde95da07589b7a3a0cee35ec9b390c72aa (diff) | |
| download | rust-6af36387095b5578711fb9bc75f45140d3c77410.tar.gz rust-6af36387095b5578711fb9bc75f45140d3c77410.zip | |
Prevent the creation of `TraitRef` without dedicated methods
Diffstat (limited to 'compiler/rustc_privacy/src')
| -rw-r--r-- | compiler/rustc_privacy/src/lib.rs | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index cbe11ee6ac2..72d38aeac7a 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -110,26 +110,25 @@ where V: DefIdVisitor<'tcx> + ?Sized, { fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> ControlFlow<V::BreakTy> { - let TraitRef { def_id, substs } = trait_ref; + let TraitRef { def_id, substs, .. } = trait_ref; self.def_id_visitor.visit_def_id(def_id, "trait", &trait_ref.print_only_trait_path())?; if self.def_id_visitor.shallow() { ControlFlow::CONTINUE } else { substs.visit_with(self) } } fn visit_projection_ty(&mut self, projection: ty::AliasTy<'tcx>) -> ControlFlow<V::BreakTy> { let tcx = self.def_id_visitor.tcx(); - let (trait_ref, assoc_substs) = if tcx.def_kind(projection.def_id) - != DefKind::ImplTraitPlaceholder - { - projection.trait_ref_and_own_substs(tcx) - } else { - // HACK(RPITIT): Remove this when RPITITs are lowered to regular assoc tys - let def_id = tcx.impl_trait_in_trait_parent(projection.def_id); - let trait_generics = tcx.generics_of(def_id); - ( - ty::TraitRef { def_id, substs: projection.substs.truncate_to(tcx, trait_generics) }, - &projection.substs[trait_generics.count()..], - ) - }; + let (trait_ref, assoc_substs) = + if tcx.def_kind(projection.def_id) != DefKind::ImplTraitPlaceholder { + projection.trait_ref_and_own_substs(tcx) + } else { + // HACK(RPITIT): Remove this when RPITITs are lowered to regular assoc tys + let def_id = tcx.impl_trait_in_trait_parent(projection.def_id); + let trait_generics = tcx.generics_of(def_id); + ( + tcx.mk_trait_ref(def_id, projection.substs.truncate_to(tcx, trait_generics)), + &projection.substs[trait_generics.count()..], + ) + }; self.visit_trait(trait_ref)?; if self.def_id_visitor.shallow() { ControlFlow::CONTINUE |
