Skip to content

Commit acff39f

Browse files
committed
More eagerly resolve expr tys before writing them
This allows the expressions to have more accurate types when showing inference steps.
1 parent a66bd95 commit acff39f

File tree

8 files changed

+12
-23
lines changed

8 files changed

+12
-23
lines changed

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
234234
) => self.check_expr_path(qpath, expr, args),
235235
_ => self.check_expr_kind(expr, expected),
236236
});
237+
let ty = self.resolve_vars_if_possible(ty);
237238

238239
// Warn for non-block expressions with diverging children.
239240
match expr.kind {

src/test/ui/issues/issue-15783.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-15783.rs:8:19
33
|
44
LL | let x = Some(&[name]);
5-
| ------------- here the type of `x` is inferred to be `Option<_>`
5+
| ------------- here the type of `x` is inferred to be `Option<&[&str; 1]>`
66
LL | let msg = foo(x);
77
| --- ^ expected slice `[&str]`, found array `[&str; 1]`
88
| |

src/test/ui/let-else/let-else-ref-bindings.stderr

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ error[E0308]: mismatched types
2020
--> $DIR/let-else-ref-bindings.rs:24:34
2121
|
2222
LL | let some = Some(bytes);
23-
| ----------- here the type of `some` is inferred to be `Option<_>`
24-
...
25-
LL | let Some(ref a): Option<&[u8]> = some else { return };
26-
| ---- here the type of `some` is inferred to be `Option<Vec<u8>>`
23+
| ----------- here the type of `some` is inferred to be `Option<Vec<u8>>`
2724
...
2825
LL | let Some(a): Option<&[u8]> = some else { return };
2926
| ------------- ^^^^ expected `&[u8]`, found struct `Vec`
@@ -66,10 +63,7 @@ error[E0308]: mismatched types
6663
--> $DIR/let-else-ref-bindings.rs:52:38
6764
|
6865
LL | let mut some = Some(bytes);
69-
| ----------- here the type of `some` is inferred to be `Option<_>`
70-
...
71-
LL | let Some(ref mut a): Option<&mut [u8]> = some else { return };
72-
| ---- here the type of `some` is inferred to be `Option<Vec<u8>>`
66+
| ----------- here the type of `some` is inferred to be `Option<Vec<u8>>`
7367
...
7468
LL | let Some(a): Option<&mut [u8]> = some else { return };
7569
| ----------------- ^^^^ expected `&mut [u8]`, found struct `Vec`

src/test/ui/mismatched_types/abridged.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ LL | | y: 2,
6363
LL | | },
6464
LL | | y: 3,
6565
LL | | };
66-
| |_____- here the type of `x` is inferred to be `X<_, _>`
66+
| |_____- here the type of `x` is inferred to be `X<X<String, {integer}>, {integer}>`
6767
LL | x
6868
| ^ expected struct `String`, found integer
6969
|
@@ -83,7 +83,7 @@ LL | | y: 2,
8383
LL | | },
8484
LL | | y: "".to_string(),
8585
LL | | };
86-
| |_____- here the type of `x` is inferred to be `X<_, _>`
86+
| |_____- here the type of `x` is inferred to be `X<X<String, {integer}>, String>`
8787
LL | x
8888
| ^ expected struct `String`, found integer
8989
|

src/test/ui/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.stderr

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,7 @@ error[E0308]: mismatched types
101101
--> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:9:19
102102
|
103103
LL | let opt = Some(1i32);
104-
| ---------- here the type of `opt` is inferred to be `Option<_>`
105-
LL |
106-
LL | let Some(n) = opt else {
107-
| --- here the type of `opt` is inferred to be `Option<i32>`
104+
| ---------- here the type of `opt` is inferred to be `Option<i32>`
108105
...
109106
LL | let Some(n) = opt && n == 1 else {
110107
| ^^^ expected `bool`, found enum `Option`
@@ -127,10 +124,7 @@ error[E0308]: mismatched types
127124
--> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:15:19
128125
|
129126
LL | let opt = Some(1i32);
130-
| ---------- here the type of `opt` is inferred to be `Option<_>`
131-
LL |
132-
LL | let Some(n) = opt else {
133-
| --- here the type of `opt` is inferred to be `Option<i32>`
127+
| ---------- here the type of `opt` is inferred to be `Option<i32>`
134128
...
135129
LL | let Some(n) = opt && let another = n else {
136130
| ^^^ expected `bool`, found enum `Option`

src/test/ui/suggestions/call-boxed.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let y = Box::new(|| 1);
77
| --------------
88
| | |
99
| | the found closure
10-
| here the type of `y` is inferred to be `Box<_>`
10+
| here the type of `y` is inferred to be `Box<[[email protected]:3:22]>`
1111
LL | x = y;
1212
| ^ expected `i32`, found struct `Box`
1313
|

src/test/ui/tuple/wrong_argument_ice-3.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0061]: this function takes 1 argument but 2 arguments were supplied
22
--> $DIR/wrong_argument_ice-3.rs:9:16
33
|
44
LL | let new_group = vec![String::new()];
5-
| ------------------- here the type of `new_group` is inferred to be `Vec<_, _>`
5+
| ------------------- here the type of `new_group` is inferred to be `Vec<String>`
66
...
77
LL | groups.push(new_group, vec![process]);
88
| ^^^^ ------------- argument of type `Vec<&Process>` unexpected

src/test/ui/type/type-mismatch-same-crate-name.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/type-mismatch-same-crate-name.rs:16:20
33
|
44
LL | let foo2 = {extern crate crate_a2 as a; a::Foo};
5-
| ------------------------------------ here the type of `foo2` is inferred to be `_`
5+
| ------------------------------------ here the type of `foo2` is inferred to be `Foo`
66
...
77
LL | a::try_foo(foo2);
88
| ---------- ^^^^ expected struct `main::a::Foo`, found a different struct `main::a::Foo`
@@ -31,7 +31,7 @@ error[E0308]: mismatched types
3131
--> $DIR/type-mismatch-same-crate-name.rs:20:20
3232
|
3333
LL | let bar2 = {extern crate crate_a2 as a; a::bar()};
34-
| -------------------------------------- here the type of `bar2` is inferred to be `_`
34+
| -------------------------------------- here the type of `bar2` is inferred to be `Box<dyn Bar>`
3535
...
3636
LL | a::try_bar(bar2);
3737
| ---------- ^^^^ expected trait `main::a::Bar`, found a different trait `main::a::Bar`

0 commit comments

Comments
 (0)