Skip to content

Commit 96925d5

Browse files
Merge pull request #19570 from ChayimFriedman2/fix-store-panic
fix: Fix an incorrect `ExpressionStore` that was passed
2 parents bee9998 + 8bde16d commit 96925d5

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

crates/hir/src/display.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,21 @@ impl HirDisplay for Function {
3939
// Write container (trait or impl)
4040
let container_params = match container {
4141
Some(AssocItemContainer::Trait(trait_)) => {
42-
let params = f.db.generic_params(trait_.id.into());
42+
let (params, params_store) = f.db.generic_params_and_store(trait_.id.into());
4343
if f.show_container_bounds() && !params.is_empty() {
4444
write_trait_header(&trait_, f)?;
4545
f.write_char('\n')?;
46-
has_disaplayable_predicates(&params).then_some(params)
46+
has_disaplayable_predicates(&params).then_some((params, params_store))
4747
} else {
4848
None
4949
}
5050
}
5151
Some(AssocItemContainer::Impl(impl_)) => {
52-
let params = f.db.generic_params(impl_.id.into());
52+
let (params, params_store) = f.db.generic_params_and_store(impl_.id.into());
5353
if f.show_container_bounds() && !params.is_empty() {
5454
write_impl_header(&impl_, f)?;
5555
f.write_char('\n')?;
56-
has_disaplayable_predicates(&params).then_some(params)
56+
has_disaplayable_predicates(&params).then_some((params, params_store))
5757
} else {
5858
None
5959
}
@@ -169,7 +169,7 @@ impl HirDisplay for Function {
169169

170170
// Write where clauses
171171
let has_written_where = write_where_clause(GenericDefId::FunctionId(self.id), f)?;
172-
if let Some(container_params) = container_params {
172+
if let Some((container_params, container_params_store)) = container_params {
173173
if !has_written_where {
174174
f.write_str("\nwhere")?;
175175
}
@@ -178,7 +178,7 @@ impl HirDisplay for Function {
178178
AssocItemContainer::Impl(_) => "impl",
179179
};
180180
write!(f, "\n // Bounds from {container_name}:",)?;
181-
write_where_predicates(&container_params, &data.store, f)?;
181+
write_where_predicates(&container_params, &container_params_store, f)?;
182182
}
183183
Ok(())
184184
}

crates/ide/src/hover/tests.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10724,3 +10724,41 @@ impl PublicFlags for NoteDialects {
1072410724
"#]],
1072510725
);
1072610726
}
10727+
10728+
#[test]
10729+
fn bounds_from_container_do_not_panic() {
10730+
check(
10731+
r#"
10732+
//- minicore: copy
10733+
struct Foo<T>(T);
10734+
10735+
impl<T: Copy> Foo<T> {
10736+
fn foo<U: Copy>(&self, _u: U) {}
10737+
}
10738+
10739+
fn bar(v: &Foo<i32>) {
10740+
v.$0foo(1u32);
10741+
}
10742+
"#,
10743+
expect![[r#"
10744+
*foo*
10745+
10746+
```rust
10747+
ra_test_fixture::Foo
10748+
```
10749+
10750+
```rust
10751+
impl<T> Foo<T>
10752+
fn foo<U>(&self, _u: U)
10753+
where
10754+
U: Copy,
10755+
// Bounds from impl:
10756+
T: Copy,
10757+
```
10758+
10759+
---
10760+
10761+
`T` = `i32`, `U` = `u32`
10762+
"#]],
10763+
);
10764+
}

0 commit comments

Comments
 (0)