Skip to content

Commit 3bcdf30

Browse files
split out AliasTy -> AliasTerm
1 parent ecbe3fd commit 3bcdf30

File tree

70 files changed

+688
-387
lines changed

Some content is hidden

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

70 files changed

+688
-387
lines changed

Diff for: compiler/rustc_borrowck/src/diagnostics/region_name.rs

+2-1
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))

Diff for: compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2205,7 +2205,7 @@ fn param_env_with_gat_bounds<'tcx>(
22052205
_ => predicates.push(
22062206
ty::Binder::bind_with_vars(
22072207
ty::ProjectionPredicate {
2208-
projection_ty: ty::AliasTy::new(tcx, trait_ty.def_id, rebased_args),
2208+
projection_term: ty::AliasTerm::new(tcx, trait_ty.def_id, rebased_args),
22092209
term: normalize_impl_ty.into(),
22102210
},
22112211
bound_vars,

Diff for: compiler/rustc_hir_analysis/src/check/mod.rs

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

Diff for: compiler/rustc_hir_analysis/src/collect/item_bounds.rs

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

Diff for: compiler/rustc_hir_analysis/src/collect/predicates_of.rs

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

Diff for: compiler/rustc_hir_analysis/src/constrained_generic_params.rs

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

Diff for: compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
326326
})
327327
.or_insert(binding.span);
328328

