Skip to content

Commit 3458211

Browse files
committed
Auto merge of rust-lang#125076 - compiler-errors:alias-term, r=lcnr
Split out `ty::AliasTerm` from `ty::AliasTy` Splitting out `AliasTerm` (for use in project and normalizes goals) and `AliasTy` (for use in `ty::Alias`) r? lcnr
2 parents ab14f94 + fa84018 commit 3458211

File tree

73 files changed

+695
-458
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+695
-458
lines changed

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
10101010
clauses.iter().any(|pred| {
10111011
match pred.kind().skip_binder() {
10121012
ty::ClauseKind::Trait(data) if data.self_ty() == ty => {}
1013-
ty::ClauseKind::Projection(data) if data.projection_ty.self_ty() == ty => {}
1013+
ty::ClauseKind::Projection(data)
1014+
if data.projection_term.self_ty() == ty => {}
10141015
_ => return false,
10151016
}
10161017
tcx.any_free_region_meets(pred, |r| *r == ty::ReEarlyParam(region))

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2206,7 +2206,7 @@ fn param_env_with_gat_bounds<'tcx>(
22062206
_ => predicates.push(
22072207
ty::Binder::bind_with_vars(
22082208
ty::ProjectionPredicate {
2209-
projection_ty: ty::AliasTy::new(tcx, trait_ty.def_id, rebased_args),
2209+
projection_term: ty::AliasTerm::new(tcx, trait_ty.def_id, rebased_args),
22102210
term: normalize_impl_ty.into(),
22112211
},
22122212
bound_vars,

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,10 @@ fn bounds_from_generic_predicates<'tcx>(
344344
let mut projections_str = vec![];
345345
for projection in &projections {
346346
let p = projection.skip_binder();
347-
let alias_ty = p.projection_ty;
348-
if bound == tcx.parent(alias_ty.def_id) && alias_ty.self_ty() == ty {
349-
let name = tcx.item_name(alias_ty.def_id);
347+
if bound == tcx.parent(p.projection_term.def_id)
348+
&& p.projection_term.self_ty() == ty
349+
{
350+
let name = tcx.item_name(p.projection_term.def_id);
350351
projections_str.push(format!("{} = {}", name, p.term));
351352
}
352353
}

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn associated_type_bounds<'tcx>(
4040
let bounds_from_parent = trait_predicates.predicates.iter().copied().filter(|(pred, _)| {
4141
match pred.kind().skip_binder() {
4242
ty::ClauseKind::Trait(tr) => tr.self_ty() == item_ty,
43-
ty::ClauseKind::Projection(proj) => proj.projection_ty.self_ty() == item_ty,
43+
ty::ClauseKind::Projection(proj) => proj.projection_term.self_ty() == item_ty,
4444
ty::ClauseKind::TypeOutlives(outlives) => outlives.0 == item_ty,
4545
_ => false,
4646
}

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,9 @@ pub(super) fn explicit_predicates_of<'tcx>(
446446
.copied()
447447
.filter(|(pred, _)| match pred.kind().skip_binder() {
448448
ty::ClauseKind::Trait(tr) => !is_assoc_item_ty(tr.self_ty()),
449-
ty::ClauseKind::Projection(proj) => !is_assoc_item_ty(proj.projection_ty.self_ty()),
449+
ty::ClauseKind::Projection(proj) => {
450+
!is_assoc_item_ty(proj.projection_term.self_ty())
451+
}
450452
ty::ClauseKind::TypeOutlives(outlives) => !is_assoc_item_ty(outlives.0),
451453
_ => true,
452454
})

compiler/rustc_hir_analysis/src/constrained_generic_params.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub fn setup_constraining_predicates<'tcx>(
198198
// Special case: watch out for some kind of sneaky attempt
199199
// to project out an associated type defined by this very
200200
// trait.
201-
let unbound_trait_ref = projection.projection_ty.trait_ref(tcx);
201+
let unbound_trait_ref = projection.projection_term.trait_ref(tcx);
202202
if Some(unbound_trait_ref) == impl_trait_ref {
203203
continue;
204204
}
@@ -208,7 +208,7 @@ pub fn setup_constraining_predicates<'tcx>(
208208
// `<<T as Bar>::Baz as Iterator>::Output = <U as Iterator>::Output`
209209
// Then the projection only applies if `T` is known, but it still
210210
// does not determine `U`.
211-
let inputs = parameters_for(tcx, projection.projection_ty, true);
211+
let inputs = parameters_for(tcx, projection.projection_term, true);
212212
let relies_only_on_inputs = inputs.iter().all(|p| input_parameters.contains(p));
213213
if !relies_only_on_inputs {
214214
continue;

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
327327
})
328328
.or_insert(binding.span);
329329

330-
let projection_ty = if let ty::AssocKind::Fn = assoc_kind {
330+
let projection_term = if let ty::AssocKind::Fn = assoc_kind {
331331
let mut emitted_bad_param_err = None;
332332
// If we have an method return type bound, then we need to instantiate
333333
// the method's early bound params with suitable late-bound params.
@@ -381,7 +381,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
381381
let output = if let ty::Alias(ty::Projection, alias_ty) = *output.skip_binder().kind()
382382
&& tcx.is_impl_trait_in_trait(alias_ty.def_id)
383383
{
384-
alias_ty
384+
alias_ty.into()
385385
} else {
386386
return Err(tcx.dcx().emit_err(crate::errors::ReturnTypeNotationOnNonRpitit {
387387
span: binding.span,
@@ -422,10 +422,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
422422
);
423423
debug!(?alias_args);
424424

425-
// Note that we're indeed also using `AliasTy` (alias *type*) for associated
426-
// *constants* to represent *const projections*. Alias *term* would be a more
427-
// appropriate name but alas.
428-
ty::AliasTy::new(tcx, assoc_item.def_id, alias_args)
425+
ty::AliasTerm::new(tcx, assoc_item.def_id, alias_args)
429426
});
430427

431428
// Provide the resolved type of the associated constant to `type_of(AnonConst)`.
@@ -462,7 +459,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
462459
// for<'a> <T as Iterator>::Item = &'a str // <-- 'a is bad
463460
// for<'a> <T as FnMut<(&'a u32,)>>::Output = &'a str // <-- 'a is ok
464461
let late_bound_in_projection_ty =
465-
tcx.collect_constrained_late_bound_regions(projection_ty);
462+
tcx.collect_constrained_late_bound_regions(projection_term);
466463
let late_bound_in_term =
467464
tcx.collect_referenced_late_bound_regions(trait_ref.rebind(term));
468465
debug!(?late_bound_in_projection_ty);
@@ -491,8 +488,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
491488

492489
bounds.push_projection_bound(
493490
tcx,
494-
projection_ty
495-
.map_bound(|projection_ty| ty::ProjectionPredicate { projection_ty, term }),
491+
projection_term.map_bound(|projection_term| ty::ProjectionPredicate {
492+
projection_term,
493+
term,
494+
}),
496495
binding.span,
497496
);
498497
}
@@ -502,6 +501,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
502501
// NOTE: If `only_self_bounds` is true, do NOT expand this associated type bound into
503502
// a trait predicate, since we only want to add predicates for the `Self` type.
504503
if !only_self_bounds.0 {
504+
let projection_ty = projection_term
505+
.map_bound(|projection_term| projection_term.expect_ty(self.tcx()));
505506
// Calling `skip_binder` is okay, because `lower_bounds` expects the `param_ty`
506507
// parameter to have a skipped binder.
507508
let param_ty = Ty::new_alias(tcx, ty::Projection, projection_ty.skip_binder());

compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -626,25 +626,17 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
626626
let bound_predicate = pred.kind();
627627
match bound_predicate.skip_binder() {
628628
ty::PredicateKind::Clause(ty::ClauseKind::Projection(pred)) => {
629-
let pred = bound_predicate.rebind(pred);
630629
// `<Foo as Iterator>::Item = String`.
631-
let projection_ty = pred.skip_binder().projection_ty;
630+
let projection_term = pred.projection_term;
631+
let quiet_projection_term =
632+
projection_term.with_self_ty(tcx, Ty::new_var(tcx, ty::TyVid::ZERO));
632633

633-
let args_with_infer_self = tcx.mk_args_from_iter(
634-
std::iter::once(Ty::new_var(tcx, ty::TyVid::ZERO).into())
635-
.chain(projection_ty.args.iter().skip(1)),
636-
);
637-
638-
let quiet_projection_ty =
639-
ty::AliasTy::new(tcx, projection_ty.def_id, args_with_infer_self);
640-
641-
let term = pred.skip_binder().term;
642-
643-
let obligation = format!("{projection_ty} = {term}");
644-
let quiet = format!("{quiet_projection_ty} = {term}");
634+
let term = pred.term;
635+
let obligation = format!("{projection_term} = {term}");
636+
let quiet = format!("{quiet_projection_term} = {term}");
645637

646-
bound_span_label(projection_ty.self_ty(), &obligation, &quiet);
647-
Some((obligation, projection_ty.self_ty()))
638+
bound_span_label(projection_term.self_ty(), &obligation, &quiet);
639+
Some((obligation, projection_term.self_ty()))
648640
}
649641
ty::PredicateKind::Clause(ty::ClauseKind::Trait(poly_trait_ref)) => {
650642
let p = poly_trait_ref.trait_ref;

compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
281281

282282
let existential_projections = projection_bounds.iter().map(|(bound, _)| {
283283
bound.map_bound(|mut b| {
284-
assert_eq!(b.projection_ty.self_ty(), dummy_self);
284+
assert_eq!(b.projection_term.self_ty(), dummy_self);
285285

286286
// Like for trait refs, verify that `dummy_self` did not leak inside default type
287287
// parameters.
288-
let references_self = b.projection_ty.args.iter().skip(1).any(|arg| {
288+
let references_self = b.projection_term.args.iter().skip(1).any(|arg| {
289289
if arg.walk().any(|arg| arg == dummy_self.into()) {
290290
return true;
291291
}
@@ -295,7 +295,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
295295
let guar = tcx
296296
.dcx()
297297
.span_delayed_bug(span, "trait object projection bounds reference `Self`");
298-
b.projection_ty = replace_dummy_self_with_error(tcx, b.projection_ty, guar);
298+
b.projection_term = replace_dummy_self_with_error(tcx, b.projection_term, guar);
299299
}
300300

301301
ty::ExistentialProjection::erase_self_ty(tcx, b)

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -258,23 +258,20 @@ fn unconstrained_parent_impl_args<'tcx>(
258258
// unconstrained parameters.
259259
for (clause, _) in impl_generic_predicates.predicates.iter() {
260260
if let ty::ClauseKind::Projection(proj) = clause.kind().skip_binder() {
261-
let projection_ty = proj.projection_ty;
262-
let projected_ty = proj.term;
263-
264-
let unbound_trait_ref = projection_ty.trait_ref(tcx);
261+
let unbound_trait_ref = proj.projection_term.trait_ref(tcx);
265262
if Some(unbound_trait_ref) == impl_trait_ref {
266263
continue;
267264
}
268265

269-
unconstrained_parameters.extend(cgp::parameters_for(tcx, projection_ty, true));
266+
unconstrained_parameters.extend(cgp::parameters_for(tcx, proj.projection_term, true));
270267

271-
for param in cgp::parameters_for(tcx, projected_ty, false) {
268+
for param in cgp::parameters_for(tcx, proj.term, false) {
272269
if !unconstrained_parameters.contains(&param) {
273270
constrained_params.insert(param.0);
274271
}
275272
}
276273

277-
unconstrained_parameters.extend(cgp::parameters_for(tcx, projected_ty, true));
274+
unconstrained_parameters.extend(cgp::parameters_for(tcx, proj.term, true));
278275
}
279276
}
280277

@@ -495,11 +492,11 @@ fn check_specialization_on<'tcx>(
495492
.emit())
496493
}
497494
}
498-
ty::ClauseKind::Projection(ty::ProjectionPredicate { projection_ty, term }) => Err(tcx
495+
ty::ClauseKind::Projection(ty::ProjectionPredicate { projection_term, term }) => Err(tcx
499496
.dcx()
500497
.struct_span_err(
501498
span,
502-
format!("cannot specialize on associated type `{projection_ty} == {term}`",),
499+
format!("cannot specialize on associated type `{projection_term} == {term}`",),
503500
)
504501
.emit()),
505502
ty::ClauseKind::ConstArgHasType(..) => {

0 commit comments

Comments
 (0)