Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/hir-ty/src/infer.rs2
-rw-r--r--crates/hir-ty/src/infer/unify.rs6
-rw-r--r--crates/hir-ty/src/next_solver/interner.rs12
-rw-r--r--crates/hir-ty/src/tests/regression.rs31
4 files changed, 44 insertions, 7 deletions
diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs
index 319a8ae9bd..935b2f9ffa 100644
--- a/crates/hir-ty/src/infer.rs
+++ b/crates/hir-ty/src/infer.rs
@@ -1438,7 +1438,7 @@ impl<'db> InferenceContext<'db> {
lowering_mode: LoweringMode,
) -> Self {
let trait_env = db.trait_environment(generic_def);
- let table = unify::InferenceTable::new(db, trait_env, resolver.krate(), store_owner);
+ let table = unify::InferenceTable::new(db, trait_env, resolver.krate(), owner);
let types = crate::next_solver::default_types(db);
InferenceContext {
result: InferenceResult::new(types.types.error),
diff --git a/crates/hir-ty/src/infer/unify.rs b/crates/hir-ty/src/infer/unify.rs
index 6157f51500..7b589efba2 100644
--- a/crates/hir-ty/src/infer/unify.rs
+++ b/crates/hir-ty/src/infer/unify.rs
@@ -3,7 +3,7 @@
use std::fmt;
use base_db::Crate;
-use hir_def::{ExpressionStoreOwnerId, GenericParamId, TraitId};
+use hir_def::{GenericParamId, TraitId};
use rustc_hash::FxHashSet;
use rustc_type_ir::{
TyVid, TypeFoldable, TypeVisitableExt,
@@ -14,7 +14,7 @@ use smallvec::SmallVec;
use thin_vec::ThinVec;
use crate::{
- InferenceDiagnostic, Span,
+ InferBodyId, InferenceDiagnostic, Span,
db::HirDatabase,
next_solver::{
Canonical, ClauseKind, Const, ConstKind, DbInterner, ErrorGuaranteed, GenericArg,
@@ -144,7 +144,7 @@ impl<'db> InferenceTable<'db> {
db: &'db dyn HirDatabase,
trait_env: ParamEnv<'db>,
krate: Crate,
- owner: ExpressionStoreOwnerId,
+ owner: InferBodyId<'db>,
) -> Self {
let interner = DbInterner::new_with(db, krate);
let typing_mode = TypingMode::typeck_for_body(interner, owner.into());
diff --git a/crates/hir-ty/src/next_solver/interner.rs b/crates/hir-ty/src/next_solver/interner.rs
index 7554ca6bcd..02baf27e0b 100644
--- a/crates/hir-ty/src/next_solver/interner.rs
+++ b/crates/hir-ty/src/next_solver/interner.rs
@@ -2085,13 +2085,19 @@ impl<'db> Interner for DbInterner<'db> {
opaque: Self::LocalOpaqueTyId,
) -> EarlyBinder<Self, Self::Ty> {
let impl_trait_id = opaque.0.loc(self.db);
- match impl_trait_id {
+ // The entry is missing when this call cycles back into the still-running inference
+ // of the defining body, as the cycle fallback is an empty result.
+ let hidden_type = match impl_trait_id {
crate::ImplTraitId::ReturnTypeImplTrait(func, idx) => {
- crate::opaques::rpit_hidden_types(self.db, func)[idx].get()
+ crate::opaques::rpit_hidden_types(self.db, func).get(idx)
}
crate::ImplTraitId::TypeAliasImplTrait(type_alias, idx) => {
- crate::opaques::tait_hidden_types(self.db, type_alias)[idx].get()
+ crate::opaques::tait_hidden_types(self.db, type_alias).get(idx)
}
+ };
+ match hidden_type {
+ Some(hidden_type) => hidden_type.get(),
+ None => EarlyBinder::bind(Ty::new_error(self, ErrorGuaranteed)),
}
}
diff --git a/crates/hir-ty/src/tests/regression.rs b/crates/hir-ty/src/tests/regression.rs
index 683c938fb5..59f33f0f1b 100644
--- a/crates/hir-ty/src/tests/regression.rs
+++ b/crates/hir-ty/src/tests/regression.rs
@@ -3063,3 +3063,34 @@ fn main() {
"#,
);
}
+
+#[test]
+fn regression_22820() {
+ check_no_mismatches(
+ r#"
+//- minicore: copy
+trait MyTrait: Copy {
+ const ASSOC: usize;
+}
+
+const fn output<T: MyTrait>(_: T) -> usize {
+ <T as MyTrait>::ASSOC
+}
+
+const fn yeet() -> impl Clone {
+ let x = [0u8; output(yeet())];
+}
+ "#,
+ );
+}
+
+#[test]
+fn rpit_function_with_non_trivial_anon_const() {
+ check_no_mismatches(
+ r#"
+fn f() -> impl Sized {
+ let x = [0u8; 1 + 2];
+}
+ "#,
+ );
+}