329-
let projection_ty = if let ty::AssocKind::Fn = assoc_kind {
329+
let projection_term = if let ty::AssocKind::Fn = assoc_kind {
330330
let mut emitted_bad_param_err = None;
331331
// If we have an method return type bound, then we need to instantiate
332332
// the method's early bound params with suitable late-bound params.
@@ -380,7 +380,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
380380
let output = if let ty::Alias(ty::Projection, alias_ty) = *output.skip_binder().kind()
381381
&& tcx.is_impl_trait_in_trait(alias_ty.def_id)
382382
{
383-
alias_ty
383+
alias_ty.into()
384384
} else {
385385
return Err(tcx.dcx().emit_err(crate::errors::ReturnTypeNotationOnNonRpitit {
386386
span: binding.span,
@@ -424,7 +424,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
424424
// Note that we're indeed also using `AliasTy` (alias *type*) for associated
425425
// *constants* to represent *const projections*. Alias *term* would be a more
426426
// appropriate name but alas.
427-
ty::AliasTy::new(tcx, assoc_item.def_id, alias_args)
427+
ty::AliasTerm::new(tcx, assoc_item.def_id, alias_args)
428428
});
429429

430430
// Provide the resolved type of the associated constant to `type_of(AnonConst)`.
@@ -461,7 +461,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
461461
// for<'a> <T as Iterator>::Item = &'a str // <-- 'a is bad
462462
// for<'a> <T as FnMut<(&'a u32,)>>::Output = &'a str // <-- 'a is ok
463463
let late_bound_in_projection_ty =
464-
tcx.collect_constrained_late_bound_regions(projection_ty);
464+
tcx.collect_constrained_late_bound_regions(projection_term);
465465
let late_bound_in_term =
466466
tcx.collect_referenced_late_bound_regions(trait_ref.rebind(term));
467467
debug!(?late_bound_in_projection_ty);
@@ -490,8 +490,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
490490

491491
bounds.push_projection_bound(
492492
tcx,
493-
projection_ty
494-
.map_bound(|projection_ty| ty::ProjectionPredicate { projection_ty, term }),
493+
projection_term.map_bound(|projection_term| ty::ProjectionPredicate {
494+
projection_term,
495+
term,
496+
}),
495497
binding.span,
496498
);
497499
}
@@ -501,6 +503,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
501503
// NOTE: If `only_self_bounds` is true, do NOT expand this associated type bound into
502504
// a trait predicate, since we only want to add predicates for the `Self` type.
503505
if !only_self_bounds.0 {
506+
let projection_ty = projection_term
507+
.map_bound(|projection_term| projection_term.expect_ty(self.tcx()));
504508
// Calling `skip_binder` is okay, because `lower_bounds` expects the `param_ty`
505509
// parameter to have a skipped binder.
506510
let param_ty = Ty::new_alias(tcx, ty::Projection, projection_ty.skip_binder());

Diff for: compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -627,23 +627,23 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
627627
ty::PredicateKind::Clause(ty::ClauseKind::Projection(pred)) => {
628628
let pred = bound_predicate.rebind(pred);
629629
// `<Foo as Iterator>::Item = String`.
630-
let projection_ty = pred.skip_binder().projection_ty;
630+
let projection_term = pred.skip_binder().projection_term;
631631

632632
let args_with_infer_self = tcx.mk_args_from_iter(
633633
std::iter::once(Ty::new_var(tcx, ty::TyVid::ZERO).into())
634-
.chain(projection_ty.args.iter().skip(1)),
634+
.chain(projection_term.args.iter().skip(1)),
635635
);
636636

637637
let quiet_projection_ty =
638-
ty::AliasTy::new(tcx, projection_ty.def_id, args_with_infer_self);
638+
ty::AliasTerm::new(tcx, projection_term.def_id, args_with_infer_self);
639639

640640
let term = pred.skip_binder().term;
641641

642-
let obligation = format!("{projection_ty} = {term}");
642+
let obligation = format!("{projection_term} = {term}");
643643
let quiet = format!("{quiet_projection_ty} = {term}");
644644

645-
bound_span_label(projection_ty.self_ty(), &obligation, &quiet);
646-
Some((obligation, projection_ty.self_ty()))
645+
bound_span_label(projection_term.self_ty(), &obligation, &quiet);
646+
Some((obligation, projection_term.self_ty()))
647647
}
648648
ty::PredicateKind::Clause(ty::ClauseKind::Trait(poly_trait_ref)) => {
649649
let p = poly_trait_ref.trait_ref;

Diff for: compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
280280

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

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

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

Diff for: compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -258,23 +258,23 @@ 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;
261+
let projection_term = proj.projection_term;
262+
let projected_term = proj.term;
263263

264-
let unbound_trait_ref = projection_ty.trait_ref(tcx);
264+
let unbound_trait_ref = projection_term.trait_ref(tcx);
265265
if Some(unbound_trait_ref) == impl_trait_ref {
266266
continue;
267267
}
268268

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

271-
for param in cgp::parameters_for(tcx, projected_ty, false) {
271+
for param in cgp::parameters_for(tcx, projected_term, false) {
272272
if !unconstrained_parameters.contains(&param) {
273273
constrained_params.insert(param.0);
274274
}
275275
}
276276

277-
unconstrained_parameters.extend(cgp::parameters_for(tcx, projected_ty, true));
277+
unconstrained_parameters.extend(cgp::parameters_for(tcx, projected_term, true));
278278
}
279279
}
280280

@@ -495,11 +495,11 @@ fn check_specialization_on<'tcx>(
495495
.emit())
496496
}
497497
}
498-
ty::ClauseKind::Projection(ty::ProjectionPredicate { projection_ty, term }) => Err(tcx
498+
ty::ClauseKind::Projection(ty::ProjectionPredicate { projection_term, term }) => Err(tcx
499499
.dcx()
500500
.struct_span_err(
501501
span,
502-
format!("cannot specialize on associated type `{projection_ty} == {term}`",),
502+
format!("cannot specialize on associated type `{projection_term} == {term}`",),
503503
)
504504
.emit()),
505505
ty::ClauseKind::ConstArgHasType(..) => {

Diff for: compiler/rustc_hir_analysis/src/variance/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
166166
}
167167
}
168168
ty::ClauseKind::Projection(ty::ProjectionPredicate {
169-
projection_ty: ty::AliasTy { args, .. },
169+
projection_term: ty::AliasTerm { args, .. },
170170
term,
171171
}) => {
172172
for arg in &args[1..] {

Diff for: compiler/rustc_hir_typeck/src/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
574574
self.misc(span),
575575
self.param_env,
576576
ty::ProjectionPredicate {
577-
projection_ty: ty::AliasTy::new(
577+
projection_term: ty::AliasTerm::new(
578578
self.tcx,
579579
fn_once_output_def_id,
580580
[arg_ty.into(), fn_sig.inputs()[0].into(), const_param],

Diff for: compiler/rustc_hir_typeck/src/closure.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
414414
// many viable options, so pick the most restrictive.
415415
let trait_def_id = match bound_predicate.skip_binder() {
416416
ty::PredicateKind::Clause(ty::ClauseKind::Projection(data)) => {
417-
Some(data.projection_ty.trait_def_id(self.tcx))
417+
Some(data.projection_term.trait_def_id(self.tcx))
418418
}
419419
ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => Some(data.def_id()),
420420
_ => None,
@@ -475,7 +475,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
475475
_ => return None,
476476
}
477477

478-
let arg_param_ty = projection.skip_binder().projection_ty.args.type_at(1);
478+
let arg_param_ty = projection.skip_binder().projection_term.args.type_at(1);
479479
let arg_param_ty = self.resolve_vars_if_possible(arg_param_ty);
480480
debug!(?arg_param_ty);
481481

@@ -930,7 +930,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
930930
};
931931

932932
// Check that this is a projection from the `Future` trait.
933-
let trait_def_id = predicate.projection_ty.trait_def_id(self.tcx);
933+
let trait_def_id = predicate.projection_term.trait_def_id(self.tcx);
934934
let future_trait = self.tcx.require_lang_item(LangItem::Future, Some(cause_span));
935935
if trait_def_id != future_trait {
936936
debug!("deduce_future_output_from_projection: not a future");
@@ -940,11 +940,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
940940
// The `Future` trait has only one associated item, `Output`,
941941
// so check that this is what we see.
942942
let output_assoc_item = self.tcx.associated_item_def_ids(future_trait)[0];
943-
if output_assoc_item != predicate.projection_ty.def_id {
943+
if output_assoc_item != predicate.projection_term.def_id {
944944
span_bug!(
945945
cause_span,
946946
"projecting associated item `{:?}` from future, which is not Output `{:?}`",
947-
predicate.projection_ty.def_id,
947+
predicate.projection_term.def_id,
948948
output_assoc_item,
949949
);
950950
}

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3737
ty::ClauseKind::Trait(pred) => {
3838
(pred.trait_ref.args.to_vec(), Some(pred.self_ty().into()))
3939
}
40-
ty::ClauseKind::Projection(pred) => (pred.projection_ty.args.to_vec(), None),
40+
ty::ClauseKind::Projection(pred) => (pred.projection_term.args.to_vec(), None),
4141
ty::ClauseKind::ConstArgHasType(arg, ty) => (vec![ty.into(), arg.into()], None),
4242
ty::ClauseKind::ConstEvaluatable(e) => (vec![e.into()], None),
4343
_ => return false,

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3838
self.type_matches_expected_vid(expected_vid, data.self_ty())
3939
}
4040
ty::PredicateKind::Clause(ty::ClauseKind::Projection(data)) => {
41-
self.type_matches_expected_vid(expected_vid, data.projection_ty.self_ty())
41+
self.type_matches_expected_vid(expected_vid, data.projection_term.self_ty())
4242
}
4343
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))
4444
| ty::PredicateKind::Subtype(..)

Diff for: compiler/rustc_hir_typeck/src/method/suggest.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
172172
}
173173
}
174174
}
175-
ty::Slice(..) | ty::Adt(..) | ty::Alias(ty::AliasKind::Opaque, _) => {
175+
ty::Slice(..) | ty::Adt(..) | ty::Alias(ty::Opaque, _) => {
176176
for unsatisfied in unsatisfied_predicates.iter() {
177177
if is_iterator_predicate(unsatisfied.0, self.tcx) {
178178
return true;
@@ -787,26 +787,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
787787
ty::PredicateKind::Clause(ty::ClauseKind::Projection(pred)) => {
788788
let pred = bound_predicate.rebind(pred);
789789
// `<Foo as Iterator>::Item = String`.
790-
let projection_ty = pred.skip_binder().projection_ty;
790+
let projection_term = pred.skip_binder().projection_term;
791791

792792
let args_with_infer_self = tcx.mk_args_from_iter(
793793
iter::once(Ty::new_var(tcx, ty::TyVid::ZERO).into())
794-
.chain(projection_ty.args.iter().skip(1)),
794+
.chain(projection_term.args.iter().skip(1)),
795795
);
796796

797-
let quiet_projection_ty =
798-
ty::AliasTy::new(tcx, projection_ty.def_id, args_with_infer_self);
797+
let quiet_projection_term =
798+
ty::AliasTerm::new(tcx, projection_term.def_id, args_with_infer_self);
799799

800800
let term = pred.skip_binder().term;
801801

802-
let obligation = format!("{projection_ty} = {term}");
802+
let obligation = format!("{projection_term} = {term}");
803803
let quiet = with_forced_trimmed_paths!(format!(
804804
"{} = {}",
805-
quiet_projection_ty, term
805+
quiet_projection_term, term
806806
));
807807

808-
bound_span_label(projection_ty.self_ty(), &obligation, &quiet);
809-
Some((obligation, projection_ty.self_ty()))
808+
bound_span_label(projection_term.self_ty(), &obligation, &quiet);
809+
Some((obligation, projection_term.self_ty()))
810810
}
811811
ty::PredicateKind::Clause(ty::ClauseKind::Trait(poly_trait_ref)) => {
812812
let p = poly_trait_ref.trait_ref;

Diff for: compiler/rustc_infer/src/infer/at.rs

+14
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,20 @@ impl<'tcx> ToTrace<'tcx> for ty::TraitRef<'tcx> {
430430
}
431431

432432
impl<'tcx> ToTrace<'tcx> for ty::AliasTy<'tcx> {
433+
fn to_trace(
434+
cause: &ObligationCause<'tcx>,
435+
a_is_expected: bool,
436+
a: Self,
437+
b: Self,
438+
) -> TypeTrace<'tcx> {
439+
TypeTrace {
440+
cause: cause.clone(),
441+
values: Aliases(ExpectedFound::new(a_is_expected, a.into(), b.into())),
442+
}
443+
}
444+
}
445+
446+
impl<'tcx> ToTrace<'tcx> for ty::AliasTerm<'tcx> {
433447
fn to_trace(
434448
cause: &ObligationCause<'tcx>,
435449
a_is_expected: bool,

Diff for: compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ impl<'tcx> InferCtxt<'tcx> {
410410
.kind()
411411
.map_bound(|kind| match kind {
412412
ty::ClauseKind::Projection(projection_predicate)
413-
if projection_predicate.projection_ty.def_id == item_def_id =>
413+
if projection_predicate.projection_term.def_id == item_def_id =>
414414
{
415415
projection_predicate.term.ty()
416416
}

0 commit comments

Comments
 (0)