1
Fork 0

Rollup merge of #139669 - nnethercote:overhaul-AssocItem, r=oli-obk

Overhaul `AssocItem`

`AssocItem` has multiple fields that only make sense some of the time. E.g. the `name` can be empty if it's an RPITIT associated type. It's clearer and less error prone if these fields are moved to the relevant `kind` variants.

r? ``@fee1-dead``
This commit is contained in:
Stuart Cook 2025-04-15 15:47:27 +10:00 committed by GitHub
commit 13cd5256ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
86 changed files with 609 additions and 546 deletions

View file

@ -855,11 +855,11 @@ impl<'tcx> LateContext<'tcx> {
&self,
self_ty: Ty<'tcx>,
trait_id: DefId,
name: &str,
name: Symbol,
) -> Option<Ty<'tcx>> {
let tcx = self.tcx;
tcx.associated_items(trait_id)
.find_by_ident_and_kind(tcx, Ident::from_str(name), ty::AssocKind::Type, trait_id)
.find_by_ident_and_kind(tcx, Ident::with_dummy_span(name), ty::AssocTag::Type, trait_id)
.and_then(|assoc| {
let proj = Ty::new_projection(tcx, assoc.def_id, [self_ty]);
tcx.try_normalize_erasing_regions(self.typing_env(), proj).ok()

View file

@ -69,7 +69,7 @@ impl<'tcx> LateLintPass<'tcx> for DerefIntoDynSupertrait {
&& let ty::Dynamic(data, _, ty::Dyn) = self_ty.kind()
&& let Some(self_principal) = data.principal()
// `<T as Deref>::Target` is `dyn target_principal`
&& let Some(target) = cx.get_associated_type(self_ty, did, "Target")
&& let Some(target) = cx.get_associated_type(self_ty, did, sym::Target)
&& let ty::Dynamic(data, _, ty::Dyn) = target.kind()
&& let Some(target_principal) = data.principal()
// `target_principal` is a supertrait of `t_principal`