Skip to content

Commit 01630f3

Browse files
Separate between creating an interner without crate and with crate
Via separate methods. This is both more clear, shorter, and will be required for the next commit.
1 parent ac118f9 commit 01630f3

File tree

35 files changed

+153
-149
lines changed

35 files changed

+153
-149
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn autoderef<'db>(
3838
env: Arc<TraitEnvironment<'db>>,
3939
ty: Canonical<'db, Ty<'db>>,
4040
) -> impl Iterator<Item = Ty<'db>> + use<'db> {
41-
let interner = DbInterner::new_with(db, Some(env.krate), env.block);
41+
let interner = DbInterner::new_with(db, env.krate, env.block);
4242
let infcx = interner.infer_ctxt().build(TypingMode::PostAnalysis);
4343
let (ty, _) = infcx.instantiate_canonical(&ty);
4444
let autoderef = Autoderef::new(&infcx, &env, ty);

src/tools/rust-analyzer/crates/hir-ty/src/consteval.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub fn intern_const_ref<'a>(
8383
ty: Ty<'a>,
8484
krate: Crate,
8585
) -> Const<'a> {
86-
let interner = DbInterner::new_with(db, Some(krate), None);
86+
let interner = DbInterner::new_no_crate(db);
8787
let layout = db.layout_of_ty(ty, TraitEnvironment::empty(krate));
8888
let kind = match value {
8989
LiteralConstRef::Int(i) => {
@@ -128,7 +128,7 @@ pub fn usize_const<'db>(db: &'db dyn HirDatabase, value: Option<u128>, krate: Cr
128128
intern_const_ref(
129129
db,
130130
&value.map_or(LiteralConstRef::Unknown, LiteralConstRef::UInt),
131-
Ty::new_uint(DbInterner::new_with(db, Some(krate), None), rustc_type_ir::UintTy::Usize),
131+
Ty::new_uint(DbInterner::new_no_crate(db), rustc_type_ir::UintTy::Usize),
132132
krate,
133133
)
134134
}
@@ -183,7 +183,7 @@ pub(crate) fn const_eval_discriminant_variant<'db>(
183183
db: &'db dyn HirDatabase,
184184
variant_id: EnumVariantId,
185185
) -> Result<i128, ConstEvalError<'db>> {
186-
let interner = DbInterner::new_with(db, None, None);
186+
let interner = DbInterner::new_no_crate(db);
187187
let def = variant_id.into();
188188
let body = db.body(def);
189189
let loc = variant_id.lookup(db);
@@ -292,7 +292,7 @@ pub(crate) fn const_eval_static_query<'db>(
292292
db: &'db dyn HirDatabase,
293293
def: StaticId,
294294
) -> Result<Const<'db>, ConstEvalError<'db>> {
295-
let interner = DbInterner::new_with(db, None, None);
295+
let interner = DbInterner::new_no_crate(db);
296296
let body = db.monomorphized_mir_body(
297297
def.into(),
298298
GenericArgs::new_from_iter(interner, []),

src/tools/rust-analyzer/crates/hir-ty/src/consteval/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn pretty_print_err(e: ConstEvalError<'_>, db: &TestDB) -> String {
123123

124124
fn eval_goal(db: &TestDB, file_id: EditionedFileId) -> Result<Const<'_>, ConstEvalError<'_>> {
125125
let _tracing = setup_tracing();
126-
let interner = DbInterner::new_with(db, None, None);
126+
let interner = DbInterner::new_no_crate(db);
127127
let module_id = db.module_for_file(file_id.file_id(db));
128128
let def_map = module_id.def_map(db);
129129
let scope = &def_map[module_id.local_id].scope;

src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl BodyValidationDiagnostic {
7979
let infer = db.infer(owner);
8080
let body = db.body(owner);
8181
let env = db.trait_environment_for_body(owner);
82-
let interner = DbInterner::new_with(db, Some(env.krate), env.block);
82+
let interner = DbInterner::new_with(db, env.krate, env.block);
8383
let infcx =
8484
interner.infer_ctxt().build(TypingMode::typeck_for_body(interner, owner.into()));
8585
let mut validator = ExprValidator {

src/tools/rust-analyzer/crates/hir-ty/src/display.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ pub trait HirDisplay<'db> {
309309
allow_opaque: bool,
310310
) -> Result<String, DisplaySourceCodeError> {
311311
let mut result = String::new();
312-
let interner =
313-
DbInterner::new_with(db, Some(module_id.krate()), module_id.containing_block());
312+
let interner = DbInterner::new_with(db, module_id.krate(), module_id.containing_block());
314313
match self.hir_fmt(&mut HirFormatter {
315314
db,
316315
interner,
@@ -544,7 +543,7 @@ impl<'db, T: HirDisplay<'db>> HirDisplayWrapper<'_, 'db, T> {
544543
DisplayKind::SourceCode { target_module_id, .. } => target_module_id.containing_block(),
545544
DisplayKind::Diagnostics | DisplayKind::Test => None,
546545
};
547-
let interner = DbInterner::new_with(self.db, Some(krate), block);
546+
let interner = DbInterner::new_with(self.db, krate, block);
548547
self.t.hir_fmt(&mut HirFormatter {
549548
db: self.db,
550549
interner,

src/tools/rust-analyzer/crates/hir-ty/src/dyn_compatibility.rs

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn dyn_compatibility(
5353
db: &dyn HirDatabase,
5454
trait_: TraitId,
5555
) -> Option<DynCompatibilityViolation> {
56-
let interner = DbInterner::new_with(db, Some(trait_.krate(db)), None);
56+
let interner = DbInterner::new_no_crate(db);
5757
for super_trait in elaborate::supertrait_def_ids(interner, trait_.into()) {
5858
if let Some(v) = db.dyn_compatibility_of_trait(super_trait.0) {
5959
return if super_trait.0 == trait_ {
@@ -75,7 +75,7 @@ pub fn dyn_compatibility_with_callback<F>(
7575
where
7676
F: FnMut(DynCompatibilityViolation) -> ControlFlow<()>,
7777
{
78-
let interner = DbInterner::new_with(db, Some(trait_.krate(db)), None);
78+
let interner = DbInterner::new_no_crate(db);
7979
for super_trait in elaborate::supertrait_def_ids(interner, trait_.into()).skip(1) {
8080
if db.dyn_compatibility_of_trait(super_trait.0).is_some() {
8181
cb(DynCompatibilityViolation::HasNonCompatibleSuperTrait(trait_))?;
@@ -135,7 +135,7 @@ pub fn generics_require_sized_self(db: &dyn HirDatabase, def: GenericDefId) -> b
135135
return false;
136136
};
137137

138-
let interner = DbInterner::new_with(db, Some(krate), None);
138+
let interner = DbInterner::new_no_crate(db);
139139
let predicates = GenericPredicates::query_explicit(db, def);
140140
// FIXME: We should use `explicit_predicates_of` here, which hasn't been implemented to
141141
// rust-analyzer yet
@@ -234,34 +234,34 @@ fn contains_illegal_self_type_reference<'db, T: rustc_type_ir::TypeVisitable<DbI
234234
&mut self,
235235
ty: <DbInterner<'db> as rustc_type_ir::Interner>::Ty,
236236
) -> Self::Result {
237-
let interner = DbInterner::new_with(self.db, None, None);
237+
let interner = DbInterner::new_no_crate(self.db);
238238
match ty.kind() {
239239
rustc_type_ir::TyKind::Param(param) if param.index == 0 => ControlFlow::Break(()),
240240
rustc_type_ir::TyKind::Param(_) => ControlFlow::Continue(()),
241-
rustc_type_ir::TyKind::Alias(AliasTyKind::Projection, proj) => match self
242-
.allow_self_projection
243-
{
244-
AllowSelfProjection::Yes => {
245-
let trait_ = proj.trait_def_id(DbInterner::new_with(self.db, None, None));
246-
let trait_ = match trait_ {
247-
SolverDefId::TraitId(id) => id,
248-
_ => unreachable!(),
249-
};
250-
if self.super_traits.is_none() {
251-
self.super_traits = Some(
252-
elaborate::supertrait_def_ids(interner, self.trait_.into())
253-
.map(|super_trait| super_trait.0)
254-
.collect(),
255-
)
256-
}
257-
if self.super_traits.as_ref().is_some_and(|s| s.contains(&trait_)) {
258-
ControlFlow::Continue(())
259-
} else {
260-
ty.super_visit_with(self)
241+
rustc_type_ir::TyKind::Alias(AliasTyKind::Projection, proj) => {
242+
match self.allow_self_projection {
243+
AllowSelfProjection::Yes => {
244+
let trait_ = proj.trait_def_id(interner);
245+
let trait_ = match trait_ {
246+
SolverDefId::TraitId(id) => id,
247+
_ => unreachable!(),
248+
};
249+
if self.super_traits.is_none() {
250+
self.super_traits = Some(
251+
elaborate::supertrait_def_ids(interner, self.trait_.into())
252+
.map(|super_trait| super_trait.0)
253+
.collect(),
254+
)
255+
}
256+
if self.super_traits.as_ref().is_some_and(|s| s.contains(&trait_)) {
257+
ControlFlow::Continue(())
258+
} else {
259+
ty.super_visit_with(self)
260+
}
261261
}
262+
AllowSelfProjection::No => ty.super_visit_with(self),
262263
}
263-
AllowSelfProjection::No => ty.super_visit_with(self),
264-
},
264+
}
265265
_ => ty.super_visit_with(self),
266266
}
267267
}
@@ -401,7 +401,8 @@ fn receiver_is_dispatchable<'db>(
401401
) -> bool {
402402
let sig = sig.instantiate_identity();
403403

404-
let interner: DbInterner<'_> = DbInterner::new_with(db, Some(trait_.krate(db)), None);
404+
let module = trait_.module(db);
405+
let interner = DbInterner::new_with(db, module.krate(), module.containing_block());
405406
let self_param_id = TypeParamId::from_unchecked(TypeOrConstParamId {
406407
parent: trait_.into(),
407408
local_id: LocalTypeOrConstParamId::from_raw(la_arena::RawIdx::from_u32(0)),

src/tools/rust-analyzer/crates/hir-ty/src/infer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub(crate) fn infer_cycle_result(
167167
) -> Arc<InferenceResult<'_>> {
168168
Arc::new(InferenceResult {
169169
has_errors: true,
170-
..InferenceResult::new(Ty::new_error(DbInterner::new_with(db, None, None), ErrorGuaranteed))
170+
..InferenceResult::new(Ty::new_error(DbInterner::new_no_crate(db), ErrorGuaranteed))
171171
})
172172
}
173173

src/tools/rust-analyzer/crates/hir-ty/src/infer/closure/analysis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'db> CapturedItem<'db> {
101101
}
102102

103103
pub fn ty(&self, db: &'db dyn HirDatabase, subst: GenericArgs<'db>) -> Ty<'db> {
104-
let interner = DbInterner::new_with(db, None, None);
104+
let interner = DbInterner::new_no_crate(db);
105105
self.ty.instantiate(interner, subst.split_closure_args_untupled().parent_args)
106106
}
107107

src/tools/rust-analyzer/crates/hir-ty/src/infer/coerce.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ fn coerce<'db>(
15781578
env: Arc<TraitEnvironment<'db>>,
15791579
tys: &Canonical<'db, (Ty<'db>, Ty<'db>)>,
15801580
) -> Result<(Vec<Adjustment<'db>>, Ty<'db>), TypeError<DbInterner<'db>>> {
1581-
let interner = DbInterner::new_with(db, Some(env.krate), env.block);
1581+
let interner = DbInterner::new_with(db, env.krate, env.block);
15821582
let infcx = interner.infer_ctxt().build(TypingMode::PostAnalysis);
15831583
let ((ty1_with_vars, ty2_with_vars), vars) = infcx.instantiate_canonical(tys);
15841584

src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn could_unify_impl<'db>(
113113
tys: &Canonical<'db, (Ty<'db>, Ty<'db>)>,
114114
select: for<'a> fn(&mut ObligationCtxt<'a, 'db>) -> Vec<NextSolverError<'db>>,
115115
) -> bool {
116-
let interner = DbInterner::new_with(db, Some(env.krate), env.block);
116+
let interner = DbInterner::new_with(db, env.krate, env.block);
117117
let infcx = interner.infer_ctxt().build(TypingMode::PostAnalysis);
118118
let cause = ObligationCause::dummy();
119119
let at = infcx.at(&cause, env.env);
@@ -148,7 +148,7 @@ impl<'db> InferenceTable<'db> {
148148
trait_env: Arc<TraitEnvironment<'db>>,
149149
owner: Option<DefWithBodyId>,
150150
) -> Self {
151-
let interner = DbInterner::new_with(db, Some(trait_env.krate), trait_env.block);
151+
let interner = DbInterner::new_with(db, trait_env.krate, trait_env.block);
152152
let typing_mode = match owner {
153153
Some(owner) => TypingMode::typeck_for_body(interner, owner.into()),
154154
// IDE things wants to reveal opaque types.

0 commit comments

Comments
 (0)