Skip to content

Commit 16de9a7

Browse files
committed
Auto merge of rust-lang#13774 - lowr:fix/no-infer-vars-in-inference-result, r=Veykril
fix: resolve all inference vars in `InferenceResult::assoc_resolutions` I think this fixes 'rust-lang#13773, ~but still haven't found repro. I'll try finding one so we can have a regression test~. We should resolve every inference variable in `InferenceResult` after inference is done. We started recording `Substitution`s for each resolved associated items in rust-lang#13725, but failed to do so which causes crash when analyzing source in IDE layer.
2 parents fb4e935 + bb99d2a commit 16de9a7

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

crates/hir-ty/src/infer.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,9 @@ impl<'a> InferenceContext<'a> {
535535
for (_, subst) in result.method_resolutions.values_mut() {
536536
*subst = table.resolve_completely(subst.clone());
537537
}
538+
for (_, subst) in result.assoc_resolutions.values_mut() {
539+
*subst = table.resolve_completely(subst.clone());
540+
}
538541
for adjustment in result.expr_adjustments.values_mut().flatten() {
539542
adjustment.target = table.resolve_completely(adjustment.target.clone());
540543
}

crates/ide/src/hover/tests.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4079,6 +4079,37 @@ const FOO$0: f64 = 1.0f64;
40794079
);
40804080
}
40814081

4082+
#[test]
4083+
fn hover_const_eval_in_generic_trait() {
4084+
// Doesn't compile, but we shouldn't crash.
4085+
check(
4086+
r#"
4087+
trait Trait<T> {
4088+
const FOO: bool = false;
4089+
}
4090+
struct S<T>(T);
4091+
impl<T> Trait<T> for S<T> {
4092+
const FOO: bool = true;
4093+
}
4094+
4095+
fn test() {
4096+
S::FOO$0;
4097+
}
4098+
"#,
4099+
expect![[r#"
4100+
*FOO*
4101+
4102+
```rust
4103+
test
4104+
```
4105+
4106+
```rust
4107+
const FOO: bool = true
4108+
```
4109+
"#]],
4110+
);
4111+
}
4112+
40824113
#[test]
40834114
fn hover_const_pat() {
40844115
check(

0 commit comments

Comments
 (0)