mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-10-31 12:04:43 +00:00 
			
		
		
		
	Add 'db to TraitEnvironment
This commit is contained in:
		
							parent
							
								
									7b9ad945ec
								
							
						
					
					
						commit
						c2513538cd
					
				
					 22 changed files with 122 additions and 109 deletions
				
			
		|  | @ -32,11 +32,11 @@ const AUTODEREF_RECURSION_LIMIT: usize = 20; | |||
| /// - the yielded types don't contain inference variables (but may contain `TyKind::Error`).
 | ||||
| /// - a type won't be yielded more than once; in other words, the returned iterator will stop if it
 | ||||
| ///   detects a cycle in the deref chain.
 | ||||
| pub fn autoderef( | ||||
|     db: &dyn HirDatabase, | ||||
|     env: Arc<TraitEnvironment>, | ||||
| pub fn autoderef<'db>( | ||||
|     db: &'db dyn HirDatabase, | ||||
|     env: Arc<TraitEnvironment<'db>>, | ||||
|     ty: crate::Canonical<crate::Ty>, | ||||
| ) -> impl Iterator<Item = crate::Ty> { | ||||
| ) -> impl Iterator<Item = crate::Ty> + use<> { | ||||
|     let mut table = InferenceTable::new(db, env); | ||||
|     let interner = table.interner; | ||||
|     let ty = table.instantiate_canonical(ty); | ||||
|  |  | |||
|  | @ -229,7 +229,7 @@ pub(crate) fn const_eval_cycle_result( | |||
|     _: &dyn HirDatabase, | ||||
|     _: GeneralConstId, | ||||
|     _: Substitution, | ||||
|     _: Option<Arc<TraitEnvironment>>, | ||||
|     _: Option<Arc<TraitEnvironment<'_>>>, | ||||
| ) -> Result<Const, ConstEvalError> { | ||||
|     Err(ConstEvalError::MirLowerError(MirLowerError::Loop)) | ||||
| } | ||||
|  | @ -252,7 +252,7 @@ pub(crate) fn const_eval_query( | |||
|     db: &dyn HirDatabase, | ||||
|     def: GeneralConstId, | ||||
|     subst: Substitution, | ||||
|     trait_env: Option<Arc<TraitEnvironment>>, | ||||
|     trait_env: Option<Arc<TraitEnvironment<'_>>>, | ||||
| ) -> Result<Const, ConstEvalError> { | ||||
|     let body = match def { | ||||
|         GeneralConstId::ConstId(c) => { | ||||
|  |  | |||
|  | @ -49,7 +49,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug { | |||
|         &self, | ||||
|         def: DefWithBodyId, | ||||
|         subst: Substitution, | ||||
|         env: Arc<TraitEnvironment>, | ||||
|         env: Arc<TraitEnvironment<'_>>, | ||||
|     ) -> Result<Arc<MirBody>, MirLowerError>; | ||||
| 
 | ||||
|     #[salsa::invoke(crate::mir::monomorphized_mir_body_for_closure_query)] | ||||
|  | @ -57,7 +57,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug { | |||
|         &self, | ||||
|         def: InternedClosureId, | ||||
|         subst: Substitution, | ||||
|         env: Arc<TraitEnvironment>, | ||||
|         env: Arc<TraitEnvironment<'_>>, | ||||
|     ) -> Result<Arc<MirBody>, MirLowerError>; | ||||
| 
 | ||||
|     #[salsa::invoke(crate::mir::borrowck_query)] | ||||
|  | @ -70,7 +70,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug { | |||
|         &self, | ||||
|         def: GeneralConstId, | ||||
|         subst: Substitution, | ||||
|         trait_env: Option<Arc<TraitEnvironment>>, | ||||
|         trait_env: Option<Arc<TraitEnvironment<'_>>>, | ||||
|     ) -> Result<Const, ConstEvalError>; | ||||
| 
 | ||||
|     #[salsa::invoke(crate::consteval::const_eval_static_query)] | ||||
|  | @ -84,7 +84,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug { | |||
|     #[salsa::invoke(crate::method_resolution::lookup_impl_method_query)] | ||||
|     fn lookup_impl_method( | ||||
|         &self, | ||||
|         env: Arc<TraitEnvironment>, | ||||
|         env: Arc<TraitEnvironment<'_>>, | ||||
|         func: FunctionId, | ||||
|         fn_subst: Substitution, | ||||
|     ) -> (FunctionId, Substitution); | ||||
|  | @ -97,7 +97,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug { | |||
|         &'db self, | ||||
|         def: AdtId, | ||||
|         args: crate::next_solver::GenericArgs<'db>, | ||||
|         trait_env: Arc<TraitEnvironment>, | ||||
|         trait_env: Arc<TraitEnvironment<'db>>, | ||||
|     ) -> Result<Arc<Layout>, LayoutError>; | ||||
| 
 | ||||
|     #[salsa::invoke(crate::layout::layout_of_ty_query)] | ||||
|  | @ -105,7 +105,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug { | |||
|     fn layout_of_ty<'db>( | ||||
|         &'db self, | ||||
|         ty: crate::next_solver::Ty<'db>, | ||||
|         env: Arc<TraitEnvironment>, | ||||
|         env: Arc<TraitEnvironment<'db>>, | ||||
|     ) -> Result<Arc<Layout>, LayoutError>; | ||||
| 
 | ||||
|     #[salsa::invoke(crate::layout::target_data_layout_query)] | ||||
|  | @ -184,10 +184,11 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug { | |||
| 
 | ||||
|     #[salsa::invoke(crate::lower::trait_environment_for_body_query)] | ||||
|     #[salsa::transparent] | ||||
|     fn trait_environment_for_body(&self, def: DefWithBodyId) -> Arc<TraitEnvironment>; | ||||
|     fn trait_environment_for_body<'db>(&'db self, def: DefWithBodyId) | ||||
|     -> Arc<TraitEnvironment<'db>>; | ||||
| 
 | ||||
|     #[salsa::invoke(crate::lower::trait_environment_query)] | ||||
|     fn trait_environment(&self, def: GenericDefId) -> Arc<TraitEnvironment>; | ||||
|     fn trait_environment<'db>(&'db self, def: GenericDefId) -> Arc<TraitEnvironment<'db>>; | ||||
| 
 | ||||
|     #[salsa::invoke(crate::lower::generic_defaults_with_diagnostics_query)] | ||||
|     #[salsa::cycle(cycle_result = crate::lower::generic_defaults_with_diagnostics_cycle_result)] | ||||
|  | @ -258,7 +259,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug { | |||
|     fn normalize_projection( | ||||
|         &self, | ||||
|         projection: crate::ProjectionTy, | ||||
|         env: Arc<TraitEnvironment>, | ||||
|         env: Arc<TraitEnvironment<'_>>, | ||||
|     ) -> Ty; | ||||
| 
 | ||||
|     #[salsa::invoke(crate::traits::trait_solve_query)] | ||||
|  | @ -272,7 +273,7 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug { | |||
| 
 | ||||
|     #[salsa::invoke(crate::drop::has_drop_glue)] | ||||
|     #[salsa::cycle(cycle_result = crate::drop::has_drop_glue_cycle_result)] | ||||
|     fn has_drop_glue(&self, ty: Ty, env: Arc<TraitEnvironment>) -> DropGlue; | ||||
|     fn has_drop_glue(&self, ty: Ty, env: Arc<TraitEnvironment<'_>>) -> DropGlue; | ||||
| 
 | ||||
|     // next trait solver
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -81,17 +81,17 @@ impl BodyValidationDiagnostic { | |||
|     } | ||||
| } | ||||
| 
 | ||||
| struct ExprValidator { | ||||
| struct ExprValidator<'db> { | ||||
|     owner: DefWithBodyId, | ||||
|     body: Arc<Body>, | ||||
|     infer: Arc<InferenceResult>, | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'db>>, | ||||
|     diagnostics: Vec<BodyValidationDiagnostic>, | ||||
|     validate_lints: bool, | ||||
| } | ||||
| 
 | ||||
| impl ExprValidator { | ||||
|     fn validate_body(&mut self, db: &dyn HirDatabase) { | ||||
| impl<'db> ExprValidator<'db> { | ||||
|     fn validate_body(&mut self, db: &'db dyn HirDatabase) { | ||||
|         let mut filter_map_next_checker = None; | ||||
|         // we'll pass &mut self while iterating over body.exprs, so they need to be disjoint
 | ||||
|         let body = Arc::clone(&self.body); | ||||
|  |  | |||
|  | @ -70,7 +70,7 @@ pub(crate) struct MatchCheckCtx<'db> { | |||
|     body: DefWithBodyId, | ||||
|     pub(crate) db: &'db dyn HirDatabase, | ||||
|     exhaustive_patterns: bool, | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'db>>, | ||||
| } | ||||
| 
 | ||||
| impl<'db> MatchCheckCtx<'db> { | ||||
|  | @ -78,7 +78,7 @@ impl<'db> MatchCheckCtx<'db> { | |||
|         module: ModuleId, | ||||
|         body: DefWithBodyId, | ||||
|         db: &'db dyn HirDatabase, | ||||
|         env: Arc<TraitEnvironment>, | ||||
|         env: Arc<TraitEnvironment<'db>>, | ||||
|     ) -> Self { | ||||
|         let def_map = module.crate_def_map(db); | ||||
|         let exhaustive_patterns = def_map.is_unstable_feature_enabled(&sym::exhaustive_patterns); | ||||
|  |  | |||
|  | @ -799,12 +799,12 @@ fn render_const_scalar_ns( | |||
|     render_const_scalar_inner(f, b, memory_map, ty, trait_env) | ||||
| } | ||||
| 
 | ||||
| fn render_const_scalar_inner( | ||||
| fn render_const_scalar_inner<'db>( | ||||
|     f: &mut HirFormatter<'_>, | ||||
|     b: &[u8], | ||||
|     memory_map: &MemoryMap<'_>, | ||||
|     ty: crate::next_solver::Ty<'_>, | ||||
|     trait_env: Arc<TraitEnvironment>, | ||||
|     ty: crate::next_solver::Ty<'db>, | ||||
|     trait_env: Arc<TraitEnvironment<'db>>, | ||||
| ) -> Result<(), HirDisplayError> { | ||||
|     use rustc_type_ir::TyKind; | ||||
|     match ty.kind() { | ||||
|  | @ -1068,11 +1068,11 @@ fn render_const_scalar_inner( | |||
|     } | ||||
| } | ||||
| 
 | ||||
| fn render_variant_after_name( | ||||
| fn render_variant_after_name<'db>( | ||||
|     data: &VariantFields, | ||||
|     f: &mut HirFormatter<'_>, | ||||
|     field_types: &ArenaMap<LocalFieldId, Binders<Ty>>, | ||||
|     trait_env: Arc<TraitEnvironment>, | ||||
|     trait_env: Arc<TraitEnvironment<'db>>, | ||||
|     layout: &Layout, | ||||
|     args: GenericArgs<'_>, | ||||
|     b: &[u8], | ||||
|  |  | |||
|  | @ -43,7 +43,11 @@ pub enum DropGlue { | |||
|     HasDropGlue, | ||||
| } | ||||
| 
 | ||||
| pub(crate) fn has_drop_glue(db: &dyn HirDatabase, ty: Ty, env: Arc<TraitEnvironment>) -> DropGlue { | ||||
| pub(crate) fn has_drop_glue( | ||||
|     db: &dyn HirDatabase, | ||||
|     ty: Ty, | ||||
|     env: Arc<TraitEnvironment<'_>>, | ||||
| ) -> DropGlue { | ||||
|     match ty.kind(Interner) { | ||||
|         TyKind::Adt(adt, subst) => { | ||||
|             if has_destructor(db, adt.0) { | ||||
|  | @ -165,7 +169,7 @@ pub(crate) fn has_drop_glue(db: &dyn HirDatabase, ty: Ty, env: Arc<TraitEnvironm | |||
| 
 | ||||
| fn projection_has_drop_glue( | ||||
|     db: &dyn HirDatabase, | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'_>>, | ||||
|     projection: ProjectionTy, | ||||
|     ty: Ty, | ||||
| ) -> DropGlue { | ||||
|  | @ -178,7 +182,7 @@ fn projection_has_drop_glue( | |||
|     } | ||||
| } | ||||
| 
 | ||||
| fn is_copy(db: &dyn HirDatabase, ty: Ty, env: Arc<TraitEnvironment>) -> bool { | ||||
| fn is_copy(db: &dyn HirDatabase, ty: Ty, env: Arc<TraitEnvironment<'_>>) -> bool { | ||||
|     let Some(copy_trait) = LangItem::Copy.resolve_trait(db, env.krate) else { | ||||
|         return false; | ||||
|     }; | ||||
|  | @ -193,7 +197,7 @@ fn is_copy(db: &dyn HirDatabase, ty: Ty, env: Arc<TraitEnvironment>) -> bool { | |||
| pub(crate) fn has_drop_glue_cycle_result( | ||||
|     _db: &dyn HirDatabase, | ||||
|     _ty: Ty, | ||||
|     _env: Arc<TraitEnvironment>, | ||||
|     _env: Arc<TraitEnvironment<'_>>, | ||||
| ) -> DropGlue { | ||||
|     DropGlue::None | ||||
| } | ||||
|  |  | |||
|  | @ -152,7 +152,7 @@ pub(crate) fn infer_cycle_result(_: &dyn HirDatabase, _: DefWithBodyId) -> Arc<I | |||
| /// This is appropriate to use only after type-check: it assumes
 | ||||
| /// that normalization will succeed, for example.
 | ||||
| #[tracing::instrument(level = "debug", skip(db))] | ||||
| pub(crate) fn normalize(db: &dyn HirDatabase, trait_env: Arc<TraitEnvironment>, ty: Ty) -> Ty { | ||||
| pub(crate) fn normalize(db: &dyn HirDatabase, trait_env: Arc<TraitEnvironment<'_>>, ty: Ty) -> Ty { | ||||
|     // FIXME: TypeFlags::HAS_CT_PROJECTION is not implemented in chalk, so TypeFlags::HAS_PROJECTION only
 | ||||
|     // works for the type case, so we check array unconditionally. Remove the array part
 | ||||
|     // when the bug in chalk becomes fixed.
 | ||||
|  |  | |||
|  | @ -1564,9 +1564,9 @@ impl<'db, 'exprs> CoerceMany<'db, 'exprs> { | |||
|     } | ||||
| } | ||||
| 
 | ||||
| pub fn could_coerce( | ||||
|     db: &dyn HirDatabase, | ||||
|     env: Arc<TraitEnvironment>, | ||||
| pub fn could_coerce<'db>( | ||||
|     db: &'db dyn HirDatabase, | ||||
|     env: Arc<TraitEnvironment<'db>>, | ||||
|     tys: &crate::Canonical<(crate::Ty, crate::Ty)>, | ||||
| ) -> bool { | ||||
|     coerce(db, env, tys).is_ok() | ||||
|  | @ -1574,7 +1574,7 @@ pub fn could_coerce( | |||
| 
 | ||||
| fn coerce<'db>( | ||||
|     db: &'db dyn HirDatabase, | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'db>>, | ||||
|     tys: &crate::Canonical<(crate::Ty, crate::Ty)>, | ||||
| ) -> Result<(Vec<Adjustment>, crate::Ty), TypeError<DbInterner<'db>>> { | ||||
|     let mut table = InferenceTable::new(db, env); | ||||
|  |  | |||
|  | @ -121,7 +121,7 @@ impl<'a, 'db> ProofTreeVisitor<'db> for NestedObligationsForSelfTy<'a, 'db> { | |||
| /// unresolved goal `T = U`.
 | ||||
| pub fn could_unify( | ||||
|     db: &dyn HirDatabase, | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'_>>, | ||||
|     tys: &Canonical<(Ty, Ty)>, | ||||
| ) -> bool { | ||||
|     unify(db, env, tys).is_some() | ||||
|  | @ -133,7 +133,7 @@ pub fn could_unify( | |||
| /// them. For example `Option<T>` and `Option<U>` do not unify as we cannot show that `T = U`
 | ||||
| pub fn could_unify_deeply( | ||||
|     db: &dyn HirDatabase, | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'_>>, | ||||
|     tys: &Canonical<(Ty, Ty)>, | ||||
| ) -> bool { | ||||
|     let mut table = InferenceTable::new(db, env); | ||||
|  | @ -151,7 +151,7 @@ pub fn could_unify_deeply( | |||
| 
 | ||||
| pub(crate) fn unify( | ||||
|     db: &dyn HirDatabase, | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'_>>, | ||||
|     tys: &Canonical<(Ty, Ty)>, | ||||
| ) -> Option<Substitution> { | ||||
|     let mut table = InferenceTable::new(db, env); | ||||
|  | @ -212,7 +212,7 @@ bitflags::bitflags! { | |||
| pub(crate) struct InferenceTable<'db> { | ||||
|     pub(crate) db: &'db dyn HirDatabase, | ||||
|     pub(crate) interner: DbInterner<'db>, | ||||
|     pub(crate) trait_env: Arc<TraitEnvironment>, | ||||
|     pub(crate) trait_env: Arc<TraitEnvironment<'db>>, | ||||
|     pub(crate) param_env: ParamEnv<'db>, | ||||
|     pub(crate) tait_coercion_table: Option<FxHashMap<OpaqueTyId, Ty>>, | ||||
|     pub(crate) infer_ctxt: InferCtxt<'db>, | ||||
|  | @ -227,7 +227,7 @@ pub(crate) struct InferenceTableSnapshot<'db> { | |||
| } | ||||
| 
 | ||||
| impl<'db> InferenceTable<'db> { | ||||
|     pub(crate) fn new(db: &'db dyn HirDatabase, trait_env: Arc<TraitEnvironment>) -> Self { | ||||
|     pub(crate) fn new(db: &'db dyn HirDatabase, trait_env: Arc<TraitEnvironment<'db>>) -> Self { | ||||
|         let interner = DbInterner::new_with(db, Some(trait_env.krate), trait_env.block); | ||||
|         let infer_ctxt = interner.infer_ctxt().build(rustc_type_ir::TypingMode::Analysis { | ||||
|             defining_opaque_types_and_generators: SolverDefIds::new_from_iter(interner, []), | ||||
|  |  | |||
|  | @ -20,7 +20,7 @@ pub(crate) fn is_ty_uninhabited_from( | |||
|     db: &dyn HirDatabase, | ||||
|     ty: &Ty, | ||||
|     target_mod: ModuleId, | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'_>>, | ||||
| ) -> bool { | ||||
|     let _p = tracing::info_span!("is_ty_uninhabited_from", ?ty).entered(); | ||||
|     let mut uninhabited_from = | ||||
|  | @ -36,7 +36,7 @@ pub(crate) fn is_enum_variant_uninhabited_from( | |||
|     variant: EnumVariantId, | ||||
|     subst: &Substitution, | ||||
|     target_mod: ModuleId, | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'_>>, | ||||
| ) -> bool { | ||||
|     let _p = tracing::info_span!("is_enum_variant_uninhabited_from").entered(); | ||||
| 
 | ||||
|  | @ -52,7 +52,7 @@ struct UninhabitedFrom<'a> { | |||
|     // guard for preventing stack overflow in non trivial non terminating types
 | ||||
|     max_depth: usize, | ||||
|     db: &'a dyn HirDatabase, | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'a>>, | ||||
| } | ||||
| 
 | ||||
| const CONTINUE_OPAQUELY_INHABITED: ControlFlow<VisiblyUninhabited> = Continue(()); | ||||
|  |  | |||
|  | @ -132,7 +132,7 @@ fn layout_of_simd_ty<'db>( | |||
|     id: StructId, | ||||
|     repr_packed: bool, | ||||
|     args: &GenericArgs<'db>, | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'db>>, | ||||
|     dl: &TargetDataLayout, | ||||
| ) -> Result<Arc<Layout>, LayoutError> { | ||||
|     // Supported SIMD vectors are homogeneous ADTs with exactly one array field:
 | ||||
|  | @ -160,7 +160,7 @@ fn layout_of_simd_ty<'db>( | |||
| pub fn layout_of_ty_query<'db>( | ||||
|     db: &'db dyn HirDatabase, | ||||
|     ty: Ty<'db>, | ||||
|     trait_env: Arc<TraitEnvironment>, | ||||
|     trait_env: Arc<TraitEnvironment<'db>>, | ||||
| ) -> Result<Arc<Layout>, LayoutError> { | ||||
|     let krate = trait_env.krate; | ||||
|     let interner = DbInterner::new_with(db, Some(krate), trait_env.block); | ||||
|  | @ -371,7 +371,7 @@ pub fn layout_of_ty_query<'db>( | |||
| pub(crate) fn layout_of_ty_cycle_result<'db>( | ||||
|     _: &dyn HirDatabase, | ||||
|     _: Ty<'db>, | ||||
|     _: Arc<TraitEnvironment>, | ||||
|     _: Arc<TraitEnvironment<'db>>, | ||||
| ) -> Result<Arc<Layout>, LayoutError> { | ||||
|     Err(LayoutError::RecursiveTypeWithoutIndirection) | ||||
| } | ||||
|  |  | |||
|  | @ -23,7 +23,7 @@ pub fn layout_of_adt_query<'db>( | |||
|     db: &'db dyn HirDatabase, | ||||
|     def: AdtId, | ||||
|     args: GenericArgs<'db>, | ||||
|     trait_env: Arc<TraitEnvironment>, | ||||
|     trait_env: Arc<TraitEnvironment<'db>>, | ||||
| ) -> Result<Arc<Layout>, LayoutError> { | ||||
|     let krate = trait_env.krate; | ||||
|     let Ok(target) = db.target_data_layout(krate) else { | ||||
|  | @ -99,7 +99,7 @@ pub(crate) fn layout_of_adt_cycle_result<'db>( | |||
|     _: &'db dyn HirDatabase, | ||||
|     _def: AdtId, | ||||
|     _args: GenericArgs<'db>, | ||||
|     _trait_env: Arc<TraitEnvironment>, | ||||
|     _trait_env: Arc<TraitEnvironment<'db>>, | ||||
| ) -> Result<Arc<Layout>, LayoutError> { | ||||
|     Err(LayoutError::RecursiveTypeWithoutIndirection) | ||||
| } | ||||
|  |  | |||
|  | @ -940,10 +940,10 @@ where | |||
|     Canonical { value, binders: chalk_ir::CanonicalVarKinds::from_iter(Interner, kinds) } | ||||
| } | ||||
| 
 | ||||
| pub fn callable_sig_from_fn_trait( | ||||
| pub fn callable_sig_from_fn_trait<'db>( | ||||
|     self_ty: &Ty, | ||||
|     trait_env: Arc<TraitEnvironment>, | ||||
|     db: &dyn HirDatabase, | ||||
|     trait_env: Arc<TraitEnvironment<'db>>, | ||||
|     db: &'db dyn HirDatabase, | ||||
| ) -> Option<(FnTrait, CallableSig)> { | ||||
|     let krate = trait_env.krate; | ||||
|     let fn_once_trait = FnTrait::FnOnce.get_id(db, krate)?; | ||||
|  |  | |||
|  | @ -1089,7 +1089,7 @@ pub(crate) fn generic_predicates_for_param_cycle_result( | |||
| pub(crate) fn trait_environment_for_body_query( | ||||
|     db: &dyn HirDatabase, | ||||
|     def: DefWithBodyId, | ||||
| ) -> Arc<TraitEnvironment> { | ||||
| ) -> Arc<TraitEnvironment<'_>> { | ||||
|     let Some(def) = def.as_generic_def_id(db) else { | ||||
|         let krate = def.module(db).krate(); | ||||
|         return TraitEnvironment::empty(krate); | ||||
|  | @ -1097,10 +1097,10 @@ pub(crate) fn trait_environment_for_body_query( | |||
|     db.trait_environment(def) | ||||
| } | ||||
| 
 | ||||
| pub(crate) fn trait_environment_query( | ||||
|     db: &dyn HirDatabase, | ||||
| pub(crate) fn trait_environment_query<'db>( | ||||
|     db: &'db dyn HirDatabase, | ||||
|     def: GenericDefId, | ||||
| ) -> Arc<TraitEnvironment> { | ||||
| ) -> Arc<TraitEnvironment<'db>> { | ||||
|     let generics = generics(db, def); | ||||
|     if generics.has_no_predicates() && generics.is_empty() { | ||||
|         return TraitEnvironment::empty(def.krate(db)); | ||||
|  |  | |||
|  | @ -545,7 +545,7 @@ pub fn def_crates(db: &dyn HirDatabase, ty: &Ty, cur_crate: Crate) -> Option<Sma | |||
| pub(crate) fn lookup_method<'db>( | ||||
|     db: &'db dyn HirDatabase, | ||||
|     ty: &next_solver::Canonical<'db, crate::next_solver::Ty<'db>>, | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'db>>, | ||||
|     traits_in_scope: &FxHashSet<TraitId>, | ||||
|     visible_from_module: VisibleFromModule, | ||||
|     name: &Name, | ||||
|  | @ -714,7 +714,7 @@ impl ReceiverAdjustments { | |||
| pub(crate) fn iterate_method_candidates<'db, T>( | ||||
|     ty: &next_solver::Canonical<'db, crate::next_solver::Ty<'db>>, | ||||
|     db: &'db dyn HirDatabase, | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'db>>, | ||||
|     traits_in_scope: &FxHashSet<TraitId>, | ||||
|     visible_from_module: VisibleFromModule, | ||||
|     name: Option<&Name>, | ||||
|  | @ -742,9 +742,9 @@ pub(crate) fn iterate_method_candidates<'db, T>( | |||
|     slot | ||||
| } | ||||
| 
 | ||||
| pub fn lookup_impl_const( | ||||
|     db: &dyn HirDatabase, | ||||
|     env: Arc<TraitEnvironment>, | ||||
| pub fn lookup_impl_const<'db>( | ||||
|     db: &'db dyn HirDatabase, | ||||
|     env: Arc<TraitEnvironment<'db>>, | ||||
|     const_id: ConstId, | ||||
|     subs: Substitution, | ||||
| ) -> (ConstId, Substitution) { | ||||
|  | @ -770,9 +770,9 @@ pub fn lookup_impl_const( | |||
| 
 | ||||
| /// Checks if the self parameter of `Trait` method is the `dyn Trait` and we should
 | ||||
| /// call the method using the vtable.
 | ||||
| pub fn is_dyn_method( | ||||
|     db: &dyn HirDatabase, | ||||
|     _env: Arc<TraitEnvironment>, | ||||
| pub fn is_dyn_method<'db>( | ||||
|     db: &'db dyn HirDatabase, | ||||
|     _env: Arc<TraitEnvironment<'db>>, | ||||
|     func: FunctionId, | ||||
|     fn_subst: Substitution, | ||||
| ) -> Option<usize> { | ||||
|  | @ -812,9 +812,9 @@ pub fn is_dyn_method( | |||
| /// Looks up the impl method that actually runs for the trait method `func`.
 | ||||
| ///
 | ||||
| /// Returns `func` if it's not a method defined in a trait or the lookup failed.
 | ||||
| pub(crate) fn lookup_impl_method_query( | ||||
|     db: &dyn HirDatabase, | ||||
|     env: Arc<TraitEnvironment>, | ||||
| pub(crate) fn lookup_impl_method_query<'db>( | ||||
|     db: &'db dyn HirDatabase, | ||||
|     env: Arc<TraitEnvironment<'db>>, | ||||
|     func: FunctionId, | ||||
|     fn_subst: Substitution, | ||||
| ) -> (FunctionId, Substitution) { | ||||
|  | @ -845,10 +845,10 @@ pub(crate) fn lookup_impl_method_query( | |||
|     ) | ||||
| } | ||||
| 
 | ||||
| fn lookup_impl_assoc_item_for_trait_ref( | ||||
| fn lookup_impl_assoc_item_for_trait_ref<'db>( | ||||
|     trait_ref: TraitRef, | ||||
|     db: &dyn HirDatabase, | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     db: &'db dyn HirDatabase, | ||||
|     env: Arc<TraitEnvironment<'db>>, | ||||
|     name: &Name, | ||||
| ) -> Option<(AssocItemId, Substitution)> { | ||||
|     let hir_trait_id = trait_ref.hir_trait_id(); | ||||
|  | @ -1067,7 +1067,7 @@ pub fn check_orphan_rules(db: &dyn HirDatabase, impl_: ImplId) -> bool { | |||
| pub fn iterate_path_candidates<'db>( | ||||
|     ty: &next_solver::Canonical<'db, crate::next_solver::Ty<'db>>, | ||||
|     db: &'db dyn HirDatabase, | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'db>>, | ||||
|     traits_in_scope: &FxHashSet<TraitId>, | ||||
|     visible_from_module: VisibleFromModule, | ||||
|     name: Option<&Name>, | ||||
|  | @ -1089,7 +1089,7 @@ pub fn iterate_path_candidates<'db>( | |||
| pub fn iterate_method_candidates_dyn<'db>( | ||||
|     ty: &next_solver::Canonical<'db, crate::next_solver::Ty<'db>>, | ||||
|     db: &'db dyn HirDatabase, | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'db>>, | ||||
|     traits_in_scope: &FxHashSet<TraitId>, | ||||
|     visible_from_module: VisibleFromModule, | ||||
|     name: Option<&Name>, | ||||
|  | @ -1351,7 +1351,7 @@ fn iterate_method_candidates_by_receiver<'db>( | |||
| fn iterate_method_candidates_for_self_ty<'db>( | ||||
|     self_ty: &next_solver::Canonical<'db, crate::next_solver::Ty<'db>>, | ||||
|     db: &'db dyn HirDatabase, | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'db>>, | ||||
|     traits_in_scope: &FxHashSet<TraitId>, | ||||
|     visible_from_module: VisibleFromModule, | ||||
|     name: Option<&Name>, | ||||
|  | @ -1856,10 +1856,10 @@ fn is_valid_impl_fn_candidate( | |||
|     }) | ||||
| } | ||||
| 
 | ||||
| pub fn implements_trait_unique( | ||||
| pub fn implements_trait_unique<'db>( | ||||
|     ty: &Canonical<Ty>, | ||||
|     db: &dyn HirDatabase, | ||||
|     env: &TraitEnvironment, | ||||
|     db: &'db dyn HirDatabase, | ||||
|     env: &TraitEnvironment<'db>, | ||||
|     trait_: TraitId, | ||||
| ) -> bool { | ||||
|     let goal = generic_implements_goal(db, env, trait_, ty); | ||||
|  | @ -1869,9 +1869,9 @@ pub fn implements_trait_unique( | |||
| /// This creates Substs for a trait with the given Self type and type variables
 | ||||
| /// for all other parameters, to query next solver with it.
 | ||||
| #[tracing::instrument(skip_all)] | ||||
| fn generic_implements_goal( | ||||
|     db: &dyn HirDatabase, | ||||
|     env: &TraitEnvironment, | ||||
| fn generic_implements_goal<'db>( | ||||
|     db: &'db dyn HirDatabase, | ||||
|     env: &TraitEnvironment<'db>, | ||||
|     trait_: TraitId, | ||||
|     self_ty: &Canonical<Ty>, | ||||
| ) -> Canonical<InEnvironment<super::DomainGoal>> { | ||||
|  |  | |||
|  | @ -165,7 +165,7 @@ enum MirOrDynIndex { | |||
| 
 | ||||
| pub struct Evaluator<'a> { | ||||
|     db: &'a dyn HirDatabase, | ||||
|     trait_env: Arc<TraitEnvironment>, | ||||
|     trait_env: Arc<TraitEnvironment<'a>>, | ||||
|     target_data_layout: Arc<TargetDataLayout>, | ||||
|     stack: Vec<u8>, | ||||
|     heap: Vec<u8>, | ||||
|  | @ -582,8 +582,8 @@ impl MirOutput { | |||
|     } | ||||
| } | ||||
| 
 | ||||
| pub fn interpret_mir( | ||||
|     db: &dyn HirDatabase, | ||||
| pub fn interpret_mir<'db>( | ||||
|     db: &'db dyn HirDatabase, | ||||
|     body: Arc<MirBody>, | ||||
|     // FIXME: This is workaround. Ideally, const generics should have a separate body (issue #7434), but now
 | ||||
|     // they share their body with their parent, so in MIR lowering we have locals of the parent body, which
 | ||||
|  | @ -591,7 +591,7 @@ pub fn interpret_mir( | |||
|     // a zero size, hoping that they are all outside of our current body. Even without a fix for #7434, we can
 | ||||
|     // (and probably should) do better here, for example by excluding bindings outside of the target expression.
 | ||||
|     assert_placeholder_ty_is_unused: bool, | ||||
|     trait_env: Option<Arc<TraitEnvironment>>, | ||||
|     trait_env: Option<Arc<TraitEnvironment<'db>>>, | ||||
| ) -> Result<(Result<Const>, MirOutput)> { | ||||
|     let ty = body.locals[return_slot()].ty.clone(); | ||||
|     let mut evaluator = Evaluator::new(db, body.owner, assert_placeholder_ty_is_unused, trait_env)?; | ||||
|  | @ -632,11 +632,11 @@ const EXECUTION_LIMIT: usize = 10_000_000; | |||
| 
 | ||||
| impl<'db> Evaluator<'db> { | ||||
|     pub fn new( | ||||
|         db: &dyn HirDatabase, | ||||
|         db: &'db dyn HirDatabase, | ||||
|         owner: DefWithBodyId, | ||||
|         assert_placeholder_ty_is_unused: bool, | ||||
|         trait_env: Option<Arc<TraitEnvironment>>, | ||||
|     ) -> Result<Evaluator<'_>> { | ||||
|         trait_env: Option<Arc<TraitEnvironment<'db>>>, | ||||
|     ) -> Result<Evaluator<'db>> { | ||||
|         let crate_id = owner.module(db).krate(); | ||||
|         let target_data_layout = match db.target_data_layout(crate_id) { | ||||
|             Ok(target_data_layout) => target_data_layout, | ||||
|  |  | |||
|  | @ -82,7 +82,7 @@ struct MirLowerCtx<'db> { | |||
|     infer: &'db InferenceResult, | ||||
|     resolver: Resolver<'db>, | ||||
|     drop_scopes: Vec<DropScope>, | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'db>>, | ||||
| } | ||||
| 
 | ||||
| // FIXME: Make this smaller, its stored in database queries
 | ||||
|  |  | |||
|  | @ -35,7 +35,7 @@ macro_rules! not_supported { | |||
| 
 | ||||
| struct Filler<'a> { | ||||
|     db: &'a dyn HirDatabase, | ||||
|     trait_env: Arc<TraitEnvironment>, | ||||
|     trait_env: Arc<TraitEnvironment<'a>>, | ||||
|     subst: &'a Substitution, | ||||
|     generics: Option<Generics>, | ||||
| } | ||||
|  | @ -301,11 +301,11 @@ impl Filler<'_> { | |||
|     } | ||||
| } | ||||
| 
 | ||||
| pub fn monomorphized_mir_body_query( | ||||
|     db: &dyn HirDatabase, | ||||
| pub fn monomorphized_mir_body_query<'db>( | ||||
|     db: &'db dyn HirDatabase, | ||||
|     owner: DefWithBodyId, | ||||
|     subst: Substitution, | ||||
|     trait_env: Arc<crate::TraitEnvironment>, | ||||
|     trait_env: Arc<crate::TraitEnvironment<'db>>, | ||||
| ) -> Result<Arc<MirBody>, MirLowerError> { | ||||
|     let generics = owner.as_generic_def_id(db).map(|g_def| generics(db, g_def)); | ||||
|     let filler = &mut Filler { db, subst: &subst, trait_env, generics }; | ||||
|  | @ -315,20 +315,20 @@ pub fn monomorphized_mir_body_query( | |||
|     Ok(Arc::new(body)) | ||||
| } | ||||
| 
 | ||||
| pub(crate) fn monomorphized_mir_body_cycle_result( | ||||
|     _db: &dyn HirDatabase, | ||||
| pub(crate) fn monomorphized_mir_body_cycle_result<'db>( | ||||
|     _db: &'db dyn HirDatabase, | ||||
|     _: DefWithBodyId, | ||||
|     _: Substitution, | ||||
|     _: Arc<crate::TraitEnvironment>, | ||||
|     _: Arc<crate::TraitEnvironment<'db>>, | ||||
| ) -> Result<Arc<MirBody>, MirLowerError> { | ||||
|     Err(MirLowerError::Loop) | ||||
| } | ||||
| 
 | ||||
| pub fn monomorphized_mir_body_for_closure_query( | ||||
|     db: &dyn HirDatabase, | ||||
| pub fn monomorphized_mir_body_for_closure_query<'db>( | ||||
|     db: &'db dyn HirDatabase, | ||||
|     closure: InternedClosureId, | ||||
|     subst: Substitution, | ||||
|     trait_env: Arc<crate::TraitEnvironment>, | ||||
|     trait_env: Arc<crate::TraitEnvironment<'db>>, | ||||
| ) -> Result<Arc<MirBody>, MirLowerError> { | ||||
|     let InternedClosure(owner, _) = db.lookup_intern_closure(closure); | ||||
|     let generics = owner.as_generic_def_id(db).map(|g_def| generics(db, g_def)); | ||||
|  |  | |||
|  | @ -39,21 +39,23 @@ use crate::{ | |||
| /// ```
 | ||||
| /// we assume that `T: Default`.
 | ||||
| #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||||
| pub struct TraitEnvironment { | ||||
| pub struct TraitEnvironment<'db> { | ||||
|     pub krate: Crate, | ||||
|     pub block: Option<BlockId>, | ||||
|     // FIXME make this a BTreeMap
 | ||||
|     traits_from_clauses: Box<[(Ty, TraitId)]>, | ||||
|     pub env: chalk_ir::Environment<Interner>, | ||||
|     _db: std::marker::PhantomData<&'db ()>, | ||||
| } | ||||
| 
 | ||||
| impl TraitEnvironment { | ||||
| impl<'db> TraitEnvironment<'db> { | ||||
|     pub fn empty(krate: Crate) -> Arc<Self> { | ||||
|         Arc::new(TraitEnvironment { | ||||
|             krate, | ||||
|             block: None, | ||||
|             traits_from_clauses: Box::default(), | ||||
|             env: chalk_ir::Environment::new(Interner), | ||||
|             _db: std::marker::PhantomData, | ||||
|         }) | ||||
|     } | ||||
| 
 | ||||
|  | @ -63,7 +65,13 @@ impl TraitEnvironment { | |||
|         traits_from_clauses: Box<[(Ty, TraitId)]>, | ||||
|         env: chalk_ir::Environment<Interner>, | ||||
|     ) -> Arc<Self> { | ||||
|         Arc::new(TraitEnvironment { krate, block, traits_from_clauses, env }) | ||||
|         Arc::new(TraitEnvironment { | ||||
|             krate, | ||||
|             block, | ||||
|             traits_from_clauses, | ||||
|             env, | ||||
|             _db: std::marker::PhantomData, | ||||
|         }) | ||||
|     } | ||||
| 
 | ||||
|     // pub fn with_block(self: &mut Arc<Self>, block: BlockId) {
 | ||||
|  | @ -78,10 +86,10 @@ impl TraitEnvironment { | |||
|     } | ||||
| } | ||||
| 
 | ||||
| pub(crate) fn normalize_projection_query( | ||||
|     db: &dyn HirDatabase, | ||||
| pub(crate) fn normalize_projection_query<'db>( | ||||
|     db: &'db dyn HirDatabase, | ||||
|     projection: ProjectionTy, | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'db>>, | ||||
| ) -> Ty { | ||||
|     if projection.substitution.iter(Interner).any(|arg| { | ||||
|         arg.ty(Interner) | ||||
|  |  | |||
|  | @ -3808,12 +3808,12 @@ impl GenericDef { | |||
| pub struct GenericSubstitution<'db> { | ||||
|     def: GenericDefId, | ||||
|     subst: Substitution, | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'db>>, | ||||
|     _pd: PhantomCovariantLifetime<'db>, | ||||
| } | ||||
| 
 | ||||
| impl<'db> GenericSubstitution<'db> { | ||||
|     fn new(def: GenericDefId, subst: Substitution, env: Arc<TraitEnvironment>) -> Self { | ||||
|     fn new(def: GenericDefId, subst: Substitution, env: Arc<TraitEnvironment<'db>>) -> Self { | ||||
|         Self { def, subst, env, _pd: PhantomCovariantLifetime::new() } | ||||
|     } | ||||
| 
 | ||||
|  | @ -4567,7 +4567,7 @@ impl Impl { | |||
| 
 | ||||
| #[derive(Clone, PartialEq, Eq, Debug, Hash)] | ||||
| pub struct TraitRef<'db> { | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'db>>, | ||||
|     trait_ref: hir_ty::next_solver::TraitRef<'db>, | ||||
|     _pd: PhantomCovariantLifetime<'db>, | ||||
| } | ||||
|  | @ -4790,7 +4790,7 @@ impl CaptureUsageSource { | |||
| 
 | ||||
| #[derive(Clone, PartialEq, Eq, Debug, Hash)] | ||||
| pub struct Type<'db> { | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'db>>, | ||||
|     ty: Ty, | ||||
|     _pd: PhantomCovariantLifetime<'db>, | ||||
| } | ||||
|  | @ -5945,7 +5945,7 @@ impl<'db> Type<'db> { | |||
| 
 | ||||
| #[derive(Clone, PartialEq, Eq, Debug, Hash)] | ||||
| pub struct TypeNs<'db> { | ||||
|     env: Arc<TraitEnvironment>, | ||||
|     env: Arc<TraitEnvironment<'db>>, | ||||
|     ty: hir_ty::next_solver::Ty<'db>, | ||||
|     _pd: PhantomCovariantLifetime<'db>, | ||||
| } | ||||
|  |  | |||
|  | @ -219,7 +219,7 @@ impl<'db> SourceAnalyzer<'db> { | |||
|         }) | ||||
|     } | ||||
| 
 | ||||
|     fn trait_environment(&self, db: &'db dyn HirDatabase) -> Arc<TraitEnvironment> { | ||||
|     fn trait_environment(&self, db: &'db dyn HirDatabase) -> Arc<TraitEnvironment<'db>> { | ||||
|         self.body_().map(|(def, ..)| def).map_or_else( | ||||
|             || TraitEnvironment::empty(self.resolver.krate()), | ||||
|             |def| db.trait_environment_for_body(def), | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jack Huey
						Jack Huey