mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-01 12:24:29 +00:00
Remove all upcasts!
It turns out there were a lot redundant too.
This commit is contained in:
parent
a775d21112
commit
8a9a1e3345
80 changed files with 1009 additions and 1257 deletions
|
|
@ -209,12 +209,12 @@ impl TyBuilder<()> {
|
|||
}
|
||||
|
||||
pub fn placeholder_subst(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> Substitution {
|
||||
let params = generics(db.upcast(), def.into());
|
||||
let params = generics(db, def.into());
|
||||
params.placeholder_subst(db)
|
||||
}
|
||||
|
||||
pub fn unknown_subst(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> Substitution {
|
||||
let params = generics(db.upcast(), def.into());
|
||||
let params = generics(db, def.into());
|
||||
Substitution::from_iter(
|
||||
Interner,
|
||||
params.iter_id().map(|id| match id {
|
||||
|
|
@ -233,7 +233,7 @@ impl TyBuilder<()> {
|
|||
def: impl Into<GenericDefId>,
|
||||
parent_subst: Option<Substitution>,
|
||||
) -> TyBuilder<()> {
|
||||
let generics = generics(db.upcast(), def.into());
|
||||
let generics = generics(db, def.into());
|
||||
assert!(generics.parent_generics().is_some() == parent_subst.is_some());
|
||||
let params = generics
|
||||
.iter_self()
|
||||
|
|
@ -259,9 +259,8 @@ impl TyBuilder<()> {
|
|||
/// This method prepopulates the builder with placeholder substitution of `parent`, so you
|
||||
/// should only push exactly 3 `GenericArg`s before building.
|
||||
pub fn subst_for_coroutine(db: &dyn HirDatabase, parent: DefWithBodyId) -> TyBuilder<()> {
|
||||
let parent_subst = parent
|
||||
.as_generic_def_id(db.upcast())
|
||||
.map(|p| generics(db.upcast(), p).placeholder_subst(db));
|
||||
let parent_subst =
|
||||
parent.as_generic_def_id(db).map(|p| generics(db, p).placeholder_subst(db));
|
||||
// These represent resume type, yield type, and return type of coroutine.
|
||||
let params = std::iter::repeat_n(ParamKind::Type, 3).collect();
|
||||
TyBuilder::new((), params, parent_subst)
|
||||
|
|
@ -274,13 +273,13 @@ impl TyBuilder<()> {
|
|||
) -> Substitution {
|
||||
let sig_ty = sig_ty.cast(Interner);
|
||||
let self_subst = iter::once(&sig_ty);
|
||||
let Some(parent) = parent.as_generic_def_id(db.upcast()) else {
|
||||
let Some(parent) = parent.as_generic_def_id(db) else {
|
||||
return Substitution::from_iter(Interner, self_subst);
|
||||
};
|
||||
Substitution::from_iter(
|
||||
Interner,
|
||||
self_subst
|
||||
.chain(generics(db.upcast(), parent).placeholder_subst(db).iter(Interner))
|
||||
.chain(generics(db, parent).placeholder_subst(db).iter(Interner))
|
||||
.cloned()
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -426,19 +426,19 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
|
|||
|
||||
fn trait_name(&self, trait_id: chalk_ir::TraitId<Interner>) -> String {
|
||||
let id = from_chalk_trait_id(trait_id);
|
||||
self.db.trait_signature(id).name.display(self.db.upcast(), self.edition()).to_string()
|
||||
self.db.trait_signature(id).name.display(self.db, self.edition()).to_string()
|
||||
}
|
||||
fn adt_name(&self, chalk_ir::AdtId(adt_id): AdtId) -> String {
|
||||
let edition = self.edition();
|
||||
match adt_id {
|
||||
hir_def::AdtId::StructId(id) => {
|
||||
self.db.struct_signature(id).name.display(self.db.upcast(), edition).to_string()
|
||||
self.db.struct_signature(id).name.display(self.db, edition).to_string()
|
||||
}
|
||||
hir_def::AdtId::EnumId(id) => {
|
||||
self.db.enum_signature(id).name.display(self.db.upcast(), edition).to_string()
|
||||
self.db.enum_signature(id).name.display(self.db, edition).to_string()
|
||||
}
|
||||
hir_def::AdtId::UnionId(id) => {
|
||||
self.db.union_signature(id).name.display(self.db.upcast(), edition).to_string()
|
||||
self.db.union_signature(id).name.display(self.db, edition).to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -448,7 +448,7 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
|
|||
}
|
||||
fn assoc_type_name(&self, assoc_ty_id: chalk_ir::AssocTypeId<Interner>) -> String {
|
||||
let id = self.db.associated_ty_data(from_assoc_type_id(assoc_ty_id)).name;
|
||||
self.db.type_alias_signature(id).name.display(self.db.upcast(), self.edition()).to_string()
|
||||
self.db.type_alias_signature(id).name.display(self.db, self.edition()).to_string()
|
||||
}
|
||||
fn opaque_type_name(&self, opaque_ty_id: chalk_ir::OpaqueTyId<Interner>) -> String {
|
||||
format!("Opaque_{:?}", opaque_ty_id.0)
|
||||
|
|
@ -537,13 +537,13 @@ impl ChalkContext<'_> {
|
|||
// `impl_datum` relies on that and will panic if the trait can't be resolved.
|
||||
let in_deps = self.db.trait_impls_in_deps(self.krate);
|
||||
let in_self = self.db.trait_impls_in_crate(self.krate);
|
||||
let trait_module = trait_id.module(self.db.upcast());
|
||||
let trait_module = trait_id.module(self.db);
|
||||
let type_module = match self_ty_fp {
|
||||
Some(TyFingerprint::Adt(adt_id)) => Some(adt_id.module(self.db.upcast())),
|
||||
Some(TyFingerprint::Adt(adt_id)) => Some(adt_id.module(self.db)),
|
||||
Some(TyFingerprint::ForeignType(type_id)) => {
|
||||
Some(from_foreign_def_id(type_id).module(self.db.upcast()))
|
||||
Some(from_foreign_def_id(type_id).module(self.db))
|
||||
}
|
||||
Some(TyFingerprint::Dyn(trait_id)) => Some(trait_id.module(self.db.upcast())),
|
||||
Some(TyFingerprint::Dyn(trait_id)) => Some(trait_id.module(self.db)),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
|
|
@ -605,15 +605,15 @@ pub(crate) fn associated_ty_data_query(
|
|||
type_alias: TypeAliasId,
|
||||
) -> Arc<AssociatedTyDatum> {
|
||||
debug!("associated_ty_data {:?}", type_alias);
|
||||
let trait_ = match type_alias.lookup(db.upcast()).container {
|
||||
let trait_ = match type_alias.lookup(db).container {
|
||||
ItemContainerId::TraitId(t) => t,
|
||||
_ => panic!("associated type not in trait"),
|
||||
};
|
||||
|
||||
// Lower bounds -- we could/should maybe move this to a separate query in `lower`
|
||||
let type_alias_data = db.type_alias_signature(type_alias);
|
||||
let generic_params = generics(db.upcast(), type_alias.into());
|
||||
let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast());
|
||||
let generic_params = generics(db, type_alias.into());
|
||||
let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db);
|
||||
let mut ctx =
|
||||
crate::TyLoweringContext::new(db, &resolver, &type_alias_data.store, type_alias.into())
|
||||
.with_type_param_mode(crate::lower::ParamLoweringMode::Variable);
|
||||
|
|
@ -671,11 +671,11 @@ pub(crate) fn trait_datum_query(
|
|||
let trait_ = from_chalk_trait_id(trait_id);
|
||||
let trait_data = db.trait_signature(trait_);
|
||||
debug!("trait {:?} = {:?}", trait_id, trait_data.name);
|
||||
let generic_params = generics(db.upcast(), trait_.into());
|
||||
let generic_params = generics(db, trait_.into());
|
||||
let bound_vars = generic_params.bound_vars_subst(db, DebruijnIndex::INNERMOST);
|
||||
let flags = rust_ir::TraitFlags {
|
||||
auto: trait_data.flags.contains(TraitFlags::IS_AUTO),
|
||||
upstream: trait_.lookup(db.upcast()).container.krate() != krate,
|
||||
upstream: trait_.lookup(db).container.krate() != krate,
|
||||
non_enumerable: true,
|
||||
coinductive: false, // only relevant for Chalk testing
|
||||
// FIXME: set these flags correctly
|
||||
|
|
@ -754,7 +754,7 @@ pub(crate) fn adt_datum_query(
|
|||
chalk_ir::AdtId(adt_id): AdtId,
|
||||
) -> Arc<AdtDatum> {
|
||||
debug!("adt_datum {:?}", adt_id);
|
||||
let generic_params = generics(db.upcast(), adt_id.into());
|
||||
let generic_params = generics(db, adt_id.into());
|
||||
let bound_vars_subst = generic_params.bound_vars_subst(db, DebruijnIndex::INNERMOST);
|
||||
let where_clauses = convert_where_clauses(db, adt_id.into(), &bound_vars_subst);
|
||||
|
||||
|
|
@ -771,14 +771,14 @@ pub(crate) fn adt_datum_query(
|
|||
hir_def::AdtId::EnumId(_) => (false, false),
|
||||
};
|
||||
let flags = rust_ir::AdtFlags {
|
||||
upstream: adt_id.module(db.upcast()).krate() != krate,
|
||||
upstream: adt_id.module(db).krate() != krate,
|
||||
fundamental,
|
||||
phantom_data,
|
||||
};
|
||||
|
||||
// this slows down rust-analyzer by quite a bit unfortunately, so enabling this is currently not worth it
|
||||
let _variant_id_to_fields = |id: VariantId| {
|
||||
let variant_data = &id.variant_data(db.upcast());
|
||||
let variant_data = &id.variant_data(db);
|
||||
let fields = if variant_data.fields().is_empty() {
|
||||
vec![]
|
||||
} else {
|
||||
|
|
@ -842,10 +842,10 @@ fn impl_def_datum(db: &dyn HirDatabase, krate: Crate, impl_id: hir_def::ImplId)
|
|||
.0;
|
||||
let impl_data = db.impl_signature(impl_id);
|
||||
|
||||
let generic_params = generics(db.upcast(), impl_id.into());
|
||||
let generic_params = generics(db, impl_id.into());
|
||||
let bound_vars = generic_params.bound_vars_subst(db, DebruijnIndex::INNERMOST);
|
||||
let trait_ = trait_ref.hir_trait_id();
|
||||
let impl_type = if impl_id.lookup(db.upcast()).container.krate() == krate {
|
||||
let impl_type = if impl_id.lookup(db).container.krate() == krate {
|
||||
rust_ir::ImplType::Local
|
||||
} else {
|
||||
rust_ir::ImplType::External
|
||||
|
|
@ -896,7 +896,7 @@ fn type_alias_associated_ty_value(
|
|||
type_alias: TypeAliasId,
|
||||
) -> Arc<AssociatedTyValue> {
|
||||
let type_alias_data = db.type_alias_signature(type_alias);
|
||||
let impl_id = match type_alias.lookup(db.upcast()).container {
|
||||
let impl_id = match type_alias.lookup(db).container {
|
||||
ItemContainerId::ImplId(it) => it,
|
||||
_ => panic!("assoc ty value should be in impl"),
|
||||
};
|
||||
|
|
@ -925,8 +925,8 @@ pub(crate) fn fn_def_datum_query(
|
|||
db: &dyn HirDatabase,
|
||||
callable_def: CallableDefId,
|
||||
) -> Arc<FnDefDatum> {
|
||||
let generic_def = GenericDefId::from_callable(db.upcast(), callable_def);
|
||||
let generic_params = generics(db.upcast(), generic_def);
|
||||
let generic_def = GenericDefId::from_callable(db, callable_def);
|
||||
let generic_params = generics(db, generic_def);
|
||||
let (sig, binders) = db.callable_item_signature(callable_def).into_value_and_skipped_binders();
|
||||
let bound_vars = generic_params.bound_vars_subst(db, DebruijnIndex::INNERMOST);
|
||||
let where_clauses = convert_where_clauses(db, generic_def, &bound_vars);
|
||||
|
|
@ -960,7 +960,7 @@ pub(crate) fn fn_def_variance_query(
|
|||
) -> Variances {
|
||||
Variances::from_iter(
|
||||
Interner,
|
||||
db.variances_of(GenericDefId::from_callable(db.upcast(), callable_def))
|
||||
db.variances_of(GenericDefId::from_callable(db, callable_def))
|
||||
.as_deref()
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
|
|
@ -1023,8 +1023,7 @@ pub(super) fn generic_predicate_to_inline_bound(
|
|||
Some(chalk_ir::Binders::new(binders, rust_ir::InlineBound::TraitBound(trait_bound)))
|
||||
}
|
||||
WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => {
|
||||
let generics =
|
||||
generics(db.upcast(), from_assoc_type_id(projection_ty.associated_ty_id).into());
|
||||
let generics = generics(db, from_assoc_type_id(projection_ty.associated_ty_id).into());
|
||||
let (assoc_args, trait_args) =
|
||||
projection_ty.substitution.as_slice(Interner).split_at(generics.len_self());
|
||||
let (self_ty, args_no_self) =
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ impl TyExt for Ty {
|
|||
match *self.kind(Interner) {
|
||||
TyKind::Adt(AdtId(adt), ..) => Some(adt.into()),
|
||||
TyKind::FnDef(callable, ..) => Some(GenericDefId::from_callable(
|
||||
db.upcast(),
|
||||
db,
|
||||
db.lookup_intern_callable_def(callable.into()),
|
||||
)),
|
||||
TyKind::AssociatedType(type_alias, ..) => Some(from_assoc_type_id(type_alias).into()),
|
||||
|
|
@ -250,7 +250,7 @@ impl TyExt for Ty {
|
|||
TyKind::OpaqueType(opaque_ty_id, subst) => {
|
||||
match db.lookup_intern_impl_trait_id((*opaque_ty_id).into()) {
|
||||
ImplTraitId::AsyncBlockTypeImplTrait(def, _expr) => {
|
||||
let krate = def.module(db.upcast()).krate();
|
||||
let krate = def.module(db).krate();
|
||||
if let Some(future_trait) =
|
||||
db.lang_item(krate, LangItem::Future).and_then(|item| item.as_trait())
|
||||
{
|
||||
|
|
@ -348,17 +348,12 @@ impl TyExt for Ty {
|
|||
|
||||
fn associated_type_parent_trait(&self, db: &dyn HirDatabase) -> Option<TraitId> {
|
||||
match self.kind(Interner) {
|
||||
TyKind::AssociatedType(id, ..) => {
|
||||
match from_assoc_type_id(*id).lookup(db.upcast()).container {
|
||||
ItemContainerId::TraitId(trait_id) => Some(trait_id),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
TyKind::AssociatedType(id, ..) => match from_assoc_type_id(*id).lookup(db).container {
|
||||
ItemContainerId::TraitId(trait_id) => Some(trait_id),
|
||||
_ => None,
|
||||
},
|
||||
TyKind::Alias(AliasTy::Projection(projection_ty)) => {
|
||||
match from_assoc_type_id(projection_ty.associated_ty_id)
|
||||
.lookup(db.upcast())
|
||||
.container
|
||||
{
|
||||
match from_assoc_type_id(projection_ty.associated_ty_id).lookup(db).container {
|
||||
ItemContainerId::TraitId(trait_id) => Some(trait_id),
|
||||
_ => None,
|
||||
}
|
||||
|
|
@ -368,7 +363,7 @@ impl TyExt for Ty {
|
|||
}
|
||||
|
||||
fn is_copy(self, db: &dyn HirDatabase, owner: DefWithBodyId) -> bool {
|
||||
let crate_id = owner.module(db.upcast()).krate();
|
||||
let crate_id = owner.module(db).krate();
|
||||
let Some(copy_trait) = db.lang_item(crate_id, LangItem::Copy).and_then(|it| it.as_trait())
|
||||
else {
|
||||
return false;
|
||||
|
|
@ -422,7 +417,7 @@ pub trait ProjectionTyExt {
|
|||
impl ProjectionTyExt for ProjectionTy {
|
||||
fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef {
|
||||
// FIXME: something like `Split` trait from chalk-solve might be nice.
|
||||
let generics = generics(db.upcast(), from_assoc_type_id(self.associated_ty_id).into());
|
||||
let generics = generics(db, from_assoc_type_id(self.associated_ty_id).into());
|
||||
let substitution = Substitution::from_iter(
|
||||
Interner,
|
||||
self.substitution.iter(Interner).skip(generics.len_self()),
|
||||
|
|
@ -431,7 +426,7 @@ impl ProjectionTyExt for ProjectionTy {
|
|||
}
|
||||
|
||||
fn trait_(&self, db: &dyn HirDatabase) -> TraitId {
|
||||
match from_assoc_type_id(self.associated_ty_id).lookup(db.upcast()).container {
|
||||
match from_assoc_type_id(self.associated_ty_id).lookup(db).container {
|
||||
ItemContainerId::TraitId(it) => it,
|
||||
_ => panic!("projection ty without parent trait"),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ pub(crate) fn path_to_const<'g>(
|
|||
debruijn: DebruijnIndex,
|
||||
expected_ty: Ty,
|
||||
) -> Option<Const> {
|
||||
match resolver.resolve_path_in_value_ns_fully(db.upcast(), path, HygieneId::ROOT) {
|
||||
match resolver.resolve_path_in_value_ns_fully(db, path, HygieneId::ROOT) {
|
||||
Some(ValueNs::GenericParam(p)) => {
|
||||
let ty = db.const_param_ty(p);
|
||||
let value = match mode {
|
||||
|
|
@ -263,7 +263,7 @@ pub(crate) fn const_eval_query(
|
|||
db.monomorphized_mir_body(c.into(), subst, db.trait_environment(c.into()))?
|
||||
}
|
||||
GeneralConstId::StaticId(s) => {
|
||||
let krate = s.module(db.upcast()).krate();
|
||||
let krate = s.module(db).krate();
|
||||
db.monomorphized_mir_body(s.into(), subst, TraitEnvironment::empty(krate))?
|
||||
}
|
||||
};
|
||||
|
|
@ -290,7 +290,7 @@ pub(crate) fn const_eval_discriminant_variant(
|
|||
) -> Result<i128, ConstEvalError> {
|
||||
let def = variant_id.into();
|
||||
let body = db.body(def);
|
||||
let loc = variant_id.lookup(db.upcast());
|
||||
let loc = variant_id.lookup(db);
|
||||
if body.exprs[body.body_expr] == Expr::Missing {
|
||||
let prev_idx = loc.index.checked_sub(1);
|
||||
let value = match prev_idx {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
use std::sync;
|
||||
|
||||
use base_db::{Crate, Upcast, impl_intern_key};
|
||||
use base_db::{Crate, impl_intern_key};
|
||||
use hir_def::{
|
||||
AdtId, BlockId, CallableDefId, ConstParamId, DefWithBodyId, EnumVariantId, FunctionId,
|
||||
GeneralConstId, GenericDefId, ImplId, LifetimeParamId, LocalFieldId, StaticId, TraitId,
|
||||
|
|
@ -29,7 +29,7 @@ use crate::{
|
|||
};
|
||||
|
||||
#[query_group::query_group]
|
||||
pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> + std::fmt::Debug {
|
||||
pub trait HirDatabase: DefDatabase + std::fmt::Debug {
|
||||
#[salsa::invoke_actual(crate::infer::infer_query)]
|
||||
fn infer(&self, def: DefWithBodyId) -> Arc<InferenceResult>;
|
||||
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ impl<'a> DeclValidator<'a> {
|
|||
|
||||
fn validate_module(&mut self, module_id: ModuleId) {
|
||||
// Check the module name.
|
||||
let Some(module_name) = module_id.name(self.db.upcast()) else { return };
|
||||
let Some(module_name) = module_id.name(self.db) else { return };
|
||||
let Some(module_name_replacement) =
|
||||
to_lower_snake_case(module_name.as_str()).map(|new_name| Replacement {
|
||||
current_name: module_name,
|
||||
|
|
@ -164,8 +164,8 @@ impl<'a> DeclValidator<'a> {
|
|||
else {
|
||||
return;
|
||||
};
|
||||
let module_data = &module_id.def_map(self.db.upcast())[module_id.local_id];
|
||||
let Some(module_src) = module_data.declaration_source(self.db.upcast()) else {
|
||||
let module_data = &module_id.def_map(self.db)[module_id.local_id];
|
||||
let Some(module_src) = module_data.declaration_source(self.db) else {
|
||||
return;
|
||||
};
|
||||
self.create_incorrect_case_diagnostic_for_ast_node(
|
||||
|
|
@ -188,7 +188,7 @@ impl<'a> DeclValidator<'a> {
|
|||
}
|
||||
|
||||
fn validate_func(&mut self, func: FunctionId) {
|
||||
let container = func.lookup(self.db.upcast()).container;
|
||||
let container = func.lookup(self.db).container;
|
||||
if matches!(container, ItemContainerId::ExternBlockId(_)) {
|
||||
cov_mark::hit!(extern_func_incorrect_case_ignored);
|
||||
return;
|
||||
|
|
@ -259,7 +259,7 @@ impl<'a> DeclValidator<'a> {
|
|||
let Some(ptr) = source_ptr.value.cast::<ast::IdentPat>() else {
|
||||
continue;
|
||||
};
|
||||
let root = source_ptr.file_syntax(self.db.upcast());
|
||||
let root = source_ptr.file_syntax(self.db);
|
||||
let ident_pat = ptr.to_node(&root);
|
||||
let Some(parent) = ident_pat.syntax().parent() else {
|
||||
continue;
|
||||
|
|
@ -287,7 +287,7 @@ impl<'a> DeclValidator<'a> {
|
|||
}
|
||||
|
||||
fn edition(&self, id: impl HasModule) -> span::Edition {
|
||||
let krate = id.krate(self.db.upcast());
|
||||
let krate = id.krate(self.db);
|
||||
krate.data(self.db).edition
|
||||
}
|
||||
|
||||
|
|
@ -331,8 +331,8 @@ impl<'a> DeclValidator<'a> {
|
|||
return;
|
||||
}
|
||||
|
||||
let struct_loc = struct_id.lookup(self.db.upcast());
|
||||
let struct_src = struct_loc.source(self.db.upcast());
|
||||
let struct_loc = struct_id.lookup(self.db);
|
||||
let struct_src = struct_loc.source(self.db);
|
||||
|
||||
let Some(ast::FieldList::RecordFieldList(struct_fields_list)) =
|
||||
struct_src.value.field_list()
|
||||
|
|
@ -421,8 +421,8 @@ impl<'a> DeclValidator<'a> {
|
|||
return;
|
||||
}
|
||||
|
||||
let enum_loc = enum_id.lookup(self.db.upcast());
|
||||
let enum_src = enum_loc.source(self.db.upcast());
|
||||
let enum_loc = enum_id.lookup(self.db);
|
||||
let enum_src = enum_loc.source(self.db);
|
||||
|
||||
let Some(enum_variants_list) = enum_src.value.variant_list() else {
|
||||
always!(
|
||||
|
|
@ -492,8 +492,8 @@ impl<'a> DeclValidator<'a> {
|
|||
return;
|
||||
}
|
||||
|
||||
let variant_loc = variant_id.lookup(self.db.upcast());
|
||||
let variant_src = variant_loc.source(self.db.upcast());
|
||||
let variant_loc = variant_id.lookup(self.db);
|
||||
let variant_src = variant_loc.source(self.db);
|
||||
|
||||
let Some(ast::FieldList::RecordFieldList(variant_fields_list)) =
|
||||
variant_src.value.field_list()
|
||||
|
|
@ -540,7 +540,7 @@ impl<'a> DeclValidator<'a> {
|
|||
}
|
||||
|
||||
fn validate_const(&mut self, const_id: ConstId) {
|
||||
let container = const_id.lookup(self.db.upcast()).container;
|
||||
let container = const_id.lookup(self.db).container;
|
||||
if self.is_trait_impl_container(container) {
|
||||
cov_mark::hit!(trait_impl_assoc_const_incorrect_case_ignored);
|
||||
return;
|
||||
|
|
@ -574,7 +574,7 @@ impl<'a> DeclValidator<'a> {
|
|||
}
|
||||
|
||||
fn validate_type_alias(&mut self, type_alias_id: TypeAliasId) {
|
||||
let container = type_alias_id.lookup(self.db.upcast()).container;
|
||||
let container = type_alias_id.lookup(self.db).container;
|
||||
if self.is_trait_impl_container(container) {
|
||||
cov_mark::hit!(trait_impl_assoc_type_incorrect_case_ignored);
|
||||
return;
|
||||
|
|
@ -607,19 +607,16 @@ impl<'a> DeclValidator<'a> {
|
|||
CaseType::UpperCamelCase => to_camel_case,
|
||||
};
|
||||
let edition = self.edition(item_id);
|
||||
let Some(replacement) = to_expected_case_type(
|
||||
&name.display(self.db.upcast(), edition).to_smolstr(),
|
||||
)
|
||||
.map(|new_name| Replacement {
|
||||
current_name: name.clone(),
|
||||
suggested_text: new_name,
|
||||
expected_case,
|
||||
}) else {
|
||||
let Some(replacement) =
|
||||
to_expected_case_type(&name.display(self.db, edition).to_smolstr()).map(|new_name| {
|
||||
Replacement { current_name: name.clone(), suggested_text: new_name, expected_case }
|
||||
})
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
let item_loc = item_id.lookup(self.db.upcast());
|
||||
let item_src = item_loc.source(self.db.upcast());
|
||||
let item_loc = item_id.lookup(self.db);
|
||||
let item_src = item_loc.source(self.db);
|
||||
self.create_incorrect_case_diagnostic_for_ast_node(
|
||||
replacement,
|
||||
item_src.file_id,
|
||||
|
|
@ -647,13 +644,13 @@ impl<'a> DeclValidator<'a> {
|
|||
return;
|
||||
};
|
||||
|
||||
let edition = file_id.original_file(self.db.upcast()).edition();
|
||||
let edition = file_id.original_file(self.db).edition();
|
||||
let diagnostic = IncorrectCase {
|
||||
file: file_id,
|
||||
ident_type,
|
||||
ident: AstPtr::new(&name_ast),
|
||||
expected_case: replacement.expected_case,
|
||||
ident_text: replacement.current_name.display(self.db.upcast(), edition).to_string(),
|
||||
ident_text: replacement.current_name.display(self.db, edition).to_string(),
|
||||
suggested_text: replacement.suggested_text,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -164,9 +164,8 @@ impl ExprValidator {
|
|||
None => return,
|
||||
};
|
||||
|
||||
let checker = filter_map_next_checker.get_or_insert_with(|| {
|
||||
FilterMapNextChecker::new(&self.owner.resolver(db.upcast()), db)
|
||||
});
|
||||
let checker = filter_map_next_checker
|
||||
.get_or_insert_with(|| FilterMapNextChecker::new(&self.owner.resolver(db), db));
|
||||
|
||||
if checker.check(call_id, receiver, &callee).is_some() {
|
||||
self.diagnostics.push(BodyValidationDiagnostic::ReplaceFilterMapNextWithFindMap {
|
||||
|
|
@ -191,7 +190,7 @@ impl ExprValidator {
|
|||
return;
|
||||
}
|
||||
|
||||
let cx = MatchCheckCtx::new(self.owner.module(db.upcast()), self.owner, db);
|
||||
let cx = MatchCheckCtx::new(self.owner.module(db), self.owner, db);
|
||||
|
||||
let pattern_arena = Arena::new();
|
||||
let mut m_arms = Vec::with_capacity(arms.len());
|
||||
|
|
@ -264,7 +263,7 @@ impl ExprValidator {
|
|||
scrut_ty,
|
||||
witnesses,
|
||||
m_arms.is_empty(),
|
||||
self.owner.krate(db.upcast()),
|
||||
self.owner.krate(db),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
|
@ -288,17 +287,16 @@ impl ExprValidator {
|
|||
match &self.body[scrutinee_expr] {
|
||||
Expr::UnaryOp { op: UnaryOp::Deref, .. } => false,
|
||||
Expr::Path(path) => {
|
||||
let value_or_partial =
|
||||
self.owner.resolver(db.upcast()).resolve_path_in_value_ns_fully(
|
||||
db.upcast(),
|
||||
path,
|
||||
self.body.expr_path_hygiene(scrutinee_expr),
|
||||
);
|
||||
let value_or_partial = self.owner.resolver(db).resolve_path_in_value_ns_fully(
|
||||
db,
|
||||
path,
|
||||
self.body.expr_path_hygiene(scrutinee_expr),
|
||||
);
|
||||
value_or_partial.is_none_or(|v| !matches!(v, ValueNs::StaticId(_)))
|
||||
}
|
||||
Expr::Field { expr, .. } => match self.infer.type_of_expr[*expr].kind(Interner) {
|
||||
TyKind::Adt(adt, ..)
|
||||
if db.adt_datum(self.owner.krate(db.upcast()), *adt).kind == AdtKind::Union =>
|
||||
if db.adt_datum(self.owner.krate(db), *adt).kind == AdtKind::Union =>
|
||||
{
|
||||
false
|
||||
}
|
||||
|
|
@ -319,7 +317,7 @@ impl ExprValidator {
|
|||
return;
|
||||
};
|
||||
let pattern_arena = Arena::new();
|
||||
let cx = MatchCheckCtx::new(self.owner.module(db.upcast()), self.owner, db);
|
||||
let cx = MatchCheckCtx::new(self.owner.module(db), self.owner, db);
|
||||
for stmt in &**statements {
|
||||
let &Statement::Let { pat, initializer, else_branch: None, .. } = stmt else {
|
||||
continue;
|
||||
|
|
@ -359,7 +357,7 @@ impl ExprValidator {
|
|||
ty,
|
||||
witnesses,
|
||||
false,
|
||||
self.owner.krate(db.upcast()),
|
||||
self.owner.krate(db),
|
||||
),
|
||||
});
|
||||
}
|
||||
|
|
@ -438,7 +436,7 @@ impl ExprValidator {
|
|||
let Ok(source_ptr) = source_map.expr_syntax(id) else {
|
||||
return;
|
||||
};
|
||||
let root = source_ptr.file_syntax(db.upcast());
|
||||
let root = source_ptr.file_syntax(db);
|
||||
let either::Left(ast::Expr::IfExpr(if_expr)) =
|
||||
source_ptr.value.to_node(&root)
|
||||
else {
|
||||
|
|
@ -490,7 +488,7 @@ impl FilterMapNextChecker {
|
|||
{
|
||||
Some(next_function_id) => (
|
||||
Some(next_function_id),
|
||||
match next_function_id.lookup(db.upcast()).container {
|
||||
match next_function_id.lookup(db).container {
|
||||
ItemContainerId::TraitId(iterator_trait_id) => {
|
||||
let iterator_trait_items = &db.trait_items(iterator_trait_id).items;
|
||||
iterator_trait_items.iter().find_map(|(name, it)| match it {
|
||||
|
|
@ -558,7 +556,7 @@ pub fn record_literal_missing_fields(
|
|||
return None;
|
||||
}
|
||||
|
||||
let variant_data = variant_def.variant_data(db.upcast());
|
||||
let variant_data = variant_def.variant_data(db);
|
||||
|
||||
let specified_fields: FxHashSet<_> = fields.iter().map(|f| &f.name).collect();
|
||||
let missed_fields: Vec<LocalFieldId> = variant_data
|
||||
|
|
@ -588,7 +586,7 @@ pub fn record_pattern_missing_fields(
|
|||
return None;
|
||||
}
|
||||
|
||||
let variant_data = variant_def.variant_data(db.upcast());
|
||||
let variant_data = variant_def.variant_data(db);
|
||||
|
||||
let specified_fields: FxHashSet<_> = fields.iter().map(|f| &f.name).collect();
|
||||
let missed_fields: Vec<LocalFieldId> = variant_data
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ impl<'a> PatCtxt<'a> {
|
|||
(BindingMode::Ref(_), _) => {
|
||||
never!(
|
||||
"`ref {}` has wrong type {:?}",
|
||||
name.display(self.db.upcast(), Edition::LATEST),
|
||||
name.display(self.db, Edition::LATEST),
|
||||
ty
|
||||
);
|
||||
self.errors.push(PatternError::UnexpectedType);
|
||||
|
|
@ -169,13 +169,13 @@ impl<'a> PatCtxt<'a> {
|
|||
}
|
||||
|
||||
hir_def::hir::Pat::TupleStruct { ref args, ellipsis, .. } if variant.is_some() => {
|
||||
let expected_len = variant.unwrap().variant_data(self.db.upcast()).fields().len();
|
||||
let expected_len = variant.unwrap().variant_data(self.db).fields().len();
|
||||
let subpatterns = self.lower_tuple_subpats(args, expected_len, ellipsis);
|
||||
self.lower_variant_or_leaf(pat, ty, subpatterns)
|
||||
}
|
||||
|
||||
hir_def::hir::Pat::Record { ref args, .. } if variant.is_some() => {
|
||||
let variant_data = variant.unwrap().variant_data(self.db.upcast());
|
||||
let variant_data = variant.unwrap().variant_data(self.db);
|
||||
let subpatterns = args
|
||||
.iter()
|
||||
.map(|field| {
|
||||
|
|
@ -304,7 +304,7 @@ impl HirDisplay for Pat {
|
|||
PatKind::Wild => write!(f, "_"),
|
||||
PatKind::Never => write!(f, "!"),
|
||||
PatKind::Binding { name, subpattern } => {
|
||||
write!(f, "{}", name.display(f.db.upcast(), f.edition()))?;
|
||||
write!(f, "{}", name.display(f.db, f.edition()))?;
|
||||
if let Some(subpattern) = subpattern {
|
||||
write!(f, " @ ")?;
|
||||
subpattern.hir_fmt(f)?;
|
||||
|
|
@ -324,28 +324,28 @@ impl HirDisplay for Pat {
|
|||
if let Some(variant) = variant {
|
||||
match variant {
|
||||
VariantId::EnumVariantId(v) => {
|
||||
let loc = v.lookup(f.db.upcast());
|
||||
let loc = v.lookup(f.db);
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
f.db.enum_variants(loc.parent).variants[loc.index as usize]
|
||||
.1
|
||||
.display(f.db.upcast(), f.edition())
|
||||
.display(f.db, f.edition())
|
||||
)?;
|
||||
}
|
||||
VariantId::StructId(s) => write!(
|
||||
f,
|
||||
"{}",
|
||||
f.db.struct_signature(s).name.display(f.db.upcast(), f.edition())
|
||||
f.db.struct_signature(s).name.display(f.db, f.edition())
|
||||
)?,
|
||||
VariantId::UnionId(u) => write!(
|
||||
f,
|
||||
"{}",
|
||||
f.db.union_signature(u).name.display(f.db.upcast(), f.edition())
|
||||
f.db.union_signature(u).name.display(f.db, f.edition())
|
||||
)?,
|
||||
};
|
||||
|
||||
let variant_data = variant.variant_data(f.db.upcast());
|
||||
let variant_data = variant.variant_data(f.db);
|
||||
if variant_data.shape == FieldsShape::Record {
|
||||
write!(f, " {{ ")?;
|
||||
|
||||
|
|
@ -361,7 +361,7 @@ impl HirDisplay for Pat {
|
|||
"{}: ",
|
||||
variant_data.fields()[p.field]
|
||||
.name
|
||||
.display(f.db.upcast(), f.edition())
|
||||
.display(f.db, f.edition())
|
||||
)?;
|
||||
p.pattern.hir_fmt(f)
|
||||
})
|
||||
|
|
@ -376,8 +376,8 @@ impl HirDisplay for Pat {
|
|||
}
|
||||
}
|
||||
|
||||
let num_fields = variant
|
||||
.map_or(subpatterns.len(), |v| v.variant_data(f.db.upcast()).fields().len());
|
||||
let num_fields =
|
||||
variant.map_or(subpatterns.len(), |v| v.variant_data(f.db).fields().len());
|
||||
if num_fields != 0 || variant.is_none() {
|
||||
write!(f, "(")?;
|
||||
let subpats = (0..num_fields).map(|i| {
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ impl EnumVariantContiguousIndex {
|
|||
fn from_enum_variant_id(db: &dyn HirDatabase, target_evid: EnumVariantId) -> Self {
|
||||
// Find the index of this variant in the list of variants.
|
||||
use hir_def::Lookup;
|
||||
let i = target_evid.lookup(db.upcast()).index as usize;
|
||||
let i = target_evid.lookup(db).index as usize;
|
||||
EnumVariantContiguousIndex(i)
|
||||
}
|
||||
|
||||
|
|
@ -105,7 +105,7 @@ impl<'db> MatchCheckCtx<'db> {
|
|||
|
||||
/// Returns whether the given ADT is from another crate declared `#[non_exhaustive]`.
|
||||
fn is_foreign_non_exhaustive(&self, adt: hir_def::AdtId) -> bool {
|
||||
let is_local = adt.krate(self.db.upcast()) == self.module.krate();
|
||||
let is_local = adt.krate(self.db) == self.module.krate();
|
||||
!is_local && self.db.attrs(adt.into()).by_key(&sym::non_exhaustive).exists()
|
||||
}
|
||||
|
||||
|
|
@ -139,7 +139,7 @@ impl<'db> MatchCheckCtx<'db> {
|
|||
let (_, substs) = ty.as_adt().unwrap();
|
||||
|
||||
let field_tys = self.db.field_types(variant);
|
||||
let fields_len = variant.variant_data(self.db.upcast()).fields().len() as u32;
|
||||
let fields_len = variant.variant_data(self.db).fields().len() as u32;
|
||||
|
||||
(0..fields_len).map(|idx| LocalFieldId::from_raw(idx.into())).map(move |fid| {
|
||||
let ty = field_tys[fid].clone().substitute(Interner, substs);
|
||||
|
|
@ -222,7 +222,7 @@ impl<'db> MatchCheckCtx<'db> {
|
|||
}
|
||||
};
|
||||
let variant = Self::variant_id_for_adt(self.db, &ctor, adt).unwrap();
|
||||
arity = variant.variant_data(self.db.upcast()).fields().len();
|
||||
arity = variant.variant_data(self.db).fields().len();
|
||||
}
|
||||
_ => {
|
||||
never!("pattern has unexpected type: pat: {:?}, ty: {:?}", pat, &pat.ty);
|
||||
|
|
@ -341,7 +341,7 @@ impl PatCx for MatchCheckCtx<'_> {
|
|||
1
|
||||
} else {
|
||||
let variant = Self::variant_id_for_adt(self.db, ctor, adt).unwrap();
|
||||
variant.variant_data(self.db.upcast()).fields().len()
|
||||
variant.variant_data(self.db).fields().len()
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
|
|
@ -389,8 +389,7 @@ impl PatCx for MatchCheckCtx<'_> {
|
|||
.map(move |(fid, ty)| {
|
||||
let is_visible = || {
|
||||
matches!(adt, hir_def::AdtId::EnumId(..))
|
||||
|| visibilities[fid]
|
||||
.is_visible_from(self.db.upcast(), self.module)
|
||||
|| visibilities[fid].is_visible_from(self.db, self.module)
|
||||
};
|
||||
let is_uninhabited = self.is_uninhabited(&ty);
|
||||
let private_uninhabited = is_uninhabited && !is_visible();
|
||||
|
|
@ -493,13 +492,13 @@ impl PatCx for MatchCheckCtx<'_> {
|
|||
// if let Some(variant) = variant {
|
||||
// match variant {
|
||||
// VariantId::EnumVariantId(v) => {
|
||||
// write!(f, "{}", db.enum_variant_data(v).name.display(db.upcast()))?;
|
||||
// write!(f, "{}", db.enum_variant_data(v).name.display(db))?;
|
||||
// }
|
||||
// VariantId::StructId(s) => {
|
||||
// write!(f, "{}", db.struct_data(s).name.display(db.upcast()))?
|
||||
// write!(f, "{}", db.struct_data(s).name.display(db))?
|
||||
// }
|
||||
// VariantId::UnionId(u) => {
|
||||
// write!(f, "{}", db.union_data(u).name.display(db.upcast()))?
|
||||
// write!(f, "{}", db.union_data(u).name.display(db))?
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ pub fn unsafe_operations(
|
|||
}
|
||||
};
|
||||
let mut visitor = UnsafeVisitor::new(db, infer, body, def, &mut visitor_callback);
|
||||
_ = visitor.resolver.update_to_inner_scope(db.upcast(), def, current);
|
||||
_ = visitor.resolver.update_to_inner_scope(db, def, current);
|
||||
visitor.walk_expr(current);
|
||||
}
|
||||
|
||||
|
|
@ -154,7 +154,7 @@ impl<'a> UnsafeVisitor<'a> {
|
|||
def: DefWithBodyId,
|
||||
unsafe_expr_cb: &'a mut dyn FnMut(UnsafeDiagnostic),
|
||||
) -> Self {
|
||||
let resolver = def.resolver(db.upcast());
|
||||
let resolver = def.resolver(db);
|
||||
let def_target_features = match def {
|
||||
DefWithBodyId::FunctionId(func) => TargetFeatures::from_attrs(&db.attrs(func.into())),
|
||||
_ => TargetFeatures::default(),
|
||||
|
|
@ -200,7 +200,7 @@ impl<'a> UnsafeVisitor<'a> {
|
|||
}
|
||||
|
||||
fn walk_pats_top(&mut self, pats: impl Iterator<Item = PatId>, parent_expr: ExprId) {
|
||||
let guard = self.resolver.update_to_inner_scope(self.db.upcast(), self.def, parent_expr);
|
||||
let guard = self.resolver.update_to_inner_scope(self.db, self.def, parent_expr);
|
||||
pats.for_each(|pat| self.walk_pat(pat));
|
||||
self.resolver.reset_to_guard(guard);
|
||||
}
|
||||
|
|
@ -268,8 +268,7 @@ impl<'a> UnsafeVisitor<'a> {
|
|||
}
|
||||
}
|
||||
Expr::Path(path) => {
|
||||
let guard =
|
||||
self.resolver.update_to_inner_scope(self.db.upcast(), self.def, current);
|
||||
let guard = self.resolver.update_to_inner_scope(self.db, self.def, current);
|
||||
self.mark_unsafe_path(current.into(), path);
|
||||
self.resolver.reset_to_guard(guard);
|
||||
}
|
||||
|
|
@ -357,8 +356,7 @@ impl<'a> UnsafeVisitor<'a> {
|
|||
|
||||
fn mark_unsafe_path(&mut self, node: ExprOrPatId, path: &Path) {
|
||||
let hygiene = self.body.expr_or_pat_path_hygiene(node);
|
||||
let value_or_partial =
|
||||
self.resolver.resolve_path_in_value_ns(self.db.upcast(), path, hygiene);
|
||||
let value_or_partial = self.resolver.resolve_path_in_value_ns(self.db, path, hygiene);
|
||||
if let Some(ResolveValueResult::ValueNs(ValueNs::StaticId(id), _)) = value_or_partial {
|
||||
let static_data = self.db.static_signature(id);
|
||||
if static_data.flags.contains(StaticFlags::MUTABLE) {
|
||||
|
|
|
|||
|
|
@ -570,7 +570,7 @@ impl HirDisplay for ProjectionTy {
|
|||
if !f.bounds_formatting_ctx.contains(self) {
|
||||
let db = f.db;
|
||||
let id = from_placeholder_idx(db, *idx);
|
||||
let generics = generics(db.upcast(), id.parent);
|
||||
let generics = generics(db, id.parent);
|
||||
|
||||
let substs = generics.placeholder_subst(db);
|
||||
let bounds = db
|
||||
|
|
@ -619,7 +619,7 @@ impl HirDisplay for ProjectionTy {
|
|||
">::{}",
|
||||
f.db.type_alias_signature(from_assoc_type_id(self.associated_ty_id))
|
||||
.name
|
||||
.display(f.db.upcast(), f.edition())
|
||||
.display(f.db, f.edition())
|
||||
)?;
|
||||
let proj_params_count =
|
||||
self.substitution.len(Interner) - trait_ref.substitution.len(Interner);
|
||||
|
|
@ -656,21 +656,16 @@ impl HirDisplay for Const {
|
|||
ConstValue::InferenceVar(..) => write!(f, "#c#"),
|
||||
ConstValue::Placeholder(idx) => {
|
||||
let id = from_placeholder_idx(f.db, *idx);
|
||||
let generics = generics(f.db.upcast(), id.parent);
|
||||
let generics = generics(f.db, id.parent);
|
||||
let param_data = &generics[id.local_id];
|
||||
write!(f, "{}", param_data.name().unwrap().display(f.db.upcast(), f.edition()))?;
|
||||
write!(f, "{}", param_data.name().unwrap().display(f.db, f.edition()))?;
|
||||
Ok(())
|
||||
}
|
||||
ConstValue::Concrete(c) => match &c.interned {
|
||||
ConstScalar::Bytes(b, m) => render_const_scalar(f, b, m, &data.ty),
|
||||
ConstScalar::UnevaluatedConst(c, parameters) => {
|
||||
write!(f, "{}", c.name(f.db.upcast()))?;
|
||||
hir_fmt_generics(
|
||||
f,
|
||||
parameters.as_slice(Interner),
|
||||
c.generic_def(f.db.upcast()),
|
||||
None,
|
||||
)?;
|
||||
write!(f, "{}", c.name(f.db))?;
|
||||
hir_fmt_generics(f, parameters.as_slice(Interner), c.generic_def(f.db), None)?;
|
||||
Ok(())
|
||||
}
|
||||
ConstScalar::Unknown => f.write_char('_'),
|
||||
|
|
@ -790,7 +785,7 @@ fn render_const_scalar(
|
|||
TyKind::Adt(adt, _) if b.len() == 2 * size_of::<usize>() => match adt.0 {
|
||||
hir_def::AdtId::StructId(s) => {
|
||||
let data = f.db.struct_signature(s);
|
||||
write!(f, "&{}", data.name.display(f.db.upcast(), f.edition()))?;
|
||||
write!(f, "&{}", data.name.display(f.db, f.edition()))?;
|
||||
Ok(())
|
||||
}
|
||||
_ => f.write_str("<unsized-enum-or-union>"),
|
||||
|
|
@ -848,7 +843,7 @@ fn render_const_scalar(
|
|||
match adt.0 {
|
||||
hir_def::AdtId::StructId(s) => {
|
||||
let data = f.db.struct_signature(s);
|
||||
write!(f, "{}", data.name.display(f.db.upcast(), f.edition()))?;
|
||||
write!(f, "{}", data.name.display(f.db, f.edition()))?;
|
||||
let field_types = f.db.field_types(s.into());
|
||||
render_variant_after_name(
|
||||
&f.db.variant_fields(s.into()),
|
||||
|
|
@ -862,11 +857,7 @@ fn render_const_scalar(
|
|||
)
|
||||
}
|
||||
hir_def::AdtId::UnionId(u) => {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
f.db.union_signature(u).name.display(f.db.upcast(), f.edition())
|
||||
)
|
||||
write!(f, "{}", f.db.union_signature(u).name.display(f.db, f.edition()))
|
||||
}
|
||||
hir_def::AdtId::EnumId(e) => {
|
||||
let Ok(target_data_layout) = f.db.target_data_layout(trait_env.krate) else {
|
||||
|
|
@ -877,13 +868,13 @@ fn render_const_scalar(
|
|||
else {
|
||||
return f.write_str("<failed-to-detect-variant>");
|
||||
};
|
||||
let loc = var_id.lookup(f.db.upcast());
|
||||
let loc = var_id.lookup(f.db);
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
f.db.enum_variants(loc.parent).variants[loc.index as usize]
|
||||
.1
|
||||
.display(f.db.upcast(), f.edition())
|
||||
.display(f.db, f.edition())
|
||||
)?;
|
||||
let field_types = f.db.field_types(var_id.into());
|
||||
render_variant_after_name(
|
||||
|
|
@ -969,11 +960,11 @@ fn render_variant_after_name(
|
|||
if matches!(data.shape, FieldsShape::Record) {
|
||||
write!(f, " {{")?;
|
||||
if let Some((id, data)) = it.next() {
|
||||
write!(f, " {}: ", data.name.display(f.db.upcast(), f.edition()))?;
|
||||
write!(f, " {}: ", data.name.display(f.db, f.edition()))?;
|
||||
render_field(f, id)?;
|
||||
}
|
||||
for (id, data) in it {
|
||||
write!(f, ", {}: ", data.name.display(f.db.upcast(), f.edition()))?;
|
||||
write!(f, ", {}: ", data.name.display(f.db, f.edition()))?;
|
||||
render_field(f, id)?;
|
||||
}
|
||||
write!(f, " }}")?;
|
||||
|
|
@ -1059,7 +1050,7 @@ impl HirDisplay for Ty {
|
|||
bounds.iter().any(|bound| {
|
||||
if let WhereClause::Implemented(trait_ref) = bound.skip_binders() {
|
||||
let trait_ = trait_ref.hir_trait_id();
|
||||
fn_traits(db.upcast(), trait_).any(|it| it == trait_)
|
||||
fn_traits(db, trait_).any(|it| it == trait_)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
|
@ -1087,8 +1078,7 @@ impl HirDisplay for Ty {
|
|||
|
||||
// Don't count Sized but count when it absent
|
||||
// (i.e. when explicit ?Sized bound is set).
|
||||
let default_sized =
|
||||
SizedByDefault::Sized { anchor: func.krate(db.upcast()) };
|
||||
let default_sized = SizedByDefault::Sized { anchor: func.krate(db) };
|
||||
let sized_bounds = bounds
|
||||
.skip_binders()
|
||||
.iter()
|
||||
|
|
@ -1098,7 +1088,7 @@ impl HirDisplay for Ty {
|
|||
WhereClause::Implemented(trait_ref)
|
||||
if default_sized.is_sized_trait(
|
||||
trait_ref.hir_trait_id(),
|
||||
db.upcast(),
|
||||
db,
|
||||
),
|
||||
)
|
||||
})
|
||||
|
|
@ -1166,32 +1156,28 @@ impl HirDisplay for Ty {
|
|||
write!(f, "fn ")?;
|
||||
f.start_location_link(def.into());
|
||||
match def {
|
||||
CallableDefId::FunctionId(ff) => write!(
|
||||
f,
|
||||
"{}",
|
||||
db.function_signature(ff).name.display(f.db.upcast(), f.edition())
|
||||
)?,
|
||||
CallableDefId::StructId(s) => write!(
|
||||
f,
|
||||
"{}",
|
||||
db.struct_signature(s).name.display(f.db.upcast(), f.edition())
|
||||
)?,
|
||||
CallableDefId::FunctionId(ff) => {
|
||||
write!(f, "{}", db.function_signature(ff).name.display(f.db, f.edition()))?
|
||||
}
|
||||
CallableDefId::StructId(s) => {
|
||||
write!(f, "{}", db.struct_signature(s).name.display(f.db, f.edition()))?
|
||||
}
|
||||
CallableDefId::EnumVariantId(e) => {
|
||||
let loc = e.lookup(db.upcast());
|
||||
let loc = e.lookup(db);
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
db.enum_variants(loc.parent).variants[loc.index as usize]
|
||||
.1
|
||||
.display(db.upcast(), f.edition())
|
||||
.display(db, f.edition())
|
||||
)?
|
||||
}
|
||||
};
|
||||
f.end_location_link();
|
||||
|
||||
if parameters.len(Interner) > 0 {
|
||||
let generic_def_id = GenericDefId::from_callable(db.upcast(), def);
|
||||
let generics = generics(db.upcast(), generic_def_id);
|
||||
let generic_def_id = GenericDefId::from_callable(db, def);
|
||||
let generics = generics(db, generic_def_id);
|
||||
let (parent_len, self_param, type_, const_, impl_, lifetime) =
|
||||
generics.provenance_split();
|
||||
let parameters = parameters.as_slice(Interner);
|
||||
|
|
@ -1252,11 +1238,11 @@ impl HirDisplay for Ty {
|
|||
hir_def::AdtId::UnionId(it) => db.union_signature(it).name.clone(),
|
||||
hir_def::AdtId::EnumId(it) => db.enum_signature(it).name.clone(),
|
||||
};
|
||||
write!(f, "{}", name.display(f.db.upcast(), f.edition()))?;
|
||||
write!(f, "{}", name.display(f.db, f.edition()))?;
|
||||
}
|
||||
DisplayKind::SourceCode { target_module_id: module_id, allow_opaque: _ } => {
|
||||
if let Some(path) = find_path::find_path(
|
||||
db.upcast(),
|
||||
db,
|
||||
ItemInNs::Types((*def_id).into()),
|
||||
module_id,
|
||||
PrefixKind::Plain,
|
||||
|
|
@ -1269,7 +1255,7 @@ impl HirDisplay for Ty {
|
|||
allow_unstable: true,
|
||||
},
|
||||
) {
|
||||
write!(f, "{}", path.display(f.db.upcast(), f.edition()))?;
|
||||
write!(f, "{}", path.display(f.db, f.edition()))?;
|
||||
} else {
|
||||
return Err(HirDisplayError::DisplaySourceCodeError(
|
||||
DisplaySourceCodeError::PathNotFound,
|
||||
|
|
@ -1285,7 +1271,7 @@ impl HirDisplay for Ty {
|
|||
}
|
||||
TyKind::AssociatedType(assoc_type_id, parameters) => {
|
||||
let type_alias = from_assoc_type_id(*assoc_type_id);
|
||||
let trait_ = match type_alias.lookup(db.upcast()).container {
|
||||
let trait_ = match type_alias.lookup(db).container {
|
||||
ItemContainerId::TraitId(it) => it,
|
||||
_ => panic!("not an associated type"),
|
||||
};
|
||||
|
|
@ -1295,12 +1281,12 @@ impl HirDisplay for Ty {
|
|||
// Use placeholder associated types when the target is test (https://rust-lang.github.io/chalk/book/clauses/type_equality.html#placeholder-associated-types)
|
||||
if f.display_kind.is_test() {
|
||||
f.start_location_link(trait_.into());
|
||||
write!(f, "{}", trait_data.name.display(f.db.upcast(), f.edition()))?;
|
||||
write!(f, "{}", trait_data.name.display(f.db, f.edition()))?;
|
||||
f.end_location_link();
|
||||
write!(f, "::")?;
|
||||
|
||||
f.start_location_link(type_alias.into());
|
||||
write!(f, "{}", type_alias_data.name.display(f.db.upcast(), f.edition()))?;
|
||||
write!(f, "{}", type_alias_data.name.display(f.db, f.edition()))?;
|
||||
f.end_location_link();
|
||||
// Note that the generic args for the associated type come before those for the
|
||||
// trait (including the self type).
|
||||
|
|
@ -1318,7 +1304,7 @@ impl HirDisplay for Ty {
|
|||
let alias = from_foreign_def_id(*type_alias);
|
||||
let type_alias = db.type_alias_signature(alias);
|
||||
f.start_location_link(alias.into());
|
||||
write!(f, "{}", type_alias.name.display(f.db.upcast(), f.edition()))?;
|
||||
write!(f, "{}", type_alias.name.display(f.db, f.edition()))?;
|
||||
f.end_location_link();
|
||||
}
|
||||
TyKind::OpaqueType(opaque_ty_id, parameters) => {
|
||||
|
|
@ -1335,7 +1321,7 @@ impl HirDisplay for Ty {
|
|||
let data =
|
||||
(*datas).as_ref().map(|rpit| rpit.impl_traits[idx].bounds.clone());
|
||||
let bounds = data.substitute(Interner, ¶meters);
|
||||
let krate = func.krate(db.upcast());
|
||||
let krate = func.krate(db);
|
||||
write_bounds_like_dyn_trait_with_prefix(
|
||||
f,
|
||||
"impl",
|
||||
|
|
@ -1350,7 +1336,7 @@ impl HirDisplay for Ty {
|
|||
db.type_alias_impl_traits(alias).expect("impl trait id without data");
|
||||
let data = (*datas).as_ref().map(|it| it.impl_traits[idx].bounds.clone());
|
||||
let bounds = data.substitute(Interner, ¶meters);
|
||||
let krate = alias.krate(db.upcast());
|
||||
let krate = alias.krate(db);
|
||||
write_bounds_like_dyn_trait_with_prefix(
|
||||
f,
|
||||
"impl",
|
||||
|
|
@ -1361,7 +1347,7 @@ impl HirDisplay for Ty {
|
|||
}
|
||||
ImplTraitId::AsyncBlockTypeImplTrait(body, ..) => {
|
||||
let future_trait = db
|
||||
.lang_item(body.module(db.upcast()).krate(), LangItem::Future)
|
||||
.lang_item(body.module(db).krate(), LangItem::Future)
|
||||
.and_then(LangItemTarget::as_trait);
|
||||
let output = future_trait.and_then(|t| {
|
||||
db.trait_items(t).associated_type_by_name(&Name::new_symbol_root(
|
||||
|
|
@ -1442,7 +1428,7 @@ impl HirDisplay for Ty {
|
|||
}
|
||||
TyKind::Placeholder(idx) => {
|
||||
let id = from_placeholder_idx(db, *idx);
|
||||
let generics = generics(db.upcast(), id.parent);
|
||||
let generics = generics(db, id.parent);
|
||||
let param_data = &generics[id.local_id];
|
||||
match param_data {
|
||||
TypeOrConstParamData::TypeParamData(p) => match p.provenance {
|
||||
|
|
@ -1453,7 +1439,7 @@ impl HirDisplay for Ty {
|
|||
p.name
|
||||
.clone()
|
||||
.unwrap_or_else(Name::missing)
|
||||
.display(f.db.upcast(), f.edition())
|
||||
.display(f.db, f.edition())
|
||||
)?
|
||||
}
|
||||
TypeParamProvenance::ArgumentImplTrait => {
|
||||
|
|
@ -1475,7 +1461,7 @@ impl HirDisplay for Ty {
|
|||
WhereClause::LifetimeOutlives(_) => false,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let krate = id.parent.module(db.upcast()).krate();
|
||||
let krate = id.parent.module(db).krate();
|
||||
write_bounds_like_dyn_trait_with_prefix(
|
||||
f,
|
||||
"impl",
|
||||
|
|
@ -1486,7 +1472,7 @@ impl HirDisplay for Ty {
|
|||
}
|
||||
},
|
||||
TypeOrConstParamData::ConstParamData(p) => {
|
||||
write!(f, "{}", p.name.display(f.db.upcast(), f.edition()))?;
|
||||
write!(f, "{}", p.name.display(f.db, f.edition()))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1525,7 +1511,7 @@ impl HirDisplay for Ty {
|
|||
let data =
|
||||
(*datas).as_ref().map(|rpit| rpit.impl_traits[idx].bounds.clone());
|
||||
let bounds = data.substitute(Interner, &opaque_ty.substitution);
|
||||
let krate = func.krate(db.upcast());
|
||||
let krate = func.krate(db);
|
||||
write_bounds_like_dyn_trait_with_prefix(
|
||||
f,
|
||||
"impl",
|
||||
|
|
@ -1540,7 +1526,7 @@ impl HirDisplay for Ty {
|
|||
let data =
|
||||
(*datas).as_ref().map(|rpit| rpit.impl_traits[idx].bounds.clone());
|
||||
let bounds = data.substitute(Interner, &opaque_ty.substitution);
|
||||
let krate = alias.krate(db.upcast());
|
||||
let krate = alias.krate(db);
|
||||
write_bounds_like_dyn_trait_with_prefix(
|
||||
f,
|
||||
"impl",
|
||||
|
|
@ -1788,7 +1774,7 @@ fn write_bounds_like_dyn_trait(
|
|||
match p.skip_binders() {
|
||||
WhereClause::Implemented(trait_ref) => {
|
||||
let trait_ = trait_ref.hir_trait_id();
|
||||
if default_sized.is_sized_trait(trait_, f.db.upcast()) {
|
||||
if default_sized.is_sized_trait(trait_, f.db) {
|
||||
is_sized = true;
|
||||
if matches!(default_sized, SizedByDefault::Sized { .. }) {
|
||||
// Don't print +Sized, but rather +?Sized if absent.
|
||||
|
|
@ -1796,7 +1782,7 @@ fn write_bounds_like_dyn_trait(
|
|||
}
|
||||
}
|
||||
if !is_fn_trait {
|
||||
is_fn_trait = fn_traits(f.db.upcast(), trait_).any(|it| it == trait_);
|
||||
is_fn_trait = fn_traits(f.db, trait_).any(|it| it == trait_);
|
||||
}
|
||||
if !is_fn_trait && angle_open {
|
||||
write!(f, ">")?;
|
||||
|
|
@ -1809,11 +1795,7 @@ fn write_bounds_like_dyn_trait(
|
|||
// existential) here, which is the only thing that's
|
||||
// possible in actual Rust, and hence don't print it
|
||||
f.start_location_link(trait_.into());
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
f.db.trait_signature(trait_).name.display(f.db.upcast(), f.edition())
|
||||
)?;
|
||||
write!(f, "{}", f.db.trait_signature(trait_).name.display(f.db, f.edition()))?;
|
||||
f.end_location_link();
|
||||
if is_fn_trait {
|
||||
if let [self_, params @ ..] = trait_ref.substitution.as_slice(Interner) {
|
||||
|
|
@ -1887,10 +1869,10 @@ fn write_bounds_like_dyn_trait(
|
|||
let assoc_ty_id = from_assoc_type_id(proj.associated_ty_id);
|
||||
let type_alias = f.db.type_alias_signature(assoc_ty_id);
|
||||
f.start_location_link(assoc_ty_id.into());
|
||||
write!(f, "{}", type_alias.name.display(f.db.upcast(), f.edition()))?;
|
||||
write!(f, "{}", type_alias.name.display(f.db, f.edition()))?;
|
||||
f.end_location_link();
|
||||
|
||||
let proj_arg_count = generics(f.db.upcast(), assoc_ty_id.into()).len_self();
|
||||
let proj_arg_count = generics(f.db, assoc_ty_id.into()).len_self();
|
||||
if proj_arg_count > 0 {
|
||||
write!(f, "<")?;
|
||||
hir_fmt_generic_arguments(
|
||||
|
|
@ -1938,7 +1920,7 @@ impl HirDisplay for TraitRef {
|
|||
fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> {
|
||||
let trait_ = self.hir_trait_id();
|
||||
f.start_location_link(trait_.into());
|
||||
write!(f, "{}", f.db.trait_signature(trait_).name.display(f.db.upcast(), f.edition()))?;
|
||||
write!(f, "{}", f.db.trait_signature(trait_).name.display(f.db, f.edition()))?;
|
||||
f.end_location_link();
|
||||
let substs = self.substitution.as_slice(Interner);
|
||||
hir_fmt_generics(f, &substs[1..], None, substs[0].ty(Interner))
|
||||
|
|
@ -1969,7 +1951,7 @@ impl HirDisplay for WhereClause {
|
|||
write!(
|
||||
f,
|
||||
"{}",
|
||||
f.db.type_alias_signature(type_alias).name.display(f.db.upcast(), f.edition()),
|
||||
f.db.type_alias_signature(type_alias).name.display(f.db, f.edition()),
|
||||
)?;
|
||||
f.end_location_link();
|
||||
write!(f, " = ")?;
|
||||
|
|
@ -2004,9 +1986,9 @@ impl HirDisplay for LifetimeData {
|
|||
match self {
|
||||
LifetimeData::Placeholder(idx) => {
|
||||
let id = lt_from_placeholder_idx(f.db, *idx);
|
||||
let generics = generics(f.db.upcast(), id.parent);
|
||||
let generics = generics(f.db, id.parent);
|
||||
let param_data = &generics[id.local_id];
|
||||
write!(f, "{}", param_data.name.display(f.db.upcast(), f.edition()))?;
|
||||
write!(f, "{}", param_data.name.display(f.db, f.edition()))?;
|
||||
Ok(())
|
||||
}
|
||||
_ if f.display_kind.is_source_code() => write!(f, "'_"),
|
||||
|
|
@ -2048,14 +2030,14 @@ pub fn write_visibility(
|
|||
match vis {
|
||||
Visibility::Public => write!(f, "pub "),
|
||||
Visibility::Module(vis_id, _) => {
|
||||
let def_map = module_id.def_map(f.db.upcast());
|
||||
let def_map = module_id.def_map(f.db);
|
||||
let root_module_id = def_map.module_id(DefMap::ROOT);
|
||||
if vis_id == module_id {
|
||||
// pub(self) or omitted
|
||||
Ok(())
|
||||
} else if root_module_id == vis_id {
|
||||
write!(f, "pub(crate) ")
|
||||
} else if module_id.containing_module(f.db.upcast()) == Some(vis_id) {
|
||||
} else if module_id.containing_module(f.db) == Some(vis_id) {
|
||||
write!(f, "pub(super) ")
|
||||
} else {
|
||||
write!(f, "pub(in ...) ")
|
||||
|
|
@ -2109,7 +2091,7 @@ impl HirDisplayWithExpressionStore for LifetimeRef {
|
|||
_store: &ExpressionStore,
|
||||
) -> Result<(), HirDisplayError> {
|
||||
match self {
|
||||
LifetimeRef::Named(name) => write!(f, "{}", name.display(f.db.upcast(), f.edition())),
|
||||
LifetimeRef::Named(name) => write!(f, "{}", name.display(f.db, f.edition())),
|
||||
LifetimeRef::Static => write!(f, "'static"),
|
||||
LifetimeRef::Placeholder => write!(f, "'_"),
|
||||
LifetimeRef::Error => write!(f, "'{{error}}"),
|
||||
|
|
@ -2127,7 +2109,7 @@ impl HirDisplayWithExpressionStore for TypeRefId {
|
|||
TypeRef::TypeParam(param) => {
|
||||
let generic_params = f.db.generic_params(param.parent());
|
||||
match generic_params[param.local_id()].name() {
|
||||
Some(name) => write!(f, "{}", name.display(f.db.upcast(), f.edition()))?,
|
||||
Some(name) => write!(f, "{}", name.display(f.db, f.edition()))?,
|
||||
None => {
|
||||
write!(f, "impl ")?;
|
||||
f.write_joined(
|
||||
|
|
@ -2208,7 +2190,7 @@ impl HirDisplayWithExpressionStore for TypeRefId {
|
|||
for index in 0..function_parameters.len() {
|
||||
let (param_name, param_type) = &function_parameters[index];
|
||||
if let Some(name) = param_name {
|
||||
write!(f, "{}: ", name.display(f.db.upcast(), f.edition()))?;
|
||||
write!(f, "{}: ", name.display(f.db, f.edition()))?;
|
||||
}
|
||||
|
||||
param_type.hir_fmt(f, store)?;
|
||||
|
|
@ -2277,7 +2259,7 @@ impl HirDisplayWithExpressionStore for TypeBound {
|
|||
write!(
|
||||
f,
|
||||
"for<{}> ",
|
||||
lifetimes.iter().map(|it| it.display(f.db.upcast(), edition)).format(", ")
|
||||
lifetimes.iter().map(|it| it.display(f.db, edition)).format(", ")
|
||||
)?;
|
||||
store[*path].hir_fmt(f, store)
|
||||
}
|
||||
|
|
@ -2287,7 +2269,7 @@ impl HirDisplayWithExpressionStore for TypeBound {
|
|||
for (idx, arg) in args.iter().enumerate() {
|
||||
match arg {
|
||||
UseArgRef::Lifetime(lt) => lt.hir_fmt(f, store)?,
|
||||
UseArgRef::Name(n) => write!(f, "{}", n.display(f.db.upcast(), edition))?,
|
||||
UseArgRef::Name(n) => write!(f, "{}", n.display(f.db, edition))?,
|
||||
}
|
||||
if idx != last {
|
||||
write!(f, ", ")?;
|
||||
|
|
@ -2361,7 +2343,7 @@ impl HirDisplayWithExpressionStore for Path {
|
|||
if !matches!(self.kind(), PathKind::Plain) || seg_idx > 0 {
|
||||
write!(f, "::")?;
|
||||
}
|
||||
write!(f, "{}", segment.name.display(f.db.upcast(), f.edition()))?;
|
||||
write!(f, "{}", segment.name.display(f.db, f.edition()))?;
|
||||
if let Some(generic_args) = segment.args_and_bindings {
|
||||
// We should be in type context, so format as `Foo<Bar>` instead of `Foo::<Bar>`.
|
||||
// Do we actually format expressions?
|
||||
|
|
@ -2414,7 +2396,7 @@ impl HirDisplayWithExpressionStore for Path {
|
|||
} else {
|
||||
write!(f, ", ")?;
|
||||
}
|
||||
write!(f, "{}", binding.name.display(f.db.upcast(), f.edition()))?;
|
||||
write!(f, "{}", binding.name.display(f.db, f.edition()))?;
|
||||
match &binding.type_ref {
|
||||
Some(ty) => {
|
||||
write!(f, " = ")?;
|
||||
|
|
@ -2461,7 +2443,7 @@ impl HirDisplayWithExpressionStore for hir_def::expr_store::path::GenericArg {
|
|||
match self {
|
||||
hir_def::expr_store::path::GenericArg::Type(ty) => ty.hir_fmt(f, store),
|
||||
hir_def::expr_store::path::GenericArg::Const(_c) => {
|
||||
// write!(f, "{}", c.display(f.db.upcast(), f.edition()))
|
||||
// write!(f, "{}", c.display(f.db, f.edition()))
|
||||
write!(f, "<expr>")
|
||||
}
|
||||
hir_def::expr_store::path::GenericArg::Lifetime(lifetime) => lifetime.hir_fmt(f, store),
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ pub fn dyn_compatibility(
|
|||
db: &dyn HirDatabase,
|
||||
trait_: TraitId,
|
||||
) -> Option<DynCompatibilityViolation> {
|
||||
for super_trait in all_super_traits(db.upcast(), trait_).into_iter().skip(1).rev() {
|
||||
for super_trait in all_super_traits(db, trait_).into_iter().skip(1).rev() {
|
||||
if db.dyn_compatibility_of_trait(super_trait).is_some() {
|
||||
return Some(DynCompatibilityViolation::HasNonCompatibleSuperTrait(super_trait));
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ pub fn dyn_compatibility_with_callback<F>(
|
|||
where
|
||||
F: FnMut(DynCompatibilityViolation) -> ControlFlow<()>,
|
||||
{
|
||||
for super_trait in all_super_traits(db.upcast(), trait_).into_iter().skip(1).rev() {
|
||||
for super_trait in all_super_traits(db, trait_).into_iter().skip(1).rev() {
|
||||
if db.dyn_compatibility_of_trait(super_trait).is_some() {
|
||||
cb(DynCompatibilityViolation::HasNonCompatibleSuperTrait(trait_))?;
|
||||
}
|
||||
|
|
@ -124,12 +124,12 @@ pub fn dyn_compatibility_of_trait_query(
|
|||
}
|
||||
|
||||
fn generics_require_sized_self(db: &dyn HirDatabase, def: GenericDefId) -> bool {
|
||||
let krate = def.module(db.upcast()).krate();
|
||||
let krate = def.module(db).krate();
|
||||
let Some(sized) = db.lang_item(krate, LangItem::Sized).and_then(|l| l.as_trait()) else {
|
||||
return false;
|
||||
};
|
||||
|
||||
let Some(trait_self_param_idx) = trait_self_param_idx(db.upcast(), def) else {
|
||||
let Some(trait_self_param_idx) = trait_self_param_idx(db, def) else {
|
||||
return false;
|
||||
};
|
||||
|
||||
|
|
@ -254,7 +254,7 @@ fn contains_illegal_self_type_reference<T: TypeVisitable<Interner>>(
|
|||
outer_binder: DebruijnIndex,
|
||||
allow_self_projection: AllowSelfProjection,
|
||||
) -> bool {
|
||||
let Some(trait_self_param_idx) = trait_self_param_idx(db.upcast(), def) else {
|
||||
let Some(trait_self_param_idx) = trait_self_param_idx(db, def) else {
|
||||
return false;
|
||||
};
|
||||
struct IllegalSelfTypeVisitor<'a> {
|
||||
|
|
@ -288,8 +288,7 @@ fn contains_illegal_self_type_reference<T: TypeVisitable<Interner>>(
|
|||
AllowSelfProjection::Yes => {
|
||||
let trait_ = proj.trait_(self.db);
|
||||
if self.super_traits.is_none() {
|
||||
self.super_traits =
|
||||
Some(all_super_traits(self.db.upcast(), self.trait_));
|
||||
self.super_traits = Some(all_super_traits(self.db, self.trait_));
|
||||
}
|
||||
if self.super_traits.as_ref().is_some_and(|s| s.contains(&trait_)) {
|
||||
ControlFlow::Continue(())
|
||||
|
|
@ -345,7 +344,7 @@ where
|
|||
})
|
||||
}
|
||||
AssocItemId::TypeAliasId(it) => {
|
||||
let def_map = db.crate_def_map(trait_.krate(db.upcast()));
|
||||
let def_map = db.crate_def_map(trait_.krate(db));
|
||||
if def_map.is_unstable_feature_enabled(&intern::sym::generic_associated_type_extended) {
|
||||
ControlFlow::Continue(())
|
||||
} else {
|
||||
|
|
@ -419,7 +418,7 @@ where
|
|||
}
|
||||
|
||||
let predicates = &*db.generic_predicates_without_parent(func.into());
|
||||
let trait_self_idx = trait_self_param_idx(db.upcast(), func.into());
|
||||
let trait_self_idx = trait_self_param_idx(db, func.into());
|
||||
for pred in predicates {
|
||||
let pred = pred.skip_binders().skip_binders();
|
||||
|
||||
|
|
@ -466,7 +465,7 @@ fn receiver_is_dispatchable(
|
|||
func: FunctionId,
|
||||
sig: &Binders<CallableSig>,
|
||||
) -> bool {
|
||||
let Some(trait_self_idx) = trait_self_param_idx(db.upcast(), func.into()) else {
|
||||
let Some(trait_self_idx) = trait_self_param_idx(db, func.into()) else {
|
||||
return false;
|
||||
};
|
||||
|
||||
|
|
@ -484,14 +483,14 @@ fn receiver_is_dispatchable(
|
|||
return true;
|
||||
}
|
||||
|
||||
let placeholder_subst = generics(db.upcast(), func.into()).placeholder_subst(db);
|
||||
let placeholder_subst = generics(db, func.into()).placeholder_subst(db);
|
||||
|
||||
let substituted_sig = sig.clone().substitute(Interner, &placeholder_subst);
|
||||
let Some(receiver_ty) = substituted_sig.params().first() else {
|
||||
return false;
|
||||
};
|
||||
|
||||
let krate = func.module(db.upcast()).krate();
|
||||
let krate = func.module(db).krate();
|
||||
let traits = (
|
||||
db.lang_item(krate, LangItem::Unsize).and_then(|it| it.as_trait()),
|
||||
db.lang_item(krate, LangItem::DispatchFromDyn).and_then(|it| it.as_trait()),
|
||||
|
|
@ -550,8 +549,8 @@ fn receiver_is_dispatchable(
|
|||
}
|
||||
|
||||
fn receiver_for_self_ty(db: &dyn HirDatabase, func: FunctionId, ty: Ty) -> Option<Ty> {
|
||||
let generics = generics(db.upcast(), func.into());
|
||||
let trait_self_idx = trait_self_param_idx(db.upcast(), func.into())?;
|
||||
let generics = generics(db, func.into());
|
||||
let trait_self_idx = trait_self_param_idx(db, func.into())?;
|
||||
let subst = generics.placeholder_subst(db);
|
||||
let subst = Substitution::from_iter(
|
||||
Interner,
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ pub(crate) use closure::{CaptureKind, CapturedItem, CapturedItemWithoutTy};
|
|||
/// The entry point of type inference.
|
||||
pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> {
|
||||
let _p = tracing::info_span!("infer_query").entered();
|
||||
let resolver = def.resolver(db.upcast());
|
||||
let resolver = def.resolver(db);
|
||||
let body = db.body(def);
|
||||
let mut ctx = InferenceContext::new(db, def, &body, resolver);
|
||||
|
||||
|
|
@ -99,7 +99,7 @@ pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<Infer
|
|||
DefWithBodyId::StaticId(s) => ctx.collect_static(&db.static_signature(s)),
|
||||
DefWithBodyId::VariantId(v) => {
|
||||
ctx.return_ty = TyBuilder::builtin(
|
||||
match db.enum_signature(v.lookup(db.upcast()).parent).variant_body_type() {
|
||||
match db.enum_signature(v.lookup(db).parent).variant_body_type() {
|
||||
hir_def::layout::IntegerType::Pointer(signed) => match signed {
|
||||
true => BuiltinType::Int(BuiltinInt::Isize),
|
||||
false => BuiltinType::Uint(BuiltinUint::Usize),
|
||||
|
|
@ -702,10 +702,10 @@ impl<'a> InferenceContext<'a> {
|
|||
DefWithBodyId::FunctionId(it) => it.into(),
|
||||
DefWithBodyId::StaticId(it) => it.into(),
|
||||
DefWithBodyId::ConstId(it) => it.into(),
|
||||
DefWithBodyId::VariantId(it) => it.lookup(db.upcast()).parent.into(),
|
||||
DefWithBodyId::VariantId(it) => it.lookup(db).parent.into(),
|
||||
},
|
||||
body,
|
||||
traits_in_scope: resolver.traits_in_scope(db.upcast()),
|
||||
traits_in_scope: resolver.traits_in_scope(db),
|
||||
resolver,
|
||||
diverges: Diverges::Maybe,
|
||||
breakables: Vec::new(),
|
||||
|
|
@ -721,7 +721,7 @@ impl<'a> InferenceContext<'a> {
|
|||
}
|
||||
|
||||
pub(crate) fn generics(&self) -> &Generics {
|
||||
self.generics.get_or_init(|| crate::generics::generics(self.db.upcast(), self.generic_def))
|
||||
self.generics.get_or_init(|| crate::generics::generics(self.db, self.generic_def))
|
||||
}
|
||||
|
||||
// FIXME: This function should be private in module. It is currently only used in the consteval, since we need
|
||||
|
|
@ -1470,7 +1470,7 @@ impl<'a> InferenceContext<'a> {
|
|||
) -> Ty {
|
||||
match assoc_ty {
|
||||
Some(res_assoc_ty) => {
|
||||
let trait_ = match res_assoc_ty.lookup(self.db.upcast()).container {
|
||||
let trait_ = match res_assoc_ty.lookup(self.db).container {
|
||||
hir_def::ItemContainerId::TraitId(trait_) => trait_,
|
||||
_ => panic!("resolve_associated_type called with non-associated type"),
|
||||
};
|
||||
|
|
@ -1523,7 +1523,7 @@ impl<'a> InferenceContext<'a> {
|
|||
ValueNs::EnumVariantId(var) => {
|
||||
let substs = path_ctx.substs_from_path(var.into(), true);
|
||||
drop(ctx);
|
||||
let ty = self.db.ty(var.lookup(self.db.upcast()).parent.into());
|
||||
let ty = self.db.ty(var.lookup(self.db).parent.into());
|
||||
let ty = self.insert_type_vars(ty.substitute(Interner, &substs));
|
||||
return (ty, Some(var.into()));
|
||||
}
|
||||
|
|
@ -1566,12 +1566,12 @@ impl<'a> InferenceContext<'a> {
|
|||
TypeNs::EnumVariantId(var) => {
|
||||
let substs = path_ctx.substs_from_path(var.into(), true);
|
||||
drop(ctx);
|
||||
let ty = self.db.ty(var.lookup(self.db.upcast()).parent.into());
|
||||
let ty = self.db.ty(var.lookup(self.db).parent.into());
|
||||
let ty = self.insert_type_vars(ty.substitute(Interner, &substs));
|
||||
forbid_unresolved_segments((ty, Some(var.into())), unresolved)
|
||||
}
|
||||
TypeNs::SelfType(impl_id) => {
|
||||
let generics = crate::generics::generics(self.db.upcast(), impl_id.into());
|
||||
let generics = crate::generics::generics(self.db, impl_id.into());
|
||||
let substs = generics.placeholder_subst(self.db);
|
||||
let mut ty = self.db.impl_self_ty(impl_id).substitute(Interner, &substs);
|
||||
|
||||
|
|
@ -1757,7 +1757,7 @@ impl<'a> InferenceContext<'a> {
|
|||
let ItemContainerId::TraitId(trait_) = self
|
||||
.resolve_lang_item(LangItem::IntoFutureIntoFuture)?
|
||||
.as_function()?
|
||||
.lookup(self.db.upcast())
|
||||
.lookup(self.db)
|
||||
.container
|
||||
else {
|
||||
return None;
|
||||
|
|
|
|||
|
|
@ -44,11 +44,7 @@ impl CastTy {
|
|||
return None;
|
||||
};
|
||||
let enum_data = table.db.enum_variants(id);
|
||||
if enum_data.is_payload_free(table.db.upcast()) {
|
||||
Some(Self::Int(Int::CEnum))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
if enum_data.is_payload_free(table.db) { Some(Self::Int(Int::CEnum)) } else { None }
|
||||
}
|
||||
TyKind::Raw(m, ty) => Some(Self::Ptr(ty.clone(), *m)),
|
||||
TyKind::Function(_) => Some(Self::FnPtr),
|
||||
|
|
|
|||
|
|
@ -335,7 +335,7 @@ impl InferenceContext<'_> {
|
|||
// Search for a predicate like `<$self as FnX<Args>>::Output == Ret`
|
||||
|
||||
let fn_traits: SmallVec<[ChalkTraitId; 3]> =
|
||||
utils::fn_traits(self.db.upcast(), self.owner.module(self.db.upcast()).krate())
|
||||
utils::fn_traits(self.db, self.owner.module(self.db).krate())
|
||||
.map(to_chalk_trait_id)
|
||||
.collect();
|
||||
|
||||
|
|
@ -386,7 +386,7 @@ impl InferenceContext<'_> {
|
|||
projected_ty: &Ty,
|
||||
) -> Option<FnSubst<Interner>> {
|
||||
let container =
|
||||
from_assoc_type_id(projection_ty.associated_ty_id).lookup(self.db.upcast()).container;
|
||||
from_assoc_type_id(projection_ty.associated_ty_id).lookup(self.db).container;
|
||||
let trait_ = match container {
|
||||
hir_def::ItemContainerId::TraitId(trait_) => trait_,
|
||||
_ => return None,
|
||||
|
|
@ -567,7 +567,7 @@ impl HirPlace {
|
|||
|_, _, _| {
|
||||
unreachable!("Closure field only happens in MIR");
|
||||
},
|
||||
ctx.owner.module(ctx.db.upcast()).krate(),
|
||||
ctx.owner.module(ctx.db).krate(),
|
||||
);
|
||||
}
|
||||
ty
|
||||
|
|
@ -641,7 +641,7 @@ impl CapturedItem {
|
|||
match proj {
|
||||
ProjectionElem::Deref => {}
|
||||
ProjectionElem::Field(Either::Left(f)) => {
|
||||
let variant_data = f.parent.variant_data(db.upcast());
|
||||
let variant_data = f.parent.variant_data(db);
|
||||
match variant_data.shape {
|
||||
FieldsShape::Record => {
|
||||
result.push('_');
|
||||
|
|
@ -668,7 +668,7 @@ impl CapturedItem {
|
|||
}
|
||||
}
|
||||
}
|
||||
if is_raw_identifier(&result, owner.module(db.upcast()).krate().data(db).edition) {
|
||||
if is_raw_identifier(&result, owner.module(db).krate().data(db).edition) {
|
||||
result.insert_str(0, "r#");
|
||||
}
|
||||
result
|
||||
|
|
@ -676,20 +676,20 @@ impl CapturedItem {
|
|||
|
||||
pub fn display_place_source_code(&self, owner: DefWithBodyId, db: &dyn HirDatabase) -> String {
|
||||
let body = db.body(owner);
|
||||
let krate = owner.krate(db.upcast());
|
||||
let krate = owner.krate(db);
|
||||
let edition = krate.data(db).edition;
|
||||
let mut result = body[self.place.local].name.display(db.upcast(), edition).to_string();
|
||||
let mut result = body[self.place.local].name.display(db, edition).to_string();
|
||||
for proj in &self.place.projections {
|
||||
match proj {
|
||||
// In source code autoderef kicks in.
|
||||
ProjectionElem::Deref => {}
|
||||
ProjectionElem::Field(Either::Left(f)) => {
|
||||
let variant_data = f.parent.variant_data(db.upcast());
|
||||
let variant_data = f.parent.variant_data(db);
|
||||
match variant_data.shape {
|
||||
FieldsShape::Record => format_to!(
|
||||
result,
|
||||
".{}",
|
||||
variant_data.fields()[f.local_id].name.display(db.upcast(), edition)
|
||||
variant_data.fields()[f.local_id].name.display(db, edition)
|
||||
),
|
||||
FieldsShape::Tuple => format_to!(
|
||||
result,
|
||||
|
|
@ -732,9 +732,9 @@ impl CapturedItem {
|
|||
|
||||
pub fn display_place(&self, owner: DefWithBodyId, db: &dyn HirDatabase) -> String {
|
||||
let body = db.body(owner);
|
||||
let krate = owner.krate(db.upcast());
|
||||
let krate = owner.krate(db);
|
||||
let edition = krate.data(db).edition;
|
||||
let mut result = body[self.place.local].name.display(db.upcast(), edition).to_string();
|
||||
let mut result = body[self.place.local].name.display(db, edition).to_string();
|
||||
let mut field_need_paren = false;
|
||||
for proj in &self.place.projections {
|
||||
match proj {
|
||||
|
|
@ -746,7 +746,7 @@ impl CapturedItem {
|
|||
if field_need_paren {
|
||||
result = format!("({result})");
|
||||
}
|
||||
let variant_data = f.parent.variant_data(db.upcast());
|
||||
let variant_data = f.parent.variant_data(db);
|
||||
let field = match variant_data.shape {
|
||||
FieldsShape::Record => {
|
||||
variant_data.fields()[f.local_id].name.as_str().to_owned()
|
||||
|
|
@ -880,8 +880,8 @@ impl InferenceContext<'_> {
|
|||
return None;
|
||||
}
|
||||
let hygiene = self.body.expr_or_pat_path_hygiene(id);
|
||||
self.resolver.resolve_path_in_value_ns_fully(self.db.upcast(), path, hygiene).and_then(
|
||||
|result| match result {
|
||||
self.resolver.resolve_path_in_value_ns_fully(self.db, path, hygiene).and_then(|result| {
|
||||
match result {
|
||||
ValueNs::LocalBinding(binding) => {
|
||||
let mir_span = match id {
|
||||
ExprOrPatId::ExprId(id) => MirSpan::ExprId(id),
|
||||
|
|
@ -891,8 +891,8 @@ impl InferenceContext<'_> {
|
|||
Some(HirPlace { local: binding, projections: Vec::new() })
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Changes `current_capture_span_stack` to contain the stack of spans for this expr.
|
||||
|
|
@ -901,7 +901,7 @@ impl InferenceContext<'_> {
|
|||
match &self.body[tgt_expr] {
|
||||
Expr::Path(p) => {
|
||||
let resolver_guard =
|
||||
self.resolver.update_to_inner_scope(self.db.upcast(), self.owner, tgt_expr);
|
||||
self.resolver.update_to_inner_scope(self.db, self.owner, tgt_expr);
|
||||
let result = self.path_place(p, tgt_expr.into());
|
||||
self.resolver.reset_to_guard(resolver_guard);
|
||||
return result;
|
||||
|
|
@ -1263,7 +1263,7 @@ impl InferenceContext<'_> {
|
|||
&Expr::Assignment { target, value } => {
|
||||
self.walk_expr(value);
|
||||
let resolver_guard =
|
||||
self.resolver.update_to_inner_scope(self.db.upcast(), self.owner, tgt_expr);
|
||||
self.resolver.update_to_inner_scope(self.db, self.owner, tgt_expr);
|
||||
match self.place_of_expr(value) {
|
||||
Some(rhs_place) => {
|
||||
self.inside_assignment = true;
|
||||
|
|
@ -1322,7 +1322,7 @@ impl InferenceContext<'_> {
|
|||
| Pat::Or(_) => (),
|
||||
Pat::TupleStruct { .. } | Pat::Record { .. } => {
|
||||
if let Some(variant) = self.result.variant_resolution_for_pat(p) {
|
||||
let adt = variant.adt_id(self.db.upcast());
|
||||
let adt = variant.adt_id(self.db);
|
||||
let is_multivariant = match adt {
|
||||
hir_def::AdtId::EnumId(e) => self.db.enum_variants(e).variants.len() != 1,
|
||||
_ => false,
|
||||
|
|
@ -1413,7 +1413,7 @@ impl InferenceContext<'_> {
|
|||
|_, _, _| {
|
||||
unreachable!("Closure field only happens in MIR");
|
||||
},
|
||||
self.owner.module(self.db.upcast()).krate(),
|
||||
self.owner.module(self.db).krate(),
|
||||
);
|
||||
if ty.as_raw_ptr().is_some() || ty.is_union() {
|
||||
capture.kind = CaptureKind::ByRef(BorrowKind::Shared);
|
||||
|
|
|
|||
|
|
@ -197,11 +197,7 @@ impl InferenceContext<'_> {
|
|||
Expr::Path(Path::Normal(path)) => path.type_anchor.is_none(),
|
||||
Expr::Path(path) => self
|
||||
.resolver
|
||||
.resolve_path_in_value_ns_fully(
|
||||
self.db.upcast(),
|
||||
path,
|
||||
self.body.expr_path_hygiene(expr),
|
||||
)
|
||||
.resolve_path_in_value_ns_fully(self.db, path, self.body.expr_path_hygiene(expr))
|
||||
.is_none_or(|res| matches!(res, ValueNs::LocalBinding(_) | ValueNs::StaticId(_))),
|
||||
Expr::Underscore => true,
|
||||
Expr::UnaryOp { op: UnaryOp::Deref, .. } => true,
|
||||
|
|
@ -543,16 +539,15 @@ impl InferenceContext<'_> {
|
|||
_ if fields.is_empty() => {}
|
||||
Some(def) => {
|
||||
let field_types = self.db.field_types(def);
|
||||
let variant_data = def.variant_data(self.db.upcast());
|
||||
let variant_data = def.variant_data(self.db);
|
||||
let visibilities = self.db.field_visibilities(def);
|
||||
for field in fields.iter() {
|
||||
let field_def = {
|
||||
match variant_data.field(&field.name) {
|
||||
Some(local_id) => {
|
||||
if !visibilities[local_id].is_visible_from(
|
||||
self.db.upcast(),
|
||||
self.resolver.module(),
|
||||
) {
|
||||
if !visibilities[local_id]
|
||||
.is_visible_from(self.db, self.resolver.module())
|
||||
{
|
||||
self.push_diagnostic(
|
||||
InferenceDiagnostic::NoSuchField {
|
||||
field: field.expr.into(),
|
||||
|
|
@ -744,7 +739,7 @@ impl InferenceContext<'_> {
|
|||
} else {
|
||||
let rhs_ty = self.infer_expr(value, &Expectation::none(), ExprIsRead::Yes);
|
||||
let resolver_guard =
|
||||
self.resolver.update_to_inner_scope(self.db.upcast(), self.owner, tgt_expr);
|
||||
self.resolver.update_to_inner_scope(self.db, self.owner, tgt_expr);
|
||||
self.inside_assignment = true;
|
||||
self.infer_top_pat(target, &rhs_ty, None);
|
||||
self.inside_assignment = false;
|
||||
|
|
@ -1030,7 +1025,7 @@ impl InferenceContext<'_> {
|
|||
}
|
||||
|
||||
fn infer_expr_path(&mut self, path: &Path, id: ExprOrPatId, scope_id: ExprId) -> Ty {
|
||||
let g = self.resolver.update_to_inner_scope(self.db.upcast(), self.owner, scope_id);
|
||||
let g = self.resolver.update_to_inner_scope(self.db, self.owner, scope_id);
|
||||
let ty = match self.infer_path(path, id) {
|
||||
Some(ty) => ty,
|
||||
None => {
|
||||
|
|
@ -1403,7 +1398,7 @@ impl InferenceContext<'_> {
|
|||
expected: &Expectation,
|
||||
) -> Ty {
|
||||
let coerce_ty = expected.coercion_target_type(&mut self.table);
|
||||
let g = self.resolver.update_to_inner_scope(self.db.upcast(), self.owner, expr);
|
||||
let g = self.resolver.update_to_inner_scope(self.db, self.owner, expr);
|
||||
let prev_env = block_id.map(|block_id| {
|
||||
let prev_env = self.table.trait_env.clone();
|
||||
TraitEnvironment::with_block(&mut self.table.trait_env, block_id);
|
||||
|
|
@ -1576,7 +1571,7 @@ impl InferenceContext<'_> {
|
|||
_ => return None,
|
||||
};
|
||||
let is_visible = self.db.field_visibilities(field_id.parent)[field_id.local_id]
|
||||
.is_visible_from(self.db.upcast(), self.resolver.module());
|
||||
.is_visible_from(self.db, self.resolver.module());
|
||||
if !is_visible {
|
||||
if private_field.is_none() {
|
||||
private_field = Some((field_id, parameters));
|
||||
|
|
@ -1663,7 +1658,7 @@ impl InferenceContext<'_> {
|
|||
match resolved {
|
||||
Some((adjust, func, _)) => {
|
||||
let (ty, adjustments) = adjust.apply(&mut self.table, receiver_ty);
|
||||
let generics = generics(self.db.upcast(), func.into());
|
||||
let generics = generics(self.db, func.into());
|
||||
let substs = self.substs_for_method_call(generics, None);
|
||||
self.write_expr_adj(receiver, adjustments);
|
||||
self.write_method_resolution(tgt_expr, func, substs.clone());
|
||||
|
|
@ -1816,7 +1811,7 @@ impl InferenceContext<'_> {
|
|||
let (ty, adjustments) = adjust.apply(&mut self.table, receiver_ty);
|
||||
self.write_expr_adj(receiver, adjustments);
|
||||
|
||||
let generics = generics(self.db.upcast(), func.into());
|
||||
let generics = generics(self.db, func.into());
|
||||
let substs = self.substs_for_method_call(generics, generic_args);
|
||||
self.write_method_resolution(tgt_expr, func, substs.clone());
|
||||
self.check_method_call(
|
||||
|
|
@ -1867,7 +1862,7 @@ impl InferenceContext<'_> {
|
|||
|
||||
let recovered = match assoc_func_with_same_name {
|
||||
Some(f) => {
|
||||
let generics = generics(self.db.upcast(), f.into());
|
||||
let generics = generics(self.db, f.into());
|
||||
let substs = self.substs_for_method_call(generics, generic_args);
|
||||
let f = self
|
||||
.db
|
||||
|
|
@ -2136,7 +2131,7 @@ impl InferenceContext<'_> {
|
|||
if let TyKind::FnDef(fn_def, parameters) = callable_ty.kind(Interner) {
|
||||
let def: CallableDefId = from_chalk(self.db, *fn_def);
|
||||
let generic_predicates =
|
||||
self.db.generic_predicates(GenericDefId::from_callable(self.db.upcast(), def));
|
||||
self.db.generic_predicates(GenericDefId::from_callable(self.db, def));
|
||||
for predicate in generic_predicates.iter() {
|
||||
let (predicate, binders) = predicate
|
||||
.clone()
|
||||
|
|
@ -2148,10 +2143,10 @@ impl InferenceContext<'_> {
|
|||
// add obligation for trait implementation, if this is a trait method
|
||||
match def {
|
||||
CallableDefId::FunctionId(f) => {
|
||||
if let ItemContainerId::TraitId(trait_) = f.lookup(self.db.upcast()).container {
|
||||
if let ItemContainerId::TraitId(trait_) = f.lookup(self.db).container {
|
||||
// construct a TraitRef
|
||||
let params_len = parameters.len(Interner);
|
||||
let trait_params_len = generics(self.db.upcast(), trait_.into()).len();
|
||||
let trait_params_len = generics(self.db, trait_.into()).len();
|
||||
let substs = Substitution::from_iter(
|
||||
Interner,
|
||||
// The generic parameters for the trait come after those for the
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ impl InferenceContext<'_> {
|
|||
decl: Option<DeclContext>,
|
||||
) -> Ty {
|
||||
let (ty, def) = self.resolve_variant(id.into(), path, true);
|
||||
let var_data = def.map(|it| it.variant_data(self.db.upcast()));
|
||||
let var_data = def.map(|it| it.variant_data(self.db));
|
||||
if let Some(variant) = def {
|
||||
self.write_variant_resolution(id.into(), variant);
|
||||
}
|
||||
|
|
@ -60,7 +60,7 @@ impl InferenceContext<'_> {
|
|||
_ if subs.is_empty() => {}
|
||||
Some(def) => {
|
||||
let field_types = self.db.field_types(def);
|
||||
let variant_data = def.variant_data(self.db.upcast());
|
||||
let variant_data = def.variant_data(self.db);
|
||||
let visibilities = self.db.field_visibilities(def);
|
||||
|
||||
let (pre, post) = match ellipsis {
|
||||
|
|
@ -79,7 +79,7 @@ impl InferenceContext<'_> {
|
|||
match variant_data.field(&Name::new_tuple_field(i)) {
|
||||
Some(local_id) => {
|
||||
if !visibilities[local_id]
|
||||
.is_visible_from(self.db.upcast(), self.resolver.module())
|
||||
.is_visible_from(self.db, self.resolver.module())
|
||||
{
|
||||
// FIXME(DIAGNOSE): private tuple field
|
||||
}
|
||||
|
|
@ -129,7 +129,7 @@ impl InferenceContext<'_> {
|
|||
_ if subs.len() == 0 => {}
|
||||
Some(def) => {
|
||||
let field_types = self.db.field_types(def);
|
||||
let variant_data = def.variant_data(self.db.upcast());
|
||||
let variant_data = def.variant_data(self.db);
|
||||
let visibilities = self.db.field_visibilities(def);
|
||||
|
||||
let substs = ty.as_adt().map(TupleExt::tail);
|
||||
|
|
@ -139,7 +139,7 @@ impl InferenceContext<'_> {
|
|||
match variant_data.field(&name) {
|
||||
Some(local_id) => {
|
||||
if !visibilities[local_id]
|
||||
.is_visible_from(self.db.upcast(), self.resolver.module())
|
||||
.is_visible_from(self.db, self.resolver.module())
|
||||
{
|
||||
self.push_diagnostic(InferenceDiagnostic::NoSuchField {
|
||||
field: inner.into(),
|
||||
|
|
@ -594,8 +594,7 @@ impl InferenceContext<'_> {
|
|||
}
|
||||
|
||||
let len = before.len() + suffix.len();
|
||||
let size =
|
||||
consteval::usize_const(self.db, Some(len as u128), self.owner.krate(self.db.upcast()));
|
||||
let size = consteval::usize_const(self.db, Some(len as u128), self.owner.krate(self.db));
|
||||
|
||||
let elem_ty = self.table.new_type_var();
|
||||
let array_ty = TyKind::Array(elem_ty.clone(), size).intern(Interner);
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ impl InferenceContext<'_> {
|
|||
};
|
||||
}
|
||||
ValueNs::ImplSelf(impl_id) => {
|
||||
let generics = crate::generics::generics(self.db.upcast(), impl_id.into());
|
||||
let generics = crate::generics::generics(self.db, impl_id.into());
|
||||
let substs = generics.placeholder_subst(self.db);
|
||||
let ty = self.db.impl_self_ty(impl_id).substitute(Interner, &substs);
|
||||
return if let Some((AdtId::StructId(struct_id), substs)) = ty.as_adt() {
|
||||
|
|
@ -128,7 +128,7 @@ impl InferenceContext<'_> {
|
|||
}
|
||||
|
||||
let parent_substs = self_subst.or_else(|| {
|
||||
let generics = generics(self.db.upcast(), generic_def);
|
||||
let generics = generics(self.db, generic_def);
|
||||
let parent_params_len = generics.parent_generics()?.len();
|
||||
let parent_args = &substs[substs.len() - parent_params_len..];
|
||||
Some(Substitution::from_iter(Interner, parent_args))
|
||||
|
|
@ -255,13 +255,13 @@ impl InferenceContext<'_> {
|
|||
|
||||
// We need to add `Self: Trait` obligation when `def` is a trait assoc item.
|
||||
let container = match def {
|
||||
GenericDefId::FunctionId(id) => id.lookup(self.db.upcast()).container,
|
||||
GenericDefId::ConstId(id) => id.lookup(self.db.upcast()).container,
|
||||
GenericDefId::FunctionId(id) => id.lookup(self.db).container,
|
||||
GenericDefId::ConstId(id) => id.lookup(self.db).container,
|
||||
_ => return,
|
||||
};
|
||||
|
||||
if let ItemContainerId::TraitId(trait_) = container {
|
||||
let param_len = generics(self.db.upcast(), def).len_self();
|
||||
let param_len = generics(self.db, def).len_self();
|
||||
let parent_subst =
|
||||
Substitution::from_iter(Interner, subst.iter(Interner).skip(param_len));
|
||||
let trait_ref =
|
||||
|
|
@ -351,10 +351,8 @@ impl InferenceContext<'_> {
|
|||
let (item, visible) = res?;
|
||||
|
||||
let (def, container) = match item {
|
||||
AssocItemId::FunctionId(f) => {
|
||||
(ValueNs::FunctionId(f), f.lookup(self.db.upcast()).container)
|
||||
}
|
||||
AssocItemId::ConstId(c) => (ValueNs::ConstId(c), c.lookup(self.db.upcast()).container),
|
||||
AssocItemId::FunctionId(f) => (ValueNs::FunctionId(f), f.lookup(self.db).container),
|
||||
AssocItemId::ConstId(c) => (ValueNs::ConstId(c), c.lookup(self.db).container),
|
||||
AssocItemId::TypeAliasId(_) => unreachable!(),
|
||||
};
|
||||
let substs = match container {
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ impl UninhabitedFrom<'_> {
|
|||
ty: &Binders<Ty>,
|
||||
subst: &Substitution,
|
||||
) -> ControlFlow<VisiblyUninhabited> {
|
||||
if vis.is_none_or(|it| it.is_visible_from(self.db.upcast(), self.target_mod)) {
|
||||
if vis.is_none_or(|it| it.is_visible_from(self.db, self.target_mod)) {
|
||||
let ty = ty.clone().substitute(Interner, subst);
|
||||
ty.visit_with(self, DebruijnIndex::INNERMOST)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -301,7 +301,7 @@ impl Hash for ConstScalar {
|
|||
|
||||
/// Return an index of a parameter in the generic type parameter list by it's id.
|
||||
pub fn param_idx(db: &dyn HirDatabase, id: TypeOrConstParamId) -> Option<usize> {
|
||||
generics::generics(db.upcast(), id.parent).type_or_const_param_idx(id)
|
||||
generics::generics(db, id.parent).type_or_const_param_idx(id)
|
||||
}
|
||||
|
||||
pub(crate) fn wrap_empty_binders<T>(value: T) -> Binders<T>
|
||||
|
|
|
|||
|
|
@ -243,7 +243,7 @@ impl<'a> TyLoweringContext<'a> {
|
|||
}
|
||||
|
||||
fn generics(&self) -> &Generics {
|
||||
self.generics.get_or_init(|| generics(self.db.upcast(), self.def))
|
||||
self.generics.get_or_init(|| generics(self.db, self.def))
|
||||
}
|
||||
|
||||
pub fn lower_ty_ext(&mut self, type_ref_id: TypeRefId) -> (Ty, Option<TypeNs>) {
|
||||
|
|
@ -356,8 +356,7 @@ impl<'a> TyLoweringContext<'a> {
|
|||
|a| ImplTraitId::TypeAliasImplTrait(a, idx),
|
||||
);
|
||||
let opaque_ty_id = self.db.intern_impl_trait_id(impl_trait_id).into();
|
||||
let generics =
|
||||
generics(self.db.upcast(), origin.either(|f| f.into(), |a| a.into()));
|
||||
let generics = generics(self.db, origin.either(|f| f.into(), |a| a.into()));
|
||||
let parameters = generics.bound_vars_subst(self.db, self.in_binders);
|
||||
TyKind::OpaqueType(opaque_ty_id, parameters).intern(Interner)
|
||||
}
|
||||
|
|
@ -771,7 +770,7 @@ fn named_associated_type_shorthand_candidates<R>(
|
|||
// FIXME: A `HirDatabase` query may be handy if this process is needed in more
|
||||
// places. It'd be almost identical as `impl_trait_query` where `resolver` would be
|
||||
// of `def` instead of `impl_id`.
|
||||
let starting_idx = generics(db.upcast(), def).len_self();
|
||||
let starting_idx = generics(db, def).len_self();
|
||||
let subst = TyBuilder::subst_for_def(db, impl_id, None)
|
||||
.fill_with_bound_vars(DebruijnIndex::INNERMOST, starting_idx)
|
||||
.build();
|
||||
|
|
@ -797,9 +796,9 @@ fn named_associated_type_shorthand_candidates<R>(
|
|||
}
|
||||
// Handle `Self::Type` referring to own associated type in trait definitions
|
||||
if let GenericDefId::TraitId(trait_id) = param_id.parent() {
|
||||
let trait_generics = generics(db.upcast(), trait_id.into());
|
||||
let trait_generics = generics(db, trait_id.into());
|
||||
if trait_generics[param_id.local_id()].is_trait_self() {
|
||||
let def_generics = generics(db.upcast(), def);
|
||||
let def_generics = generics(db, def);
|
||||
let starting_idx = match def {
|
||||
GenericDefId::TraitId(_) => 0,
|
||||
// `def` is an item within trait. We need to substitute `BoundVar`s but
|
||||
|
|
@ -839,13 +838,11 @@ pub(crate) fn field_types_with_diagnostics_query(
|
|||
) -> (Arc<ArenaMap<LocalFieldId, Binders<Ty>>>, Diagnostics) {
|
||||
let var_data = db.variant_fields(variant_id);
|
||||
let (resolver, def): (_, GenericDefId) = match variant_id {
|
||||
VariantId::StructId(it) => (it.resolver(db.upcast()), it.into()),
|
||||
VariantId::UnionId(it) => (it.resolver(db.upcast()), it.into()),
|
||||
VariantId::EnumVariantId(it) => {
|
||||
(it.resolver(db.upcast()), it.lookup(db.upcast()).parent.into())
|
||||
}
|
||||
VariantId::StructId(it) => (it.resolver(db), it.into()),
|
||||
VariantId::UnionId(it) => (it.resolver(db), it.into()),
|
||||
VariantId::EnumVariantId(it) => (it.resolver(db), it.lookup(db).parent.into()),
|
||||
};
|
||||
let generics = generics(db.upcast(), def);
|
||||
let generics = generics(db, def);
|
||||
let mut res = ArenaMap::default();
|
||||
let mut ctx = TyLoweringContext::new(db, &resolver, &var_data.store, def)
|
||||
.with_type_param_mode(ParamLoweringMode::Variable);
|
||||
|
|
@ -869,8 +866,8 @@ pub(crate) fn generic_predicates_for_param_query(
|
|||
param_id: TypeOrConstParamId,
|
||||
assoc_name: Option<Name>,
|
||||
) -> GenericPredicates {
|
||||
let generics = generics(db.upcast(), def);
|
||||
let resolver = def.resolver(db.upcast());
|
||||
let generics = generics(db, def);
|
||||
let resolver = def.resolver(db);
|
||||
let mut ctx = TyLoweringContext::new(db, &resolver, generics.store(), def)
|
||||
.with_type_param_mode(ParamLoweringMode::Variable);
|
||||
|
||||
|
|
@ -903,12 +900,12 @@ pub(crate) fn generic_predicates_for_param_query(
|
|||
|
||||
let Some(assoc_name) = &assoc_name else { return true };
|
||||
let Some(TypeNs::TraitId(tr)) =
|
||||
resolver.resolve_path_in_type_ns_fully(db.upcast(), path)
|
||||
resolver.resolve_path_in_type_ns_fully(db, path)
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
|
||||
all_super_traits(db.upcast(), tr).iter().any(|tr| {
|
||||
all_super_traits(db, tr).iter().any(|tr| {
|
||||
db.trait_items(*tr).items.iter().any(|(name, item)| {
|
||||
matches!(item, AssocItemId::TypeAliasId(_)) && name == assoc_name
|
||||
})
|
||||
|
|
@ -968,8 +965,8 @@ pub(crate) fn trait_environment_for_body_query(
|
|||
db: &dyn HirDatabase,
|
||||
def: DefWithBodyId,
|
||||
) -> Arc<TraitEnvironment> {
|
||||
let Some(def) = def.as_generic_def_id(db.upcast()) else {
|
||||
let krate = def.module(db.upcast()).krate();
|
||||
let Some(def) = def.as_generic_def_id(db) else {
|
||||
let krate = def.module(db).krate();
|
||||
return TraitEnvironment::empty(krate);
|
||||
};
|
||||
db.trait_environment(def)
|
||||
|
|
@ -979,8 +976,8 @@ pub(crate) fn trait_environment_query(
|
|||
db: &dyn HirDatabase,
|
||||
def: GenericDefId,
|
||||
) -> Arc<TraitEnvironment> {
|
||||
let generics = generics(db.upcast(), def);
|
||||
let resolver = def.resolver(db.upcast());
|
||||
let generics = generics(db, def);
|
||||
let resolver = def.resolver(db);
|
||||
let mut ctx = TyLoweringContext::new(db, &resolver, generics.store(), def)
|
||||
.with_type_param_mode(ParamLoweringMode::Placeholder);
|
||||
let mut traits_in_scope = Vec::new();
|
||||
|
|
@ -1001,7 +998,7 @@ pub(crate) fn trait_environment_query(
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(trait_id) = def.assoc_trait_container(db.upcast()) {
|
||||
if let Some(trait_id) = def.assoc_trait_container(db) {
|
||||
// add `Self: Trait<T1, T2, ...>` to the environment in trait
|
||||
// function default implementations (and speculative code
|
||||
// inside consts or type aliases)
|
||||
|
|
@ -1076,8 +1073,8 @@ fn generic_predicates_filtered_by<F>(
|
|||
where
|
||||
F: Fn(&WherePredicate, GenericDefId) -> bool,
|
||||
{
|
||||
let generics = generics(db.upcast(), def);
|
||||
let resolver = def.resolver(db.upcast());
|
||||
let generics = generics(db, def);
|
||||
let resolver = def.resolver(db);
|
||||
let mut ctx = TyLoweringContext::new(db, &resolver, generics.store(), def)
|
||||
.with_type_param_mode(ParamLoweringMode::Variable);
|
||||
|
||||
|
|
@ -1128,7 +1125,7 @@ fn implicitly_sized_clauses<'a, 'subst: 'a>(
|
|||
.lang_item(resolver.krate(), LangItem::Sized)
|
||||
.and_then(|lang_item| lang_item.as_trait().map(to_chalk_trait_id))?;
|
||||
|
||||
let trait_self_idx = trait_self_param_idx(db.upcast(), def);
|
||||
let trait_self_idx = trait_self_param_idx(db, def);
|
||||
|
||||
Some(
|
||||
substitution
|
||||
|
|
@ -1172,11 +1169,11 @@ pub(crate) fn generic_defaults_with_diagnostics_query(
|
|||
db: &dyn HirDatabase,
|
||||
def: GenericDefId,
|
||||
) -> (GenericDefaults, Diagnostics) {
|
||||
let generic_params = generics(db.upcast(), def);
|
||||
let generic_params = generics(db, def);
|
||||
if generic_params.len() == 0 {
|
||||
return (GenericDefaults(None), None);
|
||||
}
|
||||
let resolver = def.resolver(db.upcast());
|
||||
let resolver = def.resolver(db);
|
||||
let parent_start_idx = generic_params.len_self();
|
||||
|
||||
let mut ctx = TyLoweringContext::new(db, &resolver, generic_params.store(), def)
|
||||
|
|
@ -1249,7 +1246,7 @@ pub(crate) fn generic_defaults_with_diagnostics_recover(
|
|||
_cycle: &Cycle,
|
||||
def: GenericDefId,
|
||||
) -> (GenericDefaults, Diagnostics) {
|
||||
let generic_params = generics(db.upcast(), def);
|
||||
let generic_params = generics(db, def);
|
||||
if generic_params.len() == 0 {
|
||||
return (GenericDefaults(None), None);
|
||||
}
|
||||
|
|
@ -1268,7 +1265,7 @@ pub(crate) fn generic_defaults_with_diagnostics_recover(
|
|||
|
||||
fn fn_sig_for_fn(db: &dyn HirDatabase, def: FunctionId) -> PolyFnSig {
|
||||
let data = db.function_signature(def);
|
||||
let resolver = def.resolver(db.upcast());
|
||||
let resolver = def.resolver(db);
|
||||
let mut ctx_params = TyLoweringContext::new(db, &resolver, &data.store, def.into())
|
||||
.with_type_param_mode(ParamLoweringMode::Variable);
|
||||
let params = data.params.iter().map(|&tr| ctx_params.lower_ty(tr));
|
||||
|
|
@ -1282,7 +1279,7 @@ fn fn_sig_for_fn(db: &dyn HirDatabase, def: FunctionId) -> PolyFnSig {
|
|||
}
|
||||
None => TyKind::Tuple(0, Substitution::empty(Interner)).intern(Interner),
|
||||
};
|
||||
let generics = generics(db.upcast(), def.into());
|
||||
let generics = generics(db, def.into());
|
||||
let sig = CallableSig::from_params_and_return(
|
||||
params,
|
||||
ret,
|
||||
|
|
@ -1296,7 +1293,7 @@ fn fn_sig_for_fn(db: &dyn HirDatabase, def: FunctionId) -> PolyFnSig {
|
|||
/// Build the declared type of a function. This should not need to look at the
|
||||
/// function body.
|
||||
fn type_for_fn(db: &dyn HirDatabase, def: FunctionId) -> Binders<Ty> {
|
||||
let generics = generics(db.upcast(), def.into());
|
||||
let generics = generics(db, def.into());
|
||||
let substs = generics.bound_vars_subst(db, DebruijnIndex::INNERMOST);
|
||||
make_binders(
|
||||
db,
|
||||
|
|
@ -1308,8 +1305,8 @@ fn type_for_fn(db: &dyn HirDatabase, def: FunctionId) -> Binders<Ty> {
|
|||
/// Build the declared type of a const.
|
||||
fn type_for_const(db: &dyn HirDatabase, def: ConstId) -> Binders<Ty> {
|
||||
let data = db.const_signature(def);
|
||||
let generics = generics(db.upcast(), def.into());
|
||||
let resolver = def.resolver(db.upcast());
|
||||
let generics = generics(db, def.into());
|
||||
let resolver = def.resolver(db);
|
||||
let mut ctx = TyLoweringContext::new(db, &resolver, &data.store, def.into())
|
||||
.with_type_param_mode(ParamLoweringMode::Variable);
|
||||
|
||||
|
|
@ -1319,7 +1316,7 @@ fn type_for_const(db: &dyn HirDatabase, def: ConstId) -> Binders<Ty> {
|
|||
/// Build the declared type of a static.
|
||||
fn type_for_static(db: &dyn HirDatabase, def: StaticId) -> Binders<Ty> {
|
||||
let data = db.static_signature(def);
|
||||
let resolver = def.resolver(db.upcast());
|
||||
let resolver = def.resolver(db);
|
||||
let mut ctx = TyLoweringContext::new(db, &resolver, &data.store, def.into());
|
||||
|
||||
Binders::empty(Interner, ctx.lower_ty(data.type_ref))
|
||||
|
|
@ -1328,7 +1325,7 @@ fn type_for_static(db: &dyn HirDatabase, def: StaticId) -> Binders<Ty> {
|
|||
fn fn_sig_for_struct_constructor(db: &dyn HirDatabase, def: StructId) -> PolyFnSig {
|
||||
let struct_data = db.variant_fields(def.into());
|
||||
let fields = struct_data.fields();
|
||||
let resolver = def.resolver(db.upcast());
|
||||
let resolver = def.resolver(db);
|
||||
let mut ctx = TyLoweringContext::new(db, &resolver, &struct_data.store, def.into())
|
||||
.with_type_param_mode(ParamLoweringMode::Variable);
|
||||
let params = fields.iter().map(|(_, field)| ctx.lower_ty(field.type_ref));
|
||||
|
|
@ -1346,7 +1343,7 @@ fn type_for_struct_constructor(db: &dyn HirDatabase, def: StructId) -> Option<Bi
|
|||
FieldsShape::Record => None,
|
||||
FieldsShape::Unit => Some(type_for_adt(db, def.into())),
|
||||
FieldsShape::Tuple => {
|
||||
let generics = generics(db.upcast(), AdtId::from(def).into());
|
||||
let generics = generics(db, AdtId::from(def).into());
|
||||
let substs = generics.bound_vars_subst(db, DebruijnIndex::INNERMOST);
|
||||
Some(make_binders(
|
||||
db,
|
||||
|
|
@ -1360,8 +1357,8 @@ fn type_for_struct_constructor(db: &dyn HirDatabase, def: StructId) -> Option<Bi
|
|||
fn fn_sig_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) -> PolyFnSig {
|
||||
let var_data = db.variant_fields(def.into());
|
||||
let fields = var_data.fields();
|
||||
let resolver = def.resolver(db.upcast());
|
||||
let parent = def.lookup(db.upcast()).parent;
|
||||
let resolver = def.resolver(db);
|
||||
let parent = def.lookup(db).parent;
|
||||
let mut ctx = TyLoweringContext::new(db, &resolver, &var_data.store, parent.into())
|
||||
.with_type_param_mode(ParamLoweringMode::Variable);
|
||||
let params = fields.iter().map(|(_, field)| ctx.lower_ty(field.type_ref));
|
||||
|
|
@ -1377,12 +1374,12 @@ fn type_for_enum_variant_constructor(
|
|||
db: &dyn HirDatabase,
|
||||
def: EnumVariantId,
|
||||
) -> Option<Binders<Ty>> {
|
||||
let e = def.lookup(db.upcast()).parent;
|
||||
let e = def.lookup(db).parent;
|
||||
match db.variant_fields(def.into()).shape {
|
||||
FieldsShape::Record => None,
|
||||
FieldsShape::Unit => Some(type_for_adt(db, e.into())),
|
||||
FieldsShape::Tuple => {
|
||||
let generics = generics(db.upcast(), e.into());
|
||||
let generics = generics(db, e.into());
|
||||
let substs = generics.bound_vars_subst(db, DebruijnIndex::INNERMOST);
|
||||
Some(make_binders(
|
||||
db,
|
||||
|
|
@ -1404,12 +1401,12 @@ pub(crate) fn type_for_adt_recovery(
|
|||
_cycle: &salsa::Cycle,
|
||||
adt: AdtId,
|
||||
) -> Binders<Ty> {
|
||||
let generics = generics(db.upcast(), adt.into());
|
||||
let generics = generics(db, adt.into());
|
||||
make_binders(db, &generics, TyKind::Error.intern(Interner))
|
||||
}
|
||||
|
||||
fn type_for_adt(db: &dyn HirDatabase, adt: AdtId) -> Binders<Ty> {
|
||||
let generics = generics(db.upcast(), adt.into());
|
||||
let generics = generics(db, adt.into());
|
||||
let subst = generics.bound_vars_subst(db, DebruijnIndex::INNERMOST);
|
||||
let ty = TyKind::Adt(crate::AdtId(adt), subst).intern(Interner);
|
||||
make_binders(db, &generics, ty)
|
||||
|
|
@ -1419,13 +1416,13 @@ pub(crate) fn type_for_type_alias_with_diagnostics_query(
|
|||
db: &dyn HirDatabase,
|
||||
t: TypeAliasId,
|
||||
) -> (Binders<Ty>, Diagnostics) {
|
||||
let generics = generics(db.upcast(), t.into());
|
||||
let generics = generics(db, t.into());
|
||||
let type_alias_data = db.type_alias_signature(t);
|
||||
let mut diags = None;
|
||||
let inner = if type_alias_data.flags.contains(TypeAliasFlags::IS_EXTERN) {
|
||||
TyKind::Foreign(crate::to_foreign_def_id(t)).intern(Interner)
|
||||
} else {
|
||||
let resolver = t.resolver(db.upcast());
|
||||
let resolver = t.resolver(db);
|
||||
let alias = db.type_alias_signature(t);
|
||||
let mut ctx = TyLoweringContext::new(db, &resolver, &alias.store, t.into())
|
||||
.with_impl_trait_mode(ImplTraitLoweringMode::Opaque)
|
||||
|
|
@ -1446,7 +1443,7 @@ pub(crate) fn type_for_type_alias_with_diagnostics_query_recover(
|
|||
_cycle: &salsa::Cycle,
|
||||
adt: TypeAliasId,
|
||||
) -> (Binders<Ty>, Diagnostics) {
|
||||
let generics = generics(db.upcast(), adt.into());
|
||||
let generics = generics(db, adt.into());
|
||||
(make_binders(db, &generics, TyKind::Error.intern(Interner)), None)
|
||||
}
|
||||
|
||||
|
|
@ -1475,7 +1472,7 @@ impl ValueTyDefId {
|
|||
Self::FunctionId(id) => id.into(),
|
||||
Self::StructId(id) => id.into(),
|
||||
Self::UnionId(id) => id.into(),
|
||||
Self::EnumVariantId(var) => var.lookup(db.upcast()).parent.into(),
|
||||
Self::EnumVariantId(var) => var.lookup(db).parent.into(),
|
||||
Self::ConstId(id) => id.into(),
|
||||
Self::StaticId(id) => id.into(),
|
||||
}
|
||||
|
|
@ -1514,8 +1511,8 @@ pub(crate) fn impl_self_ty_with_diagnostics_query(
|
|||
impl_id: ImplId,
|
||||
) -> (Binders<Ty>, Diagnostics) {
|
||||
let impl_data = db.impl_signature(impl_id);
|
||||
let resolver = impl_id.resolver(db.upcast());
|
||||
let generics = generics(db.upcast(), impl_id.into());
|
||||
let resolver = impl_id.resolver(db);
|
||||
let generics = generics(db, impl_id.into());
|
||||
let mut ctx = TyLoweringContext::new(db, &resolver, &impl_data.store, impl_id.into())
|
||||
.with_type_param_mode(ParamLoweringMode::Variable);
|
||||
(
|
||||
|
|
@ -1535,7 +1532,7 @@ pub(crate) fn const_param_ty_with_diagnostics_query(
|
|||
) -> (Ty, Diagnostics) {
|
||||
let (parent_data, store) = db.generic_params_and_store(def.parent());
|
||||
let data = &parent_data[def.local_id()];
|
||||
let resolver = def.parent().resolver(db.upcast());
|
||||
let resolver = def.parent().resolver(db);
|
||||
let mut ctx = TyLoweringContext::new(db, &resolver, &store, def.parent());
|
||||
let ty = match data {
|
||||
TypeOrConstParamData::TypeParamData(_) => {
|
||||
|
|
@ -1552,7 +1549,7 @@ pub(crate) fn impl_self_ty_with_diagnostics_recover(
|
|||
_cycle: &salsa::Cycle,
|
||||
impl_id: ImplId,
|
||||
) -> (Binders<Ty>, Diagnostics) {
|
||||
let generics = generics(db.upcast(), (impl_id).into());
|
||||
let generics = generics(db, (impl_id).into());
|
||||
(make_binders(db, &generics, TyKind::Error.intern(Interner)), None)
|
||||
}
|
||||
|
||||
|
|
@ -1565,7 +1562,7 @@ pub(crate) fn impl_trait_with_diagnostics_query(
|
|||
impl_id: ImplId,
|
||||
) -> Option<(Binders<TraitRef>, Diagnostics)> {
|
||||
let impl_data = db.impl_signature(impl_id);
|
||||
let resolver = impl_id.resolver(db.upcast());
|
||||
let resolver = impl_id.resolver(db);
|
||||
let mut ctx = TyLoweringContext::new(db, &resolver, &impl_data.store, impl_id.into())
|
||||
.with_type_param_mode(ParamLoweringMode::Variable);
|
||||
let (self_ty, binders) = db.impl_self_ty(impl_id).into_value_and_skipped_binders();
|
||||
|
|
@ -1580,14 +1577,14 @@ pub(crate) fn return_type_impl_traits(
|
|||
) -> Option<Arc<Binders<ImplTraits>>> {
|
||||
// FIXME unify with fn_sig_for_fn instead of doing lowering twice, maybe
|
||||
let data = db.function_signature(def);
|
||||
let resolver = def.resolver(db.upcast());
|
||||
let resolver = def.resolver(db);
|
||||
let mut ctx_ret = TyLoweringContext::new(db, &resolver, &data.store, def.into())
|
||||
.with_impl_trait_mode(ImplTraitLoweringMode::Opaque)
|
||||
.with_type_param_mode(ParamLoweringMode::Variable);
|
||||
if let Some(ret_type) = data.ret_type {
|
||||
let _ret = ctx_ret.lower_ty(ret_type);
|
||||
}
|
||||
let generics = generics(db.upcast(), def.into());
|
||||
let generics = generics(db, def.into());
|
||||
let return_type_impl_traits =
|
||||
ImplTraits { impl_traits: ctx_ret.impl_trait_mode.opaque_type_data };
|
||||
if return_type_impl_traits.impl_traits.is_empty() {
|
||||
|
|
@ -1602,7 +1599,7 @@ pub(crate) fn type_alias_impl_traits(
|
|||
def: hir_def::TypeAliasId,
|
||||
) -> Option<Arc<Binders<ImplTraits>>> {
|
||||
let data = db.type_alias_signature(def);
|
||||
let resolver = def.resolver(db.upcast());
|
||||
let resolver = def.resolver(db);
|
||||
let mut ctx = TyLoweringContext::new(db, &resolver, &data.store, def.into())
|
||||
.with_impl_trait_mode(ImplTraitLoweringMode::Opaque)
|
||||
.with_type_param_mode(ParamLoweringMode::Variable);
|
||||
|
|
@ -1613,7 +1610,7 @@ pub(crate) fn type_alias_impl_traits(
|
|||
if type_alias_impl_traits.impl_traits.is_empty() {
|
||||
None
|
||||
} else {
|
||||
let generics = generics(db.upcast(), def.into());
|
||||
let generics = generics(db, def.into());
|
||||
Some(Arc::new(make_binders(db, &generics, type_alias_impl_traits)))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
|
|||
None,
|
||||
);
|
||||
let len_self =
|
||||
generics(self.ctx.db.upcast(), associated_ty.into()).len_self();
|
||||
generics(self.ctx.db, associated_ty.into()).len_self();
|
||||
let substitution = Substitution::from_iter(
|
||||
Interner,
|
||||
substitution
|
||||
|
|
@ -265,7 +265,7 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
|
|||
}
|
||||
}
|
||||
TypeNs::AdtSelfType(adt) => {
|
||||
let generics = generics(self.ctx.db.upcast(), adt.into());
|
||||
let generics = generics(self.ctx.db, adt.into());
|
||||
let substs = match self.ctx.type_param_mode {
|
||||
ParamLoweringMode::Placeholder => generics.placeholder_subst(self.ctx.db),
|
||||
ParamLoweringMode::Variable => {
|
||||
|
|
@ -327,10 +327,8 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
|
|||
}
|
||||
|
||||
pub(crate) fn resolve_path_in_type_ns(&mut self) -> Option<(TypeNs, Option<usize>)> {
|
||||
let (resolution, remaining_index, _, prefix_info) = self
|
||||
.ctx
|
||||
.resolver
|
||||
.resolve_path_in_type_ns_with_prefix_info(self.ctx.db.upcast(), self.path)?;
|
||||
let (resolution, remaining_index, _, prefix_info) =
|
||||
self.ctx.resolver.resolve_path_in_type_ns_with_prefix_info(self.ctx.db, self.path)?;
|
||||
|
||||
let segments = self.segments;
|
||||
if segments.is_empty() || matches!(self.path, Path::LangItem(..)) {
|
||||
|
|
@ -385,7 +383,7 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
|
|||
hygiene_id: HygieneId,
|
||||
) -> Option<ResolveValueResult> {
|
||||
let (res, prefix_info) = self.ctx.resolver.resolve_path_in_value_ns_with_prefix_info(
|
||||
self.ctx.db.upcast(),
|
||||
self.ctx.db,
|
||||
self.path,
|
||||
hygiene_id,
|
||||
)?;
|
||||
|
|
@ -510,8 +508,7 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
|
|||
let substs = self.substs_from_path_segment(associated_ty.into(), false, None);
|
||||
|
||||
let len_self =
|
||||
crate::generics::generics(self.ctx.db.upcast(), associated_ty.into())
|
||||
.len_self();
|
||||
crate::generics::generics(self.ctx.db, associated_ty.into()).len_self();
|
||||
|
||||
let substs = Substitution::from_iter(
|
||||
Interner,
|
||||
|
|
@ -583,7 +580,7 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
|
|||
self.current_or_prev_segment = penultimate;
|
||||
}
|
||||
}
|
||||
var.lookup(self.ctx.db.upcast()).parent.into()
|
||||
var.lookup(self.ctx.db).parent.into()
|
||||
}
|
||||
};
|
||||
let result = self.substs_from_path_segment(generic_def, infer_args, None);
|
||||
|
|
@ -639,7 +636,7 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
|
|||
// - Lifetime parameters
|
||||
// - Type or Const parameters
|
||||
// - Parent parameters
|
||||
let def_generics = generics(self.ctx.db.upcast(), def);
|
||||
let def_generics = generics(self.ctx.db, def);
|
||||
let (
|
||||
parent_params,
|
||||
self_param,
|
||||
|
|
@ -742,7 +739,7 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
|
|||
// ignore them.
|
||||
let is_assoc_ty = || match def {
|
||||
GenericDefId::TypeAliasId(id) => {
|
||||
matches!(id.lookup(self.ctx.db.upcast()).container, ItemContainerId::TraitId(_))
|
||||
matches!(id.lookup(self.ctx.db).container, ItemContainerId::TraitId(_))
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
|
|
@ -816,7 +813,7 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
|
|||
false, // this is not relevant
|
||||
Some(super_trait_ref.self_type_parameter(Interner)),
|
||||
);
|
||||
let generics = generics(self.ctx.db.upcast(), associated_ty.into());
|
||||
let generics = generics(self.ctx.db, associated_ty.into());
|
||||
let self_params = generics.len_self();
|
||||
let substitution = Substitution::from_iter(
|
||||
Interner,
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ impl TraitImpls {
|
|||
// const _: () = { ... };
|
||||
for konst in module_data.scope.unnamed_consts() {
|
||||
let body = db.body(konst.into());
|
||||
for (_, block_def_map) in body.blocks(db.upcast()) {
|
||||
for (_, block_def_map) in body.blocks(db) {
|
||||
Self::collect_def_map(db, map, &block_def_map);
|
||||
}
|
||||
}
|
||||
|
|
@ -336,7 +336,7 @@ impl InherentImpls {
|
|||
// const _: () = { ... };
|
||||
for konst in module_data.scope.unnamed_consts() {
|
||||
let body = db.body(konst.into());
|
||||
for (_, block_def_map) in body.blocks(db.upcast()) {
|
||||
for (_, block_def_map) in body.blocks(db) {
|
||||
self.collect_def_map(db, &block_def_map);
|
||||
}
|
||||
}
|
||||
|
|
@ -399,7 +399,7 @@ pub fn def_crates(db: &dyn HirDatabase, ty: &Ty, cur_crate: Crate) -> Option<Sma
|
|||
Some(if rustc_has_incoherent_inherent_impls {
|
||||
db.incoherent_inherent_impl_crates(cur_crate, TyFingerprint::Adt(def_id))
|
||||
} else {
|
||||
smallvec![def_id.module(db.upcast()).krate()]
|
||||
smallvec![def_id.module(db).krate()]
|
||||
})
|
||||
}
|
||||
&TyKind::Foreign(id) => {
|
||||
|
|
@ -412,7 +412,7 @@ pub fn def_crates(db: &dyn HirDatabase, ty: &Ty, cur_crate: Crate) -> Option<Sma
|
|||
{
|
||||
db.incoherent_inherent_impl_crates(cur_crate, TyFingerprint::ForeignType(id))
|
||||
} else {
|
||||
smallvec![alias.module(db.upcast()).krate()]
|
||||
smallvec![alias.module(db).krate()]
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
@ -426,7 +426,7 @@ pub fn def_crates(db: &dyn HirDatabase, ty: &Ty, cur_crate: Crate) -> Option<Sma
|
|||
{
|
||||
db.incoherent_inherent_impl_crates(cur_crate, TyFingerprint::Dyn(trait_id))
|
||||
} else {
|
||||
smallvec![trait_id.module(db.upcast()).krate()]
|
||||
smallvec![trait_id.module(db).krate()]
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
@ -620,7 +620,7 @@ pub fn lookup_impl_const(
|
|||
const_id: ConstId,
|
||||
subs: Substitution,
|
||||
) -> (ConstId, Substitution) {
|
||||
let trait_id = match const_id.lookup(db.upcast()).container {
|
||||
let trait_id = match const_id.lookup(db).container {
|
||||
ItemContainerId::TraitId(id) => id,
|
||||
_ => return (const_id, subs),
|
||||
};
|
||||
|
|
@ -648,7 +648,7 @@ pub fn is_dyn_method(
|
|||
func: FunctionId,
|
||||
fn_subst: Substitution,
|
||||
) -> Option<usize> {
|
||||
let ItemContainerId::TraitId(trait_id) = func.lookup(db.upcast()).container else {
|
||||
let ItemContainerId::TraitId(trait_id) = func.lookup(db).container else {
|
||||
return None;
|
||||
};
|
||||
let trait_params = db.generic_params(trait_id.into()).len();
|
||||
|
|
@ -667,7 +667,7 @@ pub fn is_dyn_method(
|
|||
.map(|it| it.skip_binders())
|
||||
.flat_map(|it| match it {
|
||||
WhereClause::Implemented(tr) => {
|
||||
all_super_traits(db.upcast(), from_chalk_trait_id(tr.trait_id))
|
||||
all_super_traits(db, from_chalk_trait_id(tr.trait_id))
|
||||
}
|
||||
_ => smallvec![],
|
||||
})
|
||||
|
|
@ -690,7 +690,7 @@ pub(crate) fn lookup_impl_method_query(
|
|||
func: FunctionId,
|
||||
fn_subst: Substitution,
|
||||
) -> (FunctionId, Substitution) {
|
||||
let ItemContainerId::TraitId(trait_id) = func.lookup(db.upcast()).container else {
|
||||
let ItemContainerId::TraitId(trait_id) = func.lookup(db).container else {
|
||||
return (func, fn_subst);
|
||||
};
|
||||
let trait_params = db.generic_params(trait_id.into()).len();
|
||||
|
|
@ -729,13 +729,11 @@ fn lookup_impl_assoc_item_for_trait_ref(
|
|||
let self_ty_fp = TyFingerprint::for_trait_impl(&self_ty)?;
|
||||
let impls = db.trait_impls_in_deps(env.krate);
|
||||
|
||||
let trait_module = hir_trait_id.module(db.upcast());
|
||||
let trait_module = hir_trait_id.module(db);
|
||||
let type_module = match self_ty_fp {
|
||||
TyFingerprint::Adt(adt_id) => Some(adt_id.module(db.upcast())),
|
||||
TyFingerprint::ForeignType(type_id) => {
|
||||
Some(from_foreign_def_id(type_id).module(db.upcast()))
|
||||
}
|
||||
TyFingerprint::Dyn(trait_id) => Some(trait_id.module(db.upcast())),
|
||||
TyFingerprint::Adt(adt_id) => Some(adt_id.module(db)),
|
||||
TyFingerprint::ForeignType(type_id) => Some(from_foreign_def_id(type_id).module(db)),
|
||||
TyFingerprint::Dyn(trait_id) => Some(trait_id.module(db)),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
|
|
@ -810,9 +808,9 @@ fn is_inherent_impl_coherent(
|
|||
| TyKind::Str
|
||||
| TyKind::Scalar(_) => def_map.is_rustc_coherence_is_core(),
|
||||
|
||||
&TyKind::Adt(AdtId(adt), _) => adt.module(db.upcast()).krate() == def_map.krate(),
|
||||
&TyKind::Adt(AdtId(adt), _) => adt.module(db).krate() == def_map.krate(),
|
||||
TyKind::Dyn(it) => it.principal_id().is_some_and(|trait_id| {
|
||||
from_chalk_trait_id(trait_id).module(db.upcast()).krate() == def_map.krate()
|
||||
from_chalk_trait_id(trait_id).module(db).krate() == def_map.krate()
|
||||
}),
|
||||
|
||||
_ => true,
|
||||
|
|
@ -883,12 +881,12 @@ pub fn check_orphan_rules(db: &dyn HirDatabase, impl_: ImplId) -> bool {
|
|||
return true;
|
||||
};
|
||||
|
||||
let local_crate = impl_.lookup(db.upcast()).container.krate();
|
||||
let local_crate = impl_.lookup(db).container.krate();
|
||||
let is_local = |tgt_crate| tgt_crate == local_crate;
|
||||
|
||||
let trait_ref = impl_trait.substitute(Interner, &substs);
|
||||
let trait_id = from_chalk_trait_id(trait_ref.trait_id);
|
||||
if is_local(trait_id.module(db.upcast()).krate()) {
|
||||
if is_local(trait_id.module(db).krate()) {
|
||||
// trait to be implemented is local
|
||||
return true;
|
||||
}
|
||||
|
|
@ -920,11 +918,11 @@ pub fn check_orphan_rules(db: &dyn HirDatabase, impl_: ImplId) -> bool {
|
|||
// - No uncovered type parameters `P1..=Pn` may appear in `T0..Ti`` (excluding `Ti`)
|
||||
let is_not_orphan = trait_ref.substitution.type_parameters(Interner).any(|ty| {
|
||||
match unwrap_fundamental(ty).kind(Interner) {
|
||||
&TyKind::Adt(AdtId(id), _) => is_local(id.module(db.upcast()).krate()),
|
||||
&TyKind::Adt(AdtId(id), _) => is_local(id.module(db).krate()),
|
||||
TyKind::Error => true,
|
||||
TyKind::Dyn(it) => it.principal_id().is_some_and(|trait_id| {
|
||||
is_local(from_chalk_trait_id(trait_id).module(db.upcast()).krate())
|
||||
}),
|
||||
TyKind::Dyn(it) => it
|
||||
.principal_id()
|
||||
.is_some_and(|trait_id| is_local(from_chalk_trait_id(trait_id).module(db).krate())),
|
||||
_ => false,
|
||||
}
|
||||
});
|
||||
|
|
@ -1303,7 +1301,7 @@ fn iterate_inherent_methods(
|
|||
let env = table.trait_env.clone();
|
||||
let traits = env
|
||||
.traits_in_scope_from_clauses(self_ty.clone())
|
||||
.flat_map(|t| all_super_traits(db.upcast(), t));
|
||||
.flat_map(|t| all_super_traits(db, t));
|
||||
iterate_inherent_trait_methods(
|
||||
self_ty,
|
||||
table,
|
||||
|
|
@ -1316,7 +1314,7 @@ fn iterate_inherent_methods(
|
|||
}
|
||||
TyKind::Dyn(_) => {
|
||||
if let Some(principal_trait) = self_ty.dyn_trait() {
|
||||
let traits = all_super_traits(db.upcast(), principal_trait);
|
||||
let traits = all_super_traits(db, principal_trait);
|
||||
iterate_inherent_trait_methods(
|
||||
self_ty,
|
||||
table,
|
||||
|
|
@ -1507,7 +1505,7 @@ fn is_valid_impl_method_candidate(
|
|||
check_that!(name.is_none_or(|n| n == item_name));
|
||||
|
||||
if let Some(from_module) = visible_from_module {
|
||||
if !db.const_visibility(c).is_visible_from(db.upcast(), from_module) {
|
||||
if !db.const_visibility(c).is_visible_from(db, from_module) {
|
||||
cov_mark::hit!(const_candidate_not_visible);
|
||||
return IsValidCandidate::NotVisible;
|
||||
}
|
||||
|
|
@ -1596,7 +1594,7 @@ fn is_valid_impl_fn_candidate(
|
|||
let data = db.function_signature(fn_id);
|
||||
|
||||
if let Some(from_module) = visible_from_module {
|
||||
if !db.function_visibility(fn_id).is_visible_from(db.upcast(), from_module) {
|
||||
if !db.function_visibility(fn_id).is_visible_from(db, from_module) {
|
||||
cov_mark::hit!(autoderef_candidate_not_visible);
|
||||
return IsValidCandidate::NotVisible;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ fn moved_out_of_ref(db: &dyn HirDatabase, body: &MirBody) -> Vec<MovedOutOfRef>
|
|||
ty,
|
||||
db,
|
||||
make_fetch_closure_field(db),
|
||||
body.owner.module(db.upcast()).krate(),
|
||||
body.owner.module(db).krate(),
|
||||
);
|
||||
}
|
||||
if is_dereference_of_ref
|
||||
|
|
@ -223,7 +223,7 @@ fn partially_moved(db: &dyn HirDatabase, body: &MirBody) -> Vec<PartiallyMoved>
|
|||
ty,
|
||||
db,
|
||||
make_fetch_closure_field(db),
|
||||
body.owner.module(db.upcast()).krate(),
|
||||
body.owner.module(db).krate(),
|
||||
);
|
||||
}
|
||||
if !ty.clone().is_copy(db, body.owner)
|
||||
|
|
@ -369,12 +369,7 @@ fn place_case(db: &dyn HirDatabase, body: &MirBody, lvalue: &Place) -> Projectio
|
|||
}
|
||||
ProjectionElem::OpaqueCast(_) => (),
|
||||
}
|
||||
ty = proj.projected_ty(
|
||||
ty,
|
||||
db,
|
||||
make_fetch_closure_field(db),
|
||||
body.owner.module(db.upcast()).krate(),
|
||||
);
|
||||
ty = proj.projected_ty(ty, db, make_fetch_closure_field(db), body.owner.module(db).krate());
|
||||
}
|
||||
if is_part_of { ProjectionCase::DirectPart } else { ProjectionCase::Direct }
|
||||
}
|
||||
|
|
@ -419,10 +414,7 @@ fn ever_initialized_map(
|
|||
let Some(terminator) = &block.terminator else {
|
||||
never!(
|
||||
"Terminator should be none only in construction.\nThe body:\n{}",
|
||||
body.pretty_print(
|
||||
db,
|
||||
DisplayTarget::from_crate(db, body.owner.krate(db.upcast()))
|
||||
)
|
||||
body.pretty_print(db, DisplayTarget::from_crate(db, body.owner.krate(db)))
|
||||
);
|
||||
return;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -373,7 +373,7 @@ impl MirEvalError {
|
|||
writeln!(
|
||||
f,
|
||||
"In function {} ({:?})",
|
||||
function_name.name.display(db.upcast(), display_target.edition),
|
||||
function_name.name.display(db, display_target.edition),
|
||||
func
|
||||
)?;
|
||||
}
|
||||
|
|
@ -407,7 +407,7 @@ impl MirEvalError {
|
|||
},
|
||||
MirSpan::Unknown => continue,
|
||||
};
|
||||
let file_id = span.file_id.original_file(db.upcast());
|
||||
let file_id = span.file_id.original_file(db);
|
||||
let text_range = span.value.text_range();
|
||||
writeln!(f, "{}", span_formatter(file_id.file_id(), text_range))?;
|
||||
}
|
||||
|
|
@ -423,9 +423,9 @@ impl MirEvalError {
|
|||
}
|
||||
MirEvalError::MirLowerError(func, err) => {
|
||||
let function_name = db.function_signature(*func);
|
||||
let self_ = match func.lookup(db.upcast()).container {
|
||||
let self_ = match func.lookup(db).container {
|
||||
ItemContainerId::ImplId(impl_id) => Some({
|
||||
let generics = crate::generics::generics(db.upcast(), impl_id.into());
|
||||
let generics = crate::generics::generics(db, impl_id.into());
|
||||
let substs = generics.placeholder_subst(db);
|
||||
db.impl_self_ty(impl_id)
|
||||
.substitute(Interner, &substs)
|
||||
|
|
@ -433,10 +433,7 @@ impl MirEvalError {
|
|||
.to_string()
|
||||
}),
|
||||
ItemContainerId::TraitId(it) => Some(
|
||||
db.trait_signature(it)
|
||||
.name
|
||||
.display(db.upcast(), display_target.edition)
|
||||
.to_string(),
|
||||
db.trait_signature(it).name.display(db, display_target.edition).to_string(),
|
||||
),
|
||||
_ => None,
|
||||
};
|
||||
|
|
@ -445,7 +442,7 @@ impl MirEvalError {
|
|||
"MIR lowering for function `{}{}{}` ({:?}) failed due:",
|
||||
self_.as_deref().unwrap_or_default(),
|
||||
if self_.is_some() { "::" } else { "" },
|
||||
function_name.name.display(db.upcast(), display_target.edition),
|
||||
function_name.name.display(db, display_target.edition),
|
||||
func
|
||||
)?;
|
||||
err.pretty_print(f, db, span_formatter, display_target)?;
|
||||
|
|
@ -628,7 +625,7 @@ impl Evaluator<'_> {
|
|||
assert_placeholder_ty_is_unused: bool,
|
||||
trait_env: Option<Arc<TraitEnvironment>>,
|
||||
) -> Result<Evaluator<'_>> {
|
||||
let crate_id = owner.module(db.upcast()).krate();
|
||||
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,
|
||||
Err(e) => return Err(MirEvalError::TargetDataLayoutNotAvailable(e)),
|
||||
|
|
@ -821,7 +818,7 @@ impl Evaluator<'_> {
|
|||
Variants::Multiple { variants, .. } => {
|
||||
&variants[match f.parent {
|
||||
hir_def::VariantId::EnumVariantId(it) => {
|
||||
RustcEnumVariantIdx(it.lookup(self.db.upcast()).index as usize)
|
||||
RustcEnumVariantIdx(it.lookup(self.db).index as usize)
|
||||
}
|
||||
_ => {
|
||||
return Err(MirEvalError::InternalError(
|
||||
|
|
@ -1790,11 +1787,11 @@ impl Evaluator<'_> {
|
|||
subst: Substitution,
|
||||
locals: &Locals,
|
||||
) -> Result<(usize, Arc<Layout>, Option<(usize, usize, i128)>)> {
|
||||
let adt = it.adt_id(self.db.upcast());
|
||||
let adt = it.adt_id(self.db);
|
||||
if let DefWithBodyId::VariantId(f) = locals.body.owner {
|
||||
if let VariantId::EnumVariantId(it) = it {
|
||||
if let AdtId::EnumId(e) = adt {
|
||||
if f.lookup(self.db.upcast()).parent == e {
|
||||
if f.lookup(self.db).parent == e {
|
||||
// Computing the exact size of enums require resolving the enum discriminants. In order to prevent loops (and
|
||||
// infinite sized type errors) we use a dummy layout
|
||||
let i = self.const_eval_discriminant(it)?;
|
||||
|
|
@ -1812,7 +1809,7 @@ impl Evaluator<'_> {
|
|||
_ => not_supported!("multi variant layout for non-enums"),
|
||||
};
|
||||
let mut discriminant = self.const_eval_discriminant(enum_variant_id)?;
|
||||
let lookup = enum_variant_id.lookup(self.db.upcast());
|
||||
let lookup = enum_variant_id.lookup(self.db);
|
||||
let rustc_enum_variant_idx = RustcEnumVariantIdx(lookup.index as usize);
|
||||
let variant_layout = variants[rustc_enum_variant_idx].clone();
|
||||
let have_tag = match tag_encoding {
|
||||
|
|
@ -1919,7 +1916,7 @@ impl Evaluator<'_> {
|
|||
.db
|
||||
.const_eval(const_id, subst, Some(self.trait_env.clone()))
|
||||
.map_err(|e| {
|
||||
let name = const_id.name(self.db.upcast());
|
||||
let name = const_id.name(self.db);
|
||||
MirEvalError::ConstEvalError(name, Box::new(e))
|
||||
})?;
|
||||
if let chalk_ir::ConstValue::Concrete(c) = &result_owner.data(Interner).value {
|
||||
|
|
@ -2070,7 +2067,7 @@ impl Evaluator<'_> {
|
|||
}
|
||||
if let DefWithBodyId::VariantId(f) = locals.body.owner {
|
||||
if let Some((AdtId::EnumId(e), _)) = ty.as_adt() {
|
||||
if f.lookup(self.db.upcast()).parent == e {
|
||||
if f.lookup(self.db).parent == e {
|
||||
// Computing the exact size of enums require resolving the enum discriminants. In order to prevent loops (and
|
||||
// infinite sized type errors) we use a dummy size
|
||||
return Ok(Some((16, 16)));
|
||||
|
|
@ -2781,14 +2778,14 @@ impl Evaluator<'_> {
|
|||
match r {
|
||||
Ok(r) => Ok(r),
|
||||
Err(e) => {
|
||||
let db = self.db.upcast();
|
||||
let db = self.db;
|
||||
let loc = variant.lookup(db);
|
||||
let enum_loc = loc.parent.lookup(db);
|
||||
let edition = self.crate_id.data(self.db).edition;
|
||||
let name = format!(
|
||||
"{}::{}",
|
||||
enum_loc.id.item_tree(db)[enum_loc.id.value].name.display(db.upcast(), edition),
|
||||
loc.id.item_tree(db)[loc.id.value].name.display(db.upcast(), edition),
|
||||
enum_loc.id.item_tree(db)[enum_loc.id.value].name.display(db, edition),
|
||||
loc.id.item_tree(db)[loc.id.value].name.display(db, edition),
|
||||
);
|
||||
Err(MirEvalError::ConstEvalError(name, Box::new(e)))
|
||||
}
|
||||
|
|
@ -2921,9 +2918,9 @@ pub fn render_const_using_debug_impl(
|
|||
drop_flags: DropFlags::default(),
|
||||
};
|
||||
let data = evaluator.allocate_const_in_heap(locals, c)?;
|
||||
let resolver = owner.resolver(db.upcast());
|
||||
let resolver = owner.resolver(db);
|
||||
let Some(TypeNs::TraitId(debug_trait)) = resolver.resolve_path_in_type_ns_fully(
|
||||
db.upcast(),
|
||||
db,
|
||||
&hir_def::expr_store::path::Path::from_known_path_with_no_generic(path![core::fmt::Debug]),
|
||||
) else {
|
||||
not_supported!("core::fmt::Debug not found");
|
||||
|
|
@ -2954,7 +2951,7 @@ pub fn render_const_using_debug_impl(
|
|||
evaluator.write_memory(a3.offset(2 * evaluator.ptr_size()), &a2.to_bytes())?;
|
||||
evaluator.write_memory(a3.offset(3 * evaluator.ptr_size()), &[1])?;
|
||||
let Some(ValueNs::FunctionId(format_fn)) = resolver.resolve_path_in_value_ns_fully(
|
||||
db.upcast(),
|
||||
db,
|
||||
&hir_def::expr_store::path::Path::from_known_path_with_no_generic(path![std::fmt::format]),
|
||||
HygieneId::ROOT,
|
||||
) else {
|
||||
|
|
|
|||
|
|
@ -63,10 +63,10 @@ impl Evaluator<'_> {
|
|||
// Keep this around for a bit until extern "rustc-intrinsic" abis are no longer used
|
||||
|| (match &function_data.abi {
|
||||
Some(abi) => *abi == sym::rust_dash_intrinsic,
|
||||
None => match def.lookup(self.db.upcast()).container {
|
||||
None => match def.lookup(self.db).container {
|
||||
hir_def::ItemContainerId::ExternBlockId(block) => {
|
||||
let id = block.lookup(self.db.upcast()).id;
|
||||
id.item_tree(self.db.upcast())[id.value].abi.as_ref()
|
||||
let id = block.lookup(self.db).id;
|
||||
id.item_tree(self.db)[id.value].abi.as_ref()
|
||||
== Some(&sym::rust_dash_intrinsic)
|
||||
}
|
||||
_ => false,
|
||||
|
|
@ -85,10 +85,10 @@ impl Evaluator<'_> {
|
|||
|| attrs.by_key(&sym::rustc_intrinsic_must_be_overridden).exists(),
|
||||
);
|
||||
}
|
||||
let is_extern_c = match def.lookup(self.db.upcast()).container {
|
||||
let is_extern_c = match def.lookup(self.db).container {
|
||||
hir_def::ItemContainerId::ExternBlockId(block) => {
|
||||
let id = block.lookup(self.db.upcast()).id;
|
||||
id.item_tree(self.db.upcast())[id.value].abi.as_ref() == Some(&sym::C)
|
||||
let id = block.lookup(self.db).id;
|
||||
id.item_tree(self.db)[id.value].abi.as_ref() == Some(&sym::C)
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
|
|
@ -124,7 +124,7 @@ impl Evaluator<'_> {
|
|||
destination.write_from_bytes(self, &result)?;
|
||||
return Ok(true);
|
||||
}
|
||||
if let ItemContainerId::TraitId(t) = def.lookup(self.db.upcast()).container {
|
||||
if let ItemContainerId::TraitId(t) = def.lookup(self.db).container {
|
||||
if self.db.lang_attr(t.into()) == Some(LangItem::Clone) {
|
||||
let [self_ty] = generic_args.as_slice(Interner) else {
|
||||
not_supported!("wrong generic arg count for clone");
|
||||
|
|
@ -154,8 +154,7 @@ impl Evaluator<'_> {
|
|||
) -> Result<Option<FunctionId>> {
|
||||
// `PanicFmt` is redirected to `ConstPanicFmt`
|
||||
if let Some(LangItem::PanicFmt) = self.db.lang_attr(def.into()) {
|
||||
let resolver =
|
||||
self.db.crate_def_map(self.crate_id).crate_root().resolver(self.db.upcast());
|
||||
let resolver = self.db.crate_def_map(self.crate_id).crate_root().resolver(self.db);
|
||||
|
||||
let Some(hir_def::lang_item::LangItemTarget::Function(const_panic_fmt)) =
|
||||
self.db.lang_item(resolver.krate(), LangItem::ConstPanicFmt)
|
||||
|
|
@ -828,14 +827,14 @@ impl Evaluator<'_> {
|
|||
};
|
||||
let ty_name = match ty.display_source_code(
|
||||
self.db,
|
||||
locals.body.owner.module(self.db.upcast()),
|
||||
locals.body.owner.module(self.db),
|
||||
true,
|
||||
) {
|
||||
Ok(ty_name) => ty_name,
|
||||
// Fallback to human readable display in case of `Err`. Ideally we want to use `display_source_code` to
|
||||
// render full paths.
|
||||
Err(_) => {
|
||||
let krate = locals.body.owner.krate(self.db.upcast());
|
||||
let krate = locals.body.owner.krate(self.db);
|
||||
ty.display(self.db, DisplayTarget::from_crate(self.db, krate)).to_string()
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ impl MirLowerError {
|
|||
writeln!(
|
||||
f,
|
||||
"Missing function definition for {}",
|
||||
body.pretty_print_expr(db.upcast(), *owner, *it, display_target.edition)
|
||||
body.pretty_print_expr(db, *owner, *it, display_target.edition)
|
||||
)?;
|
||||
}
|
||||
MirLowerError::HasErrors => writeln!(f, "Type inference result contains errors")?,
|
||||
|
|
@ -193,10 +193,7 @@ impl MirLowerError {
|
|||
writeln!(
|
||||
f,
|
||||
"Generic arg not provided for {}",
|
||||
param
|
||||
.name()
|
||||
.unwrap_or(&Name::missing())
|
||||
.display(db.upcast(), display_target.edition)
|
||||
param.name().unwrap_or(&Name::missing()).display(db, display_target.edition)
|
||||
)?;
|
||||
writeln!(f, "Provided args: [")?;
|
||||
for g in subst.iter(Interner) {
|
||||
|
|
@ -288,7 +285,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
|||
owner,
|
||||
closures: vec![],
|
||||
};
|
||||
let resolver = owner.resolver(db.upcast());
|
||||
let resolver = owner.resolver(db);
|
||||
|
||||
MirLowerCtx {
|
||||
result: mir,
|
||||
|
|
@ -413,7 +410,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
|||
}
|
||||
Expr::Missing => {
|
||||
if let DefWithBodyId::FunctionId(f) = self.owner {
|
||||
let assoc = f.lookup(self.db.upcast());
|
||||
let assoc = f.lookup(self.db);
|
||||
if let ItemContainerId::TraitId(t) = assoc.container {
|
||||
let name = &self.db.function_signature(f).name;
|
||||
return Err(MirLowerError::TraitFunctionDefinition(t, name.clone()));
|
||||
|
|
@ -422,54 +419,53 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
|||
Err(MirLowerError::IncompleteExpr)
|
||||
}
|
||||
Expr::Path(p) => {
|
||||
let pr = if let Some((assoc, subst)) =
|
||||
self.infer.assoc_resolutions_for_expr(expr_id)
|
||||
{
|
||||
match assoc {
|
||||
hir_def::AssocItemId::ConstId(c) => {
|
||||
self.lower_const(
|
||||
c.into(),
|
||||
current,
|
||||
place,
|
||||
subst,
|
||||
expr_id.into(),
|
||||
self.expr_ty_without_adjust(expr_id),
|
||||
)?;
|
||||
return Ok(Some(current));
|
||||
let pr =
|
||||
if let Some((assoc, subst)) = self.infer.assoc_resolutions_for_expr(expr_id) {
|
||||
match assoc {
|
||||
hir_def::AssocItemId::ConstId(c) => {
|
||||
self.lower_const(
|
||||
c.into(),
|
||||
current,
|
||||
place,
|
||||
subst,
|
||||
expr_id.into(),
|
||||
self.expr_ty_without_adjust(expr_id),
|
||||
)?;
|
||||
return Ok(Some(current));
|
||||
}
|
||||
hir_def::AssocItemId::FunctionId(_) => {
|
||||
// FnDefs are zero sized, no action is needed.
|
||||
return Ok(Some(current));
|
||||
}
|
||||
hir_def::AssocItemId::TypeAliasId(_) => {
|
||||
// FIXME: If it is unreachable, use proper error instead of `not_supported`.
|
||||
not_supported!("associated functions and types")
|
||||
}
|
||||
}
|
||||
hir_def::AssocItemId::FunctionId(_) => {
|
||||
// FnDefs are zero sized, no action is needed.
|
||||
return Ok(Some(current));
|
||||
} else if let Some(variant) = self.infer.variant_resolution_for_expr(expr_id) {
|
||||
match variant {
|
||||
VariantId::EnumVariantId(e) => ValueNs::EnumVariantId(e),
|
||||
VariantId::StructId(s) => ValueNs::StructId(s),
|
||||
VariantId::UnionId(_) => implementation_error!("Union variant as path"),
|
||||
}
|
||||
hir_def::AssocItemId::TypeAliasId(_) => {
|
||||
// FIXME: If it is unreachable, use proper error instead of `not_supported`.
|
||||
not_supported!("associated functions and types")
|
||||
}
|
||||
}
|
||||
} else if let Some(variant) = self.infer.variant_resolution_for_expr(expr_id) {
|
||||
match variant {
|
||||
VariantId::EnumVariantId(e) => ValueNs::EnumVariantId(e),
|
||||
VariantId::StructId(s) => ValueNs::StructId(s),
|
||||
VariantId::UnionId(_) => implementation_error!("Union variant as path"),
|
||||
}
|
||||
} else {
|
||||
let resolver_guard =
|
||||
self.resolver.update_to_inner_scope(self.db.upcast(), self.owner, expr_id);
|
||||
let hygiene = self.body.expr_path_hygiene(expr_id);
|
||||
let result = self
|
||||
.resolver
|
||||
.resolve_path_in_value_ns_fully(self.db.upcast(), p, hygiene)
|
||||
.ok_or_else(|| {
|
||||
MirLowerError::unresolved_path(
|
||||
self.db,
|
||||
p,
|
||||
DisplayTarget::from_crate(self.db, self.krate()),
|
||||
self.body,
|
||||
)
|
||||
})?;
|
||||
self.resolver.reset_to_guard(resolver_guard);
|
||||
result
|
||||
};
|
||||
} else {
|
||||
let resolver_guard =
|
||||
self.resolver.update_to_inner_scope(self.db, self.owner, expr_id);
|
||||
let hygiene = self.body.expr_path_hygiene(expr_id);
|
||||
let result = self
|
||||
.resolver
|
||||
.resolve_path_in_value_ns_fully(self.db, p, hygiene)
|
||||
.ok_or_else(|| {
|
||||
MirLowerError::unresolved_path(
|
||||
self.db,
|
||||
p,
|
||||
DisplayTarget::from_crate(self.db, self.krate()),
|
||||
self.body,
|
||||
)
|
||||
})?;
|
||||
self.resolver.reset_to_guard(resolver_guard);
|
||||
result
|
||||
};
|
||||
match pr {
|
||||
ValueNs::LocalBinding(_) | ValueNs::StaticId(_) => {
|
||||
let Some((temp, current)) =
|
||||
|
|
@ -513,10 +509,10 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
|||
Ok(Some(current))
|
||||
}
|
||||
ValueNs::GenericParam(p) => {
|
||||
let Some(def) = self.owner.as_generic_def_id(self.db.upcast()) else {
|
||||
let Some(def) = self.owner.as_generic_def_id(self.db) else {
|
||||
not_supported!("owner without generic def id");
|
||||
};
|
||||
let generics = generics(self.db.upcast(), def);
|
||||
let generics = generics(self.db, def);
|
||||
let ty = self.expr_ty_without_adjust(expr_id);
|
||||
self.push_assignment(
|
||||
current,
|
||||
|
|
@ -577,7 +573,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
|||
};
|
||||
self.push_fake_read(current, cond_place, expr_id.into());
|
||||
let resolver_guard =
|
||||
self.resolver.update_to_inner_scope(self.db.upcast(), self.owner, expr_id);
|
||||
self.resolver.update_to_inner_scope(self.db, self.owner, expr_id);
|
||||
let (then_target, else_target) =
|
||||
self.pattern_match(current, None, cond_place, *pat)?;
|
||||
self.resolver.reset_to_guard(resolver_guard);
|
||||
|
|
@ -693,7 +689,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
|||
let (func_id, generic_args) =
|
||||
self.infer.method_resolution(expr_id).ok_or_else(|| {
|
||||
MirLowerError::UnresolvedMethod(
|
||||
method_name.display(self.db.upcast(), self.edition()).to_string(),
|
||||
method_name.display(self.db, self.edition()).to_string(),
|
||||
)
|
||||
})?;
|
||||
let func = Operand::from_fn(self.db, func_id, generic_args);
|
||||
|
|
@ -715,7 +711,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
|||
self.push_fake_read(current, cond_place, expr_id.into());
|
||||
let mut end = None;
|
||||
let resolver_guard =
|
||||
self.resolver.update_to_inner_scope(self.db.upcast(), self.owner, expr_id);
|
||||
self.resolver.update_to_inner_scope(self.db, self.owner, expr_id);
|
||||
for MatchArm { pat, guard, expr } in arms.iter() {
|
||||
let (then, mut otherwise) =
|
||||
self.pattern_match(current, None, cond_place, *pat)?;
|
||||
|
|
@ -1129,7 +1125,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
|||
};
|
||||
self.push_fake_read(current, value, expr_id.into());
|
||||
let resolver_guard =
|
||||
self.resolver.update_to_inner_scope(self.db.upcast(), self.owner, expr_id);
|
||||
self.resolver.update_to_inner_scope(self.db, self.owner, expr_id);
|
||||
current = self.pattern_match_assignment(current, value, target)?;
|
||||
self.resolver.reset_to_guard(resolver_guard);
|
||||
Ok(Some(current))
|
||||
|
|
@ -1328,7 +1324,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
|||
}
|
||||
|
||||
fn placeholder_subst(&mut self) -> Substitution {
|
||||
match self.owner.as_generic_def_id(self.db.upcast()) {
|
||||
match self.owner.as_generic_def_id(self.db) {
|
||||
Some(it) => TyBuilder::placeholder_subst(self.db, it),
|
||||
None => Substitution::empty(Interner),
|
||||
}
|
||||
|
|
@ -1369,13 +1365,13 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
|||
MirLowerError::unresolved_path(
|
||||
self.db,
|
||||
c,
|
||||
DisplayTarget::from_crate(db, owner.krate(db.upcast())),
|
||||
DisplayTarget::from_crate(db, owner.krate(db)),
|
||||
self.body,
|
||||
)
|
||||
};
|
||||
let pr = self
|
||||
.resolver
|
||||
.resolve_path_in_value_ns(self.db.upcast(), c, HygieneId::ROOT)
|
||||
.resolve_path_in_value_ns(self.db, c, HygieneId::ROOT)
|
||||
.ok_or_else(unresolved_name)?;
|
||||
match pr {
|
||||
ResolveValueResult::ValueNs(v, _) => {
|
||||
|
|
@ -1475,7 +1471,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
|||
// We can't evaluate constant with substitution now, as generics are not monomorphized in lowering.
|
||||
intern_const_scalar(ConstScalar::UnevaluatedConst(const_id, subst), ty)
|
||||
} else {
|
||||
let name = const_id.name(self.db.upcast());
|
||||
let name = const_id.name(self.db);
|
||||
self.db
|
||||
.const_eval(const_id, subst, None)
|
||||
.map_err(|e| MirLowerError::ConstEvalError(name.into(), Box::new(e)))?
|
||||
|
|
@ -1708,7 +1704,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
|||
}
|
||||
|
||||
fn is_uninhabited(&self, expr_id: ExprId) -> bool {
|
||||
is_ty_uninhabited_from(self.db, &self.infer[expr_id], self.owner.module(self.db.upcast()))
|
||||
is_ty_uninhabited_from(self.db, &self.infer[expr_id], self.owner.module(self.db))
|
||||
}
|
||||
|
||||
/// This function push `StorageLive` statement for the binding, and applies changes to add `StorageDead` and
|
||||
|
|
@ -1730,7 +1726,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
|||
}
|
||||
|
||||
fn resolve_lang_item(&self, item: LangItem) -> Result<LangItemTarget> {
|
||||
let crate_id = self.owner.module(self.db.upcast()).krate();
|
||||
let crate_id = self.owner.module(self.db).krate();
|
||||
self.db.lang_item(crate_id, item).ok_or(MirLowerError::LangItemNotFound(item))
|
||||
}
|
||||
|
||||
|
|
@ -1758,11 +1754,8 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
|||
self.push_fake_read(current, init_place, span);
|
||||
// Using the initializer for the resolver scope is good enough for us, as it cannot create new declarations
|
||||
// and has all declarations of the `let`.
|
||||
let resolver_guard = self.resolver.update_to_inner_scope(
|
||||
self.db.upcast(),
|
||||
self.owner,
|
||||
*expr_id,
|
||||
);
|
||||
let resolver_guard =
|
||||
self.resolver.update_to_inner_scope(self.db, self.owner, *expr_id);
|
||||
(current, else_block) =
|
||||
self.pattern_match(current, None, init_place, *pat)?;
|
||||
self.resolver.reset_to_guard(resolver_guard);
|
||||
|
|
@ -1906,13 +1899,13 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
|||
Ok(r) => Ok(r),
|
||||
Err(e) => {
|
||||
let edition = self.edition();
|
||||
let db = self.db.upcast();
|
||||
let db = self.db;
|
||||
let loc = variant.lookup(db);
|
||||
let enum_loc = loc.parent.lookup(db);
|
||||
let name = format!(
|
||||
"{}::{}",
|
||||
enum_loc.id.item_tree(db)[enum_loc.id.value].name.display(db.upcast(), edition),
|
||||
loc.id.item_tree(db)[loc.id.value].name.display(db.upcast(), edition),
|
||||
enum_loc.id.item_tree(db)[enum_loc.id.value].name.display(db, edition),
|
||||
loc.id.item_tree(db)[loc.id.value].name.display(db, edition),
|
||||
);
|
||||
Err(MirLowerError::ConstEvalError(name.into(), Box::new(e)))
|
||||
}
|
||||
|
|
@ -1924,7 +1917,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
|||
}
|
||||
|
||||
fn krate(&self) -> Crate {
|
||||
self.owner.krate(self.db.upcast())
|
||||
self.owner.krate(self.db)
|
||||
}
|
||||
|
||||
fn display_target(&self) -> DisplayTarget {
|
||||
|
|
@ -2046,7 +2039,7 @@ pub fn mir_body_for_closure_query(
|
|||
let Some(sig) = ClosureSubst(substs).sig_ty().callable_sig(db) else {
|
||||
implementation_error!("closure has not callable sig");
|
||||
};
|
||||
let resolver_guard = ctx.resolver.update_to_inner_scope(db.upcast(), owner, expr);
|
||||
let resolver_guard = ctx.resolver.update_to_inner_scope(db, owner, expr);
|
||||
let current = ctx.lower_params_and_bindings(
|
||||
args.iter().zip(sig.params().iter()).map(|(it, y)| (*it, y.clone())),
|
||||
None,
|
||||
|
|
@ -2120,27 +2113,27 @@ pub fn mir_body_for_closure_query(
|
|||
}
|
||||
|
||||
pub fn mir_body_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Result<Arc<MirBody>> {
|
||||
let krate = def.krate(db.upcast());
|
||||
let krate = def.krate(db);
|
||||
let edition = krate.data(db).edition;
|
||||
let detail = match def {
|
||||
DefWithBodyId::FunctionId(it) => {
|
||||
db.function_signature(it).name.display(db.upcast(), edition).to_string()
|
||||
db.function_signature(it).name.display(db, edition).to_string()
|
||||
}
|
||||
DefWithBodyId::StaticId(it) => {
|
||||
db.static_signature(it).name.display(db.upcast(), edition).to_string()
|
||||
db.static_signature(it).name.display(db, edition).to_string()
|
||||
}
|
||||
DefWithBodyId::ConstId(it) => db
|
||||
.const_signature(it)
|
||||
.name
|
||||
.clone()
|
||||
.unwrap_or_else(Name::missing)
|
||||
.display(db.upcast(), edition)
|
||||
.display(db, edition)
|
||||
.to_string(),
|
||||
DefWithBodyId::VariantId(it) => {
|
||||
let loc = it.lookup(db.upcast());
|
||||
let loc = it.lookup(db);
|
||||
db.enum_variants(loc.parent).variants[loc.index as usize]
|
||||
.1
|
||||
.display(db.upcast(), edition)
|
||||
.display(db, edition)
|
||||
.to_string()
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -136,10 +136,9 @@ impl MirLowerCtx<'_> {
|
|||
match &self.body.exprs[expr_id] {
|
||||
Expr::Path(p) => {
|
||||
let resolver_guard =
|
||||
self.resolver.update_to_inner_scope(self.db.upcast(), self.owner, expr_id);
|
||||
self.resolver.update_to_inner_scope(self.db, self.owner, expr_id);
|
||||
let hygiene = self.body.expr_path_hygiene(expr_id);
|
||||
let resolved =
|
||||
self.resolver.resolve_path_in_value_ns_fully(self.db.upcast(), p, hygiene);
|
||||
let resolved = self.resolver.resolve_path_in_value_ns_fully(self.db, p, hygiene);
|
||||
self.resolver.reset_to_guard(resolver_guard);
|
||||
let Some(pr) = resolved else {
|
||||
return try_rvalue(self);
|
||||
|
|
|
|||
|
|
@ -355,7 +355,7 @@ impl MirLowerCtx<'_> {
|
|||
let hygiene = self.body.pat_path_hygiene(pattern);
|
||||
let pr = self
|
||||
.resolver
|
||||
.resolve_path_in_value_ns(self.db.upcast(), p, hygiene)
|
||||
.resolve_path_in_value_ns(self.db, p, hygiene)
|
||||
.ok_or_else(unresolved_name)?;
|
||||
|
||||
if let (
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ impl FallibleTypeFolder<Interner> for Filler<'_> {
|
|||
owner: self.owner,
|
||||
trait_env: self.trait_env.clone(),
|
||||
subst: &subst,
|
||||
generics: Some(generics(self.db.upcast(), func.into())),
|
||||
generics: Some(generics(self.db, func.into())),
|
||||
};
|
||||
filler.try_fold_ty(infer.type_of_rpit[idx].clone(), outer_binder)
|
||||
}
|
||||
|
|
@ -305,7 +305,7 @@ pub fn monomorphized_mir_body_query(
|
|||
subst: Substitution,
|
||||
trait_env: Arc<crate::TraitEnvironment>,
|
||||
) -> Result<Arc<MirBody>, MirLowerError> {
|
||||
let generics = owner.as_generic_def_id(db.upcast()).map(|g_def| generics(db.upcast(), 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, owner };
|
||||
let body = db.mir_body(owner)?;
|
||||
let mut body = (*body).clone();
|
||||
|
|
@ -331,7 +331,7 @@ pub fn monomorphized_mir_body_for_closure_query(
|
|||
trait_env: Arc<crate::TraitEnvironment>,
|
||||
) -> Result<Arc<MirBody>, MirLowerError> {
|
||||
let InternedClosure(owner, _) = db.lookup_intern_closure(closure);
|
||||
let generics = owner.as_generic_def_id(db.upcast()).map(|g_def| generics(db.upcast(), 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, owner };
|
||||
let body = db.mir_body_for_closure(closure)?;
|
||||
let mut body = (*body).clone();
|
||||
|
|
@ -347,7 +347,7 @@ pub fn monomorphize_mir_body_bad(
|
|||
trait_env: Arc<crate::TraitEnvironment>,
|
||||
) -> Result<MirBody, MirLowerError> {
|
||||
let owner = body.owner;
|
||||
let generics = owner.as_generic_def_id(db.upcast()).map(|g_def| generics(db.upcast(), 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, owner };
|
||||
filler.fill_body(&mut body)?;
|
||||
Ok(body)
|
||||
|
|
|
|||
|
|
@ -44,15 +44,11 @@ impl MirBody {
|
|||
ctx.for_body(|this| match ctx.body.owner {
|
||||
hir_def::DefWithBodyId::FunctionId(id) => {
|
||||
let data = db.function_signature(id);
|
||||
w!(this, "fn {}() ", data.name.display(db.upcast(), this.display_target.edition));
|
||||
w!(this, "fn {}() ", data.name.display(db, this.display_target.edition));
|
||||
}
|
||||
hir_def::DefWithBodyId::StaticId(id) => {
|
||||
let data = db.static_signature(id);
|
||||
w!(
|
||||
this,
|
||||
"static {}: _ = ",
|
||||
data.name.display(db.upcast(), this.display_target.edition)
|
||||
);
|
||||
w!(this, "static {}: _ = ", data.name.display(db, this.display_target.edition));
|
||||
}
|
||||
hir_def::DefWithBodyId::ConstId(id) => {
|
||||
let data = db.const_signature(id);
|
||||
|
|
@ -62,21 +58,21 @@ impl MirBody {
|
|||
data.name
|
||||
.as_ref()
|
||||
.unwrap_or(&Name::missing())
|
||||
.display(db.upcast(), this.display_target.edition)
|
||||
.display(db, this.display_target.edition)
|
||||
);
|
||||
}
|
||||
hir_def::DefWithBodyId::VariantId(id) => {
|
||||
let loc = id.lookup(db.upcast());
|
||||
let enum_loc = loc.parent.lookup(db.upcast());
|
||||
let loc = id.lookup(db);
|
||||
let enum_loc = loc.parent.lookup(db);
|
||||
w!(
|
||||
this,
|
||||
"enum {}::{} = ",
|
||||
enum_loc.id.item_tree(db.upcast())[enum_loc.id.value]
|
||||
enum_loc.id.item_tree(db)[enum_loc.id.value]
|
||||
.name
|
||||
.display(db.upcast(), this.display_target.edition),
|
||||
loc.id.item_tree(db.upcast())[loc.id.value]
|
||||
.display(db, this.display_target.edition),
|
||||
loc.id.item_tree(db)[loc.id.value]
|
||||
.name
|
||||
.display(db.upcast(), this.display_target.edition),
|
||||
.display(db, this.display_target.edition),
|
||||
)
|
||||
}
|
||||
});
|
||||
|
|
@ -131,7 +127,7 @@ impl HirDisplay for LocalName {
|
|||
match self {
|
||||
LocalName::Unknown(l) => write!(f, "_{}", u32::from(l.into_raw())),
|
||||
LocalName::Binding(n, l) => {
|
||||
write!(f, "{}_{}", n.display(f.db.upcast(), f.edition()), u32::from(l.into_raw()))
|
||||
write!(f, "{}_{}", n.display(f.db, f.edition()), u32::from(l.into_raw()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -336,23 +332,19 @@ impl<'a> MirPrettyCtx<'a> {
|
|||
hir_def::VariantId::EnumVariantId(e) => {
|
||||
w!(this, "(");
|
||||
f(this, local, head);
|
||||
let loc = e.lookup(this.db.upcast());
|
||||
let loc = e.lookup(this.db);
|
||||
w!(
|
||||
this,
|
||||
" as {}).{}",
|
||||
this.db.enum_variants(loc.parent).variants[loc.index as usize]
|
||||
.1
|
||||
.display(this.db.upcast(), this.display_target.edition),
|
||||
name.display(this.db.upcast(), this.display_target.edition)
|
||||
.display(this.db, this.display_target.edition),
|
||||
name.display(this.db, this.display_target.edition)
|
||||
);
|
||||
}
|
||||
hir_def::VariantId::StructId(_) | hir_def::VariantId::UnionId(_) => {
|
||||
f(this, local, head);
|
||||
w!(
|
||||
this,
|
||||
".{}",
|
||||
name.display(this.db.upcast(), this.display_target.edition)
|
||||
);
|
||||
w!(this, ".{}", name.display(this.db, this.display_target.edition));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,10 @@ use std::{fmt, panic, sync::Mutex};
|
|||
|
||||
use base_db::{
|
||||
CrateGraphBuilder, CratesMap, FileSourceRootInput, FileText, RootQueryDb, SourceDatabase,
|
||||
SourceRoot, SourceRootId, SourceRootInput, Upcast,
|
||||
SourceRoot, SourceRootId, SourceRootInput,
|
||||
};
|
||||
|
||||
use hir_def::{ModuleId, db::DefDatabase};
|
||||
use hir_expand::db::ExpandDatabase;
|
||||
use rustc_hash::FxHashMap;
|
||||
use salsa::{AsDynDatabase, Durability};
|
||||
use span::{EditionedFileId, FileId};
|
||||
|
|
@ -47,30 +46,6 @@ impl fmt::Debug for TestDB {
|
|||
}
|
||||
}
|
||||
|
||||
impl Upcast<dyn ExpandDatabase> for TestDB {
|
||||
fn upcast(&self) -> &(dyn ExpandDatabase + 'static) {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Upcast<dyn DefDatabase> for TestDB {
|
||||
fn upcast(&self) -> &(dyn DefDatabase + 'static) {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Upcast<dyn RootQueryDb> for TestDB {
|
||||
fn upcast(&self) -> &(dyn RootQueryDb + 'static) {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Upcast<dyn SourceDatabase> for TestDB {
|
||||
fn upcast(&self) -> &(dyn SourceDatabase + 'static) {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[salsa::db]
|
||||
impl SourceDatabase for TestDB {
|
||||
fn file_text(&self, file_id: base_db::FileId) -> FileText {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ impl DebugContext<'_> {
|
|||
AdtId::UnionId(it) => self.0.union_signature(it).name.clone(),
|
||||
AdtId::EnumId(it) => self.0.enum_signature(it).name.clone(),
|
||||
};
|
||||
name.display(self.0.upcast(), Edition::LATEST).fmt(f)?;
|
||||
name.display(self.0, Edition::LATEST).fmt(f)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ impl DebugContext<'_> {
|
|||
) -> Result<(), fmt::Error> {
|
||||
let trait_: hir_def::TraitId = from_chalk_trait_id(id);
|
||||
let trait_data = self.0.trait_signature(trait_);
|
||||
trait_data.name.display(self.0.upcast(), Edition::LATEST).fmt(f)?;
|
||||
trait_data.name.display(self.0, Edition::LATEST).fmt(f)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ impl DebugContext<'_> {
|
|||
) -> Result<(), fmt::Error> {
|
||||
let type_alias: TypeAliasId = from_assoc_type_id(id);
|
||||
let type_alias_data = self.0.type_alias_signature(type_alias);
|
||||
let trait_ = match type_alias.lookup(self.0.upcast()).container {
|
||||
let trait_ = match type_alias.lookup(self.0).container {
|
||||
ItemContainerId::TraitId(t) => t,
|
||||
_ => panic!("associated type not in trait"),
|
||||
};
|
||||
|
|
@ -55,8 +55,8 @@ impl DebugContext<'_> {
|
|||
write!(
|
||||
fmt,
|
||||
"{}::{}",
|
||||
trait_data.name.display(self.0.upcast(), Edition::LATEST),
|
||||
type_alias_data.name.display(self.0.upcast(), Edition::LATEST)
|
||||
trait_data.name.display(self.0, Edition::LATEST),
|
||||
type_alias_data.name.display(self.0, Edition::LATEST)
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -68,7 +68,7 @@ impl DebugContext<'_> {
|
|||
) -> Result<(), fmt::Error> {
|
||||
let type_alias = from_assoc_type_id(projection_ty.associated_ty_id);
|
||||
let type_alias_data = self.0.type_alias_signature(type_alias);
|
||||
let trait_ = match type_alias.lookup(self.0.upcast()).container {
|
||||
let trait_ = match type_alias.lookup(self.0).container {
|
||||
ItemContainerId::TraitId(t) => t,
|
||||
_ => panic!("associated type not in trait"),
|
||||
};
|
||||
|
|
@ -76,7 +76,7 @@ impl DebugContext<'_> {
|
|||
let trait_ref = projection_ty.trait_ref(self.0);
|
||||
let trait_params = trait_ref.substitution.as_slice(Interner);
|
||||
let self_ty = trait_ref.self_type_parameter(Interner);
|
||||
write!(fmt, "<{self_ty:?} as {}", trait_name.display(self.0.upcast(), Edition::LATEST))?;
|
||||
write!(fmt, "<{self_ty:?} as {}", trait_name.display(self.0, Edition::LATEST))?;
|
||||
if trait_params.len() > 1 {
|
||||
write!(
|
||||
fmt,
|
||||
|
|
@ -84,7 +84,7 @@ impl DebugContext<'_> {
|
|||
trait_params[1..].iter().format_with(", ", |x, f| f(&format_args!("{x:?}"))),
|
||||
)?;
|
||||
}
|
||||
write!(fmt, ">::{}", type_alias_data.name.display(self.0.upcast(), Edition::LATEST))?;
|
||||
write!(fmt, ">::{}", type_alias_data.name.display(self.0, Edition::LATEST))?;
|
||||
|
||||
let proj_params_count = projection_ty.substitution.len(Interner) - trait_params.len();
|
||||
let proj_params = &projection_ty.substitution.as_slice(Interner)[..proj_params_count];
|
||||
|
|
@ -109,16 +109,16 @@ impl DebugContext<'_> {
|
|||
CallableDefId::FunctionId(ff) => self.0.function_signature(ff).name.clone(),
|
||||
CallableDefId::StructId(s) => self.0.struct_signature(s).name.clone(),
|
||||
CallableDefId::EnumVariantId(e) => {
|
||||
let loc = e.lookup(self.0.upcast());
|
||||
let loc = e.lookup(self.0);
|
||||
self.0.enum_variants(loc.parent).variants[loc.index as usize].1.clone()
|
||||
}
|
||||
};
|
||||
match def {
|
||||
CallableDefId::FunctionId(_) => {
|
||||
write!(fmt, "{{fn {}}}", name.display(self.0.upcast(), Edition::LATEST))
|
||||
write!(fmt, "{{fn {}}}", name.display(self.0, Edition::LATEST))
|
||||
}
|
||||
CallableDefId::StructId(_) | CallableDefId::EnumVariantId(_) => {
|
||||
write!(fmt, "{{ctor {}}}", name.display(self.0.upcast(), Edition::LATEST))
|
||||
write!(fmt, "{{ctor {}}}", name.display(self.0, Edition::LATEST))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ pub(crate) fn trait_solve_query(
|
|||
GoalData::DomainGoal(DomainGoal::Holds(WhereClause::Implemented(it))) => db
|
||||
.trait_signature(it.hir_trait_id())
|
||||
.name
|
||||
.display(db.upcast(), Edition::LATEST)
|
||||
.display(db, Edition::LATEST)
|
||||
.to_string(),
|
||||
GoalData::DomainGoal(DomainGoal::Holds(WhereClause::AliasEq(_))) => "alias_eq".to_owned(),
|
||||
_ => "??".to_owned(),
|
||||
|
|
|
|||
|
|
@ -296,12 +296,12 @@ pub fn is_fn_unsafe_to_call(
|
|||
}
|
||||
}
|
||||
|
||||
let loc = func.lookup(db.upcast());
|
||||
let loc = func.lookup(db);
|
||||
match loc.container {
|
||||
hir_def::ItemContainerId::ExternBlockId(block) => {
|
||||
let id = block.lookup(db.upcast()).id;
|
||||
let id = block.lookup(db).id;
|
||||
let is_intrinsic_block =
|
||||
id.item_tree(db.upcast())[id.value].abi.as_ref() == Some(&sym::rust_dash_intrinsic);
|
||||
id.item_tree(db)[id.value].abi.as_ref() == Some(&sym::rust_dash_intrinsic);
|
||||
if is_intrinsic_block {
|
||||
// legacy intrinsics
|
||||
// extern "rust-intrinsic" intrinsics are unsafe unless they have the rustc_safe_intrinsic attribute
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ pub(crate) fn variances_of(db: &dyn HirDatabase, def: GenericDefId) -> Option<Ar
|
|||
_ => return None,
|
||||
}
|
||||
|
||||
let generics = generics(db.upcast(), def);
|
||||
let generics = generics(db, def);
|
||||
let count = generics.len();
|
||||
if count == 0 {
|
||||
return None;
|
||||
|
|
@ -60,7 +60,7 @@ pub(crate) fn variances_of_cycle(
|
|||
_cycle: &Cycle,
|
||||
def: GenericDefId,
|
||||
) -> Option<Arc<[Variance]>> {
|
||||
let generics = generics(db.upcast(), def);
|
||||
let generics = generics(db, def);
|
||||
let count = generics.len();
|
||||
|
||||
if count == 0 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue