diff options
Diffstat (limited to 'compiler/rustc_traits/src')
| -rw-r--r-- | compiler/rustc_traits/src/chalk/db.rs | 110 | ||||
| -rw-r--r-- | compiler/rustc_traits/src/chalk/lowering.rs | 93 | ||||
| -rw-r--r-- | compiler/rustc_traits/src/chalk/mod.rs | 21 | ||||
| -rw-r--r-- | compiler/rustc_traits/src/implied_outlives_bounds.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_traits/src/lib.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_traits/src/normalize_erasing_regions.rs | 21 | ||||
| -rw-r--r-- | compiler/rustc_traits/src/type_op.rs | 12 |
7 files changed, 130 insertions, 136 deletions
diff --git a/compiler/rustc_traits/src/chalk/db.rs b/compiler/rustc_traits/src/chalk/db.rs index 1d457d6761f..3f51442277f 100644 --- a/compiler/rustc_traits/src/chalk/db.rs +++ b/compiler/rustc_traits/src/chalk/db.rs @@ -46,7 +46,9 @@ impl<'tcx> RustIrDatabase<'tcx> { .iter() .map(|(wc, _)| wc.subst(self.interner.tcx, bound_vars)) .map(|wc| wc.fold_with(&mut regions_substitutor)) - .filter_map(|wc| LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(wc, &self.interner)).collect() + .filter_map(|wc| LowerInto::< + Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> + >::lower_into(wc, self.interner)).collect() } fn bounds_for<T>(&self, def_id: DefId, bound_vars: SubstsRef<'tcx>) -> Vec<T> @@ -58,14 +60,14 @@ impl<'tcx> RustIrDatabase<'tcx> { .explicit_item_bounds(def_id) .iter() .map(|(bound, _)| bound.subst(self.interner.tcx, &bound_vars)) - .filter_map(|bound| LowerInto::<Option<_>>::lower_into(bound, &self.interner)) + .filter_map(|bound| LowerInto::<Option<_>>::lower_into(bound, self.interner)) .collect() } } impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'tcx> { - fn interner(&self) -> &RustInterner<'tcx> { - &self.interner + fn interner(&self) -> RustInterner<'tcx> { + self.interner } fn associated_ty_data( @@ -83,7 +85,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t _ => unimplemented!("Not possible??"), } let bound_vars = bound_vars_for_item(self.interner.tcx, def_id); - let binders = binders_for(&self.interner, bound_vars); + let binders = binders_for(self.interner, bound_vars); let where_clauses = self.where_clauses_for(def_id, bound_vars); let bounds = self.bounds_for(def_id, bound_vars); @@ -107,7 +109,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t let trait_def = self.interner.tcx.trait_def(def_id); let bound_vars = bound_vars_for_item(self.interner.tcx, def_id); - let binders = binders_for(&self.interner, bound_vars); + let binders = binders_for(self.interner, bound_vars); let where_clauses = self.where_clauses_for(def_id, bound_vars); @@ -170,7 +172,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t let adt_def = adt_id.0; let bound_vars = bound_vars_for_item(self.interner.tcx, adt_def.did); - let binders = binders_for(&self.interner, bound_vars); + let binders = binders_for(self.interner, bound_vars); let where_clauses = self.where_clauses_for(adt_def.did, bound_vars); @@ -181,7 +183,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t fields: variant .fields .iter() - .map(|field| field.ty(self.interner.tcx, bound_vars).lower_into(&self.interner)) + .map(|field| field.ty(self.interner.tcx, bound_vars).lower_into(self.interner)) .collect(), }) .collect(); @@ -209,8 +211,8 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t adt_id: chalk_ir::AdtId<RustInterner<'tcx>>, ) -> Arc<chalk_solve::rust_ir::AdtRepr<RustInterner<'tcx>>> { let adt_def = adt_id.0; - let int = |i| chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Int(i)).intern(&self.interner); - let uint = |i| chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Uint(i)).intern(&self.interner); + let int = |i| chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Int(i)).intern(self.interner); + let uint = |i| chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Uint(i)).intern(self.interner); Arc::new(chalk_solve::rust_ir::AdtRepr { c: adt_def.repr.c(), packed: adt_def.repr.packed(), @@ -241,25 +243,25 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t ) -> Arc<chalk_solve::rust_ir::FnDefDatum<RustInterner<'tcx>>> { let def_id = fn_def_id.0; let bound_vars = bound_vars_for_item(self.interner.tcx, def_id); - let binders = binders_for(&self.interner, bound_vars); + let binders = binders_for(self.interner, bound_vars); let where_clauses = self.where_clauses_for(def_id, bound_vars); let sig = self.interner.tcx.fn_sig(def_id); let (inputs_and_output, iobinders, _) = crate::chalk::lowering::collect_bound_vars( - &self.interner, + self.interner, self.interner.tcx, sig.inputs_and_output().subst(self.interner.tcx, bound_vars), ); let argument_types = inputs_and_output[..inputs_and_output.len() - 1] .iter() - .map(|t| t.subst(self.interner.tcx, &bound_vars).lower_into(&self.interner)) + .map(|t| t.subst(self.interner.tcx, &bound_vars).lower_into(self.interner)) .collect(); let return_type = inputs_and_output[inputs_and_output.len() - 1] .subst(self.interner.tcx, &bound_vars) - .lower_into(&self.interner); + .lower_into(self.interner); let bound = chalk_solve::rust_ir::FnDefDatumBound { inputs_and_output: chalk_ir::Binders::new( @@ -270,7 +272,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t }; Arc::new(chalk_solve::rust_ir::FnDefDatum { id: fn_def_id, - sig: sig.lower_into(&self.interner), + sig: sig.lower_into(self.interner), binders: chalk_ir::Binders::new(binders, bound), }) } @@ -281,7 +283,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t ) -> Arc<chalk_solve::rust_ir::ImplDatum<RustInterner<'tcx>>> { let def_id = impl_id.0; let bound_vars = bound_vars_for_item(self.interner.tcx, def_id); - let binders = binders_for(&self.interner, bound_vars); + let binders = binders_for(self.interner, bound_vars); let trait_ref = self.interner.tcx.impl_trait_ref(def_id).expect("not an impl"); let trait_ref = trait_ref.subst(self.interner.tcx, bound_vars); @@ -292,7 +294,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t let where_clauses = self.where_clauses_for(def_id, bound_vars); let value = chalk_solve::rust_ir::ImplDatumBound { - trait_ref: trait_ref.lower_into(&self.interner), + trait_ref: trait_ref.lower_into(self.interner), where_clauses, }; @@ -306,7 +308,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t .collect(); Arc::new(chalk_solve::rust_ir::ImplDatum { - polarity: self.interner.tcx.impl_polarity(def_id).lower_into(&self.interner), + polarity: self.interner.tcx.impl_polarity(def_id).lower_into(self.interner), binders: chalk_ir::Binders::new(binders, value), impl_type: chalk_solve::rust_ir::ImplType::Local, associated_ty_value_ids, @@ -336,10 +338,10 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t let mut regions_substitutor = lowering::RegionsSubstitutor::new(self.interner.tcx, self.reempty_placeholder); let self_ty = self_ty.fold_with(&mut regions_substitutor); - let lowered_ty = self_ty.lower_into(&self.interner); + let lowered_ty = self_ty.lower_into(self.interner); - parameters[0].assert_ty_ref(&self.interner).could_match( - &self.interner, + parameters[0].assert_ty_ref(self.interner).could_match( + self.interner, self.unification_database(), &lowered_ty, ) @@ -434,35 +436,25 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t ) -> Arc<chalk_solve::rust_ir::AssociatedTyValue<RustInterner<'tcx>>> { let def_id = associated_ty_id.0; let assoc_item = self.interner.tcx.associated_item(def_id); - let (impl_id, trait_id) = match assoc_item.container { - AssocItemContainer::TraitContainer(def_id) => (def_id, def_id), - AssocItemContainer::ImplContainer(def_id) => { - (def_id, self.interner.tcx.impl_trait_ref(def_id).unwrap().def_id) - } - }; + let impl_id = assoc_item.container.id(); match assoc_item.kind { AssocKind::Type => {} _ => unimplemented!("Not possible??"), } - let trait_item = self - .interner - .tcx - .associated_items(trait_id) - .find_by_name_and_kind(self.interner.tcx, assoc_item.ident, assoc_item.kind, trait_id) - .unwrap(); + let trait_item_id = assoc_item.trait_item_def_id.expect("assoc_ty with no trait version"); let bound_vars = bound_vars_for_item(self.interner.tcx, def_id); - let binders = binders_for(&self.interner, bound_vars); + let binders = binders_for(self.interner, bound_vars); let ty = self .interner .tcx .type_of(def_id) .subst(self.interner.tcx, bound_vars) - .lower_into(&self.interner); + .lower_into(self.interner); Arc::new(chalk_solve::rust_ir::AssociatedTyValue { impl_id: chalk_ir::ImplId(impl_id), - associated_ty_id: chalk_ir::AssocTypeId(trait_item.def_id), + associated_ty_id: chalk_ir::AssocTypeId(trait_item_id), value: chalk_ir::Binders::new( binders, chalk_solve::rust_ir::AssociatedTyValueBound { ty }, @@ -521,13 +513,13 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t .filter_map(|bound| { LowerInto::< Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> - >::lower_into(bound, &self.interner) + >::lower_into(bound, self.interner) }) .collect(); // Binder for the bound variable representing the concrete impl Trait type. let existential_binder = chalk_ir::VariableKinds::from1( - &self.interner, + self.interner, chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General), ); @@ -536,7 +528,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t where_clauses: chalk_ir::Binders::new(existential_binder, where_clauses), }; - let binders = binders_for(&self.interner, bound_vars); + let binders = binders_for(self.interner, bound_vars); Arc::new(chalk_solve::rust_ir::OpaqueTyDatum { opaque_ty_id, bound: chalk_ir::Binders::new(binders, value), @@ -568,6 +560,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t Unpin => lang_items.unpin_trait(), CoerceUnsized => lang_items.coerce_unsized_trait(), DiscriminantKind => lang_items.discriminant_kind_trait(), + Generator => lang_items.generator_return(), }; def_id.map(chalk_ir::TraitId) } @@ -584,7 +577,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t self.interner .tcx .mk_ty(ty::Tuple(self.interner.tcx.intern_substs(&[]))) - .lower_into(&self.interner) + .lower_into(self.interner) } fn closure_kind( @@ -592,8 +585,8 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t _closure_id: chalk_ir::ClosureId<RustInterner<'tcx>>, substs: &chalk_ir::Substitution<RustInterner<'tcx>>, ) -> chalk_solve::rust_ir::ClosureKind { - let kind = &substs.as_slice(&self.interner)[substs.len(&self.interner) - 3]; - match kind.assert_ty_ref(&self.interner).kind(&self.interner) { + let kind = &substs.as_slice(self.interner)[substs.len(self.interner) - 3]; + match kind.assert_ty_ref(self.interner).kind(self.interner) { chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Int(int_ty)) => match int_ty { chalk_ir::IntTy::I8 => chalk_solve::rust_ir::ClosureKind::Fn, chalk_ir::IntTy::I16 => chalk_solve::rust_ir::ClosureKind::FnMut, @@ -610,18 +603,17 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t substs: &chalk_ir::Substitution<RustInterner<'tcx>>, ) -> chalk_ir::Binders<chalk_solve::rust_ir::FnDefInputsAndOutputDatum<RustInterner<'tcx>>> { - let sig = &substs.as_slice(&self.interner)[substs.len(&self.interner) - 2]; - match sig.assert_ty_ref(&self.interner).kind(&self.interner) { + let sig = &substs.as_slice(self.interner)[substs.len(self.interner) - 2]; + match sig.assert_ty_ref(self.interner).kind(self.interner) { chalk_ir::TyKind::Function(f) => { - let substitution = f.substitution.0.as_slice(&self.interner); - let return_type = - substitution.last().unwrap().assert_ty_ref(&self.interner).clone(); + let substitution = f.substitution.0.as_slice(self.interner); + let return_type = substitution.last().unwrap().assert_ty_ref(self.interner).clone(); // Closure arguments are tupled - let argument_tuple = substitution[0].assert_ty_ref(&self.interner); - let argument_types = match argument_tuple.kind(&self.interner) { + let argument_tuple = substitution[0].assert_ty_ref(self.interner); + let argument_types = match argument_tuple.kind(self.interner) { chalk_ir::TyKind::Tuple(_len, substitution) => substitution - .iter(&self.interner) - .map(|arg| arg.assert_ty_ref(&self.interner)) + .iter(self.interner) + .map(|arg| arg.assert_ty_ref(self.interner)) .cloned() .collect(), _ => bug!("Expecting closure FnSig args to be tupled."), @@ -629,7 +621,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t chalk_ir::Binders::new( chalk_ir::VariableKinds::from_iter( - &self.interner, + self.interner, (0..f.num_binders).map(|_| chalk_ir::VariableKind::Lifetime), ), chalk_solve::rust_ir::FnDefInputsAndOutputDatum { argument_types, return_type }, @@ -645,7 +637,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t substs: &chalk_ir::Substitution<RustInterner<'tcx>>, ) -> chalk_ir::Binders<chalk_ir::Ty<RustInterner<'tcx>>> { let inputs_and_output = self.closure_inputs_and_output(_closure_id, substs); - let tuple = substs.as_slice(&self.interner).last().unwrap().assert_ty_ref(&self.interner); + let tuple = substs.as_slice(self.interner).last().unwrap().assert_ty_ref(self.interner); inputs_and_output.map_ref(|_| tuple.clone()) } @@ -654,8 +646,8 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t _closure_id: chalk_ir::ClosureId<RustInterner<'tcx>>, substs: &chalk_ir::Substitution<RustInterner<'tcx>>, ) -> chalk_ir::Substitution<RustInterner<'tcx>> { - let substitution = &substs.as_slice(&self.interner)[0..substs.len(&self.interner) - 3]; - chalk_ir::Substitution::from_iter(&self.interner, substitution) + let substitution = &substs.as_slice(self.interner)[0..substs.len(self.interner) - 3]; + chalk_ir::Substitution::from_iter(self.interner, substitution) } fn generator_datum( @@ -691,7 +683,7 @@ impl<'tcx> chalk_ir::UnificationDatabase<RustInterner<'tcx>> for RustIrDatabase< ) -> chalk_ir::Variances<RustInterner<'tcx>> { let variances = self.interner.tcx.variances_of(def_id.0); chalk_ir::Variances::from_iter( - &self.interner, + self.interner, variances.iter().map(|v| match v { ty::Variance::Invariant => chalk_ir::Variance::Invariant, ty::Variance::Covariant => chalk_ir::Variance::Covariant, @@ -707,7 +699,7 @@ impl<'tcx> chalk_ir::UnificationDatabase<RustInterner<'tcx>> for RustIrDatabase< ) -> chalk_ir::Variances<RustInterner<'tcx>> { let variances = self.interner.tcx.variances_of(def_id.0.did); chalk_ir::Variances::from_iter( - &self.interner, + self.interner, variances.iter().map(|v| match v { ty::Variance::Invariant => chalk_ir::Variance::Invariant, ty::Variance::Covariant => chalk_ir::Variance::Covariant, @@ -722,7 +714,7 @@ impl<'tcx> chalk_ir::UnificationDatabase<RustInterner<'tcx>> for RustIrDatabase< /// var bound at index `0`. For types, we use a `BoundVar` index equal to /// the type parameter index. For regions, we use the `BoundRegionKind::BrNamed` /// variant (which has a `DefId`). -fn bound_vars_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx> { +fn bound_vars_for_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx> { InternalSubsts::for_item(tcx, def_id, |param, substs| match param.kind { ty::GenericParamDefKind::Type { .. } => tcx .mk_ty(ty::Bound( @@ -752,7 +744,7 @@ fn bound_vars_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx> { } fn binders_for<'tcx>( - interner: &RustInterner<'tcx>, + interner: RustInterner<'tcx>, bound_vars: SubstsRef<'tcx>, ) -> chalk_ir::VariableKinds<RustInterner<'tcx>> { chalk_ir::VariableKinds::from_iter( diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index e24f699adf6..67d0ba39667 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -46,26 +46,26 @@ use std::ops::ControlFlow; /// Essentially an `Into` with a `&RustInterner` parameter crate trait LowerInto<'tcx, T> { /// Lower a rustc construct (e.g., `ty::TraitPredicate`) to a chalk type, consuming `self`. - fn lower_into(self, interner: &RustInterner<'tcx>) -> T; + fn lower_into(self, interner: RustInterner<'tcx>) -> T; } impl<'tcx> LowerInto<'tcx, chalk_ir::Substitution<RustInterner<'tcx>>> for SubstsRef<'tcx> { fn lower_into( self, - interner: &RustInterner<'tcx>, + interner: RustInterner<'tcx>, ) -> chalk_ir::Substitution<RustInterner<'tcx>> { chalk_ir::Substitution::from_iter(interner, self.iter().map(|s| s.lower_into(interner))) } } impl<'tcx> LowerInto<'tcx, SubstsRef<'tcx>> for &chalk_ir::Substitution<RustInterner<'tcx>> { - fn lower_into(self, interner: &RustInterner<'tcx>) -> SubstsRef<'tcx> { + fn lower_into(self, interner: RustInterner<'tcx>) -> SubstsRef<'tcx> { interner.tcx.mk_substs(self.iter(interner).map(|subst| subst.lower_into(interner))) } } impl<'tcx> LowerInto<'tcx, chalk_ir::AliasTy<RustInterner<'tcx>>> for ty::ProjectionTy<'tcx> { - fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::AliasTy<RustInterner<'tcx>> { + fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::AliasTy<RustInterner<'tcx>> { chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { associated_ty_id: chalk_ir::AssocTypeId(self.item_def_id), substitution: self.substs.lower_into(interner), @@ -78,7 +78,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<' { fn lower_into( self, - interner: &RustInterner<'tcx>, + interner: RustInterner<'tcx>, ) -> chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'tcx>>> { let clauses = self.environment.into_iter().map(|predicate| { let (predicate, binders, _named_regions) = @@ -122,18 +122,18 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<' chalk_ir::ProgramClauseData(chalk_ir::Binders::new(binders, value)).intern(interner) }); - let goal: chalk_ir::GoalData<RustInterner<'tcx>> = self.goal.lower_into(&interner); + let goal: chalk_ir::GoalData<RustInterner<'tcx>> = self.goal.lower_into(interner); chalk_ir::InEnvironment { environment: chalk_ir::Environment { - clauses: chalk_ir::ProgramClauses::from_iter(&interner, clauses), + clauses: chalk_ir::ProgramClauses::from_iter(interner, clauses), }, - goal: goal.intern(&interner), + goal: goal.intern(interner), } } } impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predicate<'tcx> { - fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GoalData<RustInterner<'tcx>> { + fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::GoalData<RustInterner<'tcx>> { let (predicate, binders, _named_regions) = collect_bound_vars(interner, interner.tcx, self.kind()); @@ -214,7 +214,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi impl<'tcx> LowerInto<'tcx, chalk_ir::TraitRef<RustInterner<'tcx>>> for rustc_middle::ty::TraitRef<'tcx> { - fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::TraitRef<RustInterner<'tcx>> { + fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::TraitRef<RustInterner<'tcx>> { chalk_ir::TraitRef { trait_id: chalk_ir::TraitId(self.def_id), substitution: self.substs.lower_into(interner), @@ -225,16 +225,29 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::TraitRef<RustInterner<'tcx>>> impl<'tcx> LowerInto<'tcx, chalk_ir::AliasEq<RustInterner<'tcx>>> for rustc_middle::ty::ProjectionPredicate<'tcx> { - fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::AliasEq<RustInterner<'tcx>> { + fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::AliasEq<RustInterner<'tcx>> { + // FIXME(associated_const_equality): teach chalk about terms for alias eq. chalk_ir::AliasEq { - ty: self.ty.lower_into(interner), + ty: self.term.ty().unwrap().lower_into(interner), alias: self.projection_ty.lower_into(interner), } } } +/* +// FIXME(...): Where do I add this to Chalk? I can't find it in the rustc repo anywhere. +impl<'tcx> LowerInto<'tcx, chalk_ir::Term<RustInterner<'tcx>>> for rustc_middle::ty::Term<'tcx> { + fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::Term<RustInterner<'tcx>> { + match self { + ty::Term::Ty(ty) => ty.lower_into(interner).into(), + ty::Term::Const(c) => c.lower_into(interner).into(), + } + } +} +*/ + impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> { - fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::Ty<RustInterner<'tcx>> { + fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::Ty<RustInterner<'tcx>> { let int = |i| chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Int(i)); let uint = |i| chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Uint(i)); let float = |f| chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Float(f)); @@ -336,7 +349,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> { } impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> { - fn lower_into(self, interner: &RustInterner<'tcx>) -> Ty<'tcx> { + fn lower_into(self, interner: RustInterner<'tcx>) -> Ty<'tcx> { use chalk_ir::TyKind; let kind = match self.kind(interner) { @@ -429,7 +442,7 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> { } impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'tcx> { - fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::Lifetime<RustInterner<'tcx>> { + fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::Lifetime<RustInterner<'tcx>> { use rustc_middle::ty::RegionKind::*; match self { @@ -459,7 +472,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'t } impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'tcx>> { - fn lower_into(self, interner: &RustInterner<'tcx>) -> Region<'tcx> { + fn lower_into(self, interner: RustInterner<'tcx>) -> Region<'tcx> { let kind = match self.data(interner) { chalk_ir::LifetimeData::BoundVar(var) => ty::RegionKind::ReLateBound( ty::DebruijnIndex::from_u32(var.debruijn.depth()), @@ -487,7 +500,7 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'t } impl<'tcx> LowerInto<'tcx, chalk_ir::Const<RustInterner<'tcx>>> for ty::Const<'tcx> { - fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::Const<RustInterner<'tcx>> { + fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::Const<RustInterner<'tcx>> { let ty = self.ty.lower_into(interner); let value = match self.val { ty::ConstKind::Value(val) => { @@ -503,7 +516,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Const<RustInterner<'tcx>>> for ty::Const<'t } impl<'tcx> LowerInto<'tcx, ty::Const<'tcx>> for &chalk_ir::Const<RustInterner<'tcx>> { - fn lower_into(self, interner: &RustInterner<'tcx>) -> ty::Const<'tcx> { + fn lower_into(self, interner: RustInterner<'tcx>) -> ty::Const<'tcx> { let data = self.data(interner); let ty = data.ty.lower_into(interner); let val = match data.value { @@ -520,7 +533,7 @@ impl<'tcx> LowerInto<'tcx, ty::Const<'tcx>> for &chalk_ir::Const<RustInterner<'t } impl<'tcx> LowerInto<'tcx, chalk_ir::GenericArg<RustInterner<'tcx>>> for GenericArg<'tcx> { - fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GenericArg<RustInterner<'tcx>> { + fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::GenericArg<RustInterner<'tcx>> { match self.unpack() { ty::subst::GenericArgKind::Type(ty) => { chalk_ir::GenericArgData::Ty(ty.lower_into(interner)) @@ -539,7 +552,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GenericArg<RustInterner<'tcx>>> for Generic impl<'tcx> LowerInto<'tcx, ty::subst::GenericArg<'tcx>> for &chalk_ir::GenericArg<RustInterner<'tcx>> { - fn lower_into(self, interner: &RustInterner<'tcx>) -> ty::subst::GenericArg<'tcx> { + fn lower_into(self, interner: RustInterner<'tcx>) -> ty::subst::GenericArg<'tcx> { match self.data(interner) { chalk_ir::GenericArgData::Ty(ty) => { let t: Ty<'tcx> = ty.lower_into(interner); @@ -566,7 +579,7 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<' { fn lower_into( self, - interner: &RustInterner<'tcx>, + interner: RustInterner<'tcx>, ) -> Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> { let (predicate, binders, _named_regions) = collect_bound_vars(interner, interner.tcx, self.kind()); @@ -610,7 +623,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<Ru { fn lower_into( self, - interner: &RustInterner<'tcx>, + interner: RustInterner<'tcx>, ) -> chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<RustInterner<'tcx>>> { // `Self` has one binder: // Binder<&'tcx ty::List<ty::ExistentialPredicate<'tcx>>> @@ -651,7 +664,8 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<Ru .mk_substs_trait(self_ty, predicate.substs) .lower_into(interner), }), - ty: predicate.ty.lower_into(interner), + // FIXME(associated_const_equality): teach chalk about terms for alias eq. + ty: predicate.term.ty().unwrap().lower_into(interner), }), ), ty::ExistentialPredicate::AutoTrait(def_id) => chalk_ir::Binders::new( @@ -680,7 +694,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<Ru impl<'tcx> LowerInto<'tcx, chalk_ir::FnSig<RustInterner<'tcx>>> for ty::Binder<'tcx, ty::FnSig<'tcx>> { - fn lower_into(self, _interner: &RustInterner<'_>) -> FnSig<RustInterner<'tcx>> { + fn lower_into(self, _interner: RustInterner<'_>) -> FnSig<RustInterner<'tcx>> { chalk_ir::FnSig { abi: self.abi(), safety: match self.unsafety() { @@ -700,7 +714,7 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_solve::rust_ir::QuantifiedInlineBound<Ru { fn lower_into( self, - interner: &RustInterner<'tcx>, + interner: RustInterner<'tcx>, ) -> Option<chalk_solve::rust_ir::QuantifiedInlineBound<RustInterner<'tcx>>> { let (predicate, binders, _named_regions) = collect_bound_vars(interner, interner.tcx, self.kind()); @@ -737,7 +751,7 @@ impl<'tcx> LowerInto<'tcx, chalk_solve::rust_ir::TraitBound<RustInterner<'tcx>>> { fn lower_into( self, - interner: &RustInterner<'tcx>, + interner: RustInterner<'tcx>, ) -> chalk_solve::rust_ir::TraitBound<RustInterner<'tcx>> { chalk_solve::rust_ir::TraitBound { trait_id: chalk_ir::TraitId(self.def_id), @@ -747,7 +761,7 @@ impl<'tcx> LowerInto<'tcx, chalk_solve::rust_ir::TraitBound<RustInterner<'tcx>>> } impl<'tcx> LowerInto<'tcx, chalk_ir::Mutability> for ast::Mutability { - fn lower_into(self, _interner: &RustInterner<'tcx>) -> chalk_ir::Mutability { + fn lower_into(self, _interner: RustInterner<'tcx>) -> chalk_ir::Mutability { match self { rustc_ast::Mutability::Mut => chalk_ir::Mutability::Mut, rustc_ast::Mutability::Not => chalk_ir::Mutability::Not, @@ -756,7 +770,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Mutability> for ast::Mutability { } impl<'tcx> LowerInto<'tcx, ast::Mutability> for chalk_ir::Mutability { - fn lower_into(self, _interner: &RustInterner<'tcx>) -> ast::Mutability { + fn lower_into(self, _interner: RustInterner<'tcx>) -> ast::Mutability { match self { chalk_ir::Mutability::Mut => ast::Mutability::Mut, chalk_ir::Mutability::Not => ast::Mutability::Not, @@ -765,7 +779,7 @@ impl<'tcx> LowerInto<'tcx, ast::Mutability> for chalk_ir::Mutability { } impl<'tcx> LowerInto<'tcx, chalk_solve::rust_ir::Polarity> for ty::ImplPolarity { - fn lower_into(self, _interner: &RustInterner<'tcx>) -> chalk_solve::rust_ir::Polarity { + fn lower_into(self, _interner: RustInterner<'tcx>) -> chalk_solve::rust_ir::Polarity { match self { ty::ImplPolarity::Positive => chalk_solve::rust_ir::Polarity::Positive, ty::ImplPolarity::Negative => chalk_solve::rust_ir::Polarity::Negative, @@ -780,14 +794,14 @@ impl<'tcx> LowerInto<'tcx, chalk_solve::rust_ir::AliasEqBound<RustInterner<'tcx> { fn lower_into( self, - interner: &RustInterner<'tcx>, + interner: RustInterner<'tcx>, ) -> chalk_solve::rust_ir::AliasEqBound<RustInterner<'tcx>> { let (trait_ref, own_substs) = self.projection_ty.trait_ref_and_own_substs(interner.tcx); chalk_solve::rust_ir::AliasEqBound { trait_bound: trait_ref.lower_into(interner), associated_ty_id: chalk_ir::AssocTypeId(self.projection_ty.item_def_id), parameters: own_substs.iter().map(|arg| arg.lower_into(interner)).collect(), - value: self.ty.lower_into(interner), + value: self.term.ty().unwrap().lower_into(interner), } } } @@ -802,11 +816,11 @@ impl<'tcx> LowerInto<'tcx, chalk_solve::rust_ir::AliasEqBound<RustInterner<'tcx> /// late-bound regions, even outside of fn contexts, since this is the best way /// to prep types for chalk lowering. crate fn collect_bound_vars<'tcx, T: TypeFoldable<'tcx>>( - interner: &RustInterner<'tcx>, + interner: RustInterner<'tcx>, tcx: TyCtxt<'tcx>, ty: Binder<'tcx, T>, ) -> (T, chalk_ir::VariableKinds<RustInterner<'tcx>>, BTreeMap<DefId, u32>) { - let mut bound_vars_collector = BoundVarsCollector::new(tcx); + let mut bound_vars_collector = BoundVarsCollector::new(); ty.as_ref().skip_binder().visit_with(&mut bound_vars_collector); let mut parameters = bound_vars_collector.parameters; let named_parameters: BTreeMap<DefId, u32> = bound_vars_collector @@ -836,16 +850,14 @@ crate fn collect_bound_vars<'tcx, T: TypeFoldable<'tcx>>( } crate struct BoundVarsCollector<'tcx> { - tcx: TyCtxt<'tcx>, binder_index: ty::DebruijnIndex, crate parameters: BTreeMap<u32, chalk_ir::VariableKind<RustInterner<'tcx>>>, crate named_parameters: Vec<DefId>, } impl<'tcx> BoundVarsCollector<'tcx> { - crate fn new(tcx: TyCtxt<'tcx>) -> Self { + crate fn new() -> Self { BoundVarsCollector { - tcx, binder_index: ty::INNERMOST, parameters: BTreeMap::new(), named_parameters: vec![], @@ -854,10 +866,6 @@ impl<'tcx> BoundVarsCollector<'tcx> { } impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> { - fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>> { - Some(self.tcx) - } - fn visit_binder<T: TypeFoldable<'tcx>>( &mut self, t: &Binder<'tcx, T>, @@ -1076,11 +1084,6 @@ impl PlaceholdersCollector { } impl<'tcx> TypeVisitor<'tcx> for PlaceholdersCollector { - fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>> { - // Anon const substs do not contain placeholders by default. - None - } - fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> { match t.kind() { ty::Placeholder(p) if p.universe == self.universe_index => { diff --git a/compiler/rustc_traits/src/chalk/mod.rs b/compiler/rustc_traits/src/chalk/mod.rs index b7275bac190..09bfdabf473 100644 --- a/compiler/rustc_traits/src/chalk/mod.rs +++ b/compiler/rustc_traits/src/chalk/mod.rs @@ -63,7 +63,7 @@ crate fn evaluate_goal<'tcx>( > = chalk_ir::UCanonical { canonical: chalk_ir::Canonical { binders: chalk_ir::CanonicalVarKinds::from_iter( - &interner, + interner, obligation.variables.iter().map(|v| match v.kind { CanonicalVarKind::PlaceholderTy(_ty) => unimplemented!(), CanonicalVarKind::PlaceholderRegion(_ui) => unimplemented!(), @@ -85,11 +85,11 @@ crate fn evaluate_goal<'tcx>( chalk_ir::VariableKind::Lifetime, chalk_ir::UniverseIndex { counter: ui.index() }, ), - CanonicalVarKind::Const(_ui) => unimplemented!(), + CanonicalVarKind::Const(_ui, _ty) => unimplemented!(), CanonicalVarKind::PlaceholderConst(_pc) => unimplemented!(), }), ), - value: obligation.value.lower_into(&interner), + value: obligation.value.lower_into(interner), }, universes: max_universe + 1, }; @@ -110,11 +110,11 @@ crate fn evaluate_goal<'tcx>( use rustc_middle::infer::canonical::CanonicalVarInfo; let mut var_values: IndexVec<BoundVar, GenericArg<'tcx>> = IndexVec::new(); - subst.as_slice(&interner).iter().for_each(|p| { - var_values.push(p.lower_into(&interner)); + subst.as_slice(interner).iter().for_each(|p| { + var_values.push(p.lower_into(interner)); }); let variables: Vec<_> = binders - .iter(&interner) + .iter(interner) .map(|var| { let kind = match var.kind { chalk_ir::VariableKind::Ty(ty_kind) => CanonicalVarKind::Ty(match ty_kind { @@ -127,15 +127,14 @@ crate fn evaluate_goal<'tcx>( chalk_ir::VariableKind::Lifetime => CanonicalVarKind::Region( ty::UniverseIndex::from_usize(var.skip_kind().counter), ), - chalk_ir::VariableKind::Const(_) => CanonicalVarKind::Const( - ty::UniverseIndex::from_usize(var.skip_kind().counter), - ), + // FIXME(compiler-errors): We don't currently have a way of turning + // a Chalk ty back into a rustc ty, right? + chalk_ir::VariableKind::Const(_) => todo!(), }; CanonicalVarInfo { kind } }) .collect(); - let max_universe = - binders.iter(&interner).map(|v| v.skip_kind().counter).max().unwrap_or(0); + let max_universe = binders.iter(interner).map(|v| v.skip_kind().counter).max().unwrap_or(0); let sol = Canonical { max_universe: ty::UniverseIndex::from_usize(max_universe), variables: tcx.intern_canonical_var_infos(&variables), diff --git a/compiler/rustc_traits/src/implied_outlives_bounds.rs b/compiler/rustc_traits/src/implied_outlives_bounds.rs index 37e00733737..90c698db8fb 100644 --- a/compiler/rustc_traits/src/implied_outlives_bounds.rs +++ b/compiler/rustc_traits/src/implied_outlives_bounds.rs @@ -128,9 +128,9 @@ fn compute_implied_outlives_bounds<'tcx>( // Ensure that those obligations that we had to solve // get solved *here*. - match fulfill_cx.select_all_or_error(infcx) { - Ok(()) => Ok(implied_bounds), - Err(_) => Err(NoSolution), + match fulfill_cx.select_all_or_error(infcx).as_slice() { + [] => Ok(implied_bounds), + _ => Err(NoSolution), } } @@ -138,7 +138,7 @@ fn compute_implied_outlives_bounds<'tcx>( /// this down to determine what relationships would have to hold for /// `T: 'a` to hold. We get to assume that the caller has validated /// those relationships. -fn implied_bounds_from_components( +fn implied_bounds_from_components<'tcx>( sub_region: ty::Region<'tcx>, sup_components: SmallVec<[Component<'tcx>; 4]>, ) -> Vec<OutlivesBound<'tcx>> { diff --git a/compiler/rustc_traits/src/lib.rs b/compiler/rustc_traits/src/lib.rs index 8612499623b..b814b984dae 100644 --- a/compiler/rustc_traits/src/lib.rs +++ b/compiler/rustc_traits/src/lib.rs @@ -2,7 +2,6 @@ //! the guts are broken up into modules; see the comments in those modules. #![feature(crate_visibility_modifier)] -#![feature(in_band_lifetimes)] #![feature(nll)] #![recursion_limit = "256"] diff --git a/compiler/rustc_traits/src/normalize_erasing_regions.rs b/compiler/rustc_traits/src/normalize_erasing_regions.rs index 61ab5e28b67..46c2f7e4cf2 100644 --- a/compiler/rustc_traits/src/normalize_erasing_regions.rs +++ b/compiler/rustc_traits/src/normalize_erasing_regions.rs @@ -8,27 +8,28 @@ use std::sync::atomic::Ordering; crate fn provide(p: &mut Providers) { *p = Providers { - normalize_generic_arg_after_erasing_regions: |tcx, goal| { - debug!("normalize_generic_arg_after_erasing_regions(goal={:#?})", goal); + try_normalize_generic_arg_after_erasing_regions: |tcx, goal| { + debug!("try_normalize_generic_arg_after_erasing_regions(goal={:#?}", goal); tcx.sess .perf_stats .normalize_generic_arg_after_erasing_regions .fetch_add(1, Ordering::Relaxed); - normalize_after_erasing_regions(tcx, goal) + + try_normalize_after_erasing_regions(tcx, goal) }, - normalize_mir_const_after_erasing_regions: |tcx, goal| { - normalize_after_erasing_regions(tcx, goal) + try_normalize_mir_const_after_erasing_regions: |tcx, goal| { + try_normalize_after_erasing_regions(tcx, goal) }, ..*p }; } #[instrument(level = "debug", skip(tcx))] -fn normalize_after_erasing_regions<'tcx, T: TypeFoldable<'tcx> + PartialEq + Copy>( +fn try_normalize_after_erasing_regions<'tcx, T: TypeFoldable<'tcx> + PartialEq + Copy>( tcx: TyCtxt<'tcx>, goal: ParamEnvAnd<'tcx, T>, -) -> T { +) -> Result<T, NoSolution> { let ParamEnvAnd { param_env, value } = goal; tcx.infer_ctxt().enter(|infcx| { let cause = ObligationCause::dummy(); @@ -49,14 +50,14 @@ fn normalize_after_erasing_regions<'tcx, T: TypeFoldable<'tcx> + PartialEq + Cop debug_assert_eq!(normalized_value, resolved_value); let erased = infcx.tcx.erase_regions(resolved_value); debug_assert!(!erased.needs_infer(), "{:?}", erased); - erased + Ok(erased) } - Err(NoSolution) => bug!("could not fully normalize `{:?}`", value), + Err(NoSolution) => Err(NoSolution), } }) } -fn not_outlives_predicate(p: &ty::Predicate<'tcx>) -> bool { +fn not_outlives_predicate<'tcx>(p: &ty::Predicate<'tcx>) -> bool { match p.kind().skip_binder() { ty::PredicateKind::RegionOutlives(..) | ty::PredicateKind::TypeOutlives(..) => false, ty::PredicateKind::Trait(..) diff --git a/compiler/rustc_traits/src/type_op.rs b/compiler/rustc_traits/src/type_op.rs index cc0b7d5817b..6fcac9fcdc6 100644 --- a/compiler/rustc_traits/src/type_op.rs +++ b/compiler/rustc_traits/src/type_op.rs @@ -70,7 +70,7 @@ struct AscribeUserTypeCx<'me, 'tcx> { fulfill_cx: &'me mut dyn TraitEngine<'tcx>, } -impl AscribeUserTypeCx<'me, 'tcx> { +impl<'me, 'tcx> AscribeUserTypeCx<'me, 'tcx> { fn normalize<T>(&mut self, value: T) -> T where T: TypeFoldable<'tcx>, @@ -195,7 +195,7 @@ fn type_op_eq<'tcx>( }) } -fn type_op_normalize<T>( +fn type_op_normalize<'tcx, T>( infcx: &InferCtxt<'_, 'tcx>, fulfill_cx: &mut dyn TraitEngine<'tcx>, key: ParamEnvAnd<'tcx, Normalize<T>>, @@ -210,28 +210,28 @@ where Ok(value) } -fn type_op_normalize_ty( +fn type_op_normalize_ty<'tcx>( tcx: TyCtxt<'tcx>, canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Normalize<Ty<'tcx>>>>, ) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>, NoSolution> { tcx.infer_ctxt().enter_canonical_trait_query(&canonicalized, type_op_normalize) } -fn type_op_normalize_predicate( +fn type_op_normalize_predicate<'tcx>( tcx: TyCtxt<'tcx>, canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Normalize<Predicate<'tcx>>>>, ) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, Predicate<'tcx>>>, NoSolution> { tcx.infer_ctxt().enter_canonical_trait_query(&canonicalized, type_op_normalize) } -fn type_op_normalize_fn_sig( +fn type_op_normalize_fn_sig<'tcx>( tcx: TyCtxt<'tcx>, canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Normalize<FnSig<'tcx>>>>, ) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, FnSig<'tcx>>>, NoSolution> { tcx.infer_ctxt().enter_canonical_trait_query(&canonicalized, type_op_normalize) } -fn type_op_normalize_poly_fn_sig( +fn type_op_normalize_poly_fn_sig<'tcx>( tcx: TyCtxt<'tcx>, canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Normalize<PolyFnSig<'tcx>>>>, ) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, PolyFnSig<'tcx>>>, NoSolution> { |
