Skip to content

Commit a8847df

Browse files
committed
Auto merge of #105657 - oli-obk:mk_projection_ty, r=lcnr
Guard ProjectionTy creation against passing the wrong number of substs r? `@lcnr`
2 parents 939a3dd + b41a483 commit a8847df

File tree

71 files changed

+262
-282
lines changed

Some content is hidden

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

71 files changed

+262
-282
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
697697
.map_bound(|p| p.predicates),
698698
None,
699699
),
700-
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
700+
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
701701
find_fn_kind_from_did(tcx.bound_explicit_item_bounds(*def_id), Some(*substs))
702702
}
703703
ty::Closure(_, substs) => match substs.as_closure().kind() {

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
504504
let ErrorConstraintInfo { outlived_fr, span, .. } = errci;
505505

506506
let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty;
507-
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *output_ty.kind() {
507+
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *output_ty.kind() {
508508
output_ty = self.infcx.tcx.type_of(def_id)
509509
};
510510

compiler/rustc_const_eval/src/transform/validate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
241241
};
242242

243243
let kind = match parent_ty.ty.kind() {
244-
&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => {
244+
&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
245245
self.tcx.bound_type_of(def_id).subst(self.tcx, substs).kind()
246246
}
247247
kind => kind,

compiler/rustc_const_eval/src/util/type_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
5858
// Types with identity (print the module path).
5959
ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), substs)
6060
| ty::FnDef(def_id, substs)
61-
| ty::Alias(_, ty::AliasTy { def_id, substs })
61+
| ty::Alias(_, ty::AliasTy { def_id, substs, .. })
6262
| ty::Closure(def_id, substs)
6363
| ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs),
6464
ty::Foreign(def_id) => self.print_def_path(def_id, &[]),

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
680680
let assoc_bindings = self.create_assoc_bindings_for_generic_args(args);
681681

682682
let poly_trait_ref =
683-
ty::Binder::bind_with_vars(ty::TraitRef::new(trait_def_id, substs), bound_vars);
683+
ty::Binder::bind_with_vars(tcx.mk_trait_ref(trait_def_id, substs), bound_vars);
684684

685685
debug!(?poly_trait_ref, ?assoc_bindings);
686686
bounds.trait_bounds.push((poly_trait_ref, span, constness));
@@ -813,7 +813,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
813813
if let Some(b) = trait_segment.args().bindings.first() {
814814
Self::prohibit_assoc_ty_binding(self.tcx(), b.span);
815815
}
816-
ty::TraitRef::new(trait_def_id, substs)
816+
self.tcx().mk_trait_ref(trait_def_id, substs)
817817
}
818818

819819
#[instrument(level = "debug", skip(self, span))]
@@ -1146,7 +1146,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
11461146

11471147
debug!(?substs_trait_ref_and_assoc_item);
11481148

1149-
ty::AliasTy { def_id: assoc_item.def_id, substs: substs_trait_ref_and_assoc_item }
1149+
self.tcx().mk_alias_ty(assoc_item.def_id, substs_trait_ref_and_assoc_item)
11501150
});
11511151

11521152
if !speculative {

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
570570
assoc_item,
571571
assoc_item,
572572
default.span,
573-
ty::TraitRef { def_id: it.owner_id.to_def_id(), substs: trait_substs },
573+
tcx.mk_trait_ref(it.owner_id.to_def_id(), trait_substs),
574574
);
575575
}
576576
_ => {}
@@ -1440,7 +1440,7 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) -> E
14401440
impl<'tcx> ty::visit::TypeVisitor<'tcx> for OpaqueTypeCollector {
14411441
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
14421442
match *t.kind() {
1443-
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, substs: _ }) => {
1443+
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {
14441444
self.0.push(def);
14451445
ControlFlow::CONTINUE
14461446
}

compiler/rustc_hir_analysis/src/check/compare_method.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,10 +1746,7 @@ pub fn check_type_bounds<'tcx>(
17461746
_ => predicates.push(
17471747
ty::Binder::bind_with_vars(
17481748
ty::ProjectionPredicate {
1749-
projection_ty: ty::AliasTy {
1750-
def_id: trait_ty.def_id,
1751-
substs: rebased_substs,
1752-
},
1749+
projection_ty: tcx.mk_alias_ty(trait_ty.def_id, rebased_substs),
17531750
term: impl_ty_value.into(),
17541751
},
17551752
bound_vars,

compiler/rustc_hir_analysis/src/variance/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
111111
#[instrument(level = "trace", skip(self), ret)]
112112
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
113113
match t.kind() {
114-
ty::Alias(_, ty::AliasTy { def_id, substs })
114+
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
115115
if matches!(
116116
self.tcx.def_kind(*def_id),
117117
DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder
@@ -160,7 +160,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
160160
// instead of requiring an additional `+ 'a`.
161161
match pred.kind().skip_binder() {
162162
ty::PredicateKind::Clause(ty::Clause::Trait(ty::TraitPredicate {
163-
trait_ref: ty::TraitRef { def_id: _, substs },
163+
trait_ref: ty::TraitRef { def_id: _, substs, .. },
164164
constness: _,
165165
polarity: _,
166166
})) => {
@@ -169,7 +169,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
169169
}
170170
}
171171
ty::PredicateKind::Clause(ty::Clause::Projection(ty::ProjectionPredicate {
172-
projection_ty: ty::AliasTy { substs, def_id: _ },
172+
projection_ty: ty::AliasTy { substs, .. },
173173
term,
174174
})) => {
175175
for subst in &substs[1..] {

compiler/rustc_hir_typeck/src/_match.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
518518

519519
let substs = sig.output().walk().find_map(|arg| {
520520
if let ty::GenericArgKind::Type(ty) = arg.unpack()
521-
&& let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) = *ty.kind()
521+
&& let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) = *ty.kind()
522522
&& def_id == rpit_def_id
523523
{
524524
Some(substs)
@@ -542,15 +542,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
542542
ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) => {
543543
assert_eq!(trait_pred.trait_ref.self_ty(), opaque_ty);
544544
ty::PredicateKind::Clause(ty::Clause::Trait(
545-
trait_pred.with_self_type(self.tcx, ty),
545+
trait_pred.with_self_ty(self.tcx, ty),
546546
))
547547
}
548548
ty::PredicateKind::Clause(ty::Clause::Projection(mut proj_pred)) => {
549549
assert_eq!(proj_pred.projection_ty.self_ty(), opaque_ty);
550-
proj_pred.projection_ty.substs = self.tcx.mk_substs_trait(
551-
ty,
552-
proj_pred.projection_ty.substs.iter().skip(1),
553-
);
550+
proj_pred = proj_pred.with_self_ty(self.tcx, ty);
554551
ty::PredicateKind::Clause(ty::Clause::Projection(proj_pred))
555552
}
556553
_ => continue,

compiler/rustc_hir_typeck/src/closure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
167167
expected_ty: Ty<'tcx>,
168168
) -> (Option<ExpectedSig<'tcx>>, Option<ty::ClosureKind>) {
169169
match *expected_ty.kind() {
170-
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => self
170+
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => self
171171
.deduce_signature_from_predicates(
172172
self.tcx.bound_explicit_item_bounds(def_id).subst_iter_copied(self.tcx, substs),
173173
),
@@ -678,7 +678,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
678678
get_future_output(obligation.predicate, obligation.cause.span)
679679
})?
680680
}
681-
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => self
681+
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => self
682682
.tcx
683683
.bound_explicit_item_bounds(def_id)
684684
.subst_iter_copied(self.tcx, substs)

0 commit comments

Comments
 (0)