diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs index fae63ddc2dea..54a95e018481 100644 --- a/crates/hir-ty/src/lower.rs +++ b/crates/hir-ty/src/lower.rs @@ -1948,6 +1948,7 @@ fn resolve_type_param_assoc_type_shorthand( let mut supertraits_resolution = None; for maybe_parent_generics in generics.iter_owners().rev() { ctx.store = maybe_parent_generics.store(); + ctx.def = ExpressionStoreOwnerId::Signature(maybe_parent_generics.def()); for pred in maybe_parent_generics.where_predicates() { let (WherePredicate::TypeBound { target, bound } | WherePredicate::ForLifetime { lifetimes: _, target, bound }) = pred @@ -2366,6 +2367,7 @@ fn generic_predicates( ctx.diagnostics.clear(); ctx.store = maybe_parent_generics.store(); + ctx.def = ExpressionStoreOwnerId::Signature(maybe_parent_generics.def()); for pred in maybe_parent_generics.where_predicates() { tracing::debug!(?pred); for (pred, source) in ctx.lower_where_predicate(pred, false) { @@ -2568,6 +2570,7 @@ pub(crate) fn generic_defaults_with_diagnostics( let mut defaults = ThinVec::new(); if let Some(parent) = generics.parent() { ctx.store = parent.store(); + ctx.def = ExpressionStoreOwnerId::Signature(parent.def()); defaults.extend( parent.iter_with_idx().map(|(idx, _id, p)| handle_generic_param(&mut ctx, idx, p)), ); @@ -2575,6 +2578,7 @@ pub(crate) fn generic_defaults_with_diagnostics( ctx.diagnostics.clear(); // Don't include diagnostics from the parent. ctx.defined_anon_consts.clear(); ctx.store = store_for_self; + ctx.def = ExpressionStoreOwnerId::Signature(def); defaults.extend( generics.iter_self_with_idx().map(|(idx, _id, p)| handle_generic_param(&mut ctx, idx, p)), ); diff --git a/crates/hir-ty/src/tests/regression.rs b/crates/hir-ty/src/tests/regression.rs index 22404087bffd..c5bf521d35c9 100644 --- a/crates/hir-ty/src/tests/regression.rs +++ b/crates/hir-ty/src/tests/regression.rs @@ -43,6 +43,26 @@ fn no_panic_on_field_of_enum() { ); } +#[test] +fn anon_const_projection_in_impl_predicate() { + check_no_mismatches( + r#" +trait Trait { + type Assoc; +} + +struct S; + +impl S +where + S<{ N }>: Trait, +{ + fn new(_: as Trait>::Assoc) {} +} + "#, + ); +} + #[test] fn bug_585() { check_infer(