diff --git a/chalk-derive/src/lib.rs b/chalk-derive/src/lib.rs index 2b5dc846767..741944d89d8 100644 --- a/chalk-derive/src/lib.rs +++ b/chalk-derive/src/lib.rs @@ -177,14 +177,11 @@ fn derive_any_visit( s.bound_impl( quote!(::chalk_ir::visit:: #trait_name <#interner>), quote! { - fn #method_name <'i, B>( + fn #method_name ( &self, - visitor: &mut dyn ::chalk_ir::visit::Visitor < 'i, #interner, BreakTy = B >, + visitor: &mut dyn ::chalk_ir::visit::Visitor < #interner, BreakTy = B >, outer_binder: ::chalk_ir::DebruijnIndex, - ) -> std::ops::ControlFlow - where - #interner: 'i - { + ) -> std::ops::ControlFlow { match *self { #body } @@ -241,15 +238,12 @@ fn derive_zip(mut s: synstructure::Structure) -> TokenStream { quote!(::chalk_ir::zip::Zip<#interner>), quote! { - fn zip_with<'i, Z: ::chalk_ir::zip::Zipper<'i, #interner>>( + fn zip_with>( zipper: &mut Z, variance: ::chalk_ir::Variance, a: &Self, b: &Self, - ) -> ::chalk_ir::Fallible<()> - where - #interner: 'i, - { + ) -> ::chalk_ir::Fallible<()> { match (a, b) { #body } } }, @@ -299,14 +293,11 @@ fn derive_fold(mut s: synstructure::Structure) -> TokenStream { quote! { type Result = #result; - fn fold_with<'i, E>( + fn fold_with( self, - folder: &mut dyn ::chalk_ir::fold::Folder < 'i, #interner, Error = E >, + folder: &mut dyn ::chalk_ir::fold::Folder < #interner, Error = E >, outer_binder: ::chalk_ir::DebruijnIndex, - ) -> ::std::result::Result - where - #interner: 'i, - { + ) -> ::std::result::Result { Ok(match self { #body }) } }, diff --git a/chalk-engine/src/normalize_deep.rs b/chalk-engine/src/normalize_deep.rs index 20d2ed354d5..0c4a01ccbef 100644 --- a/chalk-engine/src/normalize_deep.rs +++ b/chalk-engine/src/normalize_deep.rs @@ -4,12 +4,12 @@ use chalk_ir::interner::Interner; use chalk_ir::*; use chalk_solve::infer::InferenceTable; -pub(crate) struct DeepNormalizer<'table, 'i, I: Interner> { +pub(crate) struct DeepNormalizer<'table, I: Interner> { table: &'table mut InferenceTable, - interner: &'i I, + interner: I, } -impl DeepNormalizer<'_, '_, I> { +impl DeepNormalizer<'_, I> { /// Given a value `value` with variables in it, replaces those variables /// with their instantiated values (if any). Uninstantiated variables are /// left as-is. @@ -23,7 +23,7 @@ impl DeepNormalizer<'_, '_, I> { /// variables. pub fn normalize_deep>( table: &mut InferenceTable, - interner: &I, + interner: I, value: T, ) -> T::Result { value @@ -35,13 +35,10 @@ impl DeepNormalizer<'_, '_, I> { } } -impl<'i, I: Interner> Folder<'i, I> for DeepNormalizer<'_, 'i, I> -where - I: 'i, -{ +impl Folder for DeepNormalizer<'_, I> { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder<'i, I, Error = Self::Error> { + fn as_dyn(&mut self) -> &mut dyn Folder { self } @@ -103,7 +100,7 @@ where true } - fn interner(&self) -> &'i I { + fn interner(&self) -> I { self.interner } } @@ -122,17 +119,17 @@ mod test { struct TestDatabase; impl UnificationDatabase for TestDatabase { fn fn_def_variance(&self, _fn_def_id: FnDefId) -> Variances { - Variances::from_iter(&ChalkIr, [Variance::Invariant; 20].iter().copied()) + Variances::from_iter(ChalkIr, [Variance::Invariant; 20].iter().copied()) } fn adt_variance(&self, _adt_id: AdtId) -> Variances { - Variances::from_iter(&ChalkIr, [Variance::Invariant; 20].iter().copied()) + Variances::from_iter(ChalkIr, [Variance::Invariant; 20].iter().copied()) } } #[test] fn infer() { - let interner = &ChalkIr; + let interner = ChalkIr; let mut table: InferenceTable = InferenceTable::new(); let environment0 = Environment::new(interner); let a = table.new_variable(U0).to_ty(interner); diff --git a/chalk-engine/src/slg.rs b/chalk-engine/src/slg.rs index 028ef8492ea..f3522e77765 100644 --- a/chalk-engine/src/slg.rs +++ b/chalk-engine/src/slg.rs @@ -91,7 +91,7 @@ pub trait ResolventOps { fn resolvent_clause( &mut self, ops: &dyn UnificationDatabase, - interner: &I, + interner: I, environment: &Environment, goal: &DomainGoal, subst: &Substitution, @@ -100,7 +100,7 @@ pub trait ResolventOps { fn apply_answer_subst( &mut self, - interner: &I, + interner: I, unification_database: &dyn UnificationDatabase, ex_clause: &mut ExClause, selected_goal: &InEnvironment>, @@ -110,11 +110,11 @@ pub trait ResolventOps { } trait SubstitutionExt { - fn may_invalidate(&self, interner: &I, subst: &Canonical>) -> bool; + fn may_invalidate(&self, interner: I, subst: &Canonical>) -> bool; } impl SubstitutionExt for Substitution { - fn may_invalidate(&self, interner: &I, subst: &Canonical>) -> bool { + fn may_invalidate(&self, interner: I, subst: &Canonical>) -> bool { self.iter(interner) .zip(subst.value.iter(interner)) .any(|(new, current)| MayInvalidate { interner }.aggregate_generic_args(new, current)) @@ -122,11 +122,11 @@ impl SubstitutionExt for Substitution { } // This is a struct in case we need to add state at any point like in AntiUnifier -struct MayInvalidate<'i, I> { - interner: &'i I, +struct MayInvalidate { + interner: I, } -impl MayInvalidate<'_, I> { +impl MayInvalidate { fn aggregate_generic_args(&mut self, new: &GenericArg, current: &GenericArg) -> bool { let interner = self.interner; match (new.data(interner), current.data(interner)) { diff --git a/chalk-engine/src/slg/aggregate.rs b/chalk-engine/src/slg/aggregate.rs index ffb79ec0477..c53d39c52d0 100644 --- a/chalk-engine/src/slg/aggregate.rs +++ b/chalk-engine/src/slg/aggregate.rs @@ -129,7 +129,7 @@ impl AggregateOps for SlgContextOps<'_, I> { /// u32` and the new answer is `?0 = i32`, then the guidance would /// become `?0 = ?X` (where `?X` is some fresh variable). fn merge_into_guidance( - interner: &I, + interner: I, root_goal: &Canonical>>, guidance: Canonical>, answer: &Canonical>, @@ -184,7 +184,7 @@ fn merge_into_guidance( infer.canonicalize(interner, aggr_subst).quantified } -fn is_trivial(interner: &I, subst: &Canonical>) -> bool { +fn is_trivial(interner: I, subst: &Canonical>) -> bool { // A subst is trivial if.. subst .value @@ -226,13 +226,13 @@ fn is_trivial(interner: &I, subst: &Canonical>) -> /// inference variables. /// /// [Anti-unification]: https://en.wikipedia.org/wiki/Anti-unification_(computer_science) -struct AntiUnifier<'infer, 'intern, I: Interner> { +struct AntiUnifier<'infer, I: Interner> { infer: &'infer mut InferenceTable, universe: UniverseIndex, - interner: &'intern I, + interner: I, } -impl AntiUnifier<'_, '_, I> { +impl AntiUnifier<'_, I> { fn aggregate_tys(&mut self, ty0: &Ty, ty1: &Ty) -> Ty { let interner = self.interner; match (ty0.kind(interner), ty1.kind(interner)) { @@ -587,7 +587,7 @@ mod test { let mut anti_unifier = AntiUnifier { infer: &mut infer, universe: UniverseIndex::root(), - interner: &ChalkIr, + interner: ChalkIr, }; let ty = anti_unifier.aggregate_tys( @@ -601,7 +601,7 @@ mod test { #[test] fn vec_i32_vs_vec_i32() { use chalk_integration::interner::ChalkIr; - let interner = &ChalkIr; + let interner = ChalkIr; let mut infer: InferenceTable = InferenceTable::new(); let mut anti_unifier = AntiUnifier { interner, @@ -620,7 +620,7 @@ mod test { #[test] fn vec_x_vs_vec_y() { use chalk_integration::interner::ChalkIr; - let interner = &ChalkIr; + let interner = ChalkIr; let mut infer: InferenceTable = InferenceTable::new(); let mut anti_unifier = AntiUnifier { interner, diff --git a/chalk-engine/src/slg/resolvent.rs b/chalk-engine/src/slg/resolvent.rs index 906f8879a95..5661497d344 100644 --- a/chalk-engine/src/slg/resolvent.rs +++ b/chalk-engine/src/slg/resolvent.rs @@ -59,7 +59,7 @@ impl ResolventOps for InferenceTable { fn resolvent_clause( &mut self, db: &dyn UnificationDatabase, - interner: &I, + interner: I, environment: &Environment, goal: &DomainGoal, subst: &Substitution, @@ -214,7 +214,7 @@ impl ResolventOps for InferenceTable { #[instrument(level = "debug", skip(self, interner))] fn apply_answer_subst( &mut self, - interner: &I, + interner: I, unification_database: &dyn UnificationDatabase, ex_clause: &mut ExClause, selected_goal: &InEnvironment>, @@ -276,13 +276,13 @@ struct AnswerSubstitutor<'t, I: Interner> { outer_binder: DebruijnIndex, ex_clause: &'t mut ExClause, - interner: &'t I, + interner: I, unification_database: &'t dyn UnificationDatabase, } impl AnswerSubstitutor<'_, I> { fn substitute>( - interner: &I, + interner: I, unification_database: &dyn UnificationDatabase, table: &mut InferenceTable, environment: &Environment, @@ -306,7 +306,7 @@ impl AnswerSubstitutor<'_, I> { fn unify_free_answer_var( &mut self, - interner: &I, + interner: I, db: &dyn UnificationDatabase, variance: Variance, answer_var: BoundVar, @@ -379,7 +379,7 @@ impl AnswerSubstitutor<'_, I> { } } -impl<'i, I: Interner> Zipper<'i, I> for AnswerSubstitutor<'i, I> { +impl<'i, I: Interner> Zipper for AnswerSubstitutor<'i, I> { fn zip_tys(&mut self, variance: Variance, answer: &Ty, pending: &Ty) -> Fallible<()> { let interner = self.interner; @@ -721,7 +721,7 @@ impl<'i, I: Interner> Zipper<'i, I> for AnswerSubstitutor<'i, I> { Ok(()) } - fn interner(&self) -> &'i I { + fn interner(&self) -> I { self.interner } diff --git a/chalk-engine/src/strand.rs b/chalk-engine/src/strand.rs index 46445797250..dfc75e94a6b 100644 --- a/chalk-engine/src/strand.rs +++ b/chalk-engine/src/strand.rs @@ -37,14 +37,11 @@ pub(crate) struct SelectedSubgoal { impl Fold for Strand { type Result = Strand; - fn fold_with<'i, E>( + fn fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i, - { + ) -> Result { Ok(Strand { ex_clause: self.ex_clause.fold_with(folder, outer_binder)?, last_pursued_time: self.last_pursued_time, diff --git a/chalk-integration/src/db.rs b/chalk-integration/src/db.rs index 262975b5654..765baeffa80 100644 --- a/chalk-integration/src/db.rs +++ b/chalk-integration/src/db.rs @@ -173,8 +173,8 @@ impl RustIrDatabase for ChalkDatabase { chalk_solve::program_clauses_for_env(self, environment) } - fn interner(&self) -> &ChalkIr { - &ChalkIr + fn interner(&self) -> ChalkIr { + ChalkIr } fn is_object_safe(&self, trait_id: TraitId) -> bool { diff --git a/chalk-integration/src/interner.rs b/chalk-integration/src/interner.rs index 41d485a8bf0..e99999c5c56 100644 --- a/chalk-integration/src/interner.rs +++ b/chalk-integration/src/interner.rs @@ -236,167 +236,167 @@ impl Interner for ChalkIr { tls::with_current_program(|prog| Some(prog?.debug_variances(variances, fmt))) } - fn intern_ty(&self, kind: TyKind) -> Arc> { + fn intern_ty(self, kind: TyKind) -> Arc> { let flags = kind.compute_flags(self); Arc::new(TyData { kind, flags }) } - fn ty_data<'a>(&self, ty: &'a Arc>) -> &'a TyData { + fn ty_data<'a>(self, ty: &'a Arc>) -> &'a TyData { ty } - fn intern_lifetime(&self, lifetime: LifetimeData) -> LifetimeData { + fn intern_lifetime(self, lifetime: LifetimeData) -> LifetimeData { lifetime } - fn lifetime_data<'a>(&self, lifetime: &'a LifetimeData) -> &'a LifetimeData { + fn lifetime_data<'a>(self, lifetime: &'a LifetimeData) -> &'a LifetimeData { lifetime } - fn intern_const(&self, constant: ConstData) -> Arc> { + fn intern_const(self, constant: ConstData) -> Arc> { Arc::new(constant) } - fn const_data<'a>(&self, constant: &'a Arc>) -> &'a ConstData { + fn const_data<'a>(self, constant: &'a Arc>) -> &'a ConstData { constant } - fn const_eq(&self, _ty: &Arc>, c1: &u32, c2: &u32) -> bool { + fn const_eq(self, _ty: &Arc>, c1: &u32, c2: &u32) -> bool { c1 == c2 } - fn intern_generic_arg(&self, generic_arg: GenericArgData) -> GenericArgData { + fn intern_generic_arg(self, generic_arg: GenericArgData) -> GenericArgData { generic_arg } fn generic_arg_data<'a>( - &self, + self, generic_arg: &'a GenericArgData, ) -> &'a GenericArgData { generic_arg } - fn intern_goal(&self, goal: GoalData) -> Arc> { + fn intern_goal(self, goal: GoalData) -> Arc> { Arc::new(goal) } - fn goal_data<'a>(&self, goal: &'a Arc>) -> &'a GoalData { + fn goal_data<'a>(self, goal: &'a Arc>) -> &'a GoalData { goal } fn intern_goals( - &self, + self, data: impl IntoIterator, E>>, ) -> Result>, E> { data.into_iter().collect() } - fn goals_data<'a>(&self, goals: &'a Vec>) -> &'a [Goal] { + fn goals_data<'a>(self, goals: &'a Vec>) -> &'a [Goal] { goals } fn intern_substitution( - &self, + self, data: impl IntoIterator, E>>, ) -> Result>, E> { data.into_iter().collect() } fn substitution_data<'a>( - &self, + self, substitution: &'a Vec>, ) -> &'a [GenericArg] { substitution } - fn intern_program_clause(&self, data: ProgramClauseData) -> ProgramClauseData { + fn intern_program_clause(self, data: ProgramClauseData) -> ProgramClauseData { data } fn program_clause_data<'a>( - &self, + self, clause: &'a ProgramClauseData, ) -> &'a ProgramClauseData { clause } fn intern_program_clauses( - &self, + self, data: impl IntoIterator, E>>, ) -> Result>, E> { data.into_iter().collect() } fn program_clauses_data<'a>( - &self, + self, clauses: &'a Vec>, ) -> &'a [ProgramClause] { clauses } fn intern_quantified_where_clauses( - &self, + self, data: impl IntoIterator, E>>, ) -> Result { data.into_iter().collect() } fn quantified_where_clauses_data<'a>( - &self, + self, clauses: &'a Self::InternedQuantifiedWhereClauses, ) -> &'a [QuantifiedWhereClause] { clauses } fn intern_generic_arg_kinds( - &self, + self, data: impl IntoIterator, E>>, ) -> Result { data.into_iter().collect() } fn variable_kinds_data<'a>( - &self, + self, variable_kinds: &'a Self::InternedVariableKinds, ) -> &'a [VariableKind] { variable_kinds } fn intern_canonical_var_kinds( - &self, + self, data: impl IntoIterator, E>>, ) -> Result { data.into_iter().collect() } fn canonical_var_kinds_data<'a>( - &self, + self, canonical_var_kinds: &'a Self::InternedCanonicalVarKinds, ) -> &'a [CanonicalVarKind] { canonical_var_kinds } fn intern_constraints( - &self, + self, data: impl IntoIterator>, E>>, ) -> Result { data.into_iter().collect() } fn constraints_data<'a>( - &self, + self, constraints: &'a Self::InternedConstraints, ) -> &'a [InEnvironment>] { constraints } fn intern_variances( - &self, + self, data: impl IntoIterator>, ) -> Result { data.into_iter().collect() } - fn variances_data<'a>(&self, variances: &'a Self::InternedVariances) -> &'a [Variance] { + fn variances_data<'a>(self, variances: &'a Self::InternedVariances) -> &'a [Variance] { variances } } diff --git a/chalk-integration/src/lowering.rs b/chalk-integration/src/lowering.rs index 86062afb00c..965f2e63e6e 100644 --- a/chalk-integration/src/lowering.rs +++ b/chalk-integration/src/lowering.rs @@ -108,7 +108,7 @@ lower_param_map!( ); fn get_type_of_usize() -> chalk_ir::Ty { - chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Uint(chalk_ir::UintTy::Usize)).intern(&ChalkIr) + chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Uint(chalk_ir::UintTy::Usize)).intern(ChalkIr) } impl Lower for VariableKind { @@ -1013,7 +1013,7 @@ impl LowerWithEnv for (&TraitDefn, chalk_ir::TraitId) { } pub fn lower_goal(goal: &Goal, program: &LoweredProgram) -> LowerResult> { - let interner = &ChalkIr; + let interner = ChalkIr; let associated_ty_lookups: BTreeMap<_, _> = program .associated_ty_data .iter() @@ -1154,7 +1154,7 @@ impl Kinded for chalk_ir::VariableKind { impl Kinded for chalk_ir::GenericArg { fn kind(&self) -> Kind { - let interner = &ChalkIr; + let interner = ChalkIr; match self.data(interner) { chalk_ir::GenericArgData::Ty(_) => Kind::Ty, chalk_ir::GenericArgData::Lifetime(_) => Kind::Lifetime, diff --git a/chalk-integration/src/lowering/env.rs b/chalk-integration/src/lowering/env.rs index 3a4e9b016bd..092baf17a64 100644 --- a/chalk-integration/src/lowering/env.rs +++ b/chalk-integration/src/lowering/env.rs @@ -87,8 +87,8 @@ pub enum TypeLookup<'k> { } impl Env<'_> { - pub fn interner(&self) -> &ChalkIr { - &ChalkIr + pub fn interner(&self) -> ChalkIr { + ChalkIr } pub fn lookup_generic_arg( diff --git a/chalk-integration/src/lowering/program_lowerer.rs b/chalk-integration/src/lowering/program_lowerer.rs index 1f39cd9bf27..b8c88cff140 100644 --- a/chalk-integration/src/lowering/program_lowerer.rs +++ b/chalk-integration/src/lowering/program_lowerer.rs @@ -243,16 +243,17 @@ impl ProgramLowerer { let (kind, inputs_and_output) = defn.lower(&empty_env)?; closure_closure_kind.insert(closure_def_id, kind); closure_inputs_and_output.insert(closure_def_id, inputs_and_output); - let upvars = empty_env.in_binders(defn.all_parameters(), |env| { - let upvar_tys: LowerResult>> = - defn.upvars.iter().map(|ty| ty.lower(&env)).collect(); - let substitution = chalk_ir::Substitution::from_iter( - &ChalkIr, - upvar_tys?.into_iter().map(|ty| ty.cast(&ChalkIr)), - ); - Ok(chalk_ir::TyKind::Tuple(defn.upvars.len(), substitution) - .intern(&ChalkIr)) - })?; + let upvars = + empty_env.in_binders(defn.all_parameters(), |env| { + let upvar_tys: LowerResult>> = + defn.upvars.iter().map(|ty| ty.lower(&env)).collect(); + let substitution = chalk_ir::Substitution::from_iter( + ChalkIr, + upvar_tys?.into_iter().map(|ty| ty.cast(ChalkIr)), + ); + Ok(chalk_ir::TyKind::Tuple(defn.upvars.len(), substitution) + .intern(ChalkIr)) + })?; closure_upvars.insert(closure_def_id, upvars); } Item::TraitDefn(ref trait_defn) => { @@ -516,7 +517,7 @@ macro_rules! lower_type_kind { sort: TypeSort::$sort, name: self.name.str.clone(), binders: chalk_ir::Binders::new( - VariableKinds::from_iter(&ChalkIr, $params(self).anonymize()), + VariableKinds::from_iter(ChalkIr, $params(self).anonymize()), crate::Unit, ), }) diff --git a/chalk-integration/src/program.rs b/chalk-integration/src/program.rs index a77d5d1915e..cc9d9e293e5 100644 --- a/chalk-integration/src/program.rs +++ b/chalk-integration/src/program.rs @@ -527,8 +527,8 @@ impl RustIrDatabase for Program { chalk_solve::program_clauses_for_env(self, environment) } - fn interner(&self) -> &ChalkIr { - &ChalkIr + fn interner(&self) -> ChalkIr { + ChalkIr } fn is_object_safe(&self, trait_id: TraitId) -> bool { diff --git a/chalk-integration/src/test_macros.rs b/chalk-integration/src/test_macros.rs index 8ac6934ec33..96bfeb0d61e 100644 --- a/chalk-integration/src/test_macros.rs +++ b/chalk-integration/src/test_macros.rs @@ -9,18 +9,18 @@ macro_rules! ty { }), chalk_ir::Substitution::from_iter( - &chalk_integration::interner::ChalkIr, + chalk_integration::interner::ChalkIr, vec![$(arg!($arg)),*] as Vec> ), ) - .intern(&chalk_integration::interner::ChalkIr) + .intern(chalk_integration::interner::ChalkIr) }; (function $n:tt $($arg:tt)*) => { chalk_ir::TyKind::Function(chalk_ir::FnPointer { num_binders: $n, substitution: chalk_ir::FnSubst(chalk_ir::Substitution::from_iter( - &chalk_integration::interner::ChalkIr, + chalk_integration::interner::ChalkIr, vec![$(arg!($arg)),*] as Vec> )), sig: chalk_ir::FnSig { @@ -28,39 +28,39 @@ macro_rules! ty { abi: ::FnAbi::Rust, variadic: false, } - }).intern(&chalk_integration::interner::ChalkIr) + }).intern(chalk_integration::interner::ChalkIr) }; (placeholder $n:expr) => { chalk_ir::TyKind::Placeholder(PlaceholderIndex { ui: UniverseIndex { counter: $n }, idx: 0, - }).intern(&chalk_integration::interner::ChalkIr) + }).intern(chalk_integration::interner::ChalkIr) }; (projection (item $n:tt) $($arg:tt)*) => { chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { associated_ty_id: AssocTypeId(chalk_integration::interner::RawId { index: $n }), substitution: chalk_ir::Substitution::from_iter( - &chalk_integration::interner::ChalkIr, + chalk_integration::interner::ChalkIr, vec![$(arg!($arg)),*] as Vec> ), - }).intern(&chalk_integration::interner::ChalkIr) + }).intern(chalk_integration::interner::ChalkIr) }; (infer $b:expr) => { chalk_ir::TyKind::InferenceVar(chalk_ir::InferenceVar::from($b), chalk_ir::TyVariableKind::General) - .intern(&chalk_integration::interner::ChalkIr) + .intern(chalk_integration::interner::ChalkIr) }; (bound $d:tt $b:tt) => { chalk_ir::TyKind::BoundVar(chalk_ir::BoundVar::new(chalk_ir::DebruijnIndex::new($d), $b)) - .intern(&chalk_integration::interner::ChalkIr) + .intern(chalk_integration::interner::ChalkIr) }; (bound $b:expr) => { chalk_ir::TyKind::BoundVar(chalk_ir::BoundVar::new(chalk_ir::DebruijnIndex::INNERMOST, $b)) - .intern(&chalk_integration::interner::ChalkIr) + .intern(chalk_integration::interner::ChalkIr) }; (expr $b:expr) => { @@ -76,14 +76,14 @@ macro_rules! ty { macro_rules! arg { ((lifetime $b:tt)) => { chalk_ir::GenericArg::new( - &chalk_integration::interner::ChalkIr, + chalk_integration::interner::ChalkIr, chalk_ir::GenericArgData::Lifetime(lifetime!($b)), ) }; ($arg:tt) => { chalk_ir::GenericArg::new( - &chalk_integration::interner::ChalkIr, + chalk_integration::interner::ChalkIr, chalk_ir::GenericArgData::Ty(ty!($arg)), ) }; @@ -93,22 +93,22 @@ macro_rules! arg { macro_rules! lifetime { (infer $b:expr) => { chalk_ir::LifetimeData::InferenceVar(chalk_ir::InferenceVar::from($b)) - .intern(&chalk_integration::interner::ChalkIr) + .intern(chalk_integration::interner::ChalkIr) }; (bound $d:tt $b:tt) => { chalk_ir::LifetimeData::BoundVar(chalk_ir::BoundVar::new(chalk_ir::DebruijnIndex::new($d), $b)) - .intern(&chalk_integration::interner::ChalkIr) + .intern(chalk_integration::interner::ChalkIr) }; (bound $b:expr) => { chalk_ir::LifetimeData::BoundVar(chalk_ir::BoundVar::new(chalk_ir::DebruijnIndex::INNERMOST, $b)) - .intern(&chalk_integration::interner::ChalkIr) + .intern(chalk_integration::interner::ChalkIr) }; (placeholder $b:expr) => { chalk_ir::LifetimeData::Placeholder(PlaceholderIndex { ui: UniverseIndex { counter: $b }, idx: 0}) - .intern(&chalk_integration::interner::ChalkIr) + .intern(chalk_integration::interner::ChalkIr) }; (expr $b:expr) => { @@ -123,6 +123,6 @@ macro_rules! lifetime { #[macro_export] macro_rules! empty_substitution { () => { - chalk_ir::Substitution::empty(&chalk_integration::interner::ChalkIr) + chalk_ir::Substitution::empty(chalk_integration::interner::ChalkIr) }; } diff --git a/chalk-ir/src/cast.rs b/chalk-ir/src/cast.rs index 801618f9893..0c6b682caf6 100644 --- a/chalk-ir/src/cast.rs +++ b/chalk-ir/src/cast.rs @@ -41,7 +41,7 @@ use std::marker::PhantomData; /// "cast to T". pub trait Cast: Sized { /// Cast a value to type `U` using `CastTo`. - fn cast(self, interner: &U::Interner) -> U + fn cast(self, interner: U::Interner) -> U where Self: CastTo, U: HasInterner, @@ -58,20 +58,20 @@ impl Cast for T {} /// like that. pub trait CastTo: Sized { /// Cast a value to type `T`. - fn cast_to(self, interner: &T::Interner) -> T; + fn cast_to(self, interner: T::Interner) -> T; } macro_rules! reflexive_impl { (for($($t:tt)*) $u:ty) => { impl<$($t)*> CastTo<$u> for $u { - fn cast_to(self, _interner: &<$u as HasInterner>::Interner) -> $u { + fn cast_to(self, _interner: <$u as HasInterner>::Interner) -> $u { self } } }; ($u:ty) => { impl CastTo<$u> for $u { - fn cast_to(self, interner: &<$u as HasInterner>::Interner) -> $u { + fn cast_to(self, interner: <$u as HasInterner>::Interner) -> $u { self } } @@ -94,25 +94,25 @@ reflexive_impl!(for(I: Interner) CanonicalVarKinds); reflexive_impl!(for(I: Interner) Constraint); impl CastTo> for TraitRef { - fn cast_to(self, _interner: &I) -> WhereClause { + fn cast_to(self, _interner: I) -> WhereClause { WhereClause::Implemented(self) } } impl CastTo> for AliasEq { - fn cast_to(self, _interner: &I) -> WhereClause { + fn cast_to(self, _interner: I) -> WhereClause { WhereClause::AliasEq(self) } } impl CastTo> for LifetimeOutlives { - fn cast_to(self, _interner: &I) -> WhereClause { + fn cast_to(self, _interner: I) -> WhereClause { WhereClause::LifetimeOutlives(self) } } impl CastTo> for TypeOutlives { - fn cast_to(self, _interner: &I) -> WhereClause { + fn cast_to(self, _interner: I) -> WhereClause { WhereClause::TypeOutlives(self) } } @@ -122,7 +122,7 @@ where T: CastTo>, I: Interner, { - fn cast_to(self, interner: &I) -> DomainGoal { + fn cast_to(self, interner: I) -> DomainGoal { DomainGoal::Holds(self.cast(interner)) } } @@ -131,43 +131,43 @@ impl CastTo> for T where T: CastTo>, { - fn cast_to(self, interner: &I) -> Goal { + fn cast_to(self, interner: I) -> Goal { GoalData::DomainGoal(self.cast(interner)).intern(interner) } } impl CastTo> for Normalize { - fn cast_to(self, _interner: &I) -> DomainGoal { + fn cast_to(self, _interner: I) -> DomainGoal { DomainGoal::Normalize(self) } } impl CastTo> for WellFormed { - fn cast_to(self, _interner: &I) -> DomainGoal { + fn cast_to(self, _interner: I) -> DomainGoal { DomainGoal::WellFormed(self) } } impl CastTo> for FromEnv { - fn cast_to(self, _interner: &I) -> DomainGoal { + fn cast_to(self, _interner: I) -> DomainGoal { DomainGoal::FromEnv(self) } } impl CastTo> for EqGoal { - fn cast_to(self, interner: &I) -> Goal { + fn cast_to(self, interner: I) -> Goal { GoalData::EqGoal(self).intern(interner) } } impl CastTo> for SubtypeGoal { - fn cast_to(self, interner: &I) -> Goal { + fn cast_to(self, interner: I) -> Goal { GoalData::SubtypeGoal(self).intern(interner) } } impl + CastTo>> CastTo> for Binders { - fn cast_to(self, interner: &I) -> Goal { + fn cast_to(self, interner: I) -> Goal { GoalData::Quantified( QuantifierKind::ForAll, self.map(|bound| bound.cast(interner)), @@ -177,31 +177,31 @@ impl + CastTo>> CastTo } impl CastTo> for AliasTy { - fn cast_to(self, _interner: &I) -> TyKind { + fn cast_to(self, _interner: I) -> TyKind { TyKind::Alias(self) } } impl CastTo> for Ty { - fn cast_to(self, interner: &I) -> GenericArg { + fn cast_to(self, interner: I) -> GenericArg { GenericArg::new(interner, GenericArgData::Ty(self)) } } impl CastTo> for Lifetime { - fn cast_to(self, interner: &I) -> GenericArg { + fn cast_to(self, interner: I) -> GenericArg { GenericArg::new(interner, GenericArgData::Lifetime(self)) } } impl CastTo> for Const { - fn cast_to(self, interner: &I) -> GenericArg { + fn cast_to(self, interner: I) -> GenericArg { GenericArg::new(interner, GenericArgData::Const(self)) } } impl CastTo> for GenericArg { - fn cast_to(self, _interner: &I) -> GenericArg { + fn cast_to(self, _interner: I) -> GenericArg { self } } @@ -211,7 +211,7 @@ where T: CastTo>, I: Interner, { - fn cast_to(self, interner: &I) -> ProgramClause { + fn cast_to(self, interner: I) -> ProgramClause { let implication = ProgramClauseImplication { consequence: self.cast(interner), conditions: Goals::empty(interner), @@ -229,7 +229,7 @@ where I: Interner, T: HasInterner + CastTo>, { - fn cast_to(self, interner: &I) -> ProgramClause { + fn cast_to(self, interner: I) -> ProgramClause { ProgramClauseData(self.map(|bound| ProgramClauseImplication { consequence: bound.cast(interner), conditions: Goals::empty(interner), @@ -245,7 +245,7 @@ where T: CastTo, U: HasInterner, { - fn cast_to(self, interner: &U::Interner) -> Option { + fn cast_to(self, interner: U::Interner) -> Option { self.map(|v| v.cast(interner)) } } @@ -256,7 +256,7 @@ where U: HasInterner, I: Interner, { - fn cast_to(self, interner: &U::Interner) -> InEnvironment { + fn cast_to(self, interner: U::Interner) -> InEnvironment { self.map(|v| v.cast(interner)) } } @@ -266,7 +266,7 @@ where T: CastTo, U: HasInterner, { - fn cast_to(self, interner: &U::Interner) -> Result { + fn cast_to(self, interner: U::Interner) -> Result { self.map(|v| v.cast(interner)) } } @@ -290,7 +290,7 @@ where T: CastTo + HasInterner, U: HasInterner, { - fn cast_to(self, interner: &T::Interner) -> Canonical { + fn cast_to(self, interner: T::Interner) -> Canonical { // Subtle point: It should be ok to re-use the binders here, // because `cast()` never introduces new inference variables, // nor changes the "substance" of the type we are working @@ -307,7 +307,7 @@ where T: CastTo + HasInterner, U: HasInterner, { - fn cast_to(self, interner: &U::Interner) -> Vec { + fn cast_to(self, interner: U::Interner) -> Vec { self.into_iter().casted(interner).collect() } } @@ -316,19 +316,19 @@ impl CastTo for &T where T: Clone + HasInterner, { - fn cast_to(self, _interner: &T::Interner) -> T { + fn cast_to(self, _interner: T::Interner) -> T { self.clone() } } /// An iterator that casts each element to some other type. -pub struct Casted<'i, IT, U: HasInterner> { - interner: &'i U::Interner, +pub struct Casted { + interner: U::Interner, iterator: IT, _cast: PhantomData, } -impl Iterator for Casted<'_, IT, U> +impl Iterator for Casted where IT::Item: CastTo, U: HasInterner, @@ -348,7 +348,7 @@ where /// to some other type. pub trait Caster: Iterator + Sized { /// Cast each element in this iterator. - fn casted(self, interner: &U::Interner) -> Casted<'_, Self, U> + fn casted(self, interner: U::Interner) -> Casted where Self::Item: CastTo, U: HasInterner, diff --git a/chalk-ir/src/could_match.rs b/chalk-ir/src/could_match.rs index e0da91e34e2..58071b90ce0 100644 --- a/chalk-ir/src/could_match.rs +++ b/chalk-ir/src/could_match.rs @@ -9,7 +9,7 @@ pub trait CouldMatch { /// Checks whether `self` and `other` could possibly match. fn could_match( &self, - interner: &T::Interner, + interner: T::Interner, db: &dyn UnificationDatabase, other: &T, ) -> bool; @@ -21,7 +21,7 @@ where T: Zip + ?Sized + HasInterner, I: Interner, { - fn could_match(&self, interner: &I, db: &dyn UnificationDatabase, other: &T) -> bool { + fn could_match(&self, interner: I, db: &dyn UnificationDatabase, other: &T) -> bool { return Zip::zip_with( &mut MatchZipper { interner, db }, Variance::Invariant, @@ -31,11 +31,11 @@ where .is_ok(); struct MatchZipper<'i, I> { - interner: &'i I, + interner: I, db: &'i dyn UnificationDatabase, } - impl<'i, I: Interner> Zipper<'i, I> for MatchZipper<'i, I> { + impl<'i, I: Interner> Zipper for MatchZipper<'i, I> { fn zip_tys(&mut self, variance: Variance, a: &Ty, b: &Ty) -> Fallible<()> { let interner = self.interner; let matches = |a: &Substitution, b: &Substitution| { @@ -179,7 +179,7 @@ where Zip::zip_with(self, variance, &a.value, &b.value) } - fn interner(&self) -> &'i I { + fn interner(&self) -> I { self.interner } @@ -193,7 +193,7 @@ where impl CouldMatch> for ProgramClauseData { fn could_match( &self, - interner: &I, + interner: I, db: &dyn UnificationDatabase, other: &DomainGoal, ) -> bool { @@ -204,7 +204,7 @@ impl CouldMatch> for ProgramClauseData { impl CouldMatch> for ProgramClause { fn could_match( &self, - interner: &I, + interner: I, db: &dyn UnificationDatabase, other: &DomainGoal, ) -> bool { diff --git a/chalk-ir/src/debug.rs b/chalk-ir/src/debug.rs index 4a13346d203..e4c5ab56a51 100644 --- a/chalk-ir/src/debug.rs +++ b/chalk-ir/src/debug.rs @@ -306,7 +306,7 @@ impl VariableKinds { } /// Helper method for debugging variable kinds. - pub fn inner_debug<'a>(&'a self, interner: &'a I) -> VariableKindsInnerDebug<'a, I> { + pub fn inner_debug<'a>(&'a self, interner: I) -> VariableKindsInnerDebug<'a, I> { VariableKindsInnerDebug { variable_kinds: self, interner, @@ -326,7 +326,7 @@ impl<'a, I: Interner> Debug for VariableKindsDebug<'a, I> { /// Helper struct for showing debug output for `VariableKinds`. pub struct VariableKindsInnerDebug<'a, I: Interner> { variable_kinds: &'a VariableKinds, - interner: &'a I, + interner: I, } impl<'a, I: Interner> Debug for VariableKindsInnerDebug<'a, I> { @@ -387,7 +387,7 @@ impl Debug for GoalData { /// Helper struct for showing debug output for `Goals`. pub struct GoalsDebug<'a, I: Interner> { goals: &'a Goals, - interner: &'a I, + interner: I, } impl<'a, I: Interner> Debug for GoalsDebug<'a, I> { @@ -406,7 +406,7 @@ impl<'a, I: Interner> Debug for GoalsDebug<'a, I> { impl Goals { /// Show debug output for `Goals`. - pub fn debug<'a>(&'a self, interner: &'a I) -> GoalsDebug<'a, I> { + pub fn debug<'a>(&'a self, interner: I) -> GoalsDebug<'a, I> { GoalsDebug { goals: self, interner, @@ -437,7 +437,7 @@ impl GenericArgData { /// Helper struct for showing debug output for program clause implications. pub struct ProgramClauseImplicationDebug<'a, I: Interner> { pci: &'a ProgramClauseImplication, - interner: &'a I, + interner: I, } impl<'a, I: Interner> Debug for ProgramClauseImplicationDebug<'a, I> { @@ -445,7 +445,7 @@ impl<'a, I: Interner> Debug for ProgramClauseImplicationDebug<'a, I> { let ProgramClauseImplicationDebug { pci, interner } = self; write!(fmt, "{:?}", pci.consequence)?; - let conditions = pci.conditions.as_slice(interner); + let conditions = pci.conditions.as_slice(*interner); let conds = conditions.len(); if conds == 0 { @@ -462,7 +462,7 @@ impl<'a, I: Interner> Debug for ProgramClauseImplicationDebug<'a, I> { impl ProgramClauseImplication { /// Show debug output for the program clause implication. - pub fn debug<'a>(&'a self, interner: &'a I) -> ProgramClauseImplicationDebug<'a, I> { + pub fn debug<'a>(&'a self, interner: I) -> ProgramClauseImplicationDebug<'a, I> { ProgramClauseImplicationDebug { pci: self, interner, @@ -473,7 +473,7 @@ impl ProgramClauseImplication { /// Helper struct for showing debug output for application types. pub struct TyKindDebug<'a, I: Interner> { ty: &'a TyKind, - interner: &'a I, + interner: I, } impl<'a, I: Interner> Debug for TyKindDebug<'a, I> { @@ -542,7 +542,7 @@ impl<'a, I: Interner> Debug for TyKindDebug<'a, I> { impl TyKind { /// Show debug output for the application type. - pub fn debug<'a>(&'a self, interner: &'a I) -> TyKindDebug<'a, I> { + pub fn debug<'a>(&'a self, interner: I) -> TyKindDebug<'a, I> { TyKindDebug { ty: self, interner } } } @@ -550,7 +550,7 @@ impl TyKind { /// Helper struct for showing debug output for substitutions. pub struct SubstitutionDebug<'a, I: Interner> { substitution: &'a Substitution, - interner: &'a I, + interner: I, } impl<'a, I: Interner> Debug for SubstitutionDebug<'a, I> { @@ -563,7 +563,7 @@ impl<'a, I: Interner> Debug for SubstitutionDebug<'a, I> { write!(fmt, "[")?; - for (index, value) in substitution.iter(interner).enumerate() { + for (index, value) in substitution.iter(*interner).enumerate() { if first { first = false; } else { @@ -581,7 +581,7 @@ impl<'a, I: Interner> Debug for SubstitutionDebug<'a, I> { impl Substitution { /// Show debug output for the substitution. - pub fn debug<'a>(&'a self, interner: &'a I) -> SubstitutionDebug<'a, I> { + pub fn debug<'a>(&'a self, interner: I) -> SubstitutionDebug<'a, I> { SubstitutionDebug { substitution: self, interner, @@ -632,7 +632,7 @@ pub struct SeparatorTraitRef<'me, I: Interner> { /// Helper struct for showing debug output for the `SeperatorTraitRef`. pub struct SeparatorTraitRefDebug<'a, 'me, I: Interner> { separator_trait_ref: &'a SeparatorTraitRef<'me, I>, - interner: &'a I, + interner: I, } impl<'a, 'me, I: Interner> Debug for SeparatorTraitRefDebug<'a, 'me, I> { @@ -644,7 +644,7 @@ impl<'a, 'me, I: Interner> Debug for SeparatorTraitRefDebug<'a, 'me, I> { let parameters = separator_trait_ref .trait_ref .substitution - .as_slice(interner); + .as_slice(*interner); write!( fmt, "{:?}{}{:?}{:?}", @@ -658,7 +658,7 @@ impl<'a, 'me, I: Interner> Debug for SeparatorTraitRefDebug<'a, 'me, I> { impl<'me, I: Interner> SeparatorTraitRef<'me, I> { /// Show debug output for the `SeperatorTraitRef`. - pub fn debug<'a>(&'a self, interner: &'a I) -> SeparatorTraitRefDebug<'a, 'me, I> { + pub fn debug<'a>(&'a self, interner: I) -> SeparatorTraitRefDebug<'a, 'me, I> { SeparatorTraitRefDebug { separator_trait_ref: self, interner, @@ -681,7 +681,7 @@ impl Debug for TypeOutlives { /// Helper struct for showing debug output for projection types. pub struct ProjectionTyDebug<'a, I: Interner> { projection_ty: &'a ProjectionTy, - interner: &'a I, + interner: I, } impl<'a, I: Interner> Debug for ProjectionTyDebug<'a, I> { @@ -694,14 +694,14 @@ impl<'a, I: Interner> Debug for ProjectionTyDebug<'a, I> { fmt, "({:?}){:?}", projection_ty.associated_ty_id, - projection_ty.substitution.with_angle(interner) + projection_ty.substitution.with_angle(*interner) ) } } impl ProjectionTy { /// Show debug output for the projection type. - pub fn debug<'a>(&'a self, interner: &'a I) -> ProjectionTyDebug<'a, I> { + pub fn debug<'a>(&'a self, interner: I) -> ProjectionTyDebug<'a, I> { ProjectionTyDebug { projection_ty: self, interner, @@ -712,7 +712,7 @@ impl ProjectionTy { /// Helper struct for showing debug output for opaque types. pub struct OpaqueTyDebug<'a, I: Interner> { opaque_ty: &'a OpaqueTy, - interner: &'a I, + interner: I, } impl<'a, I: Interner> Debug for OpaqueTyDebug<'a, I> { @@ -725,14 +725,14 @@ impl<'a, I: Interner> Debug for OpaqueTyDebug<'a, I> { fmt, "{:?}{:?}", opaque_ty.opaque_ty_id, - opaque_ty.substitution.with_angle(interner) + opaque_ty.substitution.with_angle(*interner) ) } } impl OpaqueTy { /// Show debug output for the opaque type. - pub fn debug<'a>(&'a self, interner: &'a I) -> OpaqueTyDebug<'a, I> { + pub fn debug<'a>(&'a self, interner: I) -> OpaqueTyDebug<'a, I> { OpaqueTyDebug { opaque_ty: self, interner, @@ -866,7 +866,7 @@ impl Debug for CanonicalVarKinds { impl Canonical { /// Display the canonicalized item. - pub fn display<'a>(&'a self, interner: &'a T::Interner) -> CanonicalDisplay<'a, T> { + pub fn display<'a>(&'a self, interner: T::Interner) -> CanonicalDisplay<'a, T> { CanonicalDisplay { canonical: self, interner, @@ -877,7 +877,7 @@ impl Canonical { /// Helper struct for displaying canonicalized items. pub struct CanonicalDisplay<'a, T: HasInterner> { canonical: &'a Canonical, - interner: &'a T::Interner, + interner: T::Interner, } impl<'a, T: HasInterner + Display> Display for CanonicalDisplay<'a, T> { @@ -973,7 +973,7 @@ impl Display for ConstrainedSubst { impl Substitution { /// Displays the substitution in the form `< P0, .. Pn >`, or (if /// the substitution is empty) as an empty string. - pub fn with_angle(&self, interner: &I) -> Angle<'_, GenericArg> { + pub fn with_angle(&self, interner: I) -> Angle<'_, GenericArg> { Angle(self.as_slice(interner)) } } diff --git a/chalk-ir/src/fold.rs b/chalk-ir/src/fold.rs index c8e508681bd..9b1eea3e7d7 100644 --- a/chalk-ir/src/fold.rs +++ b/chalk-ir/src/fold.rs @@ -54,10 +54,7 @@ pub use self::subst::Subst; /// ```rust,ignore /// let x = x.fold_with(&mut folder, 0); /// ``` -pub trait Folder<'i, I: Interner> -where - I: 'i, -{ +pub trait Folder { /// The type this folder returns when folding fails. This is /// commonly [`NoSolution`]. type Error; @@ -69,7 +66,7 @@ where /// method). Effectively, this limits impls of `Folder` to types /// for which we are able to create a dyn value (i.e., not `[T]` /// types). - fn as_dyn(&mut self) -> &mut dyn Folder<'i, I, Error = Self::Error>; + fn as_dyn(&mut self) -> &mut dyn Folder; /// Top-level callback: invoked for each `Ty` that is /// encountered when folding. By default, invokes @@ -305,7 +302,7 @@ where } /// Gets the interner that is being folded from. - fn interner(&self) -> &'i I; + fn interner(&self) -> I; } /// Applies the given `Folder` to a value, producing a folded result @@ -326,13 +323,11 @@ pub trait Fold: Debug { /// folder. Typically `binders` starts as 0, but is adjusted when /// we encounter `Binders` in the IR or other similar /// constructs. - fn fold_with<'i, E>( + fn fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i; + ) -> Result; } /// For types where "fold" invokes a callback on the `Folder`, the @@ -340,13 +335,11 @@ pub trait Fold: Debug { /// the contents of the type. pub trait SuperFold: Fold { /// Recursively folds the value. - fn super_fold_with<'i, E>( + fn super_fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i; + ) -> Result; } /// "Folding" a type invokes the `fold_ty` method on the folder; this @@ -355,14 +348,11 @@ pub trait SuperFold: Fold { impl Fold for Ty { type Result = Ty; - fn fold_with<'i, E>( + fn fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i, - { + ) -> Result { folder.fold_ty(self, outer_binder) } } @@ -372,14 +362,11 @@ impl SuperFold for Ty where I: Interner, { - fn super_fold_with<'i, E>( + fn super_fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result, E> - where - I: 'i, - { + ) -> Result, E> { let interner = folder.interner(); Ok(match self.kind(interner) { TyKind::BoundVar(bound_var) => { @@ -485,14 +472,11 @@ where impl Fold for Lifetime { type Result = Lifetime; - fn fold_with<'i, E>( + fn fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i, - { + ) -> Result { folder.fold_lifetime(self, outer_binder) } } @@ -501,14 +485,11 @@ impl SuperFold for Lifetime where I: Interner, { - fn super_fold_with<'i, E>( + fn super_fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result, E> - where - I: 'i, - { + ) -> Result, E> { let interner = folder.interner(); match self.data(interner) { LifetimeData::BoundVar(bound_var) => { @@ -543,14 +524,11 @@ where impl Fold for Const { type Result = Const; - fn fold_with<'i, E>( + fn fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i, - { + ) -> Result { folder.fold_const(self, outer_binder) } } @@ -559,14 +537,11 @@ impl SuperFold for Const where I: Interner, { - fn super_fold_with<'i, E>( + fn super_fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result, E> - where - I: 'i, - { + ) -> Result, E> { let interner = folder.interner(); let ConstData { ref ty, ref value } = self.data(interner); let mut fold_ty = || ty.clone().fold_with(folder, outer_binder); @@ -600,28 +575,22 @@ where impl Fold for Goal { type Result = Goal; - fn fold_with<'i, E>( + fn fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i, - { + ) -> Result { folder.fold_goal(self, outer_binder) } } /// Superfold folds recursively. impl SuperFold for Goal { - fn super_fold_with<'i, E>( + fn super_fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i, - { + ) -> Result { let interner = folder.interner(); Ok(Goal::new( interner, @@ -638,14 +607,11 @@ impl SuperFold for Goal { impl Fold for ProgramClause { type Result = ProgramClause; - fn fold_with<'i, E>( + fn fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i, - { + ) -> Result { folder.fold_program_clause(self, outer_binder) } } diff --git a/chalk-ir/src/fold/binder_impls.rs b/chalk-ir/src/fold/binder_impls.rs index 641f54a24aa..baa91249974 100644 --- a/chalk-ir/src/fold/binder_impls.rs +++ b/chalk-ir/src/fold/binder_impls.rs @@ -7,14 +7,11 @@ use crate::*; impl Fold for FnPointer { type Result = FnPointer; - fn fold_with<'i, E>( + fn fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i, - { + ) -> Result { let FnPointer { num_binders, substitution, @@ -39,14 +36,11 @@ where I: Interner, { type Result = Binders; - fn fold_with<'i, E>( + fn fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i, - { + ) -> Result { let Binders { binders: self_binders, value: self_value, @@ -66,14 +60,11 @@ where >::Result: HasInterner, { type Result = Canonical; - fn fold_with<'i, E>( + fn fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i, - { + ) -> Result { let Canonical { binders: self_binders, value: self_value, diff --git a/chalk-ir/src/fold/boring_impls.rs b/chalk-ir/src/fold/boring_impls.rs index 77a9027ca34..4eb13c1b337 100644 --- a/chalk-ir/src/fold/boring_impls.rs +++ b/chalk-ir/src/fold/boring_impls.rs @@ -10,28 +10,22 @@ use std::marker::PhantomData; impl, I: Interner> Fold for Vec { type Result = Vec; - fn fold_with<'i, E>( + fn fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i, - { + ) -> Result { in_place::fallible_map_vec(self, |e| e.fold_with(folder, outer_binder)) } } impl, I: Interner> Fold for Box { type Result = Box; - fn fold_with<'i, E>( + fn fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i, - { + ) -> Result { in_place::fallible_map_box(self, |e| e.fold_with(folder, outer_binder)) } } @@ -40,9 +34,7 @@ macro_rules! tuple_fold { ($($n:ident),*) => { impl<$($n: Fold,)* I: Interner> Fold for ($($n,)*) { type Result = ($($n::Result,)*); - fn fold_with<'i, Error>(self, folder: &mut dyn Folder<'i, I, Error = Error>, outer_binder: DebruijnIndex) -> Result - where - I: 'i, + fn fold_with(self, folder: &mut dyn Folder, outer_binder: DebruijnIndex) -> Result { #[allow(non_snake_case)] let ($($n),*) = self; @@ -59,14 +51,11 @@ tuple_fold!(A, B, C, D, E); impl, I: Interner> Fold for Option { type Result = Option; - fn fold_with<'i, E>( + fn fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i, - { + ) -> Result { match self { None => Ok(None), Some(e) => Ok(Some(e.fold_with(folder, outer_binder)?)), @@ -76,14 +65,11 @@ impl, I: Interner> Fold for Option { impl Fold for GenericArg { type Result = GenericArg; - fn fold_with<'i, E>( + fn fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i, - { + ) -> Result { let interner = folder.interner(); let data = self @@ -96,14 +82,11 @@ impl Fold for GenericArg { impl Fold for Substitution { type Result = Substitution; - fn fold_with<'i, E>( + fn fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i, - { + ) -> Result { let interner = folder.interner(); let folded = self @@ -116,14 +99,11 @@ impl Fold for Substitution { impl Fold for Goals { type Result = Goals; - fn fold_with<'i, E>( + fn fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i, - { + ) -> Result { let interner = folder.interner(); let folded = self .iter(interner) @@ -135,14 +115,11 @@ impl Fold for Goals { impl Fold for ProgramClauses { type Result = ProgramClauses; - fn fold_with<'i, E>( + fn fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i, - { + ) -> Result { let interner = folder.interner(); let folded = self .iter(interner) @@ -154,14 +131,11 @@ impl Fold for ProgramClauses { impl Fold for QuantifiedWhereClauses { type Result = QuantifiedWhereClauses; - fn fold_with<'i, E>( + fn fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i, - { + ) -> Result { let interner = folder.interner(); let folded = self .iter(interner) @@ -173,14 +147,11 @@ impl Fold for QuantifiedWhereClauses { impl Fold for Constraints { type Result = Constraints; - fn fold_with<'i, E>( + fn fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> Result - where - I: 'i, - { + ) -> Result { let interner = folder.interner(); let folded = self .iter(interner) @@ -196,14 +167,11 @@ macro_rules! copy_fold { ($t:ty) => { impl $crate::fold::Fold for $t { type Result = Self; - fn fold_with<'i, E>( + fn fold_with( self, - _folder: &mut dyn ($crate::fold::Folder<'i, I, Error = E>), + _folder: &mut dyn ($crate::fold::Folder), _outer_binder: DebruijnIndex, - ) -> ::std::result::Result - where - I: 'i, - { + ) -> ::std::result::Result { Ok(self) } } @@ -231,14 +199,11 @@ macro_rules! id_fold { ($t:ident) => { impl $crate::fold::Fold for $t { type Result = $t; - fn fold_with<'i, E>( + fn fold_with( self, - _folder: &mut dyn ($crate::fold::Folder<'i, I, Error = E>), + _folder: &mut dyn ($crate::fold::Folder), _outer_binder: DebruijnIndex, - ) -> ::std::result::Result - where - I: 'i, - { + ) -> ::std::result::Result { Ok(self) } } @@ -256,27 +221,21 @@ id_fold!(GeneratorId); id_fold!(ForeignDefId); impl SuperFold for ProgramClauseData { - fn super_fold_with<'i, E>( + fn super_fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> ::std::result::Result - where - I: 'i, - { + ) -> ::std::result::Result { Ok(ProgramClauseData(self.0.fold_with(folder, outer_binder)?)) } } impl SuperFold for ProgramClause { - fn super_fold_with<'i, E>( + fn super_fold_with( self, - folder: &mut dyn Folder<'i, I, Error = E>, + folder: &mut dyn Folder, outer_binder: DebruijnIndex, - ) -> ::std::result::Result - where - I: 'i, - { + ) -> ::std::result::Result { let clause = self.data(folder.interner()).clone(); Ok(clause .super_fold_with(folder, outer_binder)? @@ -287,14 +246,11 @@ impl SuperFold for ProgramClause { impl Fold for PhantomData { type Result = PhantomData; - fn fold_with<'i, E>( + fn fold_with( self, - _folder: &mut dyn Folder<'i, I, Error = E>, + _folder: &mut dyn Folder, _outer_binder: DebruijnIndex, - ) -> ::std::result::Result - where - I: 'i, - { + ) -> ::std::result::Result { Ok(PhantomData) } } diff --git a/chalk-ir/src/fold/shift.rs b/chalk-ir/src/fold/shift.rs index fabfb8cf3b5..2ea957b289a 100644 --- a/chalk-ir/src/fold/shift.rs +++ b/chalk-ir/src/fold/shift.rs @@ -7,28 +7,28 @@ use crate::*; /// of binders. pub trait Shift: Fold { /// Shifts this term in one level of binders. - fn shifted_in(self, interner: &I) -> Self::Result; + fn shifted_in(self, interner: I) -> Self::Result; /// Shifts a term valid at `outer_binder` so that it is /// valid at the innermost binder. See [`DebruijnIndex::shifted_in_from`] /// for a detailed explanation. - fn shifted_in_from(self, interner: &I, source_binder: DebruijnIndex) -> Self::Result; + fn shifted_in_from(self, interner: I, source_binder: DebruijnIndex) -> Self::Result; /// Shifts this term out one level of binders. - fn shifted_out(self, interner: &I) -> Fallible; + fn shifted_out(self, interner: I) -> Fallible; /// Shifts a term valid at the innermost binder so that it is /// valid at `outer_binder`. See [`DebruijnIndex::shifted_out_to`] /// for a detailed explanation. - fn shifted_out_to(self, interner: &I, target_binder: DebruijnIndex) -> Fallible; + fn shifted_out_to(self, interner: I, target_binder: DebruijnIndex) -> Fallible; } impl, I: Interner> Shift for T { - fn shifted_in(self, interner: &I) -> Self::Result { + fn shifted_in(self, interner: I) -> Self::Result { self.shifted_in_from(interner, DebruijnIndex::ONE) } - fn shifted_in_from(self, interner: &I, source_binder: DebruijnIndex) -> T::Result { + fn shifted_in_from(self, interner: I, source_binder: DebruijnIndex) -> T::Result { self.fold_with( &mut Shifter { source_binder, @@ -39,7 +39,7 @@ impl, I: Interner> Shift for T { .unwrap() } - fn shifted_out_to(self, interner: &I, target_binder: DebruijnIndex) -> Fallible { + fn shifted_out_to(self, interner: I, target_binder: DebruijnIndex) -> Fallible { self.fold_with( &mut DownShifter { target_binder, @@ -49,18 +49,18 @@ impl, I: Interner> Shift for T { ) } - fn shifted_out(self, interner: &I) -> Fallible { + fn shifted_out(self, interner: I) -> Fallible { self.shifted_out_to(interner, DebruijnIndex::ONE) } } /// A folder that adjusts debruijn indices by a certain amount. -struct Shifter<'i, I> { +struct Shifter { source_binder: DebruijnIndex, - interner: &'i I, + interner: I, } -impl Shifter<'_, I> { +impl Shifter { /// Given a free variable at `depth`, shifts that depth to `depth /// + self.adjustment`, and then wraps *that* within the internal /// set `binders`. @@ -71,10 +71,10 @@ impl Shifter<'_, I> { } } -impl<'i, I: Interner> Folder<'i, I> for Shifter<'i, I> { +impl Folder for Shifter { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder<'i, I, Error = Self::Error> { + fn as_dyn(&mut self) -> &mut dyn Folder { self } @@ -109,7 +109,7 @@ impl<'i, I: Interner> Folder<'i, I> for Shifter<'i, I> { .to_const(self.interner(), ty)) } - fn interner(&self) -> &'i I { + fn interner(&self) -> I { self.interner } } @@ -119,12 +119,12 @@ impl<'i, I: Interner> Folder<'i, I> for Shifter<'i, I> { /// A shifter that reduces debruijn indices -- in other words, which lifts a value /// *out* from binders. Consider this example: /// -struct DownShifter<'i, I> { +struct DownShifter { target_binder: DebruijnIndex, - interner: &'i I, + interner: I, } -impl DownShifter<'_, I> { +impl DownShifter { /// Given a reference to a free variable at depth `depth` /// (appearing within `binders` internal binders), attempts to /// lift that free variable out from `adjustment` levels of @@ -141,10 +141,10 @@ impl DownShifter<'_, I> { } } -impl<'i, I: Interner> Folder<'i, I> for DownShifter<'i, I> { +impl Folder for DownShifter { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder<'i, I, Error = Self::Error> { + fn as_dyn(&mut self) -> &mut dyn Folder { self } @@ -179,7 +179,7 @@ impl<'i, I: Interner> Folder<'i, I> for DownShifter<'i, I> { .to_const(self.interner(), ty)) } - fn interner(&self) -> &'i I { + fn interner(&self) -> I { self.interner } } diff --git a/chalk-ir/src/fold/subst.rs b/chalk-ir/src/fold/subst.rs index 0205e99c33b..f7a0b2d69bb 100644 --- a/chalk-ir/src/fold/subst.rs +++ b/chalk-ir/src/fold/subst.rs @@ -2,17 +2,17 @@ use super::*; use crate::fold::shift::Shift; /// Substitution used during folding -pub struct Subst<'s, 'i, I: Interner> { +pub struct Subst<'s, I: Interner> { /// Values to substitute. A reference to a free variable with /// index `i` will be mapped to `parameters[i]` -- if `i > /// parameters.len()`, then we will leave the variable untouched. parameters: &'s [GenericArg], - interner: &'i I, + interner: I, } -impl Subst<'_, '_, I> { +impl Subst<'_, I> { /// Applies the substitution by folding - pub fn apply>(interner: &I, parameters: &[GenericArg], value: T) -> T::Result { + pub fn apply>(interner: I, parameters: &[GenericArg], value: T) -> T::Result { value .fold_with( &mut Subst { @@ -25,10 +25,10 @@ impl Subst<'_, '_, I> { } } -impl<'i, I: Interner> Folder<'i, I> for Subst<'_, 'i, I> { +impl Folder for Subst<'_, I> { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder<'i, I, Error = Self::Error> { + fn as_dyn(&mut self) -> &mut dyn Folder { self } @@ -117,7 +117,7 @@ impl<'i, I: Interner> Folder<'i, I> for Subst<'_, 'i, I> { } } - fn interner(&self) -> &'i I { + fn interner(&self) -> I { self.interner } } diff --git a/chalk-ir/src/interner.rs b/chalk-ir/src/interner.rs index 325640499c6..7c80faf8cf1 100644 --- a/chalk-ir/src/interner.rs +++ b/chalk-ir/src/interner.rs @@ -57,7 +57,7 @@ use std::sync::Arc; /// (e.g., `SourceI` and `TargetI`) -- even if those type parameters /// wind up being mapped to the same underlying type families in the /// end. -pub trait Interner: Debug + Copy + Eq + Ord + Hash { +pub trait Interner: Debug + Copy + Eq + Ord + Hash + Sized { /// "Interned" representation of types. In normal user code, /// `Self::InternedType` is not referenced. Instead, we refer to /// `Ty`, which wraps this type. @@ -470,32 +470,32 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash { /// Create an "interned" type from `ty`. This is not normally /// invoked directly; instead, you invoke `TyKind::intern` (which /// will ultimately call this method). - fn intern_ty(&self, kind: TyKind) -> Self::InternedType; + fn intern_ty(self, kind: TyKind) -> Self::InternedType; /// Lookup the `TyKind` from an interned type. - fn ty_data<'a>(&self, ty: &'a Self::InternedType) -> &'a TyData; + fn ty_data<'a>(self, ty: &'a Self::InternedType) -> &'a TyData; /// Create an "interned" lifetime from `lifetime`. This is not /// normally invoked directly; instead, you invoke /// `LifetimeData::intern` (which will ultimately call this /// method). - fn intern_lifetime(&self, lifetime: LifetimeData) -> Self::InternedLifetime; + fn intern_lifetime(self, lifetime: LifetimeData) -> Self::InternedLifetime; /// Lookup the `LifetimeData` that was interned to create a `InternedLifetime`. - fn lifetime_data<'a>(&self, lifetime: &'a Self::InternedLifetime) -> &'a LifetimeData; + fn lifetime_data<'a>(self, lifetime: &'a Self::InternedLifetime) -> &'a LifetimeData; /// Create an "interned" const from `const`. This is not /// normally invoked directly; instead, you invoke /// `ConstData::intern` (which will ultimately call this /// method). - fn intern_const(&self, constant: ConstData) -> Self::InternedConst; + fn intern_const(self, constant: ConstData) -> Self::InternedConst; /// Lookup the `ConstData` that was interned to create a `InternedConst`. - fn const_data<'a>(&self, constant: &'a Self::InternedConst) -> &'a ConstData; + fn const_data<'a>(self, constant: &'a Self::InternedConst) -> &'a ConstData; /// Determine whether two concrete const values are equal. fn const_eq( - &self, + self, ty: &Self::InternedType, c1: &Self::InternedConcreteConst, c2: &Self::InternedConcreteConst, @@ -505,11 +505,11 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash { /// normally invoked directly; instead, you invoke /// `GenericArgData::intern` (which will ultimately call this /// method). - fn intern_generic_arg(&self, data: GenericArgData) -> Self::InternedGenericArg; + fn intern_generic_arg(self, data: GenericArgData) -> Self::InternedGenericArg; /// Lookup the `LifetimeData` that was interned to create a `InternedLifetime`. fn generic_arg_data<'a>( - &self, + self, lifetime: &'a Self::InternedGenericArg, ) -> &'a GenericArgData; @@ -517,35 +517,35 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash { /// normally invoked directly; instead, you invoke /// `GoalData::intern` (which will ultimately call this /// method). - fn intern_goal(&self, data: GoalData) -> Self::InternedGoal; + fn intern_goal(self, data: GoalData) -> Self::InternedGoal; /// Lookup the `GoalData` that was interned to create a `InternedGoal`. - fn goal_data<'a>(&self, goal: &'a Self::InternedGoal) -> &'a GoalData; + fn goal_data<'a>(self, goal: &'a Self::InternedGoal) -> &'a GoalData; /// Create an "interned" goals from `data`. This is not /// normally invoked directly; instead, you invoke /// `GoalsData::intern` (which will ultimately call this /// method). fn intern_goals( - &self, + self, data: impl IntoIterator, E>>, ) -> Result; /// Lookup the `GoalsData` that was interned to create a `InternedGoals`. - fn goals_data<'a>(&self, goals: &'a Self::InternedGoals) -> &'a [Goal]; + fn goals_data<'a>(self, goals: &'a Self::InternedGoals) -> &'a [Goal]; /// Create an "interned" substitution from `data`. This is not /// normally invoked directly; instead, you invoke /// `SubstitutionData::intern` (which will ultimately call this /// method). fn intern_substitution( - &self, + self, data: impl IntoIterator, E>>, ) -> Result; /// Lookup the `SubstitutionData` that was interned to create a `InternedSubstitution`. fn substitution_data<'a>( - &self, + self, substitution: &'a Self::InternedSubstitution, ) -> &'a [GenericArg]; @@ -553,11 +553,11 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash { /// normally invoked directly; instead, you invoke /// `ProgramClauseData::intern` (which will ultimately call this /// method). - fn intern_program_clause(&self, data: ProgramClauseData) -> Self::InternedProgramClause; + fn intern_program_clause(self, data: ProgramClauseData) -> Self::InternedProgramClause; /// Lookup the `ProgramClauseData` that was interned to create a `ProgramClause`. fn program_clause_data<'a>( - &self, + self, clause: &'a Self::InternedProgramClause, ) -> &'a ProgramClauseData; @@ -566,13 +566,13 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash { /// `ProgramClauses::from_iter` (which will ultimately call this /// method). fn intern_program_clauses( - &self, + self, data: impl IntoIterator, E>>, ) -> Result; /// Lookup the `ProgramClauseData` that was interned to create a `ProgramClause`. fn program_clauses_data<'a>( - &self, + self, clauses: &'a Self::InternedProgramClauses, ) -> &'a [ProgramClause]; @@ -581,14 +581,14 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash { /// `QuantifiedWhereClauses::from_iter` (which will ultimately call this /// method). fn intern_quantified_where_clauses( - &self, + self, data: impl IntoIterator, E>>, ) -> Result; /// Lookup the slice of `QuantifiedWhereClause` that was interned to /// create a `QuantifiedWhereClauses`. fn quantified_where_clauses_data<'a>( - &self, + self, clauses: &'a Self::InternedQuantifiedWhereClauses, ) -> &'a [QuantifiedWhereClause]; @@ -597,14 +597,14 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash { /// `VariableKinds::from_iter` (which will ultimately call this /// method). fn intern_generic_arg_kinds( - &self, + self, data: impl IntoIterator, E>>, ) -> Result; /// Lookup the slice of `VariableKinds` that was interned to /// create a `VariableKinds`. fn variable_kinds_data<'a>( - &self, + self, variable_kinds: &'a Self::InternedVariableKinds, ) -> &'a [VariableKind]; @@ -613,14 +613,14 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash { /// `CanonicalVarKinds::from_iter` (which will ultimately call this /// method). fn intern_canonical_var_kinds( - &self, + self, data: impl IntoIterator, E>>, ) -> Result; /// Lookup the slice of `CanonicalVariableKind` that was interned to /// create a `CanonicalVariableKinds`. fn canonical_var_kinds_data<'a>( - &self, + self, canonical_var_kinds: &'a Self::InternedCanonicalVarKinds, ) -> &'a [CanonicalVarKind]; @@ -629,14 +629,14 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash { /// `Constraints::from_iter` (which will ultimately call this /// method). fn intern_constraints( - &self, + self, data: impl IntoIterator>, E>>, ) -> Result; /// Lookup the slice of `Constraint` that was interned to /// create a `Constraints`. fn constraints_data<'a>( - &self, + self, constraints: &'a Self::InternedConstraints, ) -> &'a [InEnvironment>]; @@ -645,13 +645,13 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash { /// `Variances::from` (which will ultimately call this /// method). fn intern_variances( - &self, + self, data: impl IntoIterator>, ) -> Result; /// Lookup the slice of `Variance` that was interned to /// create a `Variances`. - fn variances_data<'a>(&self, variances: &'a Self::InternedVariances) -> &'a [Variance]; + fn variances_data<'a>(self, variances: &'a Self::InternedVariances) -> &'a [Variance]; } /// Implemented by types that have an associated interner (which diff --git a/chalk-ir/src/lib.rs b/chalk-ir/src/lib.rs index 9a6402a2b7f..2dd073ffc82 100644 --- a/chalk-ir/src/lib.rs +++ b/chalk-ir/src/lib.rs @@ -159,14 +159,14 @@ impl Copy for Environment where I::InternedProgramClauses: Copy impl Environment { /// Creates a new environment. - pub fn new(interner: &I) -> Self { + pub fn new(interner: I) -> Self { Environment { clauses: ProgramClauses::empty(interner), } } /// Adds (an iterator of) clauses to the environment. - pub fn add_clauses(&self, interner: &I, clauses: II) -> Self + pub fn add_clauses(&self, interner: I, clauses: II) -> Self where II: IntoIterator>, { @@ -178,7 +178,7 @@ impl Environment { /// True if any of the clauses in the environment have a consequence of `Compatible`. /// Panics if the conditions or constraints of that clause are not empty. - pub fn has_compatible_clause(&self, interner: &I) -> bool { + pub fn has_compatible_clause(&self, interner: I) -> bool { self.clauses.as_slice(interner).iter().any(|c| { let ProgramClauseData(implication) = c.data(interner); match implication.skip_binders().consequence { @@ -414,8 +414,8 @@ pub struct Ty { impl Ty { /// Creates a type from `TyKind`. - pub fn new(interner: &I, data: impl CastTo>) -> Self { - let ty_kind = data.cast(&interner); + pub fn new(interner: I, data: impl CastTo>) -> Self { + let ty_kind = data.cast(interner); Ty { interned: I::intern_ty(interner, ty_kind), } @@ -427,12 +427,12 @@ impl Ty { } /// Gets the underlying type data. - pub fn data(&self, interner: &I) -> &TyData { + pub fn data(&self, interner: I) -> &TyData { I::ty_data(interner, &self.interned) } /// Gets the underlying type kind. - pub fn kind(&self, interner: &I) -> &TyKind { + pub fn kind(&self, interner: I) -> &TyKind { &I::ty_data(interner, &self.interned).kind } @@ -447,12 +447,12 @@ impl Ty { } /// Creates a domain goal `FromEnv(T)` where `T` is this type. - pub fn into_from_env_goal(self, interner: &I) -> DomainGoal { + pub fn into_from_env_goal(self, interner: I) -> DomainGoal { self.from_env().cast(interner) } /// If this is a `TyKind::BoundVar(d)`, returns `Some(d)` else `None`. - pub fn bound_var(&self, interner: &I) -> Option { + pub fn bound_var(&self, interner: I) -> Option { if let TyKind::BoundVar(bv) = self.kind(interner) { Some(*bv) } else { @@ -461,7 +461,7 @@ impl Ty { } /// If this is a `TyKind::InferenceVar(d)`, returns `Some(d)` else `None`. - pub fn inference_var(&self, interner: &I) -> Option { + pub fn inference_var(&self, interner: I) -> Option { if let TyKind::InferenceVar(depth, _) = self.kind(interner) { Some(*depth) } else { @@ -470,7 +470,7 @@ impl Ty { } /// Returns true if this is a `BoundVar` or an `InferenceVar` of `TyVariableKind::General`. - pub fn is_general_var(&self, interner: &I, binders: &CanonicalVarKinds) -> bool { + pub fn is_general_var(&self, interner: I, binders: &CanonicalVarKinds) -> bool { match self.kind(interner) { TyKind::BoundVar(bv) if bv.debruijn == DebruijnIndex::INNERMOST @@ -485,7 +485,7 @@ impl Ty { } /// Returns true if this is an `Alias`. - pub fn is_alias(&self, interner: &I) -> bool { + pub fn is_alias(&self, interner: I) -> bool { match self.kind(interner) { TyKind::Alias(..) => true, _ => false, @@ -493,7 +493,7 @@ impl Ty { } /// Returns true if this is an `IntTy` or `UintTy`. - pub fn is_integer(&self, interner: &I) -> bool { + pub fn is_integer(&self, interner: I) -> bool { match self.kind(interner) { TyKind::Scalar(Scalar::Int(_)) | TyKind::Scalar(Scalar::Uint(_)) => true, _ => false, @@ -501,7 +501,7 @@ impl Ty { } /// Returns true if this is a `FloatTy`. - pub fn is_float(&self, interner: &I) -> bool { + pub fn is_float(&self, interner: I) -> bool { match self.kind(interner) { TyKind::Scalar(Scalar::Float(_)) => true, _ => false, @@ -509,7 +509,7 @@ impl Ty { } /// Returns `Some(adt_id)` if this is an ADT, `None` otherwise - pub fn adt_id(&self, interner: &I) -> Option> { + pub fn adt_id(&self, interner: I) -> Option> { match self.kind(interner) { TyKind::Adt(adt_id, _) => Some(*adt_id), _ => None, @@ -519,7 +519,7 @@ impl Ty { /// True if this type contains "bound" types/lifetimes, and hence /// needs to be shifted across binders. This is a very inefficient /// check, intended only for debug assertions, because I am lazy. - pub fn needs_shift(&self, interner: &I) -> bool { + pub fn needs_shift(&self, interner: I) -> bool { self.has_free_vars(interner) } } @@ -683,12 +683,12 @@ where impl TyKind { /// Casts the type data to a type. - pub fn intern(self, interner: &I) -> Ty { + pub fn intern(self, interner: I) -> Ty { Ty::new(interner, self) } /// Compute type flags for a TyKind - pub fn compute_flags(&self, interner: &I) -> TypeFlags { + pub fn compute_flags(&self, interner: I) -> TypeFlags { match self { TyKind::Adt(_, substitution) | TyKind::AssociatedType(_, substitution) @@ -746,7 +746,7 @@ impl TyKind { } lifetime_flags | dyn_flags } - TyKind::Alias(alias_ty) => alias_ty.compute_flags(&interner), + TyKind::Alias(alias_ty) => alias_ty.compute_flags(interner), TyKind::BoundVar(_) => TypeFlags::empty(), TyKind::InferenceVar(_, _) => TypeFlags::HAS_TY_INFER, TyKind::Function(fn_pointer) => fn_pointer.substitution.0.compute_flags(interner), @@ -793,17 +793,17 @@ impl BoundVar { } /// Casts the bound variable to a type. - pub fn to_ty(self, interner: &I) -> Ty { + pub fn to_ty(self, interner: I) -> Ty { TyKind::::BoundVar(self).intern(interner) } /// Wrap the bound variable in a lifetime. - pub fn to_lifetime(self, interner: &I) -> Lifetime { + pub fn to_lifetime(self, interner: I) -> Lifetime { LifetimeData::::BoundVar(self).intern(interner) } /// Wraps the bound variable in a constant. - pub fn to_const(self, interner: &I, ty: Ty) -> Const { + pub fn to_const(self, interner: I, ty: Ty) -> Const { ConstData { ty, value: ConstValue::::BoundVar(self), @@ -1062,17 +1062,17 @@ impl InferenceVar { } /// Wraps the inference variable in a type. - pub fn to_ty(self, interner: &I, kind: TyVariableKind) -> Ty { + pub fn to_ty(self, interner: I, kind: TyVariableKind) -> Ty { TyKind::::InferenceVar(self, kind).intern(interner) } /// Wraps the inference variable in a lifetime. - pub fn to_lifetime(self, interner: &I) -> Lifetime { + pub fn to_lifetime(self, interner: I) -> Lifetime { LifetimeData::::InferenceVar(self).intern(interner) } /// Wraps the inference variable in a constant. - pub fn to_const(self, interner: &I, ty: Ty) -> Const { + pub fn to_const(self, interner: I, ty: Ty) -> Const { ConstData { ty, value: ConstValue::::InferenceVar(self), @@ -1109,7 +1109,7 @@ impl Copy for FnPointer where I::InternedSubstitution: Copy {} impl FnPointer { /// Represent the current `Fn` as if it was wrapped in `Binders` - pub fn into_binders(self, interner: &I) -> Binders> { + pub fn into_binders(self, interner: I) -> Binders> { Binders::new( VariableKinds::from_iter( interner, @@ -1120,7 +1120,7 @@ impl FnPointer { } /// Represent the current `Fn` as if it was wrapped in `Binders` - pub fn as_binders(&self, interner: &I) -> Binders<&FnSubst> { + pub fn as_binders(&self, interner: I) -> Binders<&FnSubst> { Binders::new( VariableKinds::from_iter( interner, @@ -1139,7 +1139,7 @@ pub struct Const { impl Const { /// Create a `Const` using something that can be cast to const data. - pub fn new(interner: &I, data: impl CastTo>) -> Self { + pub fn new(interner: I, data: impl CastTo>) -> Self { Const { interned: I::intern_const(interner, data.cast(interner)), } @@ -1151,12 +1151,12 @@ impl Const { } /// Gets the constant data from the interner. - pub fn data(&self, interner: &I) -> &ConstData { + pub fn data(&self, interner: I) -> &ConstData { I::const_data(interner, &self.interned) } /// If this is a `ConstData::BoundVar(d)`, returns `Some(d)` else `None`. - pub fn bound_var(&self, interner: &I) -> Option { + pub fn bound_var(&self, interner: I) -> Option { if let ConstValue::BoundVar(bv) = &self.data(interner).value { Some(*bv) } else { @@ -1165,7 +1165,7 @@ impl Const { } /// If this is a `ConstData::InferenceVar(d)`, returns `Some(d)` else `None`. - pub fn inference_var(&self, interner: &I) -> Option { + pub fn inference_var(&self, interner: I) -> Option { if let ConstValue::InferenceVar(iv) = &self.data(interner).value { Some(*iv) } else { @@ -1175,7 +1175,7 @@ impl Const { /// True if this const is a "bound" const, and hence /// needs to be shifted across binders. Meant for debug assertions. - pub fn needs_shift(&self, interner: &I) -> bool { + pub fn needs_shift(&self, interner: I) -> bool { match &self.data(interner).value { ConstValue::BoundVar(_) => true, ConstValue::InferenceVar(_) => false, @@ -1211,7 +1211,7 @@ impl Copy for ConstValue where I::InternedConcreteConst: Copy {} impl ConstData { /// Wraps the constant data in a `Const`. - pub fn intern(self, interner: &I) -> Const { + pub fn intern(self, interner: I) -> Const { Const::new(interner, self) } } @@ -1226,7 +1226,7 @@ pub struct ConcreteConst { impl ConcreteConst { /// Checks whether two concrete constants are equal. - pub fn const_eq(&self, ty: &Ty, other: &ConcreteConst, interner: &I) -> bool { + pub fn const_eq(&self, ty: &Ty, other: &ConcreteConst, interner: I) -> bool { interner.const_eq(&ty.interned, &self.interned, &other.interned) } } @@ -1240,7 +1240,7 @@ pub struct Lifetime { impl Lifetime { /// Create a lifetime from lifetime data /// (or something that can be cast to lifetime data). - pub fn new(interner: &I, data: impl CastTo>) -> Self { + pub fn new(interner: I, data: impl CastTo>) -> Self { Lifetime { interned: I::intern_lifetime(interner, data.cast(interner)), } @@ -1252,12 +1252,12 @@ impl Lifetime { } /// Gets the lifetime data. - pub fn data(&self, interner: &I) -> &LifetimeData { + pub fn data(&self, interner: I) -> &LifetimeData { I::lifetime_data(interner, &self.interned) } /// If this is a `Lifetime::BoundVar(d)`, returns `Some(d)` else `None`. - pub fn bound_var(&self, interner: &I) -> Option { + pub fn bound_var(&self, interner: I) -> Option { if let LifetimeData::BoundVar(bv) = self.data(interner) { Some(*bv) } else { @@ -1266,7 +1266,7 @@ impl Lifetime { } /// If this is a `Lifetime::InferenceVar(d)`, returns `Some(d)` else `None`. - pub fn inference_var(&self, interner: &I) -> Option { + pub fn inference_var(&self, interner: I) -> Option { if let LifetimeData::InferenceVar(depth) = self.data(interner) { Some(*depth) } else { @@ -1276,7 +1276,7 @@ impl Lifetime { /// True if this lifetime is a "bound" lifetime, and hence /// needs to be shifted across binders. Meant for debug assertions. - pub fn needs_shift(&self, interner: &I) -> bool { + pub fn needs_shift(&self, interner: I) -> bool { match self.data(interner) { LifetimeData::BoundVar(_) => true, LifetimeData::InferenceVar(_) => false, @@ -1289,8 +1289,8 @@ impl Lifetime { } ///compute type flags for Lifetime - fn compute_flags(&self, interner: &I) -> TypeFlags { - match self.data(&interner) { + fn compute_flags(&self, interner: I) -> TypeFlags { + match self.data(interner) { LifetimeData::InferenceVar(_) => { TypeFlags::HAS_RE_INFER | TypeFlags::HAS_FREE_LOCAL_REGIONS @@ -1334,7 +1334,7 @@ pub enum LifetimeData { impl LifetimeData { /// Wrap the lifetime data in a lifetime. - pub fn intern(self, interner: &I) -> Lifetime { + pub fn intern(self, interner: I) -> Lifetime { Lifetime::new(interner, self) } } @@ -1352,17 +1352,17 @@ pub struct PlaceholderIndex { impl PlaceholderIndex { /// Wrap the placeholder instance in a lifetime. - pub fn to_lifetime(self, interner: &I) -> Lifetime { + pub fn to_lifetime(self, interner: I) -> Lifetime { LifetimeData::::Placeholder(self).intern(interner) } /// Create an interned type. - pub fn to_ty(self, interner: &I) -> Ty { + pub fn to_ty(self, interner: I) -> Ty { TyKind::Placeholder(self).intern(interner) } /// Wrap the placeholder index in a constant. - pub fn to_const(self, interner: &I, ty: Ty) -> Const { + pub fn to_const(self, interner: I, ty: Ty) -> Const { ConstData { ty, value: ConstValue::Placeholder(self), @@ -1404,7 +1404,7 @@ impl interner::HasInterner for VariableKind { impl Copy for VariableKind where I::InternedType: Copy {} impl VariableKind { - fn to_bound_variable(&self, interner: &I, bound_var: BoundVar) -> GenericArg { + fn to_bound_variable(&self, interner: I, bound_var: BoundVar) -> GenericArg { match self { VariableKind::Ty(_) => { GenericArgData::Ty(TyKind::BoundVar(bound_var).intern(interner)).intern(interner) @@ -1433,7 +1433,7 @@ pub struct GenericArg { impl GenericArg { /// Constructs a generic argument using `GenericArgData`. - pub fn new(interner: &I, data: GenericArgData) -> Self { + pub fn new(interner: I, data: GenericArgData) -> Self { let interned = I::intern_generic_arg(interner, data); GenericArg { interned } } @@ -1444,27 +1444,27 @@ impl GenericArg { } /// Gets the underlying data. - pub fn data(&self, interner: &I) -> &GenericArgData { + pub fn data(&self, interner: I) -> &GenericArgData { I::generic_arg_data(interner, &self.interned) } /// Asserts that this is a type argument. - pub fn assert_ty_ref(&self, interner: &I) -> &Ty { + pub fn assert_ty_ref(&self, interner: I) -> &Ty { self.ty(interner).unwrap() } /// Asserts that this is a lifetime argument. - pub fn assert_lifetime_ref(&self, interner: &I) -> &Lifetime { + pub fn assert_lifetime_ref(&self, interner: I) -> &Lifetime { self.lifetime(interner).unwrap() } /// Asserts that this is a constant argument. - pub fn assert_const_ref(&self, interner: &I) -> &Const { + pub fn assert_const_ref(&self, interner: I) -> &Const { self.constant(interner).unwrap() } /// Checks whether the generic argument is a type. - pub fn is_ty(&self, interner: &I) -> bool { + pub fn is_ty(&self, interner: I) -> bool { match self.data(interner) { GenericArgData::Ty(_) => true, GenericArgData::Lifetime(_) => false, @@ -1473,7 +1473,7 @@ impl GenericArg { } /// Returns the type if it is one, `None` otherwise. - pub fn ty(&self, interner: &I) -> Option<&Ty> { + pub fn ty(&self, interner: I) -> Option<&Ty> { match self.data(interner) { GenericArgData::Ty(t) => Some(t), _ => None, @@ -1481,7 +1481,7 @@ impl GenericArg { } /// Returns the lifetime if it is one, `None` otherwise. - pub fn lifetime(&self, interner: &I) -> Option<&Lifetime> { + pub fn lifetime(&self, interner: I) -> Option<&Lifetime> { match self.data(interner) { GenericArgData::Lifetime(t) => Some(t), _ => None, @@ -1489,7 +1489,7 @@ impl GenericArg { } /// Returns the constant if it is one, `None` otherwise. - pub fn constant(&self, interner: &I) -> Option<&Const> { + pub fn constant(&self, interner: I) -> Option<&Const> { match self.data(interner) { GenericArgData::Const(c) => Some(c), _ => None, @@ -1497,12 +1497,12 @@ impl GenericArg { } /// Compute type flags for GenericArg - fn compute_flags(&self, interner: &I) -> TypeFlags { - match self.data(&interner) { + fn compute_flags(&self, interner: I) -> TypeFlags { + match self.data(interner) { GenericArgData::Ty(ty) => ty.data(interner).flags, GenericArgData::Lifetime(lifetime) => lifetime.compute_flags(interner), GenericArgData::Const(constant) => { - let data = constant.data(&interner); + let data = constant.data(interner); let flags = data.ty.data(interner).flags; match data.value { ConstValue::BoundVar(_) => flags, @@ -1542,7 +1542,7 @@ where impl GenericArgData { /// Create an interned type. - pub fn intern(self, interner: &I) -> GenericArg { + pub fn intern(self, interner: I) -> GenericArg { GenericArg::new(interner, self) } } @@ -1619,12 +1619,12 @@ impl Copy for AliasTy where I::InternedSubstitution: Copy {} impl AliasTy { /// Create an interned type for this alias. - pub fn intern(self, interner: &I) -> Ty { + pub fn intern(self, interner: I) -> Ty { Ty::new(interner, self) } /// Compute type flags for aliases - fn compute_flags(&self, interner: &I) -> TypeFlags { + fn compute_flags(&self, interner: I) -> TypeFlags { match self { AliasTy::Projection(projection_ty) => { TypeFlags::HAS_TY_PROJECTION | projection_ty.substitution.compute_flags(interner) @@ -1649,7 +1649,7 @@ impl Copy for ProjectionTy where I::InternedSubstitution: Copy { impl ProjectionTy { /// Gets the type parameters of the `Self` type in this alias type. - pub fn self_type_parameter(&self, interner: &I) -> Ty { + pub fn self_type_parameter(&self, interner: I) -> Ty { self.substitution .iter(interner) .find_map(move |p| p.ty(interner)) @@ -1687,7 +1687,7 @@ impl Copy for TraitRef where I::InternedSubstitution: Copy {} impl TraitRef { /// Gets all type parameters in this trait ref, including `Self`. - pub fn type_parameters<'a>(&'a self, interner: &'a I) -> impl Iterator> + 'a { + pub fn type_parameters<'a>(&'a self, interner: I) -> impl Iterator> + 'a { self.substitution .iter(interner) .filter_map(move |p| p.ty(interner)) @@ -1695,7 +1695,7 @@ impl TraitRef { } /// Gets the type parameters of the `Self` type in this trait ref. - pub fn self_type_parameter(&self, interner: &I) -> Ty { + pub fn self_type_parameter(&self, interner: I) -> Ty { self.type_parameters(interner).next().unwrap() } @@ -1925,7 +1925,7 @@ impl WhereClause { /// * `Implemented(T: Trait)` maps to `WellFormed(T: Trait)` /// * `ProjectionEq(::Item = Foo)` maps to `WellFormed(::Item = Foo)` /// * any other clause maps to itself - pub fn into_well_formed_goal(self, interner: &I) -> DomainGoal { + pub fn into_well_formed_goal(self, interner: I) -> DomainGoal { match self { WhereClause::Implemented(trait_ref) => WellFormed::Trait(trait_ref).cast(interner), wc => wc.cast(interner), @@ -1933,7 +1933,7 @@ impl WhereClause { } /// Same as `into_well_formed_goal` but with the `FromEnv` predicate instead of `WellFormed`. - pub fn into_from_env_goal(self, interner: &I) -> DomainGoal { + pub fn into_from_env_goal(self, interner: I) -> DomainGoal { match self { WhereClause::Implemented(trait_ref) => FromEnv::Trait(trait_ref).cast(interner), wc => wc.cast(interner), @@ -1956,7 +1956,7 @@ impl QuantifiedWhereClause { /// quantified where clause. For example, `forall { /// Implemented(T: Trait)}` would map to `forall { /// WellFormed(T: Trait) }`. - pub fn into_well_formed_goal(self, interner: &I) -> Binders> { + pub fn into_well_formed_goal(self, interner: I) -> Binders> { self.map(|wc| wc.into_well_formed_goal(interner)) } @@ -1964,7 +1964,7 @@ impl QuantifiedWhereClause { /// binders. For example, `forall { /// Implemented(T: Trait)}` would map to `forall { /// FromEnv(T: Trait) }`. - pub fn into_from_env_goal(self, interner: &I) -> Binders> { + pub fn into_from_env_goal(self, interner: I) -> Binders> { self.map(|wc| wc.into_from_env_goal(interner)) } @@ -1977,7 +1977,7 @@ impl QuantifiedWhereClause { impl DomainGoal { /// Convert `Implemented(...)` into `FromEnv(...)`, but leave other /// goals unchanged. - pub fn into_from_env_goal(self, interner: &I) -> DomainGoal { + pub fn into_from_env_goal(self, interner: I) -> DomainGoal { match self { DomainGoal::Holds(wc) => wc.into_from_env_goal(interner), goal => goal, @@ -1985,7 +1985,7 @@ impl DomainGoal { } /// Lists generic arguments that are inputs to this domain goal. - pub fn inputs(&self, interner: &I) -> Vec> { + pub fn inputs(&self, interner: I) -> Vec> { match self { DomainGoal::Holds(WhereClause::AliasEq(alias_eq)) => { vec![GenericArgData::Ty(alias_eq.alias.clone().intern(interner)).intern(interner)] @@ -2093,7 +2093,7 @@ impl Binders { /// Wraps the given value in a binder without variables, i.e. `for<> /// (value)`. Since our deBruijn indices count binders, not variables, this /// is sometimes useful. - pub fn empty(interner: &T::Interner, value: T) -> Self { + pub fn empty(interner: T::Interner, value: T) -> Self { let binders = VariableKinds::empty(interner); Self { binders, value } } @@ -2168,7 +2168,7 @@ impl Binders { /// Creates a `Substitution` containing bound vars such that applying this /// substitution will not change the value, i.e. `^0.0, ^0.1, ^0.2` and so /// on. - pub fn identity_substitution(&self, interner: &T::Interner) -> Substitution { + pub fn identity_substitution(&self, interner: T::Interner) -> Substitution { Substitution::from_iter( interner, self.binders @@ -2185,7 +2185,7 @@ impl Binders { /// /// XXX FIXME -- this is potentially a pretty footgun-y function. pub fn with_fresh_type_var( - interner: &T::Interner, + interner: T::Interner, op: impl FnOnce(Ty) -> T, ) -> Binders { // The new variable is at the front and everything afterwards is shifted up by 1 @@ -2196,7 +2196,7 @@ impl Binders { } /// Returns the number of binders. - pub fn len(&self, interner: &T::Interner) -> usize { + pub fn len(&self, interner: T::Interner) -> usize { self.binders.len(interner) } } @@ -2208,7 +2208,7 @@ where I: Interner, { /// This turns two levels of binders (`for for`) into one level (`for`). - pub fn fuse_binders(self, interner: &T::Interner) -> Binders { + pub fn fuse_binders(self, interner: T::Interner) -> Binders { let num_binders = self.len(interner); // generate a substitution to shift the indexes of the inner binder: let subst = Substitution::from_iter( @@ -2248,7 +2248,7 @@ where /// B] T`. pub fn substitute( self, - interner: &I, + interner: I, parameters: &(impl AsParameters + ?Sized), ) -> T::Result { let parameters = parameters.as_parameters(interner); @@ -2338,7 +2338,7 @@ pub struct ProgramClauseData(pub Binders ProgramClauseImplication { /// Change the implication into an application holding a `FromEnv` goal. - pub fn into_from_env_clause(self, interner: &I) -> ProgramClauseImplication { + pub fn into_from_env_clause(self, interner: I) -> ProgramClauseImplication { if self.conditions.is_empty(interner) { ProgramClauseImplication { consequence: self.consequence.into_from_env_goal(interner), @@ -2354,12 +2354,12 @@ impl ProgramClauseImplication { impl ProgramClauseData { /// Change the program clause data into a `FromEnv` program clause. - pub fn into_from_env_clause(self, interner: &I) -> ProgramClauseData { + pub fn into_from_env_clause(self, interner: I) -> ProgramClauseData { ProgramClauseData(self.0.map(|i| i.into_from_env_clause(interner))) } /// Intern the program clause data. - pub fn intern(self, interner: &I) -> ProgramClause { + pub fn intern(self, interner: I) -> ProgramClause { ProgramClause { interned: interner.intern_program_clause(self), } @@ -2374,13 +2374,13 @@ pub struct ProgramClause { impl ProgramClause { /// Create a new program clause using `ProgramClauseData`. - pub fn new(interner: &I, clause: ProgramClauseData) -> Self { + pub fn new(interner: I, clause: ProgramClauseData) -> Self { let interned = interner.intern_program_clause(clause); Self { interned } } /// Change the clause into a `FromEnv` clause. - pub fn into_from_env_clause(self, interner: &I) -> ProgramClause { + pub fn into_from_env_clause(self, interner: I) -> ProgramClause { let program_clause_data = self.data(interner); let new_clause = program_clause_data.clone().into_from_env_clause(interner); Self::new(interner, new_clause) @@ -2392,7 +2392,7 @@ impl ProgramClause { } /// Get the program clause data. - pub fn data(&self, interner: &I) -> &ProgramClauseData { + pub fn data(&self, interner: I) -> &ProgramClauseData { interner.program_clause_data(&self.interned) } } @@ -2435,7 +2435,7 @@ impl UCanonical { /// substitution (e.g. an identity substitution). pub fn is_trivial_substitution( &self, - interner: &T::Interner, + interner: T::Interner, canonical_subst: &Canonical>, ) -> bool { let subst = &canonical_subst.value.subst; @@ -2447,7 +2447,7 @@ impl UCanonical { } /// Creates an identity substitution. - pub fn trivial_substitution(&self, interner: &T::Interner) -> Substitution { + pub fn trivial_substitution(&self, interner: T::Interner) -> Substitution { let binders = &self.canonical.binders; Substitution::from_iter( interner, @@ -2488,7 +2488,7 @@ pub struct Goal { impl Goal { /// Create a new goal using `GoalData`. - pub fn new(interner: &I, interned: GoalData) -> Self { + pub fn new(interner: I, interned: GoalData) -> Self { let interned = I::intern_goal(interner, interned); Self { interned } } @@ -2499,27 +2499,22 @@ impl Goal { } /// Gets the interned goal data. - pub fn data(&self, interner: &I) -> &GoalData { + pub fn data(&self, interner: I) -> &GoalData { interner.goal_data(&self.interned) } /// Create a goal using a `forall` or `exists` quantifier. - pub fn quantify( - self, - interner: &I, - kind: QuantifierKind, - binders: VariableKinds, - ) -> Goal { + pub fn quantify(self, interner: I, kind: QuantifierKind, binders: VariableKinds) -> Goal { GoalData::Quantified(kind, Binders::new(binders, self)).intern(interner) } /// Takes a goal `G` and turns it into `not { G }`. - pub fn negate(self, interner: &I) -> Self { + pub fn negate(self, interner: I) -> Self { GoalData::Not(self).intern(interner) } /// Takes a goal `G` and turns it into `compatible { G }`. - pub fn compatible(self, interner: &I) -> Self { + pub fn compatible(self, interner: I) -> Self { // compatible { G } desugars into: forall { if (Compatible, DownstreamType(T)) { G } } // This activates the compatible modality rules and introduces an anonymous downstream type GoalData::Quantified( @@ -2539,13 +2534,13 @@ impl Goal { } /// Create an implication goal that holds if the predicates are true. - pub fn implied_by(self, interner: &I, predicates: ProgramClauses) -> Goal { + pub fn implied_by(self, interner: I, predicates: ProgramClauses) -> Goal { GoalData::Implies(predicates, self).intern(interner) } /// True if this goal is "trivially true" -- i.e., no work is /// required to prove it. - pub fn is_trivially_true(&self, interner: &I) -> bool { + pub fn is_trivially_true(&self, interner: I) -> bool { match self.data(interner) { GoalData::All(goals) => goals.is_empty(interner), _ => false, @@ -2558,7 +2553,7 @@ where I: Interner, { /// Creates a single goal that only holds if a list of goals holds. - pub fn all(interner: &I, iter: II) -> Self + pub fn all(interner: I, iter: II) -> Self where II: IntoIterator>, { @@ -2633,7 +2628,7 @@ where impl GoalData { /// Create an interned goal. - pub fn intern(self, interner: &I) -> Goal { + pub fn intern(self, interner: I) -> Goal { Goal::new(interner, self) } } @@ -2696,7 +2691,7 @@ impl Substitution { /// /// Basically, each value is mapped to a type or lifetime with its /// same index. - pub fn is_identity_subst(&self, interner: &I) -> bool { + pub fn is_identity_subst(&self, interner: I) -> bool { self.iter(interner).zip(0..).all(|(generic_arg, index)| { let index_db = BoundVar::new(DebruijnIndex::INNERMOST, index); match generic_arg.data(interner) { @@ -2717,7 +2712,7 @@ impl Substitution { } /// Apply the substitution to a value. - pub fn apply(&self, value: T, interner: &I) -> T::Result + pub fn apply(&self, value: T, interner: I) -> T::Result where T: Fold, { @@ -2725,16 +2720,16 @@ impl Substitution { } /// Gets an iterator of all type parameters. - pub fn type_parameters<'a>(&'a self, interner: &'a I) -> impl Iterator> + 'a { + pub fn type_parameters<'a>(&'a self, interner: I) -> impl Iterator> + 'a { self.iter(interner) .filter_map(move |p| p.ty(interner)) .cloned() } /// Compute type flags for Substitution - fn compute_flags(&self, interner: &I) -> TypeFlags { + fn compute_flags(&self, interner: I) -> TypeFlags { let mut flags = TypeFlags::empty(); - for generic_arg in self.iter(&interner) { + for generic_arg in self.iter(interner) { flags |= generic_arg.compute_flags(interner); } flags @@ -2742,7 +2737,7 @@ impl Substitution { } struct SubstFolder<'i, I: Interner, A: AsParameters> { - interner: &'i I, + interner: I, subst: &'i A, } @@ -2757,30 +2752,30 @@ impl> SubstFolder<'_, I, A> { /// Convert a value to a list of parameters. pub trait AsParameters { /// Convert the current value to parameters. - fn as_parameters(&self, interner: &I) -> &[GenericArg]; + fn as_parameters(&self, interner: I) -> &[GenericArg]; } impl AsParameters for Substitution { #[allow(unreachable_code, unused_variables)] - fn as_parameters(&self, interner: &I) -> &[GenericArg] { + fn as_parameters(&self, interner: I) -> &[GenericArg] { self.as_slice(interner) } } impl AsParameters for [GenericArg] { - fn as_parameters(&self, _interner: &I) -> &[GenericArg] { + fn as_parameters(&self, _interner: I) -> &[GenericArg] { self } } impl AsParameters for [GenericArg; 1] { - fn as_parameters(&self, _interner: &I) -> &[GenericArg] { + fn as_parameters(&self, _interner: I) -> &[GenericArg] { self } } impl AsParameters for Vec> { - fn as_parameters(&self, _interner: &I) -> &[GenericArg] { + fn as_parameters(&self, _interner: I) -> &[GenericArg] { self } } @@ -2789,7 +2784,7 @@ impl AsParameters for &T where T: ?Sized + AsParameters, { - fn as_parameters(&self, interner: &I) -> &[GenericArg] { + fn as_parameters(&self, interner: I) -> &[GenericArg] { T::as_parameters(self, interner) } } @@ -2798,11 +2793,11 @@ where /// that it can applied as a substituion to a value pub trait Substitute: AsParameters { /// Apply the substitution to a value. - fn apply>(&self, value: T, interner: &I) -> T::Result; + fn apply>(&self, value: T, interner: I) -> T::Result; } impl> Substitute for A { - fn apply(&self, value: T, interner: &I) -> T::Result + fn apply(&self, value: T, interner: I) -> T::Result where T: Fold, { @@ -2825,26 +2820,26 @@ impl> Substitute for A { /// variable of appropriate kind at the corresponding index. pub trait ToGenericArg { /// Converts the binders in scope to references to those binders. - fn to_generic_arg(&self, interner: &I) -> GenericArg { + fn to_generic_arg(&self, interner: I) -> GenericArg { self.to_generic_arg_at_depth(interner, DebruijnIndex::INNERMOST) } /// Converts the binders at the specified depth to references to those binders. - fn to_generic_arg_at_depth(&self, interner: &I, debruijn: DebruijnIndex) -> GenericArg; + fn to_generic_arg_at_depth(&self, interner: I, debruijn: DebruijnIndex) -> GenericArg; } impl<'a, I: Interner> ToGenericArg for (usize, &'a VariableKind) { - fn to_generic_arg_at_depth(&self, interner: &I, debruijn: DebruijnIndex) -> GenericArg { + fn to_generic_arg_at_depth(&self, interner: I, debruijn: DebruijnIndex) -> GenericArg { let &(index, binder) = self; let bound_var = BoundVar::new(debruijn, index); binder.to_bound_variable(interner, bound_var) } } -impl<'i, I: Interner, A: AsParameters> Folder<'i, I> for &SubstFolder<'i, I, A> { +impl<'i, I: Interner, A: AsParameters> Folder for &SubstFolder<'i, I, A> { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder<'i, I, Error = Self::Error> { + fn as_dyn(&mut self) -> &mut dyn Folder { self } @@ -2882,7 +2877,7 @@ impl<'i, I: Interner, A: AsParameters> Folder<'i, I> for &SubstFolder<'i, I, Ok(c.clone().shifted_in_from(self.interner(), outer_binder)) } - fn interner(&self) -> &'i I { + fn interner(&self) -> I { self.interner } } @@ -2902,32 +2897,32 @@ macro_rules! interned_slice_common { } /// Returns a slice containing the elements. - pub fn as_slice(&self, interner: &I) -> &[$elem] { + pub fn as_slice(&self, interner: I) -> &[$elem] { Interner::$data(interner, &self.interned) } /// Index into the sequence. - pub fn at(&self, interner: &I, index: usize) -> &$elem { + pub fn at(&self, interner: I, index: usize) -> &$elem { &self.as_slice(interner)[index] } /// Create an empty sequence. - pub fn empty(interner: &I) -> Self { + pub fn empty(interner: I) -> Self { Self::from_iter(interner, None::<$elem>) } /// Check whether this is an empty sequence. - pub fn is_empty(&self, interner: &I) -> bool { + pub fn is_empty(&self, interner: I) -> bool { self.as_slice(interner).is_empty() } /// Get an iterator over the elements of the sequence. - pub fn iter(&self, interner: &I) -> std::slice::Iter<'_, $elem> { + pub fn iter(&self, interner: I) -> std::slice::Iter<'_, $elem> { self.as_slice(interner).iter() } /// Get the length of the sequence. - pub fn len(&self, interner: &I) -> usize { + pub fn len(&self, interner: I) -> usize { self.as_slice(interner).len() } } @@ -2941,7 +2936,7 @@ macro_rules! interned_slice { impl $seq { /// Tries to create a sequence using an iterator of element-like things. pub fn from_fallible( - interner: &I, + interner: I, elements: impl IntoIterator, E>>, ) -> Result { Ok(Self { @@ -2951,7 +2946,7 @@ macro_rules! interned_slice { /// Create a sequence from elements pub fn from_iter( - interner: &I, + interner: I, elements: impl IntoIterator>, ) -> Self { Self::from_fallible( @@ -2964,7 +2959,7 @@ macro_rules! interned_slice { } /// Create a sequence from a single element. - pub fn from1(interner: &I, element: impl CastTo<$elem>) -> Self { + pub fn from1(interner: I, element: impl CastTo<$elem>) -> Self { Self::from_iter(interner, Some(element)) } } @@ -3018,7 +3013,7 @@ interned_slice_common!( impl Variances { /// Tries to create a list of canonical variable kinds using an iterator. pub fn from_fallible( - interner: &I, + interner: I, variances: impl IntoIterator>, ) -> Result { Ok(Variances { @@ -3027,7 +3022,7 @@ impl Variances { } /// Creates a list of canonical variable kinds using an iterator. - pub fn from_iter(interner: &I, variances: impl IntoIterator) -> Self { + pub fn from_iter(interner: I, variances: impl IntoIterator) -> Self { Self::from_fallible( interner, variances @@ -3038,7 +3033,7 @@ impl Variances { } /// Creates a list of canonical variable kinds from a single canonical variable kind. - pub fn from1(interner: &I, variance: Variance) -> Self { + pub fn from1(interner: I, variance: Variance) -> Self { Self::from_iter(interner, Some(variance)) } } diff --git a/chalk-ir/src/visit.rs b/chalk-ir/src/visit.rs index 833ba1a02c8..3096ad5a5a9 100644 --- a/chalk-ir/src/visit.rs +++ b/chalk-ir/src/visit.rs @@ -35,10 +35,7 @@ macro_rules! try_break { /// ```rust,ignore /// let result = x.visit_with(&mut visitor, 0); /// ``` -pub trait Visitor<'i, I: Interner> -where - I: 'i, -{ +pub trait Visitor { /// The "break type" of the visitor, often `()`. It represents the result /// the visitor yields when it stops visiting. type BreakTy; @@ -50,7 +47,7 @@ where /// method). Effectively, this limits impls of `visitor` to types /// for which we are able to create a dyn value (i.e., not `[T]` /// types). - fn as_dyn(&mut self) -> &mut dyn Visitor<'i, I, BreakTy = Self::BreakTy>; + fn as_dyn(&mut self) -> &mut dyn Visitor; /// Top-level callback: invoked for each `Ty` that is /// encountered when visiting. By default, invokes @@ -186,7 +183,7 @@ where } /// Gets the visitor's interner. - fn interner(&self) -> &'i I; + fn interner(&self) -> I; } /// Applies the given `visitor` to a value, producing a visited result @@ -197,13 +194,11 @@ pub trait Visit: Debug { /// visitor. Typically `binders` starts as 0, but is adjusted when /// we encounter `Binders` in the IR or other similar /// constructs. - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i; + ) -> ControlFlow; } /// For types where "visit" invokes a callback on the `visitor`, the @@ -211,27 +206,22 @@ pub trait Visit: Debug { /// the contents of the type. pub trait SuperVisit: Visit { /// Recursively visits the type contents. - fn super_visit_with<'i, B>( + fn super_visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i; + ) -> ControlFlow; } /// "visiting" a type invokes the `visit_ty` method on the visitor; this /// usually (in turn) invokes `super_visit_ty` to visit the individual /// parts. impl Visit for Ty { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { visitor.visit_ty(self, outer_binder) } } @@ -241,14 +231,11 @@ impl SuperVisit for Ty where I: Interner, { - fn super_visit_with<'i, B>( + fn super_visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { let interner = visitor.interner(); match self.kind(interner) { TyKind::BoundVar(bound_var) => { @@ -315,27 +302,21 @@ where } impl Visit for Lifetime { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { visitor.visit_lifetime(self, outer_binder) } } impl SuperVisit for Lifetime { - fn super_visit_with<'i, B>( + fn super_visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { let interner = visitor.interner(); match self.data(interner) { LifetimeData::BoundVar(bound_var) => { @@ -358,27 +339,21 @@ impl SuperVisit for Lifetime { } impl Visit for Const { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { visitor.visit_const(self, outer_binder) } } impl SuperVisit for Const { - fn super_visit_with<'i, B>( + fn super_visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { let interner = visitor.interner(); match &self.data(interner).value { ConstValue::BoundVar(bound_var) => { @@ -398,67 +373,52 @@ impl SuperVisit for Const { } impl Visit for Goal { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { visitor.visit_goal(self, outer_binder) } } impl SuperVisit for Goal { - fn super_visit_with<'i, B>( + fn super_visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { let interner = visitor.interner(); self.data(interner).visit_with(visitor, outer_binder) } } impl Visit for ProgramClause { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { visitor.visit_program_clause(self, outer_binder) } } impl Visit for WhereClause { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { visitor.visit_where_clause(self, outer_binder) } } impl Visit for DomainGoal { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { visitor.visit_domain_goal(self, outer_binder) } } diff --git a/chalk-ir/src/visit/binder_impls.rs b/chalk-ir/src/visit/binder_impls.rs index 3907dcba452..074450a53a0 100644 --- a/chalk-ir/src/visit/binder_impls.rs +++ b/chalk-ir/src/visit/binder_impls.rs @@ -7,14 +7,11 @@ use crate::interner::HasInterner; use crate::{Binders, Canonical, ControlFlow, DebruijnIndex, FnPointer, Interner, Visit, Visitor}; impl Visit for FnPointer { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { self.substitution .visit_with(visitor, outer_binder.shifted_in()) } @@ -24,14 +21,11 @@ impl Visit for Binders where T: HasInterner + Visit, { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { self.value.visit_with(visitor, outer_binder.shifted_in()) } } @@ -41,14 +35,11 @@ where I: Interner, T: HasInterner + Visit, { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { self.value.visit_with(visitor, outer_binder.shifted_in()) } } diff --git a/chalk-ir/src/visit/boring_impls.rs b/chalk-ir/src/visit/boring_impls.rs index 4d45ad7b2dc..d4e52d15b35 100644 --- a/chalk-ir/src/visit/boring_impls.rs +++ b/chalk-ir/src/visit/boring_impls.rs @@ -16,7 +16,7 @@ use std::{marker::PhantomData, sync::Arc}; /// Convenience function to visit all the items in the iterator it. pub fn visit_iter<'i, T, I, B>( it: impl Iterator, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, ) -> ControlFlow where @@ -30,66 +30,51 @@ where } impl, I: Interner> Visit for &T { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { T::visit_with(self, visitor, outer_binder) } } impl, I: Interner> Visit for Vec { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { visit_iter(self.iter(), visitor, outer_binder) } } impl, I: Interner> Visit for &[T] { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { visit_iter(self.iter(), visitor, outer_binder) } } impl, I: Interner> Visit for Box { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { T::visit_with(self, visitor, outer_binder) } } impl, I: Interner> Visit for Arc { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { T::visit_with(self, visitor, outer_binder) } } @@ -97,8 +82,7 @@ impl, I: Interner> Visit for Arc { macro_rules! tuple_visit { ($($n:ident),*) => { impl<$($n: Visit,)* I: Interner> Visit for ($($n,)*) { - fn visit_with<'i, BT>(&self, visitor: &mut dyn Visitor<'i, I, BreakTy = BT>, outer_binder: DebruijnIndex) -> ControlFlow where I: 'i - { + fn visit_with(&self, visitor: &mut dyn Visitor, outer_binder: DebruijnIndex) -> ControlFlow { #[allow(non_snake_case)] let &($(ref $n),*) = self; $( @@ -116,14 +100,11 @@ tuple_visit!(A, B, C, D); tuple_visit!(A, B, C, D, E); impl, I: Interner> Visit for Option { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { match self { Some(e) => e.visit_with(visitor, outer_binder), None => ControlFlow::Continue(()), @@ -132,42 +113,33 @@ impl, I: Interner> Visit for Option { } impl Visit for GenericArg { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { let interner = visitor.interner(); self.data(interner).visit_with(visitor, outer_binder) } } impl Visit for Substitution { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { let interner = visitor.interner(); visit_iter(self.iter(interner), visitor, outer_binder) } } impl Visit for Goals { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { let interner = visitor.interner(); visit_iter(self.iter(interner), visitor, outer_binder) } @@ -178,14 +150,11 @@ impl Visit for Goals { macro_rules! const_visit { ($t:ty) => { impl $crate::visit::Visit for $t { - fn visit_with<'i, B>( + fn visit_with( &self, - _visitor: &mut dyn ($crate::visit::Visitor<'i, I, BreakTy = B>), + _visitor: &mut dyn ($crate::visit::Visitor), _outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { ControlFlow::Continue(()) } } @@ -212,14 +181,11 @@ const_visit!(Safety); macro_rules! id_visit { ($t:ident) => { impl $crate::visit::Visit for $t { - fn visit_with<'i, B>( + fn visit_with( &self, - _visitor: &mut dyn ($crate::visit::Visitor<'i, I, BreakTy = B>), + _visitor: &mut dyn ($crate::visit::Visitor), _outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { ControlFlow::Continue(()) } } @@ -237,14 +203,11 @@ id_visit!(GeneratorId); id_visit!(ForeignDefId); impl SuperVisit for ProgramClause { - fn super_visit_with<'i, B>( + fn super_visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { let interner = visitor.interner(); self.data(interner).0.visit_with(visitor, outer_binder) @@ -252,14 +215,11 @@ impl SuperVisit for ProgramClause { } impl Visit for ProgramClauses { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { let interner = visitor.interner(); visit_iter(self.iter(interner), visitor, outer_binder) @@ -267,14 +227,11 @@ impl Visit for ProgramClauses { } impl Visit for Constraints { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { let interner = visitor.interner(); visit_iter(self.iter(interner), visitor, outer_binder) @@ -282,14 +239,11 @@ impl Visit for Constraints { } impl Visit for QuantifiedWhereClauses { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { let interner = visitor.interner(); visit_iter(self.iter(interner), visitor, outer_binder) @@ -297,14 +251,11 @@ impl Visit for QuantifiedWhereClauses { } impl Visit for PhantomData { - fn visit_with<'i, B>( + fn visit_with( &self, - _visitor: &mut dyn Visitor<'i, I, BreakTy = B>, + _visitor: &mut dyn Visitor, _outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { ControlFlow::Continue(()) } } diff --git a/chalk-ir/src/visit/visitors.rs b/chalk-ir/src/visit/visitors.rs index 8d3bbe5ef2d..486b51d8675 100644 --- a/chalk-ir/src/visit/visitors.rs +++ b/chalk-ir/src/visit/visitors.rs @@ -5,7 +5,7 @@ use crate::{BoundVar, ControlFlow, DebruijnIndex, Interner, Visit, Visitor}; /// Visitor extensions. pub trait VisitExt: Visit { /// Check whether there are free (non-bound) variables. - fn has_free_vars(&self, interner: &I) -> bool { + fn has_free_vars(&self, interner: I) -> bool { let flow = self.visit_with( &mut FindFreeVarsVisitor { interner }, DebruijnIndex::INNERMOST, @@ -16,18 +16,18 @@ pub trait VisitExt: Visit { impl VisitExt for T where T: Visit {} -struct FindFreeVarsVisitor<'i, I: Interner> { - interner: &'i I, +struct FindFreeVarsVisitor { + interner: I, } -impl<'i, I: Interner> Visitor<'i, I> for FindFreeVarsVisitor<'i, I> { +impl Visitor for FindFreeVarsVisitor { type BreakTy = (); - fn as_dyn(&mut self) -> &mut dyn Visitor<'i, I, BreakTy = Self::BreakTy> { + fn as_dyn(&mut self) -> &mut dyn Visitor { self } - fn interner(&self) -> &'i I { + fn interner(&self) -> I { self.interner } diff --git a/chalk-ir/src/zip.rs b/chalk-ir/src/zip.rs index d7a70d36615..94cc1882869 100644 --- a/chalk-ir/src/zip.rs +++ b/chalk-ir/src/zip.rs @@ -21,7 +21,7 @@ use std::sync::Arc; /// represented by two distinct `ItemId` values, and the impl for /// `ItemId` requires that all `ItemId` in the two zipped values match /// up. -pub trait Zipper<'i, I: Interner + 'i> { +pub trait Zipper { /// Indicates that the two types `a` and `b` were found in matching spots. fn zip_tys(&mut self, variance: Variance, a: &Ty, b: &Ty) -> Fallible<()>; @@ -68,16 +68,16 @@ pub trait Zipper<'i, I: Interner + 'i> { } /// Retrieves the interner from the underlying zipper object - fn interner(&self) -> &'i I; + fn interner(&self) -> I; /// Retrieves the `UnificationDatabase` from the underlying zipper object fn unification_database(&self) -> &dyn UnificationDatabase; } -impl<'f, 'i, Z, I> Zipper<'i, I> for &'f mut Z +impl<'f, Z, I> Zipper for &'f mut Z where - I: Interner + 'i, - Z: Zipper<'i, I>, + I: Interner, + Z: Zipper, { fn zip_tys(&mut self, variance: Variance, a: &Ty, b: &Ty) -> Fallible<()> { (**self).zip_tys(variance, a, b) @@ -103,7 +103,7 @@ where (**self).zip_binders(variance, a, b) } - fn interner(&self) -> &'i I { + fn interner(&self) -> I { Z::interner(*self) } @@ -124,63 +124,49 @@ where I: Interner, { /// Uses the zipper to walk through two values, ensuring that they match. - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i; + ) -> Fallible<()>; } impl<'a, T: ?Sized + Zip, I: Interner> Zip for &'a T { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { >::zip_with(zipper, variance, a, b) } } impl Zip for () { - fn zip_with<'i, Z: Zipper<'i, I>>(_: &mut Z, _: Variance, _: &Self, _: &Self) -> Fallible<()> - where - I: 'i, - { + fn zip_with>(_: &mut Z, _: Variance, _: &Self, _: &Self) -> Fallible<()> { Ok(()) } } impl, I: Interner> Zip for Vec { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { <[T] as Zip>::zip_with(zipper, variance, a, b) } } impl, I: Interner> Zip for [T] { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { if a.len() != b.len() { return Err(NoSolution); } @@ -194,43 +180,34 @@ impl, I: Interner> Zip for [T] { } impl, I: Interner> Zip for Arc { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { >::zip_with(zipper, variance, a, b) } } impl, I: Interner> Zip for Box { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { >::zip_with(zipper, variance, a, b) } } impl, U: Zip, I: Interner> Zip for (T, U) { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { Zip::zip_with(zipper, variance, &a.0, &b.0)?; Zip::zip_with(zipper, variance, &a.1, &b.1)?; Ok(()) @@ -238,43 +215,34 @@ impl, U: Zip, I: Interner> Zip for (T, U) { } impl Zip for Ty { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { zipper.zip_tys(variance, a, b) } } impl Zip for Lifetime { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { zipper.zip_lifetimes(variance, a, b) } } impl Zip for Const { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { zipper.zip_consts(variance, a, b) } } @@ -282,15 +250,12 @@ impl Zip for Binders where T: Clone + HasInterner + Zip + Fold, { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { zipper.zip_binders(variance, a, b) } } @@ -300,15 +265,12 @@ where macro_rules! eq_zip { ($I:ident => $t:ty) => { impl<$I: Interner> Zip<$I> for $t { - fn zip_with<'i, Z: Zipper<'i, $I>>( + fn zip_with>( _zipper: &mut Z, _variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { if a != b { return Err(NoSolution); } @@ -334,15 +296,12 @@ eq_zip!(I => Mutability); eq_zip!(I => Scalar); impl + Zip, I: Interner> Zip for InEnvironment { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { Zip::zip_with(zipper, variance, &a.environment, &b.environment)?; Zip::zip_with(zipper, variance, &a.goal, &b.goal)?; Ok(()) @@ -350,15 +309,12 @@ impl + Zip, I: Interner> Zip for InEnvironmen } impl Zip for Environment { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { let interner = zipper.interner(); assert_eq!(a.clauses.len(interner), b.clauses.len(interner)); // or different numbers of clauses Zip::zip_with( @@ -372,15 +328,12 @@ impl Zip for Environment { } impl Zip for Goals { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { let interner = zipper.interner(); Zip::zip_with(zipper, variance, a.as_slice(interner), b.as_slice(interner))?; Ok(()) @@ -388,15 +341,12 @@ impl Zip for Goals { } impl Zip for ProgramClauses { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { let interner = zipper.interner(); Zip::zip_with(zipper, variance, a.as_slice(interner), b.as_slice(interner))?; Ok(()) @@ -404,15 +354,12 @@ impl Zip for ProgramClauses { } impl Zip for Constraints { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { let interner = zipper.interner(); Zip::zip_with(zipper, variance, a.as_slice(interner), b.as_slice(interner))?; Ok(()) @@ -420,15 +367,12 @@ impl Zip for Constraints { } impl Zip for QuantifiedWhereClauses { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { let interner = zipper.interner(); Zip::zip_with(zipper, variance, a.as_slice(interner), b.as_slice(interner))?; Ok(()) @@ -439,15 +383,12 @@ impl Zip for QuantifiedWhereClauses { // two parameters, and I'm too lazy to make the macro account for the // relevant name mangling. impl Zip for Goal { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { let interner = zipper.interner(); Zip::zip_with(zipper, variance, a.data(interner), b.data(interner)) } @@ -455,15 +396,12 @@ impl Zip for Goal { // I'm too lazy to make `enum_zip` support type parameters. impl Zip for VariableKind { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { match (a, b) { (VariableKind::Ty(a), VariableKind::Ty(b)) if a == b => Ok(()), (VariableKind::Lifetime, VariableKind::Lifetime) => Ok(()), @@ -478,45 +416,36 @@ impl Zip for VariableKind { } impl Zip for GenericArg { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { let interner = zipper.interner(); Zip::zip_with(zipper, variance, a.data(interner), b.data(interner)) } } impl Zip for ProgramClause { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { let interner = zipper.interner(); Zip::zip_with(zipper, variance, a.data(interner), b.data(interner)) } } impl Zip for TraitRef { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { let interner = zipper.interner(); Zip::zip_with(zipper, variance, &a.trait_id, &b.trait_id)?; zipper.zip_substs( @@ -529,15 +458,12 @@ impl Zip for TraitRef { } impl Zip for ProjectionTy { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { let interner = zipper.interner(); Zip::zip_with(zipper, variance, &a.associated_ty_id, &b.associated_ty_id)?; zipper.zip_substs( @@ -550,15 +476,12 @@ impl Zip for ProjectionTy { } impl Zip for OpaqueTy { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { let interner = zipper.interner(); Zip::zip_with(zipper, variance, &a.opaque_ty_id, &b.opaque_ty_id)?; zipper.zip_substs( @@ -571,15 +494,12 @@ impl Zip for OpaqueTy { } impl Zip for DynTy { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { Zip::zip_with( zipper, variance.xform(Variance::Invariant), @@ -597,15 +517,12 @@ impl Zip for DynTy { } impl Zip for FnSubst { - fn zip_with<'i, Z: Zipper<'i, I>>( + fn zip_with>( zipper: &mut Z, variance: Variance, a: &Self, b: &Self, - ) -> Fallible<()> - where - I: 'i, - { + ) -> Fallible<()> { let interner = zipper.interner(); // Parameters for (a, b) in a.0.as_slice(interner)[..a.0.len(interner) - 1] diff --git a/chalk-recursive/src/combine.rs b/chalk-recursive/src/combine.rs index df57bf666e7..a1bcde72b94 100644 --- a/chalk-recursive/src/combine.rs +++ b/chalk-recursive/src/combine.rs @@ -5,7 +5,7 @@ use chalk_ir::interner::Interner; use chalk_ir::{ClausePriority, DomainGoal, GenericArg}; pub(super) fn with_priorities( - interner: &I, + interner: I, domain_goal: &DomainGoal, a: Solution, prio_a: ClausePriority, @@ -38,7 +38,7 @@ pub(super) fn with_priorities( } fn calculate_inputs( - interner: &I, + interner: I, domain_goal: &DomainGoal, solution: &Solution, ) -> Vec> { diff --git a/chalk-recursive/src/fulfill.rs b/chalk-recursive/src/fulfill.rs index a7d99dc0752..0f26c6bc47f 100644 --- a/chalk-recursive/src/fulfill.rs +++ b/chalk-recursive/src/fulfill.rs @@ -64,7 +64,7 @@ enum NegativeSolution { fn canonicalize( infer: &mut InferenceTable, - interner: &I, + interner: I, value: T, ) -> (Canonical, Vec>) where @@ -82,7 +82,7 @@ where fn u_canonicalize( _infer: &mut InferenceTable, - interner: &I, + interner: I, value0: &Canonical, ) -> (UCanonical, UniverseMap) where @@ -95,7 +95,7 @@ where fn unify( infer: &mut InferenceTable, - interner: &I, + interner: I, db: &dyn UnificationDatabase, environment: &Environment, variance: Variance, @@ -604,7 +604,7 @@ impl<'s, I: Interner, Solver: SolveDatabase> Fulfill<'s, I, Solver> { } } - fn interner(&self) -> &I { + fn interner(&self) -> I { self.solver.interner() } } diff --git a/chalk-recursive/src/recursive.rs b/chalk-recursive/src/recursive.rs index e463168833c..7f5203f01f7 100644 --- a/chalk-recursive/src/recursive.rs +++ b/chalk-recursive/src/recursive.rs @@ -112,8 +112,8 @@ impl<'me, I: Interner> SolveDatabase for Solver<'me, I> { self.context.solve_goal(&goal, minimums, self.program) } - fn interner(&self) -> &I { - &self.program.interner() + fn interner(&self) -> I { + self.program.interner() } fn db(&self) -> &dyn RustIrDatabase { diff --git a/chalk-recursive/src/solve.rs b/chalk-recursive/src/solve.rs index 4428fe7171f..428225f99ef 100644 --- a/chalk-recursive/src/solve.rs +++ b/chalk-recursive/src/solve.rs @@ -24,7 +24,7 @@ pub(super) trait SolveDatabase: Sized { fn max_size(&self) -> usize; - fn interner(&self) -> &I; + fn interner(&self) -> I; fn db(&self) -> &dyn RustIrDatabase; } diff --git a/chalk-solve/src/clauses.rs b/chalk-solve/src/clauses.rs index 63a59b97ba2..5bccea66531 100644 --- a/chalk-solve/src/clauses.rs +++ b/chalk-solve/src/clauses.rs @@ -663,7 +663,7 @@ pub fn program_clauses_that_could_match( fn push_clauses_for_compatible_normalize( db: &dyn RustIrDatabase, builder: &mut ClauseBuilder<'_, I>, - interner: &I, + interner: I, trait_id: TraitId, associated_ty_id: AssocTypeId, ) { diff --git a/chalk-solve/src/clauses/builder.rs b/chalk-solve/src/clauses/builder.rs index ae244927d3e..de63f33dabc 100644 --- a/chalk-solve/src/clauses/builder.rs +++ b/chalk-solve/src/clauses/builder.rs @@ -201,7 +201,7 @@ impl<'me, I: Interner> ClauseBuilder<'me, I> { }); } - pub fn interner(&self) -> &'me I { + pub fn interner(&self) -> I { self.db.interner() } } diff --git a/chalk-solve/src/clauses/builtin_traits/unsize.rs b/chalk-solve/src/clauses/builtin_traits/unsize.rs index bc1a7742e75..f1d599b9e62 100644 --- a/chalk-solve/src/clauses/builtin_traits/unsize.rs +++ b/chalk-solve/src/clauses/builtin_traits/unsize.rs @@ -13,16 +13,16 @@ use chalk_ir::{ QuantifiedWhereClauses, Substitution, TraitId, Ty, TyKind, TypeOutlives, WhereClause, }; -struct UnsizeParameterCollector<'a, I: Interner> { - interner: &'a I, +struct UnsizeParameterCollector { + interner: I, // FIXME should probably use a bitset instead parameters: HashSet, } -impl<'a, I: Interner> Visitor<'a, I> for UnsizeParameterCollector<'a, I> { +impl Visitor for UnsizeParameterCollector { type BreakTy = (); - fn as_dyn(&mut self) -> &mut dyn Visitor<'a, I, BreakTy = Self::BreakTy> { + fn as_dyn(&mut self) -> &mut dyn Visitor { self } @@ -53,13 +53,13 @@ impl<'a, I: Interner> Visitor<'a, I> for UnsizeParameterCollector<'a, I> { ControlFlow::Continue(()) } - fn interner(&self) -> &'a I { + fn interner(&self) -> I { self.interner } } fn outer_binder_parameters_used( - interner: &I, + interner: I, v: &Binders + HasInterner>, ) -> HashSet { let mut visitor = UnsizeParameterCollector { @@ -71,15 +71,15 @@ fn outer_binder_parameters_used( } // has nothing to do with occurs check -struct ParameterOccurenceCheck<'a, 'p, I: Interner> { - interner: &'a I, +struct ParameterOccurenceCheck<'p, I: Interner> { + interner: I, parameters: &'p HashSet, } -impl<'a, 'p, I: Interner> Visitor<'a, I> for ParameterOccurenceCheck<'a, 'p, I> { +impl<'p, I: Interner> Visitor for ParameterOccurenceCheck<'p, I> { type BreakTy = (); - fn as_dyn(&mut self) -> &mut dyn Visitor<'a, I, BreakTy = Self::BreakTy> { + fn as_dyn(&mut self) -> &mut dyn Visitor { self } @@ -117,13 +117,13 @@ impl<'a, 'p, I: Interner> Visitor<'a, I> for ParameterOccurenceCheck<'a, 'p, I> } } - fn interner(&self) -> &'a I { + fn interner(&self) -> I { self.interner } } fn uses_outer_binder_params( - interner: &I, + interner: I, v: &Binders + HasInterner>, parameters: &HashSet, ) -> bool { diff --git a/chalk-solve/src/clauses/env_elaborator.rs b/chalk-solve/src/clauses/env_elaborator.rs index e09968ec377..6e5ca9cbf8c 100644 --- a/chalk-solve/src/clauses/env_elaborator.rs +++ b/chalk-solve/src/clauses/env_elaborator.rs @@ -43,14 +43,14 @@ struct EnvElaborator<'me, 'builder, I: Interner> { environment: &'me Environment, } -impl<'me, 'builder, I: Interner> Visitor<'me, I> for EnvElaborator<'me, 'builder, I> { +impl<'me, 'builder, I: Interner> Visitor for EnvElaborator<'me, 'builder, I> { type BreakTy = (); - fn as_dyn(&mut self) -> &mut dyn Visitor<'me, I, BreakTy = Self::BreakTy> { + fn as_dyn(&mut self) -> &mut dyn Visitor { self } - fn interner(&self) -> &'me I { + fn interner(&self) -> I { self.db.interner() } #[instrument(level = "debug", skip(self, _outer_binder))] diff --git a/chalk-solve/src/clauses/generalize.rs b/chalk-solve/src/clauses/generalize.rs index b8b4089fd12..f841a8ec68d 100644 --- a/chalk-solve/src/clauses/generalize.rs +++ b/chalk-solve/src/clauses/generalize.rs @@ -14,14 +14,14 @@ use chalk_ir::{ }; use rustc_hash::FxHashMap; -pub struct Generalize<'i, I: Interner> { +pub struct Generalize { binders: Vec>, mapping: FxHashMap, - interner: &'i I, + interner: I, } -impl Generalize<'_, I> { - pub fn apply(interner: &I, value: T) -> Binders +impl Generalize { + pub fn apply(interner: I, value: T) -> Binders where T: HasInterner + Fold, T::Result: HasInterner, @@ -41,10 +41,10 @@ impl Generalize<'_, I> { } } -impl<'i, I: Interner> Folder<'i, I> for Generalize<'i, I> { +impl Folder for Generalize { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder<'i, I, Error = Self::Error> { + fn as_dyn(&mut self) -> &mut dyn Folder { self } @@ -78,7 +78,7 @@ impl<'i, I: Interner> Folder<'i, I> for Generalize<'i, I> { Ok(LifetimeData::BoundVar(new_var).intern(self.interner())) } - fn interner(&self) -> &'i I { + fn interner(&self) -> I { self.interner } } diff --git a/chalk-solve/src/display/bounds.rs b/chalk-solve/src/display/bounds.rs index 389ee75f0ff..19dcb31871e 100644 --- a/chalk-solve/src/display/bounds.rs +++ b/chalk-solve/src/display/bounds.rs @@ -62,7 +62,7 @@ impl RenderAsRust for QuantifiedInlineBound { fn fmt(&self, s: &InternalWriterState<'_, I>, f: &'_ mut Formatter<'_>) -> Result { let interner = s.db().interner(); let s = &s.add_debrujin_index(None); - if !self.binders.is_empty(&interner) { + if !self.binders.is_empty(interner) { write!( f, "forall<{}> ", diff --git a/chalk-solve/src/display/stub.rs b/chalk-solve/src/display/stub.rs index 504b9c9e44e..ebeeafa93c2 100644 --- a/chalk-solve/src/display/stub.rs +++ b/chalk-solve/src/display/stub.rs @@ -183,7 +183,7 @@ impl> RustIrDatabase for StubWrapper<'_, D self.db.program_clauses_for_env(environment) } - fn interner(&self) -> &I { + fn interner(&self) -> I { self.db.interner() } diff --git a/chalk-solve/src/ext.rs b/chalk-solve/src/ext.rs index ee44845a429..4941dd9d326 100644 --- a/chalk-solve/src/ext.rs +++ b/chalk-solve/src/ext.rs @@ -4,7 +4,7 @@ use chalk_ir::interner::{HasInterner, Interner}; use chalk_ir::*; pub trait CanonicalExt { - fn map(self, interner: &I, op: OP) -> Canonical + fn map(self, interner: I, op: OP) -> Canonical where OP: FnOnce(T::Result) -> U, T: Fold, @@ -24,7 +24,7 @@ where /// inference context) are used in place of the quantified free /// variables. The result should be in terms of those same /// inference variables and will be re-canonicalized. - fn map(self, interner: &I, op: OP) -> Canonical + fn map(self, interner: I, op: OP) -> Canonical where OP: FnOnce(T::Result) -> U, T: Fold, @@ -51,8 +51,8 @@ where } pub trait GoalExt { - fn into_peeled_goal(self, interner: &I) -> UCanonical>>; - fn into_closed_goal(self, interner: &I) -> UCanonical>>; + fn into_peeled_goal(self, interner: I) -> UCanonical>>; + fn into_closed_goal(self, interner: I) -> UCanonical>>; } impl GoalExt for Goal { @@ -62,7 +62,7 @@ impl GoalExt for Goal { /// variables. Assumes that this goal is a "closed goal" which /// does not -- at present -- contain any variables. Useful for /// REPLs and tests but not much else. - fn into_peeled_goal(self, interner: &I) -> UCanonical>> { + fn into_peeled_goal(self, interner: I) -> UCanonical>> { let mut infer = InferenceTable::new(); let peeled_goal = { let mut env_goal = InEnvironment::new(&Environment::new(interner), self); @@ -104,7 +104,7 @@ impl GoalExt for Goal { /// # Panics /// /// Will panic if this goal does in fact contain free variables. - fn into_closed_goal(self, interner: &I) -> UCanonical>> { + fn into_closed_goal(self, interner: I) -> UCanonical>> { let mut infer = InferenceTable::new(); let env_goal = InEnvironment::new(&Environment::new(interner), self); let canonical_goal = infer.canonicalize(interner, env_goal).quantified; diff --git a/chalk-solve/src/goal_builder.rs b/chalk-solve/src/goal_builder.rs index 318dc8e0ed9..1ac558b486b 100644 --- a/chalk-solve/src/goal_builder.rs +++ b/chalk-solve/src/goal_builder.rs @@ -22,7 +22,7 @@ impl<'i, I: Interner> GoalBuilder<'i, I> { } /// Returns the interner within the goal builder. - pub fn interner(&self) -> &'i I { + pub fn interner(&self) -> I { self.db.interner() } diff --git a/chalk-solve/src/infer.rs b/chalk-solve/src/infer.rs index f5718e68967..ffe5e6ab445 100644 --- a/chalk-solve/src/infer.rs +++ b/chalk-solve/src/infer.rs @@ -47,7 +47,7 @@ impl InferenceTable { /// corresponding existential variable, along with the /// instantiated result. pub fn from_canonical( - interner: &I, + interner: I, num_universes: usize, canonical: Canonical, ) -> (Self, Substitution, T) @@ -118,7 +118,7 @@ impl InferenceTable { self.unify.commit(snapshot.unify_snapshot); } - pub fn normalize_ty_shallow(&mut self, interner: &I, leaf: &Ty) -> Option> { + pub fn normalize_ty_shallow(&mut self, interner: I, leaf: &Ty) -> Option> { // An integer/float type variable will never normalize to another // variable; but a general type variable might normalize to an // integer/float variable. So we potentially need to normalize twice to @@ -127,26 +127,26 @@ impl InferenceTable { .map(|ty| self.normalize_ty_shallow_inner(interner, &ty).unwrap_or(ty)) } - fn normalize_ty_shallow_inner(&mut self, interner: &I, leaf: &Ty) -> Option> { + fn normalize_ty_shallow_inner(&mut self, interner: I, leaf: &Ty) -> Option> { self.probe_var(leaf.inference_var(interner)?) .map(|p| p.assert_ty_ref(interner).clone()) } pub fn normalize_lifetime_shallow( &mut self, - interner: &I, + interner: I, leaf: &Lifetime, ) -> Option> { self.probe_var(leaf.inference_var(interner)?) .map(|p| p.assert_lifetime_ref(interner).clone()) } - pub fn normalize_const_shallow(&mut self, interner: &I, leaf: &Const) -> Option> { + pub fn normalize_const_shallow(&mut self, interner: I, leaf: &Const) -> Option> { self.probe_var(leaf.inference_var(interner)?) .map(|p| p.assert_const_ref(interner).clone()) } - pub fn ty_root(&mut self, interner: &I, leaf: &Ty) -> Option> { + pub fn ty_root(&mut self, interner: I, leaf: &Ty) -> Option> { Some( self.unify .find(leaf.inference_var(interner)?) @@ -154,7 +154,7 @@ impl InferenceTable { ) } - pub fn lifetime_root(&mut self, interner: &I, leaf: &Lifetime) -> Option> { + pub fn lifetime_root(&mut self, interner: I, leaf: &Lifetime) -> Option> { Some( self.unify .find(leaf.inference_var(interner)?) @@ -196,11 +196,11 @@ impl InferenceTable { } pub trait ParameterEnaVariableExt { - fn to_generic_arg(&self, interner: &I) -> GenericArg; + fn to_generic_arg(&self, interner: I) -> GenericArg; } impl ParameterEnaVariableExt for ParameterEnaVariable { - fn to_generic_arg(&self, interner: &I) -> GenericArg { + fn to_generic_arg(&self, interner: I) -> GenericArg { // we are matching on kind, so skipping it is fine let ena_variable = self.skip_kind(); match &self.kind { diff --git a/chalk-solve/src/infer/canonicalize.rs b/chalk-solve/src/infer/canonicalize.rs index f87479089b7..1510edfd120 100644 --- a/chalk-solve/src/infer/canonicalize.rs +++ b/chalk-solve/src/infer/canonicalize.rs @@ -27,7 +27,7 @@ impl InferenceTable { /// /// A substitution mapping from the free variables to their re-bound form is /// also returned. - pub fn canonicalize(&mut self, interner: &I, value: T) -> Canonicalized + pub fn canonicalize(&mut self, interner: I, value: T) -> Canonicalized where T: Fold, T::Result: HasInterner, @@ -71,7 +71,7 @@ struct Canonicalizer<'q, I: Interner> { table: &'q mut InferenceTable, free_vars: Vec>, max_universe: UniverseIndex, - interner: &'q I, + interner: I, } impl<'q, I: Interner> Canonicalizer<'q, I> { @@ -107,13 +107,10 @@ impl<'q, I: Interner> Canonicalizer<'q, I> { } } -impl<'i, I: Interner> Folder<'i, I> for Canonicalizer<'i, I> -where - I: 'i, -{ +impl<'i, I: Interner> Folder for Canonicalizer<'i, I> { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder<'i, I, Error = Self::Error> { + fn as_dyn(&mut self) -> &mut dyn Folder { self } @@ -257,7 +254,7 @@ where } } - fn interner(&self) -> &'i I { + fn interner(&self) -> I { self.interner } } diff --git a/chalk-solve/src/infer/instantiate.rs b/chalk-solve/src/infer/instantiate.rs index fb296b7d855..288efa025ed 100644 --- a/chalk-solve/src/infer/instantiate.rs +++ b/chalk-solve/src/infer/instantiate.rs @@ -13,7 +13,7 @@ impl InferenceTable { /// `self.instantiate_canonical(v)`. pub(super) fn fresh_subst( &mut self, - interner: &I, + interner: I, binders: &[CanonicalVarKind], ) -> Substitution { Substitution::from_iter( @@ -26,7 +26,7 @@ impl InferenceTable { } /// Variant on `instantiate` that takes a `Canonical`. - pub fn instantiate_canonical(&mut self, interner: &I, bound: Canonical) -> T::Result + pub fn instantiate_canonical(&mut self, interner: I, bound: Canonical) -> T::Result where T: HasInterner + Fold + Debug, { @@ -41,7 +41,7 @@ impl InferenceTable { /// argument is referring to `X, 'Y`. fn instantiate_in( &mut self, - interner: &I, + interner: I, universe: UniverseIndex, binders: impl Iterator>, arg: T, @@ -58,9 +58,9 @@ impl InferenceTable { /// Variant on `instantiate_in` that takes a `Binders`. #[instrument(level = "debug", skip(self, interner))] - pub fn instantiate_binders_existentially<'a, T>( + pub fn instantiate_binders_existentially( &mut self, - interner: &'a I, + interner: I, arg: Binders, ) -> T::Result where @@ -78,11 +78,7 @@ impl InferenceTable { } #[instrument(level = "debug", skip(self, interner))] - pub fn instantiate_binders_universally<'a, T>( - &mut self, - interner: &'a I, - arg: Binders, - ) -> T::Result + pub fn instantiate_binders_universally(&mut self, interner: I, arg: Binders) -> T::Result where T: Fold + HasInterner, { diff --git a/chalk-solve/src/infer/invert.rs b/chalk-solve/src/infer/invert.rs index f6e511dbe57..0f088543a8e 100644 --- a/chalk-solve/src/infer/invert.rs +++ b/chalk-solve/src/infer/invert.rs @@ -71,7 +71,7 @@ impl InferenceTable { /// `?T: Clone` in the case where `?T = Vec`. The current /// version would delay processing the negative goal (i.e., return /// `None`) until the second unification has occurred.) - pub fn invert(&mut self, interner: &I, value: T) -> Option + pub fn invert(&mut self, interner: I, value: T) -> Option where T: Fold + HasInterner, { @@ -99,7 +99,7 @@ impl InferenceTable { /// returning. Just a convenience function. pub fn invert_then_canonicalize( &mut self, - interner: &I, + interner: I, value: T, ) -> Option> where @@ -117,11 +117,11 @@ struct Inverter<'q, I: Interner> { table: &'q mut InferenceTable, inverted_ty: FxHashMap>, inverted_lifetime: FxHashMap>, - interner: &'q I, + interner: I, } impl<'q, I: Interner> Inverter<'q, I> { - fn new(interner: &'q I, table: &'q mut InferenceTable) -> Self { + fn new(interner: I, table: &'q mut InferenceTable) -> Self { Inverter { table, inverted_ty: FxHashMap::default(), @@ -131,13 +131,10 @@ impl<'q, I: Interner> Inverter<'q, I> { } } -impl<'i, I: Interner> Folder<'i, I> for Inverter<'i, I> -where - I: 'i, -{ +impl<'i, I: Interner> Folder for Inverter<'i, I> { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder<'i, I, Error = Self::Error> { + fn as_dyn(&mut self) -> &mut dyn Folder { self } @@ -177,7 +174,7 @@ where true } - fn interner(&self) -> &'i I { + fn interner(&self) -> I { self.interner } } diff --git a/chalk-solve/src/infer/test.rs b/chalk-solve/src/infer/test.rs index ddf09037b94..2ac35f0275d 100644 --- a/chalk-solve/src/infer/test.rs +++ b/chalk-solve/src/infer/test.rs @@ -11,18 +11,18 @@ use chalk_integration::{arg, lifetime, ty}; struct TestDatabase; impl UnificationDatabase for TestDatabase { fn fn_def_variance(&self, _fn_def_id: FnDefId) -> Variances { - Variances::from_iter(&ChalkIr, [Variance::Invariant; 20].iter().copied()) + Variances::from_iter(ChalkIr, [Variance::Invariant; 20].iter().copied()) } fn adt_variance(&self, _adt_id: AdtId) -> Variances { - Variances::from_iter(&ChalkIr, [Variance::Invariant; 20].iter().copied()) + Variances::from_iter(ChalkIr, [Variance::Invariant; 20].iter().copied()) } } #[test] fn universe_error() { // exists(A -> forall(X -> A = X)) ---> error - let interner = &ChalkIr; + let interner = ChalkIr; let mut table: InferenceTable = InferenceTable::new(); let environment0 = Environment::new(interner); let a = table.new_variable(U0).to_ty(interner); @@ -41,7 +41,7 @@ fn universe_error() { #[test] fn cycle_error() { // exists(A -> A = foo A) ---> error - let interner = &ChalkIr; + let interner = ChalkIr; let mut table: InferenceTable = InferenceTable::new(); let environment0 = Environment::new(interner); let a = table.new_variable(U0).to_ty(interner); @@ -72,7 +72,7 @@ fn cycle_error() { #[test] fn cycle_indirect() { // exists(A -> A = foo B, A = B) ---> error - let interner = &ChalkIr; + let interner = ChalkIr; let mut table: InferenceTable = InferenceTable::new(); let environment0 = Environment::new(interner); let a = table.new_variable(U0).to_ty(interner); @@ -102,7 +102,7 @@ fn cycle_indirect() { #[test] fn universe_error_indirect_1() { // exists(A -> forall(X -> exists(B -> B = X, A = B))) ---> error - let interner = &ChalkIr; + let interner = ChalkIr; let mut table: InferenceTable = InferenceTable::new(); let environment0 = Environment::new(interner); let a = table.new_variable(U0).to_ty(interner); @@ -132,7 +132,7 @@ fn universe_error_indirect_1() { #[test] fn universe_error_indirect_2() { // exists(A -> forall(X -> exists(B -> B = A, B = X))) ---> error - let interner = &ChalkIr; + let interner = ChalkIr; let mut table: InferenceTable = InferenceTable::new(); let environment0 = Environment::new(interner); let a = table.new_variable(U0).to_ty(interner); @@ -162,7 +162,7 @@ fn universe_error_indirect_2() { #[test] fn universe_promote() { // exists(A -> forall(X -> exists(B -> A = foo(B), A = foo(i32)))) ---> OK - let interner = &ChalkIr; + let interner = ChalkIr; let mut table: InferenceTable = InferenceTable::new(); let environment0 = Environment::new(interner); let a = table.new_variable(U0).to_ty(interner); @@ -192,7 +192,7 @@ fn universe_promote() { #[test] fn universe_promote_bad() { // exists(A -> forall(X -> exists(B -> A = foo(B), B = X))) ---> error - let interner = &ChalkIr; + let interner = ChalkIr; let mut table: InferenceTable = InferenceTable::new(); let environment0 = Environment::new(interner); let a = table.new_variable(U0).to_ty(interner); @@ -224,7 +224,7 @@ fn projection_eq() { // exists(A -> A = Item0<::foo>) // ^^^^^^^^^^^^ Can A repeat here? For now, // we say no, but it's an interesting question. - let interner = &ChalkIr; + let interner = ChalkIr; let mut table: InferenceTable = InferenceTable::new(); let environment0 = Environment::new(interner); let a = table.new_variable(U0).to_ty(interner); @@ -255,7 +255,7 @@ fn make_table() -> InferenceTable { #[test] fn quantify_simple() { - let interner = &ChalkIr; + let interner = ChalkIr; let mut table = make_table(); let _ = table.new_variable(U0); let _ = table.new_variable(U1); @@ -281,7 +281,7 @@ fn quantify_simple() { #[test] fn quantify_bound() { - let interner = &ChalkIr; + let interner = ChalkIr; let mut table = make_table(); let environment0 = Environment::new(interner); @@ -324,7 +324,7 @@ fn quantify_bound() { #[test] fn quantify_ty_under_binder() { - let interner = &ChalkIr; + let interner = ChalkIr; let mut table = make_table(); let v0 = table.new_variable(U0); let v1 = table.new_variable(U0); @@ -369,7 +369,7 @@ fn quantify_ty_under_binder() { #[test] fn lifetime_constraint_indirect() { - let interner = &ChalkIr; + let interner = ChalkIr; let mut table: InferenceTable = InferenceTable::new(); let _ = table.new_universe(); // U1 diff --git a/chalk-solve/src/infer/ucanonicalize.rs b/chalk-solve/src/infer/ucanonicalize.rs index e754fb75c4b..0bb85198bde 100644 --- a/chalk-solve/src/infer/ucanonicalize.rs +++ b/chalk-solve/src/infer/ucanonicalize.rs @@ -8,7 +8,7 @@ use std::ops::ControlFlow; use super::InferenceTable; impl InferenceTable { - pub fn u_canonicalize(interner: &I, value0: &Canonical) -> UCanonicalized + pub fn u_canonicalize(interner: I, value0: &Canonical) -> UCanonicalized where T: Clone + HasInterner + Fold + Visit, T::Result: HasInterner, @@ -80,7 +80,7 @@ pub trait UniverseMapExt { fn map_universe_from_canonical(&self, universe: UniverseIndex) -> UniverseIndex; fn map_from_canonical( &self, - interner: &I, + interner: I, canonical_value: &Canonical, ) -> Canonical where @@ -159,7 +159,7 @@ impl UniverseMapExt for UniverseMap { /// other original universes. fn map_from_canonical( &self, - interner: &I, + interner: I, canonical_value: &Canonical, ) -> Canonical where @@ -195,18 +195,15 @@ impl UniverseMapExt for UniverseMap { /// The `UCollector` is a "no-op" in terms of the value, but along the /// way it collects all universes that were found into a vector. -struct UCollector<'q, 'i, I> { +struct UCollector<'q, I> { universes: &'q mut UniverseMap, - interner: &'i I, + interner: I, } -impl<'i, I: Interner> Visitor<'i, I> for UCollector<'_, 'i, I> -where - I: 'i, -{ +impl Visitor for UCollector<'_, I> { type BreakTy = (); - fn as_dyn(&mut self) -> &mut dyn Visitor<'i, I, BreakTy = Self::BreakTy> { + fn as_dyn(&mut self) -> &mut dyn Visitor { self } @@ -223,23 +220,20 @@ where true } - fn interner(&self) -> &'i I { + fn interner(&self) -> I { self.interner } } struct UMapToCanonical<'q, I> { - interner: &'q I, + interner: I, universes: &'q UniverseMap, } -impl<'i, I: Interner> Folder<'i, I> for UMapToCanonical<'i, I> -where - I: 'i, -{ +impl<'i, I: Interner> Folder for UMapToCanonical<'i, I> { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder<'i, I, Error = Self::Error> { + fn as_dyn(&mut self) -> &mut dyn Folder { self } @@ -298,23 +292,20 @@ where .to_const(self.interner(), ty.clone())) } - fn interner(&self) -> &'i I { + fn interner(&self) -> I { self.interner } } struct UMapFromCanonical<'q, I> { - interner: &'q I, + interner: I, universes: &'q UniverseMap, } -impl<'i, I: Interner> Folder<'i, I> for UMapFromCanonical<'i, I> -where - I: 'i, -{ +impl<'i, I: Interner> Folder for UMapFromCanonical<'i, I> { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder<'i, I, Error = Self::Error> { + fn as_dyn(&mut self) -> &mut dyn Folder { self } @@ -348,7 +339,7 @@ where true } - fn interner(&self) -> &'i I { + fn interner(&self) -> I { self.interner } } diff --git a/chalk-solve/src/infer/unify.rs b/chalk-solve/src/infer/unify.rs index 2f7d513ac7d..19b98621d46 100644 --- a/chalk-solve/src/infer/unify.rs +++ b/chalk-solve/src/infer/unify.rs @@ -12,7 +12,7 @@ use tracing::{debug, instrument}; impl InferenceTable { pub fn relate( &mut self, - interner: &I, + interner: I, db: &dyn UnificationDatabase, environment: &Environment, variance: Variance, @@ -40,7 +40,7 @@ struct Unifier<'t, I: Interner> { table: &'t mut InferenceTable, environment: &'t Environment, goals: Vec>>, - interner: &'t I, + interner: I, db: &'t dyn UnificationDatabase, } @@ -51,7 +51,7 @@ pub struct RelationResult { impl<'t, I: Interner> Unifier<'t, I> { fn new( - interner: &'t I, + interner: I, db: &'t dyn UnificationDatabase, table: &'t mut InferenceTable, environment: &'t Environment, @@ -241,7 +241,7 @@ impl<'t, I: Interner> Unifier<'t, I> { self.zip_substs( variance, Some(Variances::from_iter( - &self.interner, + self.interner, std::iter::repeat(Variance::Covariant).take(*arity_a), )), substitution_a.as_slice(interner), @@ -759,7 +759,7 @@ impl<'t, I: Interner> Unifier<'t, I> { variance: Variance, ) -> Lifetime { let interner = self.interner; - match lifetime.data(&interner) { + match lifetime.data(interner) { LifetimeData::BoundVar(_) => { return lifetime.clone(); } @@ -777,7 +777,7 @@ impl<'t, I: Interner> Unifier<'t, I> { #[instrument(level = "debug", skip(self))] fn generalize_const(&mut self, const_: &Const, universe_index: UniverseIndex) -> Const { let interner = self.interner; - let data = const_.data(&interner); + let data = const_.data(interner); match data.value { ConstValue::BoundVar(_) => { return const_.clone(); @@ -1039,7 +1039,7 @@ impl<'t, I: Interner> Unifier<'t, I> { .unify .unify_var_value( var, - InferenceValue::from_lifetime(&self.interner, value.clone()), + InferenceValue::from_lifetime(self.interner, value.clone()), ) .unwrap(); Ok(()) @@ -1050,7 +1050,7 @@ impl<'t, I: Interner> Unifier<'t, I> { ); Ok(self.push_lifetime_outlives_goals( variance, - var.to_lifetime(&self.interner), + var.to_lifetime(self.interner), value.clone(), )) } @@ -1190,7 +1190,7 @@ impl<'t, I: Interner> Unifier<'t, I> { } } -impl<'i, I: Interner> Zipper<'i, I> for Unifier<'i, I> { +impl<'i, I: Interner> Zipper for Unifier<'i, I> { fn zip_tys(&mut self, variance: Variance, a: &Ty, b: &Ty) -> Fallible<()> { debug!("zip_tys {:?}, {:?}, {:?}", variance, a, b); self.relate_ty_ty(variance, a, b) @@ -1227,7 +1227,7 @@ impl<'i, I: Interner> Zipper<'i, I> for Unifier<'i, I> { self.relate_binders(variance, a, b) } - fn interner(&self) -> &'i I { + fn interner(&self) -> I { self.interner } @@ -1256,13 +1256,10 @@ impl<'u, 't, I: Interner> OccursCheck<'u, 't, I> { } } -impl<'i, I: Interner> Folder<'i, I> for OccursCheck<'_, 'i, I> -where - I: 'i, -{ +impl<'i, I: Interner> Folder for OccursCheck<'_, 'i, I> { type Error = NoSolution; - fn as_dyn(&mut self) -> &mut dyn Folder<'i, I, Error = Self::Error> { + fn as_dyn(&mut self) -> &mut dyn Folder { self } @@ -1468,7 +1465,7 @@ where true } - fn interner(&self) -> &'i I { + fn interner(&self) -> I { self.unifier.interner } } diff --git a/chalk-solve/src/infer/var.rs b/chalk-solve/src/infer/var.rs index c2886031aac..3fbf9200201 100644 --- a/chalk-solve/src/infer/var.rs +++ b/chalk-solve/src/infer/var.rs @@ -60,28 +60,28 @@ impl EnaVariable { /// Convert this inference variable into a type. When using this /// method, naturally you should know from context that the kind /// of this inference variable is a type (we can't check it). - pub fn to_ty_with_kind(self, interner: &I, kind: TyVariableKind) -> Ty { + pub fn to_ty_with_kind(self, interner: I, kind: TyVariableKind) -> Ty { self.var.to_ty(interner, kind) } /// Same as `to_ty_with_kind`, but the kind is set to `TyVariableKind::General`. /// This should be used instead of `to_ty_with_kind` when creating a new /// inference variable (when the kind is not known). - pub fn to_ty(self, interner: &I) -> Ty { + pub fn to_ty(self, interner: I) -> Ty { self.var.to_ty(interner, TyVariableKind::General) } /// Convert this inference variable into a lifetime. When using this /// method, naturally you should know from context that the kind /// of this inference variable is a lifetime (we can't check it). - pub fn to_lifetime(self, interner: &I) -> Lifetime { + pub fn to_lifetime(self, interner: I) -> Lifetime { self.var.to_lifetime(interner) } /// Convert this inference variable into a const. When using this /// method, naturally you should know from context that the kind /// of this inference variable is a const (we can't check it). - pub fn to_const(self, interner: &I, ty: Ty) -> Const { + pub fn to_const(self, interner: I, ty: Ty) -> Const { self.var.to_const(interner, ty) } } @@ -112,15 +112,15 @@ pub enum InferenceValue { } impl InferenceValue { - pub fn from_ty(interner: &I, ty: Ty) -> Self { + pub fn from_ty(interner: I, ty: Ty) -> Self { InferenceValue::Bound(ty.cast(interner)) } - pub fn from_lifetime(interner: &I, lifetime: Lifetime) -> Self { + pub fn from_lifetime(interner: I, lifetime: Lifetime) -> Self { InferenceValue::Bound(lifetime.cast(interner)) } - pub fn from_const(interner: &I, constant: Const) -> Self { + pub fn from_const(interner: I, constant: Const) -> Self { InferenceValue::Bound(constant.cast(interner)) } } diff --git a/chalk-solve/src/lib.rs b/chalk-solve/src/lib.rs index 6805dd9f6dd..92c76e70be7 100644 --- a/chalk-solve/src/lib.rs +++ b/chalk-solve/src/lib.rs @@ -123,7 +123,7 @@ pub trait RustIrDatabase: Debug { /// `program_clauses_for_env` function and then possibly cache the clauses. fn program_clauses_for_env(&self, environment: &Environment) -> ProgramClauses; - fn interner(&self) -> &I; + fn interner(&self) -> I; /// Check if a trait is object safe fn is_object_safe(&self, trait_id: TraitId) -> bool; diff --git a/chalk-solve/src/logging_db.rs b/chalk-solve/src/logging_db.rs index 4e7fa0c4959..15fdfadc2a5 100644 --- a/chalk-solve/src/logging_db.rs +++ b/chalk-solve/src/logging_db.rs @@ -221,7 +221,7 @@ where self.ws.db().program_clauses_for_env(environment) } - fn interner(&self) -> &I { + fn interner(&self) -> I { self.ws.db().interner() } @@ -469,7 +469,7 @@ where self.db.program_clauses_for_env(environment) } - fn interner(&self) -> &I { + fn interner(&self) -> I { self.db.interner() } diff --git a/chalk-solve/src/logging_db/id_collector.rs b/chalk-solve/src/logging_db/id_collector.rs index bfd40518c39..f406b8b9a1e 100644 --- a/chalk-solve/src/logging_db/id_collector.rs +++ b/chalk-solve/src/logging_db/id_collector.rs @@ -115,16 +115,13 @@ impl<'i, I: Interner, DB: RustIrDatabase> IdCollector<'i, I, DB> { } } -impl<'i, I: Interner, DB: RustIrDatabase> Visitor<'i, I> for IdCollector<'i, I, DB> -where - I: 'i, -{ +impl<'i, I: Interner, DB: RustIrDatabase> Visitor for IdCollector<'i, I, DB> { type BreakTy = (); - fn as_dyn(&mut self) -> &mut dyn Visitor<'i, I, BreakTy = Self::BreakTy> { + fn as_dyn(&mut self) -> &mut dyn Visitor { self } - fn interner(&self) -> &'i I { + fn interner(&self) -> I { self.db.interner() } diff --git a/chalk-solve/src/rust_ir.rs b/chalk-solve/src/rust_ir.rs index ec33d56bd3e..612d05203e9 100644 --- a/chalk-solve/src/rust_ir.rs +++ b/chalk-solve/src/rust_ir.rs @@ -38,7 +38,7 @@ impl ImplDatum { self.binders.skip_binders().trait_ref.trait_id } - pub fn self_type_adt_id(&self, interner: &I) -> Option> { + pub fn self_type_adt_id(&self, interner: I) -> Option> { match self .binders .skip_binders() @@ -142,14 +142,11 @@ pub struct FnDefDatum { /// Avoids visiting `I::FnAbi` impl Visit for FnDefDatum { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn chalk_ir::visit::Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn chalk_ir::visit::Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { try_break!(self.id.visit_with(visitor, outer_binder)); self.binders.visit_with(visitor, outer_binder) } @@ -349,7 +346,7 @@ pub type QuantifiedInlineBound = Binders>; pub trait IntoWhereClauses { type Output; - fn into_where_clauses(&self, interner: &I, self_ty: Ty) -> Vec; + fn into_where_clauses(&self, interner: I, self_ty: Ty) -> Vec; } impl IntoWhereClauses for InlineBound { @@ -360,7 +357,7 @@ impl IntoWhereClauses for InlineBound { /// /// Because an `InlineBound` does not know anything about what it's binding, /// you must provide that type as `self_ty`. - fn into_where_clauses(&self, interner: &I, self_ty: Ty) -> Vec> { + fn into_where_clauses(&self, interner: I, self_ty: Ty) -> Vec> { match self { InlineBound::TraitBound(b) => b.into_where_clauses(interner, self_ty), InlineBound::AliasEqBound(b) => b.into_where_clauses(interner, self_ty), @@ -371,7 +368,7 @@ impl IntoWhereClauses for InlineBound { impl IntoWhereClauses for QuantifiedInlineBound { type Output = QuantifiedWhereClause; - fn into_where_clauses(&self, interner: &I, self_ty: Ty) -> Vec> { + fn into_where_clauses(&self, interner: I, self_ty: Ty) -> Vec> { let self_ty = self_ty.shifted_in(interner); self.map_ref(|b| b.into_where_clauses(interner, self_ty)) .into_iter() @@ -388,12 +385,12 @@ pub struct TraitBound { } impl TraitBound { - fn into_where_clauses(&self, interner: &I, self_ty: Ty) -> Vec> { + fn into_where_clauses(&self, interner: I, self_ty: Ty) -> Vec> { let trait_ref = self.as_trait_ref(interner, self_ty); vec![WhereClause::Implemented(trait_ref)] } - pub fn as_trait_ref(&self, interner: &I, self_ty: Ty) -> TraitRef { + pub fn as_trait_ref(&self, interner: I, self_ty: Ty) -> TraitRef { TraitRef { trait_id: self.trait_id, substitution: Substitution::from_iter( @@ -416,7 +413,7 @@ pub struct AliasEqBound { } impl AliasEqBound { - fn into_where_clauses(&self, interner: &I, self_ty: Ty) -> Vec> { + fn into_where_clauses(&self, interner: I, self_ty: Ty) -> Vec> { let trait_ref = self.trait_bound.as_trait_ref(interner, self_ty); let substitution = Substitution::from_iter( @@ -491,14 +488,11 @@ pub struct AssociatedTyDatum { // Manual implementation to avoid I::Identifier type. impl Visit for AssociatedTyDatum { - fn visit_with<'i, B>( + fn visit_with( &self, - visitor: &mut dyn chalk_ir::visit::Visitor<'i, I, BreakTy = B>, + visitor: &mut dyn chalk_ir::visit::Visitor, outer_binder: DebruijnIndex, - ) -> ControlFlow - where - I: 'i, - { + ) -> ControlFlow { try_break!(self.trait_id.visit_with(visitor, outer_binder)); try_break!(self.id.visit_with(visitor, outer_binder)); self.binders.visit_with(visitor, outer_binder) @@ -528,7 +522,7 @@ impl AssociatedTyDatum { /// /// these quantified where clauses are in the scope of the /// `binders` field. - pub fn bounds_on_self(&self, interner: &I) -> Vec> { + pub fn bounds_on_self(&self, interner: I) -> Vec> { let (binders, assoc_ty_datum) = self.binders.as_ref().into(); // Create a list `P0...Pn` of references to the binders in // scope for this associated type: diff --git a/chalk-solve/src/solve.rs b/chalk-solve/src/solve.rs index 1ea76cebe0e..9bf634cd6d3 100644 --- a/chalk-solve/src/solve.rs +++ b/chalk-solve/src/solve.rs @@ -61,7 +61,7 @@ impl Solution { // Clone`. // // But you get the idea. - pub fn combine(self, other: Solution, interner: &I) -> Solution { + pub fn combine(self, other: Solution, interner: I) -> Solution { use self::Guidance::*; if self == other { @@ -100,7 +100,7 @@ impl Solution { } /// Extract a constrained substitution from this solution, even if ambiguous. - pub fn constrained_subst(&self, interner: &I) -> Option>> { + pub fn constrained_subst(&self, interner: I) -> Option>> { match *self { Solution::Unique(ref constrained) => Some(constrained.clone()), Solution::Ambig(Guidance::Definite(ref canonical)) @@ -120,7 +120,7 @@ impl Solution { /// Determine whether this solution contains type information that *must* /// hold, and returns the subst in that case. - pub fn definite_subst(&self, interner: &I) -> Option>> { + pub fn definite_subst(&self, interner: I) -> Option>> { match self { Solution::Unique(constrained) => Some(constrained.clone()), Solution::Ambig(Guidance::Definite(canonical)) => { @@ -145,7 +145,7 @@ impl Solution { matches!(*self, Solution::Ambig(_)) } - pub fn display<'a>(&'a self, interner: &'a I) -> SolutionDisplay<'a, I> { + pub fn display<'a>(&'a self, interner: I) -> SolutionDisplay<'a, I> { SolutionDisplay { solution: self, interner, @@ -155,23 +155,25 @@ impl Solution { pub struct SolutionDisplay<'a, I: Interner> { solution: &'a Solution, - interner: &'a I, + interner: I, } impl<'a, I: Interner> fmt::Display for SolutionDisplay<'a, I> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { let SolutionDisplay { solution, interner } = self; match solution { - Solution::Unique(constrained) => write!(f, "Unique; {}", constrained.display(interner)), + Solution::Unique(constrained) => { + write!(f, "Unique; {}", constrained.display(*interner)) + } Solution::Ambig(Guidance::Definite(subst)) => write!( f, "Ambiguous; definite substitution {}", - subst.display(interner) + subst.display(*interner) ), Solution::Ambig(Guidance::Suggested(subst)) => write!( f, "Ambiguous; suggested substitution {}", - subst.display(interner) + subst.display(*interner) ), Solution::Ambig(Guidance::Unknown) => write!(f, "Ambiguous; no inference guidance"), } diff --git a/chalk-solve/src/solve/truncate.rs b/chalk-solve/src/solve/truncate.rs index 78bfc7bde82..b48a0324c69 100644 --- a/chalk-solve/src/solve/truncate.rs +++ b/chalk-solve/src/solve/truncate.rs @@ -20,7 +20,7 @@ use std::ops::ControlFlow; /// - Radial Restraint /// - Grosof and Swift; 2013 pub fn needs_truncation( - interner: &I, + interner: I, infer: &mut InferenceTable, max_size: usize, value: impl Visit, @@ -31,16 +31,16 @@ pub fn needs_truncation( visitor.max_size > max_size } -struct TySizeVisitor<'infer, 'i, I: Interner> { - interner: &'i I, +struct TySizeVisitor<'infer, I: Interner> { + interner: I, infer: &'infer mut InferenceTable, size: usize, depth: usize, max_size: usize, } -impl<'infer, 'i, I: Interner> TySizeVisitor<'infer, 'i, I> { - fn new(interner: &'i I, infer: &'infer mut InferenceTable) -> Self { +impl<'infer, I: Interner> TySizeVisitor<'infer, I> { + fn new(interner: I, infer: &'infer mut InferenceTable) -> Self { Self { interner, infer, @@ -51,10 +51,10 @@ impl<'infer, 'i, I: Interner> TySizeVisitor<'infer, 'i, I> { } } -impl<'infer, 'i, I: Interner> Visitor<'i, I> for TySizeVisitor<'infer, 'i, I> { +impl<'infer, I: Interner> Visitor for TySizeVisitor<'infer, I> { type BreakTy = (); - fn as_dyn(&mut self) -> &mut dyn Visitor<'i, I, BreakTy = Self::BreakTy> { + fn as_dyn(&mut self) -> &mut dyn Visitor { self } @@ -79,7 +79,7 @@ impl<'infer, 'i, I: Interner> Visitor<'i, I> for TySizeVisitor<'infer, 'i, I> { ControlFlow::Continue(()) } - fn interner(&self) -> &'i I { + fn interner(&self) -> I { self.interner } } @@ -92,7 +92,7 @@ mod tests { #[test] fn one_type() { use chalk_integration::interner::ChalkIr; - let interner = &ChalkIr; + let interner = ChalkIr; let mut table = InferenceTable::::new(); let _u1 = table.new_universe(); @@ -111,7 +111,7 @@ mod tests { #[test] fn multiple_types() { use chalk_integration::interner::ChalkIr; - let interner = &ChalkIr; + let interner = ChalkIr; let mut table = InferenceTable::::new(); let _u1 = table.new_universe(); diff --git a/chalk-solve/src/wf.rs b/chalk-solve/src/wf.rs index 3a610bdde8f..1079e8cbf97 100644 --- a/chalk-solve/src/wf.rs +++ b/chalk-solve/src/wf.rs @@ -49,33 +49,33 @@ pub struct WfSolver<'a, I: Interner> { solver_builder: &'a dyn Fn() -> Box>, } -struct InputTypeCollector<'i, I: Interner> { +struct InputTypeCollector { types: Vec>, - interner: &'i I, + interner: I, } -impl<'i, I: Interner> InputTypeCollector<'i, I> { - fn new(interner: &'i I) -> Self { +impl InputTypeCollector { + fn new(interner: I) -> Self { Self { types: Vec::new(), interner, } } - fn types_in(interner: &'i I, value: impl Visit) -> Vec> { + fn types_in(interner: I, value: impl Visit) -> Vec> { let mut collector = Self::new(interner); value.visit_with(&mut collector, DebruijnIndex::INNERMOST); collector.types } } -impl<'i, I: Interner> Visitor<'i, I> for InputTypeCollector<'i, I> { +impl Visitor for InputTypeCollector { type BreakTy = (); - fn as_dyn(&mut self) -> &mut dyn Visitor<'i, I, BreakTy = Self::BreakTy> { + fn as_dyn(&mut self) -> &mut dyn Visitor { self } - fn interner(&self) -> &'i I { + fn interner(&self) -> I { self.interner } @@ -491,7 +491,7 @@ fn impl_header_wf_goal( /// Creates the conditions that an impl (and its contents of an impl) /// can assume to be true when proving that it is well-formed. fn impl_wf_environment<'i, I: Interner>( - interner: &'i I, + interner: I, where_clauses: &'i [QuantifiedWhereClause], trait_ref: &'i TraitRef, ) -> impl Iterator> + 'i { diff --git a/src/main.rs b/src/main.rs index 76ca4389a10..c1e85b4ac18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -70,7 +70,7 @@ impl LoadedProgram { let peeled_goal = goal.into_peeled_goal(self.db.interner()); if multiple_answers { if self.db.solve_multiple(&peeled_goal, &mut |v, has_next| { - println!("{}\n", v.as_ref().map(|v| v.display(&ChalkIr))); + println!("{}\n", v.as_ref().map(|v| v.display(ChalkIr))); if has_next { if let Some(ref mut rl) = rl { loop { @@ -97,7 +97,7 @@ impl LoadedProgram { } } else { match self.db.solve(&peeled_goal) { - Some(v) => println!("{}\n", v.display(&ChalkIr)), + Some(v) => println!("{}\n", v.display(ChalkIr)), None => println!("No possible solution.\n"), } } diff --git a/tests/display/unique_names.rs b/tests/display/unique_names.rs index a566660a46a..eb0131fde36 100644 --- a/tests/display/unique_names.rs +++ b/tests/display/unique_names.rs @@ -151,7 +151,7 @@ where ) -> chalk_ir::ProgramClauses { self.db.program_clauses_for_env(environment) } - fn interner(&self) -> &I { + fn interner(&self) -> I { self.db.interner() } fn is_object_safe(&self, trait_id: chalk_ir::TraitId) -> bool { diff --git a/tests/integration/panic.rs b/tests/integration/panic.rs index 3c282aac0a2..caee4c0523d 100644 --- a/tests/integration/panic.rs +++ b/tests/integration/panic.rs @@ -68,7 +68,7 @@ impl RustIrDatabase for MockDatabase { Arc::new(TraitDatum { id, binders: Binders::new( - VariableKinds::empty(&ChalkIr), + VariableKinds::empty(ChalkIr), TraitDatumBound { where_clauses: vec![], }, @@ -95,16 +95,16 @@ impl RustIrDatabase for MockDatabase { assert_eq!(id.0.index, 1); let substitution = Ty::new( - &ChalkIr, - TyKind::Adt(AdtId(RawId { index: 1 }), Substitution::empty(&ChalkIr)), + ChalkIr, + TyKind::Adt(AdtId(RawId { index: 1 }), Substitution::empty(ChalkIr)), ); let binders = Binders::new( - VariableKinds::empty(&ChalkIr), + VariableKinds::empty(ChalkIr), ImplDatumBound { trait_ref: TraitRef { trait_id: TraitId(RawId { index: 0 }), - substitution: Substitution::from1(&ChalkIr, substitution), + substitution: Substitution::from1(ChalkIr, substitution), }, where_clauses: vec![], }, @@ -137,7 +137,7 @@ impl RustIrDatabase for MockDatabase { // Only needed because we always access the adt datum for logging Arc::new(AdtDatum { binders: Binders::empty( - &ChalkIr, + ChalkIr, AdtDatumBound { variants: vec![], where_clauses: vec![], @@ -207,15 +207,15 @@ impl RustIrDatabase for MockDatabase { panic!("program_clauses_for_env panic") } - ProgramClauses::empty(&ChalkIr) + ProgramClauses::empty(ChalkIr) } - fn interner(&self) -> &ChalkIr { + fn interner(&self) -> ChalkIr { if let PanickingMethod::Interner = self.panicking_method { panic!("interner panic") } - &ChalkIr + ChalkIr } fn is_object_safe(&self, trait_id: TraitId) -> bool { @@ -272,23 +272,23 @@ fn prepare_goal() -> UCanonical>> { // Foo: Bar UCanonical { canonical: Canonical { - binders: CanonicalVarKinds::empty(&ChalkIr), + binders: CanonicalVarKinds::empty(ChalkIr), value: InEnvironment { - environment: Environment::new(&ChalkIr), + environment: Environment::new(ChalkIr), goal: GoalData::DomainGoal(DomainGoal::Holds(WhereClause::Implemented(TraitRef { trait_id: TraitId(interner::RawId { index: 0 }), substitution: Substitution::from1( - &ChalkIr, + ChalkIr, Ty::new( - &ChalkIr, + ChalkIr, TyKind::Adt( AdtId(interner::RawId { index: 1 }), - Substitution::empty(&ChalkIr), + Substitution::empty(ChalkIr), ), ), ), }))) - .intern(&ChalkIr), + .intern(ChalkIr), }, }, universes: 1, diff --git a/tests/test/mod.rs b/tests/test/mod.rs index d6e20364aa7..d483eaf5ad5 100644 --- a/tests/test/mod.rs +++ b/tests/test/mod.rs @@ -17,7 +17,7 @@ mod bench; mod coherence; mod wf_lowering; -pub fn assert_result(mut result: Option>, expected: &str, interner: &ChalkIr) { +pub fn assert_result(mut result: Option>, expected: &str, interner: ChalkIr) { // sort constraints, since the different solvers may output them in different order match &mut result { Some(Solution::Unique(solution)) => { @@ -28,7 +28,7 @@ pub fn assert_result(mut result: Option>, expected: &str, inte _ => {} } let result = match result { - Some(v) => format!("{}", v.display(&ChalkIr)), + Some(v) => format!("{}", v.display(ChalkIr)), None => format!("No possible solution"), }; @@ -276,7 +276,7 @@ fn solve_goal(program_text: &str, goals: Vec<(&str, SolverChoice, TestGoal)>, co assert_same( &format!( "{}", - result.as_ref().map(|v| v.display(&ChalkIr)) + result.as_ref().map(|v| v.display(ChalkIr)) ), expected, ); @@ -300,7 +300,7 @@ fn solve_goal(program_text: &str, goals: Vec<(&str, SolverChoice, TestGoal)>, co { Some(solution) => { assert_same( - &format!("{}", result.as_ref().map(|v| v.display(&ChalkIr))), + &format!("{}", result.as_ref().map(|v| v.display(ChalkIr))), solution, ); if !next_result { diff --git a/tests/test/type_flags.rs b/tests/test/type_flags.rs index c568fc7306f..bf39a9a8b03 100644 --- a/tests/test/type_flags.rs +++ b/tests/test/type_flags.rs @@ -7,7 +7,7 @@ use chalk_ir::{PlaceholderIndex, TyKind, TypeFlags, UniverseIndex}; fn placeholder_ty_flags_correct() { let placeholder_ty = ty!(placeholder 0); assert_eq!( - placeholder_ty.data(&ChalkIr).flags, + placeholder_ty.data(ChalkIr).flags, TypeFlags::HAS_TY_PLACEHOLDER ); } @@ -19,24 +19,24 @@ fn opaque_ty_flags_correct() { 0: chalk_integration::interner::RawId { index: 0 }, }, substitution: chalk_ir::Substitution::from_iter( - &ChalkIr, + ChalkIr, Some( chalk_ir::ConstData { ty: TyKind::Placeholder(PlaceholderIndex { ui: chalk_ir::UniverseIndex::ROOT, idx: 0, }) - .intern(&ChalkIr), + .intern(ChalkIr), value: chalk_ir::ConstValue::InferenceVar(chalk_ir::InferenceVar::from(0)), } - .intern(&ChalkIr) - .cast(&ChalkIr), + .intern(ChalkIr) + .cast(ChalkIr), ), ), })) - .intern(&ChalkIr); + .intern(ChalkIr); assert_eq!( - opaque_ty.data(&ChalkIr).flags, + opaque_ty.data(ChalkIr).flags, TypeFlags::HAS_TY_OPAQUE | TypeFlags::HAS_CT_INFER | TypeFlags::STILL_FURTHER_SPECIALIZABLE @@ -46,7 +46,7 @@ fn opaque_ty_flags_correct() { #[test] fn dyn_ty_flags_correct() { - let internal_ty = TyKind::Scalar(chalk_ir::Scalar::Bool).intern(&ChalkIr); + let internal_ty = TyKind::Scalar(chalk_ir::Scalar::Bool).intern(ChalkIr); let projection_ty = chalk_ir::ProjectionTy { associated_ty_id: chalk_ir::AssocTypeId { 0: chalk_integration::interner::RawId { index: 0 }, @@ -54,11 +54,11 @@ fn dyn_ty_flags_correct() { substitution: empty_substitution!(), }; let bounds = chalk_ir::Binders::>::empty( - &ChalkIr, + ChalkIr, chalk_ir::QuantifiedWhereClauses::from_iter( - &ChalkIr, + ChalkIr, vec![chalk_ir::Binders::>::empty( - &ChalkIr, + ChalkIr, chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq { ty: internal_ty, alias: chalk_ir::AliasTy::Projection(projection_ty), @@ -70,9 +70,9 @@ fn dyn_ty_flags_correct() { lifetime: lifetime!(placeholder 5), bounds, }; - let ty = TyKind::Dyn(dyn_ty).intern(&ChalkIr); + let ty = TyKind::Dyn(dyn_ty).intern(ChalkIr); assert_eq!( - ty.data(&ChalkIr).flags, + ty.data(ChalkIr).flags, TypeFlags::HAS_TY_PROJECTION | TypeFlags::HAS_RE_PLACEHOLDER | TypeFlags::HAS_FREE_LOCAL_REGIONS @@ -82,8 +82,8 @@ fn dyn_ty_flags_correct() { #[test] fn flagless_ty_has_no_flags() { - let ty = TyKind::Str.intern(&ChalkIr); - assert_eq!(ty.data(&ChalkIr).flags, TypeFlags::empty()); + let ty = TyKind::Str.intern(ChalkIr); + assert_eq!(ty.data(ChalkIr).flags, TypeFlags::empty()); let fn_ty = TyKind::Function(chalk_ir::FnPointer { num_binders: 0, @@ -94,18 +94,18 @@ fn flagless_ty_has_no_flags() { variadic: false, }, }) - .intern(&ChalkIr); - assert_eq!(fn_ty.data(&ChalkIr).flags, TypeFlags::empty()); + .intern(ChalkIr); + assert_eq!(fn_ty.data(ChalkIr).flags, TypeFlags::empty()); } #[test] fn static_and_bound_lifetimes() { let substitutions = chalk_ir::Substitution::from_iter( - &ChalkIr, + ChalkIr, vec![ - chalk_ir::GenericArgData::Lifetime(chalk_ir::LifetimeData::Static.intern(&ChalkIr)) - .intern(&ChalkIr), - chalk_ir::GenericArgData::Lifetime(lifetime!(bound 5)).intern(&ChalkIr), + chalk_ir::GenericArgData::Lifetime(chalk_ir::LifetimeData::Static.intern(ChalkIr)) + .intern(ChalkIr), + chalk_ir::GenericArgData::Lifetime(lifetime!(bound 5)).intern(ChalkIr), ], ); @@ -115,10 +115,10 @@ fn static_and_bound_lifetimes() { }, substitutions, ) - .intern(&ChalkIr); + .intern(ChalkIr); assert_eq!( - ty.data(&ChalkIr).flags, + ty.data(ChalkIr).flags, TypeFlags::HAS_FREE_REGIONS | TypeFlags::HAS_RE_LATE_BOUND ); }