Skip to content

Commit 62d0e4c

Browse files
committed
Resolve vars in note_type_err
1 parent 1549576 commit 62d0e4c

30 files changed

+146
-138
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1584,9 +1584,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15841584
Variable(ty::error::ExpectedFound<Ty<'a>>),
15851585
Fixed(&'static str),
15861586
}
1587-
let (expected_found, exp_found, is_simple_error) = match values {
1588-
None => (None, Mismatch::Fixed("type"), false),
1587+
let (expected_found, exp_found, is_simple_error, values) = match values {
1588+
None => (None, Mismatch::Fixed("type"), false, None),
15891589
Some(values) => {
1590+
let values = self.resolve_vars_if_possible(values);
15901591
let (is_simple_error, exp_found) = match values {
15911592
ValuePairs::Terms(infer::ExpectedFound {
15921593
expected: ty::Term::Ty(expected),
@@ -1614,7 +1615,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16141615
return;
16151616
}
16161617
};
1617-
(vals, exp_found, is_simple_error)
1618+
(vals, exp_found, is_simple_error, Some(values))
16181619
}
16191620
};
16201621

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
394394
break 'errors;
395395
}
396396

397+
self.set_tainted_by_errors();
398+
397399
// The algorithm here is inspired by levenshtein distance and longest common subsequence.
398400
// We'll try to detect 4 different types of mistakes:
399401
// - An extra parameter has been provided that doesn't satisfy *any* of the other inputs
@@ -569,7 +571,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
569571
self.emit_coerce_suggestions(
570572
&mut err,
571573
&provided_args[*input_idx],
572-
final_arg_types[*input_idx].map(|ty| ty.0).unwrap(),
574+
provided_ty,
573575
final_arg_types[*input_idx].map(|ty| ty.1).unwrap(),
574576
None,
575577
None,
@@ -627,12 +629,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
627629
match error {
628630
Error::Invalid(input_idx, compatibility) => {
629631
let expected_ty = expected_input_tys[input_idx];
632+
let provided_ty = final_arg_types
633+
.get(input_idx)
634+
.and_then(|x| x.as_ref())
635+
.map(|ty| ty.0)
636+
.unwrap_or(tcx.ty_error());
630637
if let Compatibility::Incompatible(error) = &compatibility {
631-
let provided_ty = final_arg_types
632-
.get(input_idx)
633-
.and_then(|x| x.as_ref())
634-
.map(|ty| ty.0)
635-
.unwrap_or(tcx.ty_error());
636638
let cause = &self.misc(
637639
provided_args.get(input_idx).map(|i| i.span).unwrap_or(call_span),
638640
);

src/test/ui/associated-types/associated-types-issue-20346.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ note: expected this to be `Option<T>`
1212
|
1313
LL | type Item = T;
1414
| ^
15-
= note: expected enum `Option<T>`
16-
found type `T`
15+
= note: expected enum `Option<T>`
16+
found type parameter `T`
1717
note: required by a bound in `is_iterator_of`
1818
--> $DIR/associated-types-issue-20346.rs:15:34
1919
|

src/test/ui/associated-types/higher-ranked-projection.bad.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | foo(());
55
| ^^^ lifetime mismatch
66
|
77
= note: expected reference `&'a ()`
8-
found type `&()`
8+
found reference `&()`
99
note: the lifetime requirement is introduced here
1010
--> $DIR/higher-ranked-projection.rs:15:33
1111
|

src/test/ui/async-await/generator-desc.stderr

+16-11
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@ LL | fun(one(), two());
2424
| |
2525
| arguments to this function are incorrect
2626
|
27+
note: while checking the return type of the `async fn`
28+
--> $DIR/generator-desc.rs:5:16
29+
|
30+
LL | async fn one() {}
31+
| ^ checked the `Output` of this `async fn`, expected opaque type
2732
note: while checking the return type of the `async fn`
2833
--> $DIR/generator-desc.rs:6:16
2934
|
3035
LL | async fn two() {}
3136
| ^ checked the `Output` of this `async fn`, found opaque type
32-
= note: expected type `impl Future<Output = ()>` (opaque type at <$DIR/generator-desc.rs:5:16>)
33-
found opaque type `impl Future<Output = ()>` (opaque type at <$DIR/generator-desc.rs:6:16>)
37+
= note: expected opaque type `impl Future<Output = ()>` (opaque type at <$DIR/generator-desc.rs:5:16>)
38+
found opaque type `impl Future<Output = ()>` (opaque type at <$DIR/generator-desc.rs:6:16>)
3439
= help: consider `await`ing on both `Future`s
3540
= note: distinct uses of `impl Trait` result in different opaque types
3641
note: function defined here
@@ -43,26 +48,26 @@ error[E0308]: mismatched types
4348
--> $DIR/generator-desc.rs:14:26
4449
|
4550
LL | fun((async || {})(), (async || {})());
46-
| --- ^^^^^^^^^^^^^^^ expected `async` closure body, found a different `async` closure body
47-
| |
51+
| --- -- ^^^^^^^^^^^^^^^ expected `async` closure body, found a different `async` closure body
52+
| | |
53+
| | the expected `async` closure body
4854
| arguments to this function are incorrect
4955
|
5056
::: $SRC_DIR/core/src/future/mod.rs:LL:COL
5157
|
5258
LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
53-
| ------------------------------- the found opaque type
59+
| -------------------------------
60+
| |
61+
| the expected opaque type
62+
| the found opaque type
5463
|
55-
= note: expected type `impl Future<Output = ()>` (`async` closure body)
56-
found opaque type `impl Future<Output = ()>` (`async` closure body)
64+
= note: expected opaque type `impl Future<Output = ()>` (`async` closure body)
65+
found opaque type `impl Future<Output = ()>` (`async` closure body)
5766
note: function defined here
5867
--> $DIR/generator-desc.rs:8:4
5968
|
6069
LL | fn fun<F: Future<Output = ()>>(f1: F, f2: F) {}
6170
| ^^^ ----- -----
62-
help: consider `await`ing on the `Future`
63-
|
64-
LL | fun((async || {})(), (async || {})().await);
65-
| ++++++
6671

6772
error: aborting due to 3 previous errors
6873

src/test/ui/async-await/suggest-missing-await.stderr

+7-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,13 @@ LL | |
6060
LL | | };
6161
| |_____- `if` and `else` have incompatible types
6262
|
63-
= note: expected type `impl Future<Output = ()>`
64-
found unit type `()`
63+
note: while checking the return type of the `async fn`
64+
--> $DIR/suggest-missing-await.rs:18:18
65+
|
66+
LL | async fn dummy() {}
67+
| ^ checked the `Output` of this `async fn`, expected opaque type
68+
= note: expected opaque type `impl Future<Output = ()>`
69+
found unit type `()`
6570
help: consider `await`ing on the `Future`
6671
|
6772
LL | dummy().await

src/test/ui/borrowck/suggest-local-var-imm-and-mut.nll.stderr

-22
This file was deleted.

src/test/ui/closures/closure_cap_coerce_many_fail.stderr

+20-11
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,27 @@ LL | | _ => unimplemented!(),
1111
LL | | };
1212
| |_____- `match` arms have incompatible types
1313
|
14-
= note: expected type `fn(i32, i32) -> i32 {add}`
15-
found closure `[closure@$DIR/closure_cap_coerce_many_fail.rs:9:16: 9:43]`
14+
= note: expected fn item `fn(i32, i32) -> i32 {add}`
15+
found closure `[closure@$DIR/closure_cap_coerce_many_fail.rs:9:16: 9:43]`
1616

1717
error[E0308]: `match` arms have incompatible types
1818
--> $DIR/closure_cap_coerce_many_fail.rs:18:16
1919
|
2020
LL | let _ = match "+" {
2121
| _____________-
2222
LL | | "+" => |a, b| (a + b) as i32,
23-
| | --------------------- this is found to be of type `[closure@$DIR/closure_cap_coerce_many_fail.rs:17:16: 17:37]`
23+
| | ---------------------
24+
| | |
25+
| | the expected closure
26+
| | this is found to be of type `[closure@$DIR/closure_cap_coerce_many_fail.rs:17:16: 17:37]`
2427
LL | | "-" => |a, b| (a - b + cap) as i32,
2528
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected closure, found a different closure
2629
LL | | _ => unimplemented!(),
2730
LL | | };
2831
| |_____- `match` arms have incompatible types
2932
|
30-
= note: expected type `[closure@$DIR/closure_cap_coerce_many_fail.rs:17:16: 17:37]`
31-
found closure `[closure@$DIR/closure_cap_coerce_many_fail.rs:18:16: 18:43]`
33+
= note: expected closure `[closure@$DIR/closure_cap_coerce_many_fail.rs:17:16: 17:37]`
34+
found closure `[closure@$DIR/closure_cap_coerce_many_fail.rs:18:16: 18:43]`
3235
= note: no two closures, even if identical, have the same type
3336
= help: consider boxing your closure and/or using it as a trait object
3437

@@ -38,15 +41,18 @@ error[E0308]: `match` arms have incompatible types
3841
LL | let _ = match "+" {
3942
| _____________-
4043
LL | | "+" => |a, b| (a + b + cap) as i32,
41-
| | --------------------------- this is found to be of type `[closure@$DIR/closure_cap_coerce_many_fail.rs:26:16: 26:43]`
44+
| | ---------------------------
45+
| | |
46+
| | the expected closure
47+
| | this is found to be of type `[closure@$DIR/closure_cap_coerce_many_fail.rs:26:16: 26:43]`
4248
LL | | "-" => |a, b| (a - b) as i32,
4349
| | ^^^^^^^^^^^^^^^^^^^^^ expected closure, found a different closure
4450
LL | | _ => unimplemented!(),
4551
LL | | };
4652
| |_____- `match` arms have incompatible types
4753
|
48-
= note: expected type `[closure@$DIR/closure_cap_coerce_many_fail.rs:26:16: 26:43]`
49-
found closure `[closure@$DIR/closure_cap_coerce_many_fail.rs:27:16: 27:37]`
54+
= note: expected closure `[closure@$DIR/closure_cap_coerce_many_fail.rs:26:16: 26:43]`
55+
found closure `[closure@$DIR/closure_cap_coerce_many_fail.rs:27:16: 27:37]`
5056
= note: no two closures, even if identical, have the same type
5157
= help: consider boxing your closure and/or using it as a trait object
5258

@@ -56,15 +62,18 @@ error[E0308]: `match` arms have incompatible types
5662
LL | let _ = match "+" {
5763
| _____________-
5864
LL | | "+" => |a, b| (a + b + cap) as i32,
59-
| | --------------------------- this is found to be of type `[closure@$DIR/closure_cap_coerce_many_fail.rs:34:16: 34:43]`
65+
| | ---------------------------
66+
| | |
67+
| | the expected closure
68+
| | this is found to be of type `[closure@$DIR/closure_cap_coerce_many_fail.rs:34:16: 34:43]`
6069
LL | | "-" => |a, b| (a - b + cap) as i32,
6170
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected closure, found a different closure
6271
LL | | _ => unimplemented!(),
6372
LL | | };
6473
| |_____- `match` arms have incompatible types
6574
|
66-
= note: expected type `[closure@$DIR/closure_cap_coerce_many_fail.rs:34:16: 34:43]`
67-
found closure `[closure@$DIR/closure_cap_coerce_many_fail.rs:35:16: 35:43]`
75+
= note: expected closure `[closure@$DIR/closure_cap_coerce_many_fail.rs:34:16: 34:43]`
76+
found closure `[closure@$DIR/closure_cap_coerce_many_fail.rs:35:16: 35:43]`
6877
= note: no two closures, even if identical, have the same type
6978
= help: consider boxing your closure and/or using it as a trait object
7079

src/test/ui/coercion/coerce-reborrow-multi-arg-fail.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ LL | test(&mut 7, &7);
66
| |
77
| arguments to this function are incorrect
88
|
9-
= note: expected type `&mut {integer}`
10-
found reference `&{integer}`
9+
= note: expected mutable reference `&mut {integer}`
10+
found reference `&{integer}`
1111
note: function defined here
1212
--> $DIR/coerce-reborrow-multi-arg-fail.rs:1:4
1313
|

src/test/ui/destructuring-assignment/default-match-bindings-forbidden.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ LL | (x, y) = &(1, 2);
66
| |
77
| expected reference, found tuple
88
|
9-
= note: expected type `&({integer}, {integer})`
10-
found tuple `(_, _)`
9+
= note: expected reference `&({integer}, {integer})`
10+
found tuple `(_, _)`
1111

1212
error: aborting due to previous error
1313

src/test/ui/destructuring-assignment/tuple_destructure_fail.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ LL | (a, a, b) = (1, 2);
1414
| |
1515
| expected a tuple with 2 elements, found one with 3 elements
1616
|
17-
= note: expected type `({integer}, {integer})`
18-
found tuple `(_, _, _)`
17+
= note: expected tuple `({integer}, {integer})`
18+
found tuple `(_, _, _)`
1919

2020
error[E0070]: invalid left-hand side of assignment
2121
--> $DIR/tuple_destructure_fail.rs:7:13
@@ -33,8 +33,8 @@ LL | (_,) = (1, 2);
3333
| |
3434
| expected a tuple with 2 elements, found one with 1 element
3535
|
36-
= note: expected type `({integer}, {integer})`
37-
found tuple `(_,)`
36+
= note: expected tuple `({integer}, {integer})`
37+
found tuple `(_,)`
3838

3939
error: aborting due to 4 previous errors
4040

src/test/ui/error-codes/E0502.nll.stderr

-13
This file was deleted.

src/test/ui/fn/fn-item-type.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl<T> Foo for T { /* `foo` is still default here */ }
1212
fn main() {
1313
eq(foo::<u8>, bar::<u8>);
1414
//~^ ERROR mismatched types
15-
//~| expected type `fn(_) -> _ {foo::<u8>}`
15+
//~| expected fn item `fn(_) -> _ {foo::<u8>}`
1616
//~| found fn item `fn(_) -> _ {bar::<u8>}`
1717
//~| expected fn item, found a different fn item
1818
//~| different `fn` items always have unique types, even if their signatures are the same
@@ -28,7 +28,6 @@ fn main() {
2828

2929
eq(bar::<String>, bar::<Vec<u8>>);
3030
//~^ ERROR mismatched types
31-
//~| expected type `fn(_) -> _ {bar::<String>}`
3231
//~| found fn item `fn(_) -> _ {bar::<Vec<u8>>}`
3332
//~| expected struct `String`, found struct `Vec`
3433
//~| different `fn` items always have unique types, even if their signatures are the same
@@ -45,7 +44,6 @@ fn main() {
4544

4645
eq(foo::<u8>, bar::<u8> as fn(isize) -> isize);
4746
//~^ ERROR mismatched types
48-
//~| expected type `fn(_) -> _ {foo::<u8>}`
4947
//~| found fn pointer `fn(_) -> _`
5048
//~| expected fn item, found fn pointer
5149
//~| change the expected type to be function pointer

0 commit comments

Comments
 (0)