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