Auto merge of #13774 - lowr:fix/no-infer-vars-in-inference-result, r=Veykril

fix: resolve all inference vars in `InferenceResult::assoc_resolutions`

I think this fixes '#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 #13725, but failed to do so which causes crash when analyzing source in IDE layer.
This commit is contained in:
bors 2022-12-14 14:27:32 +00:00
commit 16de9a7130
2 changed files with 34 additions and 0 deletions

View File

@ -535,6 +535,9 @@ impl<'a> InferenceContext<'a> {
for (_, subst) in result.method_resolutions.values_mut() {
*subst = table.resolve_completely(subst.clone());
}
for (_, subst) in result.assoc_resolutions.values_mut() {
*subst = table.resolve_completely(subst.clone());
}
for adjustment in result.expr_adjustments.values_mut().flatten() {
adjustment.target = table.resolve_completely(adjustment.target.clone());
}

View File

@ -4079,6 +4079,37 @@ const FOO$0: f64 = 1.0f64;
);
}
#[test]
fn hover_const_eval_in_generic_trait() {
// Doesn't compile, but we shouldn't crash.
check(
r#"
trait Trait<T> {
const FOO: bool = false;
}
struct S<T>(T);
impl<T> Trait<T> for S<T> {
const FOO: bool = true;
}
fn test() {
S::FOO$0;
}
"#,
expect![[r#"
*FOO*
```rust
test
```
```rust
const FOO: bool = true
```
"#]],
);
}
#[test]
fn hover_const_pat() {
check(