1
Fork 0

ProjectionTy.item_def_id -> ProjectionTy.def_id

This commit is contained in:
Michael Goulet 2022-11-26 21:21:20 +00:00
parent 7f3af72606
commit 5c6afb850c
50 changed files with 164 additions and 186 deletions

View file

@ -1146,10 +1146,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
debug!(?substs_trait_ref_and_assoc_item);
ty::ProjectionTy {
item_def_id: assoc_item.def_id,
substs: substs_trait_ref_and_assoc_item,
}
ty::ProjectionTy { def_id: assoc_item.def_id, substs: substs_trait_ref_and_assoc_item }
});
if !speculative {
@ -1195,7 +1192,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// the "projection predicate" for:
//
// `<T as Iterator>::Item = u32`
let assoc_item_def_id = projection_ty.skip_binder().item_def_id;
let assoc_item_def_id = projection_ty.skip_binder().def_id;
let def_kind = tcx.def_kind(assoc_item_def_id);
match (def_kind, term.unpack()) {
(hir::def::DefKind::AssocTy, ty::TermKind::Ty(_))

View file

@ -572,9 +572,9 @@ impl<'tcx> TypeFolder<'tcx> for ImplTraitInTraitCollector<'_, 'tcx> {
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
if let ty::Projection(proj) = ty.kind()
&& self.tcx().def_kind(proj.item_def_id) == DefKind::ImplTraitPlaceholder
&& self.tcx().def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder
{
if let Some((ty, _)) = self.types.get(&proj.item_def_id) {
if let Some((ty, _)) = self.types.get(&proj.def_id) {
return *ty;
}
//FIXME(RPITIT): Deny nested RPITIT in substs too
@ -586,9 +586,9 @@ impl<'tcx> TypeFolder<'tcx> for ImplTraitInTraitCollector<'_, 'tcx> {
span: self.span,
kind: TypeVariableOriginKind::MiscVariable,
});
self.types.insert(proj.item_def_id, (infer_ty, proj.substs));
self.types.insert(proj.def_id, (infer_ty, proj.substs));
// Recurse into bounds
for (pred, pred_span) in self.tcx().bound_explicit_item_bounds(proj.item_def_id).subst_iter_copied(self.tcx(), proj.substs) {
for (pred, pred_span) in self.tcx().bound_explicit_item_bounds(proj.def_id).subst_iter_copied(self.tcx(), proj.substs) {
let pred = pred.fold_with(self);
let pred = self.ocx.normalize(
&ObligationCause::misc(self.span, self.body_id),
@ -601,7 +601,7 @@ impl<'tcx> TypeFolder<'tcx> for ImplTraitInTraitCollector<'_, 'tcx> {
ObligationCause::new(
self.span,
self.body_id,
ObligationCauseCode::BindingObligation(proj.item_def_id, pred_span),
ObligationCauseCode::BindingObligation(proj.def_id, pred_span),
),
self.param_env,
pred,
@ -1735,7 +1735,7 @@ pub fn check_type_bounds<'tcx>(
let mut predicates = param_env.caller_bounds().iter().collect::<Vec<_>>();
match impl_ty_value.kind() {
ty::Projection(proj)
if proj.item_def_id == trait_ty.def_id && proj.substs == rebased_substs =>
if proj.def_id == trait_ty.def_id && proj.substs == rebased_substs =>
{
// Don't include this predicate if the projected type is
// exactly the same as the projection. This can occur in
@ -1747,7 +1747,7 @@ pub fn check_type_bounds<'tcx>(
ty::Binder::bind_with_vars(
ty::ProjectionPredicate {
projection_ty: ty::ProjectionTy {
item_def_id: trait_ty.def_id,
def_id: trait_ty.def_id,
substs: rebased_substs,
},
term: impl_ty_value.into(),

View file

@ -352,11 +352,7 @@ fn bounds_from_generic_predicates<'tcx>(
// insert the associated types where they correspond, but for now let's be "lazy" and
// propose this instead of the following valid resugaring:
// `T: Trait, Trait::Assoc = K` → `T: Trait<Assoc = K>`
where_clauses.push(format!(
"{} = {}",
tcx.def_path_str(p.projection_ty.item_def_id),
p.term,
));
where_clauses.push(format!("{} = {}", tcx.def_path_str(p.projection_ty.def_id), p.term,));
}
let where_clauses = if where_clauses.is_empty() {
String::new()

View file

@ -759,7 +759,7 @@ impl<'tcx> TypeVisitor<'tcx> for GATSubstCollector<'tcx> {
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
match t.kind() {
ty::Projection(p) if p.item_def_id == self.gat => {
ty::Projection(p) if p.def_id == self.gat => {
for (idx, subst) in p.substs.iter().enumerate() {
match subst.unpack() {
GenericArgKind::Lifetime(lt) if !lt.is_late_bound() => {
@ -1593,11 +1593,11 @@ fn check_return_position_impl_trait_in_trait_bounds<'tcx>(
for arg in fn_output.walk() {
if let ty::GenericArgKind::Type(ty) = arg.unpack()
&& let ty::Projection(proj) = ty.kind()
&& tcx.def_kind(proj.item_def_id) == DefKind::ImplTraitPlaceholder
&& tcx.impl_trait_in_trait_parent(proj.item_def_id) == fn_def_id.to_def_id()
&& tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder
&& tcx.impl_trait_in_trait_parent(proj.def_id) == fn_def_id.to_def_id()
{
let span = tcx.def_span(proj.item_def_id);
let bounds = wfcx.tcx().explicit_item_bounds(proj.item_def_id);
let span = tcx.def_span(proj.def_id);
let bounds = wfcx.tcx().explicit_item_bounds(proj.def_id);
let wf_obligations = bounds.iter().flat_map(|&(bound, bound_span)| {
let bound = ty::EarlyBinder(bound).subst(tcx, proj.substs);
let normalized_bound = wfcx.normalize(span, None, bound);

View file

@ -413,7 +413,7 @@ pub(super) fn explicit_predicates_of<'tcx>(
// supertrait).
if let ty::Projection(projection) = ty.kind() {
projection.substs == trait_identity_substs
&& tcx.associated_item(projection.item_def_id).container_id(tcx) == def_id
&& tcx.associated_item(projection.def_id).container_id(tcx) == def_id
} else {
false
}

View file

@ -69,7 +69,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
// as a precaution for if it's ever allowed to elide lifetimes in GAT's. It currently isn't
// but it can't hurt to be safe ^^
if let ty::Projection(projection) = ty.kind() {
let generics = tcx.generics_of(projection.item_def_id);
let generics = tcx.generics_of(projection.def_id);
let arg_index = segment
.args

View file

@ -202,7 +202,7 @@ fn insert_required_predicates_to_be_wf<'tcx>(
debug!("Projection");
check_explicit_predicates(
tcx,
tcx.parent(obj.item_def_id),
tcx.parent(obj.def_id),
obj.substs,
required_predicates,
explicit_map,

View file

@ -90,7 +90,7 @@ pub(crate) fn insert_outlives_predicate<'tcx>(
// ```
//
// Here we want to add an explicit `where <T as Iterator>::Item: 'a`.
let ty: Ty<'tcx> = tcx.mk_projection(proj_ty.item_def_id, proj_ty.substs);
let ty: Ty<'tcx> = tcx.mk_projection(proj_ty.def_id, proj_ty.substs);
required_predicates
.entry(ty::OutlivesPredicate(ty.into(), outlived_region))
.or_insert(span);

View file

@ -110,12 +110,13 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
#[instrument(level = "trace", skip(self), ret)]
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
match t.kind() {
ty::Opaque(def_id, substs) => self.visit_opaque(*def_id, substs),
// FIXME(alias): merge these
match t.kind() {
ty::Opaque(ty::OpaqueTy { def_id, substs }) => self.visit_opaque(*def_id, substs),
ty::Projection(proj)
if self.tcx.def_kind(proj.item_def_id) == DefKind::ImplTraitPlaceholder =>
if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder =>
{
self.visit_opaque(proj.item_def_id, proj.substs)
self.visit_opaque(proj.def_id, proj.substs)
}
_ => t.super_visit_with(self),
}
@ -167,7 +168,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
}
}
ty::PredicateKind::Clause(ty::Clause::Projection(ty::ProjectionPredicate {
projection_ty: ty::ProjectionTy { substs, item_def_id: _ },
projection_ty: ty::ProjectionTy { substs, def_id: _ },
term,
})) => {
for subst in &substs[1..] {