From 631cd5845e8de329d0e227aaa707d7ea228b8f8f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:20:29 +0200 Subject: Merging upstream version 1.70.0+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_traits/src/chalk/db.rs | 2 +- compiler/rustc_traits/src/chalk/lowering.rs | 61 +++++++++++++--------- compiler/rustc_traits/src/dropck_outlives.rs | 4 +- .../rustc_traits/src/implied_outlives_bounds.rs | 4 +- .../rustc_traits/src/normalize_erasing_regions.rs | 2 +- 5 files changed, 43 insertions(+), 30 deletions(-) (limited to 'compiler/rustc_traits') diff --git a/compiler/rustc_traits/src/chalk/db.rs b/compiler/rustc_traits/src/chalk/db.rs index f8c8f744e..9683e4847 100644 --- a/compiler/rustc_traits/src/chalk/db.rs +++ b/compiler/rustc_traits/src/chalk/db.rs @@ -730,7 +730,7 @@ fn bound_vars_for_item(tcx: TyCtxt<'_>, def_id: DefId) -> SubstsRef<'_> { ty::GenericParamDefKind::Lifetime => { let br = ty::BoundRegion { var: ty::BoundVar::from_usize(substs.len()), - kind: ty::BrAnon(substs.len() as u32, None), + kind: ty::BrAnon(None), }; tcx.mk_re_late_bound(ty::INNERMOST, br).into() } diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index 60e22d100..2be72879b 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -119,7 +119,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment LowerInto<'tcx, chalk_ir::GoalData>> for ty::Predi // some of these in terms of chalk operations. ty::PredicateKind::ClosureKind(..) | ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) - | ty::PredicateKind::AliasEq(..) + | ty::PredicateKind::AliasRelate(..) | ty::PredicateKind::Coerce(..) | ty::PredicateKind::ConstEvaluatable(..) | ty::PredicateKind::Ambiguous @@ -376,7 +376,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty>> for Ty<'tcx> { ty::Placeholder(_placeholder) => { chalk_ir::TyKind::Placeholder(chalk_ir::PlaceholderIndex { ui: chalk_ir::UniverseIndex { counter: _placeholder.universe.as_usize() }, - idx: _placeholder.name.expect_anon() as usize, + idx: _placeholder.bound.var.as_usize(), }) } ty::Infer(_infer) => unimplemented!(), @@ -479,12 +479,15 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty> { ty::DebruijnIndex::from_usize(bound.debruijn.depth() as usize), ty::BoundTy { var: ty::BoundVar::from_usize(bound.index), - kind: ty::BoundTyKind::Anon(bound.index as u32), + kind: ty::BoundTyKind::Anon, }, ), TyKind::Placeholder(placeholder) => ty::Placeholder(ty::Placeholder { universe: ty::UniverseIndex::from_usize(placeholder.ui.counter), - name: ty::BoundTyKind::Anon(placeholder.idx as u32), + bound: ty::BoundTy { + var: ty::BoundVar::from_usize(placeholder.idx), + kind: ty::BoundTyKind::Anon, + }, }), TyKind::InferenceVar(_, _) => unimplemented!(), TyKind::Dyn(_) => unimplemented!(), @@ -530,13 +533,16 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime unimplemented!(), chalk_ir::LifetimeData::Placeholder(p) => tcx.mk_re_placeholder(ty::Placeholder { universe: ty::UniverseIndex::from_usize(p.ui.counter), - name: ty::BoundRegionKind::BrAnon(p.idx as u32, None), + bound: ty::BoundRegion { + var: ty::BoundVar::from_usize(p.idx), + kind: ty::BoundRegionKind::BrAnon(None), + }, }), chalk_ir::LifetimeData::Static => tcx.lifetimes.re_static, chalk_ir::LifetimeData::Erased => tcx.lifetimes.re_erased, @@ -652,7 +658,7 @@ impl<'tcx> LowerInto<'tcx, Option None, ty::PredicateKind::ObjectSafe(..) - | ty::PredicateKind::AliasEq(..) + | ty::PredicateKind::AliasRelate(..) | ty::PredicateKind::ClosureKind(..) | ty::PredicateKind::Subtype(..) | ty::PredicateKind::Coerce(..) @@ -685,7 +691,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders LowerInto<'tcx, Option None, ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..)) - | ty::PredicateKind::AliasEq(..) + | ty::PredicateKind::AliasRelate(..) | ty::PredicateKind::ObjectSafe(..) | ty::PredicateKind::ClosureKind(..) | ty::PredicateKind::Subtype(..) @@ -909,8 +915,7 @@ pub(crate) fn collect_bound_vars<'tcx, T: TypeFoldable>>( .or_else(|| bug!("Skipped bound var index: parameters={:?}", parameters)); }); - let binders = - chalk_ir::VariableKinds::from_iter(interner, parameters.into_iter().map(|(_, v)| v)); + let binders = chalk_ir::VariableKinds::from_iter(interner, parameters.into_values()); (new_ty, binders, named_parameters) } @@ -971,7 +976,7 @@ impl<'tcx> TypeVisitor> for BoundVarsCollector<'tcx> { } } - ty::BoundRegionKind::BrAnon(var, _) => match self.parameters.entry(var) { + ty::BoundRegionKind::BrAnon(_) => match self.parameters.entry(br.var.as_u32()) { Entry::Vacant(entry) => { entry.insert(chalk_ir::VariableKind::Lifetime); } @@ -1031,8 +1036,8 @@ impl<'a, 'tcx> TypeFolder> for NamedBoundVarSubstitutor<'a, 'tcx> { match *r { ty::ReLateBound(index, br) if index == self.binder_index => match br.kind { ty::BrNamed(def_id, _name) => match self.named_parameters.get(&def_id) { - Some(idx) => { - let new_br = ty::BoundRegion { var: br.var, kind: ty::BrAnon(*idx, None) }; + Some(_) => { + let new_br = ty::BoundRegion { var: br.var, kind: ty::BrAnon(None) }; return self.tcx.mk_re_late_bound(index, new_br); } None => panic!("Missing `BrNamed`."), @@ -1091,7 +1096,10 @@ impl<'tcx> TypeFolder> for ParamsSubstitutor<'tcx> { ty::Param(param) => match self.list.iter().position(|r| r == ¶m) { Some(idx) => self.tcx.mk_placeholder(ty::PlaceholderType { universe: ty::UniverseIndex::from_usize(0), - name: ty::BoundTyKind::Anon(idx as u32), + bound: ty::BoundTy { + var: ty::BoundVar::from_usize(idx), + kind: ty::BoundTyKind::Anon, + }, }), None => { self.list.push(param); @@ -1099,7 +1107,10 @@ impl<'tcx> TypeFolder> for ParamsSubstitutor<'tcx> { self.params.insert(idx as u32, param); self.tcx.mk_placeholder(ty::PlaceholderType { universe: ty::UniverseIndex::from_usize(0), - name: ty::BoundTyKind::Anon(idx as u32), + bound: ty::BoundTy { + var: ty::BoundVar::from_usize(idx), + kind: ty::BoundTyKind::Anon, + }, }) } }, @@ -1116,7 +1127,7 @@ impl<'tcx> TypeFolder> for ParamsSubstitutor<'tcx> { Some(idx) => { let br = ty::BoundRegion { var: ty::BoundVar::from_u32(*idx), - kind: ty::BrAnon(*idx, None), + kind: ty::BrAnon(None), }; self.tcx.mk_re_late_bound(self.binder_index, br) } @@ -1124,7 +1135,7 @@ impl<'tcx> TypeFolder> for ParamsSubstitutor<'tcx> { let idx = self.named_regions.len() as u32; let br = ty::BoundRegion { var: ty::BoundVar::from_u32(idx), - kind: ty::BrAnon(idx, None), + kind: ty::BrAnon(None), }; self.named_regions.insert(_re.def_id, idx); self.tcx.mk_re_late_bound(self.binder_index, br) @@ -1157,8 +1168,8 @@ impl<'tcx> TypeFolder> for ReverseParamsSubstitutor<'tcx> { fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { match *t.kind() { - ty::Placeholder(ty::PlaceholderType { universe: ty::UniverseIndex::ROOT, name }) => { - match self.params.get(&name.expect_anon()) { + ty::Placeholder(ty::PlaceholderType { universe: ty::UniverseIndex::ROOT, bound }) => { + match self.params.get(&bound.var.as_u32()) { Some(&ty::ParamTy { index, name }) => self.tcx.mk_ty_param(index, name), None => t, } @@ -1190,8 +1201,7 @@ impl<'tcx> TypeVisitor> for PlaceholdersCollector { fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { match t.kind() { ty::Placeholder(p) if p.universe == self.universe_index => { - self.next_ty_placeholder = - self.next_ty_placeholder.max(p.name.expect_anon() as usize + 1); + self.next_ty_placeholder = self.next_ty_placeholder.max(p.bound.var.as_usize() + 1); } _ => (), @@ -1203,8 +1213,9 @@ impl<'tcx> TypeVisitor> for PlaceholdersCollector { fn visit_region(&mut self, r: Region<'tcx>) -> ControlFlow { match *r { ty::RePlaceholder(p) if p.universe == self.universe_index => { - if let ty::BoundRegionKind::BrAnon(anon, _) = p.name { - self.next_anon_region_placeholder = self.next_anon_region_placeholder.max(anon); + if let ty::BoundRegionKind::BrAnon(_) = p.bound.kind { + self.next_anon_region_placeholder = + self.next_anon_region_placeholder.max(p.bound.var.as_u32()); } // FIXME: This doesn't seem to handle BrNamed at all? } diff --git a/compiler/rustc_traits/src/dropck_outlives.rs b/compiler/rustc_traits/src/dropck_outlives.rs index b5924e949..58117c46f 100644 --- a/compiler/rustc_traits/src/dropck_outlives.rs +++ b/compiler/rustc_traits/src/dropck_outlives.rs @@ -292,7 +292,9 @@ pub(crate) fn adt_dtorck_constraint( let span = tcx.def_span(def_id); debug!("dtorck_constraint: {:?}", def); - if def.is_phantom_data() { + if def.is_manually_drop() { + bug!("`ManuallyDrop` should have been handled by `trivial_dropck_outlives`"); + } else if def.is_phantom_data() { // The first generic parameter here is guaranteed to be a type because it's // `PhantomData`. let substs = InternalSubsts::identity_for_item(tcx, def_id); diff --git a/compiler/rustc_traits/src/implied_outlives_bounds.rs b/compiler/rustc_traits/src/implied_outlives_bounds.rs index ddd4ca143..f5bba14d2 100644 --- a/compiler/rustc_traits/src/implied_outlives_bounds.rs +++ b/compiler/rustc_traits/src/implied_outlives_bounds.rs @@ -86,7 +86,7 @@ fn compute_implied_outlives_bounds<'tcx>( if obligation.predicate.has_non_region_infer() { match obligation.predicate.kind().skip_binder() { ty::PredicateKind::Clause(ty::Clause::Projection(..)) - | ty::PredicateKind::AliasEq(..) => { + | ty::PredicateKind::AliasRelate(..) => { ocx.register_obligation(obligation.clone()); } _ => {} @@ -110,7 +110,7 @@ fn compute_implied_outlives_bounds<'tcx>( | ty::PredicateKind::ConstEvaluatable(..) | ty::PredicateKind::ConstEquate(..) | ty::PredicateKind::Ambiguous - | ty::PredicateKind::AliasEq(..) + | ty::PredicateKind::AliasRelate(..) | ty::PredicateKind::TypeWellFormedFromEnv(..) => {} // We need to search through *all* WellFormed predicates diff --git a/compiler/rustc_traits/src/normalize_erasing_regions.rs b/compiler/rustc_traits/src/normalize_erasing_regions.rs index f0597f192..126a494f3 100644 --- a/compiler/rustc_traits/src/normalize_erasing_regions.rs +++ b/compiler/rustc_traits/src/normalize_erasing_regions.rs @@ -61,7 +61,7 @@ fn not_outlives_predicate(p: ty::Predicate<'_>) -> bool { ty::PredicateKind::Clause(ty::Clause::Trait(..)) | ty::PredicateKind::Clause(ty::Clause::Projection(..)) | ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) - | ty::PredicateKind::AliasEq(..) + | ty::PredicateKind::AliasRelate(..) | ty::PredicateKind::WellFormed(..) | ty::PredicateKind::ObjectSafe(..) | ty::PredicateKind::ClosureKind(..) -- cgit v1.2.3