diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2023-01-02 22:25:50 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2023-01-05 16:51:16 +0000 |
| commit | 48094a4a6f53ee3be636b4166a7841505bb7cabc (patch) | |
| tree | 076d61e3e06c878861828fe4d4dac4ecad2b3cd9 | |
| parent | 05c30b0ca5450b2beec0a6e4e034953e216f6bbe (diff) | |
| download | rust-48094a4a6f53ee3be636b4166a7841505bb7cabc.tar.gz rust-48094a4a6f53ee3be636b4166a7841505bb7cabc.zip | |
More eagerly resolve expr `ty`s before writing them
This allows the expressions to have more accurate types when showing inference steps.
8 files changed, 12 insertions, 23 deletions
diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 631749fcc0f..6ed1bc051a5 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -234,6 +234,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) => self.check_expr_path(qpath, expr, args), _ => self.check_expr_kind(expr, expected), }); + let ty = self.resolve_vars_if_possible(ty); // Warn for non-block expressions with diverging children. match expr.kind { diff --git a/src/test/ui/issues/issue-15783.stderr b/src/test/ui/issues/issue-15783.stderr index 74a7c5de7ab..e7fecfebdc8 100644 --- a/src/test/ui/issues/issue-15783.stderr +++ b/src/test/ui/issues/issue-15783.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/issue-15783.rs:8:19 | LL | let x = Some(&[name]); - | ------------- here the type of `x` is inferred to be `Option<_>` + | ------------- here the type of `x` is inferred to be `Option<&[&str; 1]>` LL | let msg = foo(x); | --- ^ expected slice `[&str]`, found array `[&str; 1]` | | diff --git a/src/test/ui/let-else/let-else-ref-bindings.stderr b/src/test/ui/let-else/let-else-ref-bindings.stderr index 39b57ceb43d..4c58b2db575 100644 --- a/src/test/ui/let-else/let-else-ref-bindings.stderr +++ b/src/test/ui/let-else/let-else-ref-bindings.stderr @@ -20,10 +20,7 @@ error[E0308]: mismatched types --> $DIR/let-else-ref-bindings.rs:24:34 | LL | let some = Some(bytes); - | ----------- here the type of `some` is inferred to be `Option<_>` -... -LL | let Some(ref a): Option<&[u8]> = some else { return }; - | ---- here the type of `some` is inferred to be `Option<Vec<u8>>` + | ----------- here the type of `some` is inferred to be `Option<Vec<u8>>` ... LL | let Some(a): Option<&[u8]> = some else { return }; | ------------- ^^^^ expected `&[u8]`, found struct `Vec` @@ -66,10 +63,7 @@ error[E0308]: mismatched types --> $DIR/let-else-ref-bindings.rs:52:38 | LL | let mut some = Some(bytes); - | ----------- here the type of `some` is inferred to be `Option<_>` -... -LL | let Some(ref mut a): Option<&mut [u8]> = some else { return }; - | ---- here the type of `some` is inferred to be `Option<Vec<u8>>` + | ----------- here the type of `some` is inferred to be `Option<Vec<u8>>` ... LL | let Some(a): Option<&mut [u8]> = some else { return }; | ----------------- ^^^^ expected `&mut [u8]`, found struct `Vec` diff --git a/src/test/ui/mismatched_types/abridged.stderr b/src/test/ui/mismatched_types/abridged.stderr index 8fd3239e8ee..9b5f0134f12 100644 --- a/src/test/ui/mismatched_types/abridged.stderr +++ b/src/test/ui/mismatched_types/abridged.stderr @@ -63,7 +63,7 @@ LL | | y: 2, LL | | }, LL | | y: 3, LL | | }; - | |_____- here the type of `x` is inferred to be `X<_, _>` + | |_____- here the type of `x` is inferred to be `X<X<String, {integer}>, {integer}>` LL | x | ^ expected struct `String`, found integer | @@ -83,7 +83,7 @@ LL | | y: 2, LL | | }, LL | | y: "".to_string(), LL | | }; - | |_____- here the type of `x` is inferred to be `X<_, _>` + | |_____- here the type of `x` is inferred to be `X<X<String, {integer}>, String>` LL | x | ^ expected struct `String`, found integer | diff --git a/src/test/ui/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.stderr b/src/test/ui/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.stderr index 1785c31cfb9..8c30f015c5d 100644 --- a/src/test/ui/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.stderr +++ b/src/test/ui/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.stderr @@ -101,10 +101,7 @@ error[E0308]: mismatched types --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:9:19 | LL | let opt = Some(1i32); - | ---------- here the type of `opt` is inferred to be `Option<_>` -LL | -LL | let Some(n) = opt else { - | --- here the type of `opt` is inferred to be `Option<i32>` + | ---------- here the type of `opt` is inferred to be `Option<i32>` ... LL | let Some(n) = opt && n == 1 else { | ^^^ expected `bool`, found enum `Option` @@ -127,10 +124,7 @@ error[E0308]: mismatched types --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:15:19 | LL | let opt = Some(1i32); - | ---------- here the type of `opt` is inferred to be `Option<_>` -LL | -LL | let Some(n) = opt else { - | --- here the type of `opt` is inferred to be `Option<i32>` + | ---------- here the type of `opt` is inferred to be `Option<i32>` ... LL | let Some(n) = opt && let another = n else { | ^^^ expected `bool`, found enum `Option` diff --git a/src/test/ui/suggestions/call-boxed.stderr b/src/test/ui/suggestions/call-boxed.stderr index 8295e010f40..1609c2a3094 100644 --- a/src/test/ui/suggestions/call-boxed.stderr +++ b/src/test/ui/suggestions/call-boxed.stderr @@ -7,7 +7,7 @@ LL | let y = Box::new(|| 1); | -------------- | | | | | the found closure - | here the type of `y` is inferred to be `Box<_>` + | here the type of `y` is inferred to be `Box<[closure@call-boxed.rs:3:22]>` LL | x = y; | ^ expected `i32`, found struct `Box` | diff --git a/src/test/ui/tuple/wrong_argument_ice-3.stderr b/src/test/ui/tuple/wrong_argument_ice-3.stderr index c83bc28d855..1ad1d692121 100644 --- a/src/test/ui/tuple/wrong_argument_ice-3.stderr +++ b/src/test/ui/tuple/wrong_argument_ice-3.stderr @@ -2,7 +2,7 @@ error[E0061]: this method takes 1 argument but 2 arguments were supplied --> $DIR/wrong_argument_ice-3.rs:9:16 | LL | let new_group = vec![String::new()]; - | ------------------- here the type of `new_group` is inferred to be `Vec<_, _>` + | ------------------- here the type of `new_group` is inferred to be `Vec<String>` ... LL | groups.push(new_group, vec![process]); | ^^^^ ------------- argument of type `Vec<&Process>` unexpected diff --git a/src/test/ui/type/type-mismatch-same-crate-name.stderr b/src/test/ui/type/type-mismatch-same-crate-name.stderr index e99d30d3396..0d754459f4a 100644 --- a/src/test/ui/type/type-mismatch-same-crate-name.stderr +++ b/src/test/ui/type/type-mismatch-same-crate-name.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/type-mismatch-same-crate-name.rs:16:20 | LL | let foo2 = {extern crate crate_a2 as a; a::Foo}; - | ------------------------------------ here the type of `foo2` is inferred to be `_` + | ------------------------------------ here the type of `foo2` is inferred to be `Foo` ... LL | a::try_foo(foo2); | ---------- ^^^^ expected struct `main::a::Foo`, found a different struct `main::a::Foo` @@ -31,7 +31,7 @@ error[E0308]: mismatched types --> $DIR/type-mismatch-same-crate-name.rs:20:20 | LL | let bar2 = {extern crate crate_a2 as a; a::bar()}; - | -------------------------------------- here the type of `bar2` is inferred to be `_` + | -------------------------------------- here the type of `bar2` is inferred to be `Box<dyn Bar>` ... LL | a::try_bar(bar2); | ---------- ^^^^ expected trait `main::a::Bar`, found a different trait `main::a::Bar` |
