Skip to content

Commit 403e8ea

Browse files
authored
Unrolled build for rust-lang#131795
Rollup merge of rust-lang#131795 - compiler-errors:expectation, r=Nadrieril Stop inverting expectation in normalization errors We have some funky special case logic to invert the expectation and actual type for normalization errors depending on their cause code. IMO most of the error messages get better, except for `try {}` blocks' type expectations. I think that these need to be special cased in some other way, rather than via this hack. Fixes rust-lang#131763
2 parents da93539 + 99d5f3b commit 403e8ea

19 files changed

+48
-82
lines changed

Diff for: compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

+4-21
Original file line numberDiff line numberDiff line change
@@ -1277,19 +1277,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
12771277
let normalized_term =
12781278
ocx.normalize(&obligation.cause, obligation.param_env, unnormalized_term);
12791279

1280-
let is_normalized_term_expected = !matches!(
1281-
obligation.cause.code().peel_derives(),
1282-
ObligationCauseCode::WhereClause(..)
1283-
| ObligationCauseCode::WhereClauseInExpr(..)
1284-
| ObligationCauseCode::Coercion { .. }
1285-
);
1286-
1287-
let (expected, actual) = if is_normalized_term_expected {
1288-
(normalized_term, data.term)
1289-
} else {
1290-
(data.term, normalized_term)
1291-
};
1292-
12931280
// constrain inference variables a bit more to nested obligations from normalize so
12941281
// we can have more helpful errors.
12951282
//
@@ -1298,12 +1285,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
12981285
let _ = ocx.select_where_possible();
12991286

13001287
if let Err(new_err) =
1301-
ocx.eq(&obligation.cause, obligation.param_env, expected, actual)
1288+
ocx.eq(&obligation.cause, obligation.param_env, data.term, normalized_term)
13021289
{
13031290
(
13041291
Some((
13051292
data.projection_term,
1306-
is_normalized_term_expected,
1293+
false,
13071294
self.resolve_vars_if_possible(normalized_term),
13081295
data.term,
13091296
)),
@@ -1444,12 +1431,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
14441431
&mut diag,
14451432
&obligation.cause,
14461433
secondary_span,
1447-
values.map(|(_, is_normalized_ty_expected, normalized_ty, expected_ty)| {
1448-
infer::ValuePairs::Terms(ExpectedFound::new(
1449-
is_normalized_ty_expected,
1450-
normalized_ty,
1451-
expected_ty,
1452-
))
1434+
values.map(|(_, _, normalized_ty, expected_ty)| {
1435+
infer::ValuePairs::Terms(ExpectedFound::new(true, expected_ty, normalized_ty))
14531436
}),
14541437
err,
14551438
false,

Diff for: tests/ui/associated-types/impl-trait-return-missing-constraint.stderr

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ error[E0271]: type mismatch resolving `<impl Bar as Foo>::Item == i32`
22
--> $DIR/impl-trait-return-missing-constraint.rs:25:13
33
|
44
LL | fn bar() -> impl Bar {
5-
| -------- the expected opaque type
5+
| -------- the found opaque type
66
...
77
LL | fn baz() -> impl Bar<Item = i32> {
8-
| ^^^^^^^^^^^^^^^^^^^^ expected associated type, found `i32`
8+
| ^^^^^^^^^^^^^^^^^^^^ expected `i32`, found associated type
99
LL |
1010
LL | bar()
1111
| ----- return type was inferred to be `impl Bar` here
1212
|
13-
= note: expected associated type `<impl Bar as Foo>::Item`
14-
found type `i32`
15-
= help: consider constraining the associated type `<impl Bar as Foo>::Item` to `i32` or calling a method that returns `<impl Bar as Foo>::Item`
16-
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
13+
= note: expected type `i32`
14+
found associated type `<impl Bar as Foo>::Item`
1715
help: consider constraining the associated type `<impl Bar as Foo>::Item` to `i32`
1816
|
1917
LL | fn bar() -> impl Bar<Item = i32> {

Diff for: tests/ui/coroutine/type-mismatch-signature-deduction.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ error[E0271]: type mismatch resolving `<{coroutine@$DIR/type-mismatch-signature-
2222
--> $DIR/type-mismatch-signature-deduction.rs:5:13
2323
|
2424
LL | fn foo() -> impl Coroutine<Return = i32> {
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<{integer}, _>`, found `i32`
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `Result<{integer}, _>`
2626
|
27-
= note: expected enum `Result<{integer}, _>`
28-
found type `i32`
27+
= note: expected type `i32`
28+
found enum `Result<{integer}, _>`
2929

3030
error: aborting due to 2 previous errors
3131

Diff for: tests/ui/diagnostic_namespace/do_not_recommend/as_expression.next.stderr

+1-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ error[E0271]: type mismatch resolving `<SelectInt as Expression>::SqlType == Tex
2929
--> $DIR/as_expression.rs:57:5
3030
|
3131
LL | SelectInt.check("bar");
32-
| ^^^^^^^^^^^^^^^^^^^^^^ expected `Integer`, found `Text`
33-
|
34-
= note: expected struct `Integer`
35-
found struct `Text`
32+
| ^^^^^^^^^^^^^^^^^^^^^^ expected `Text`, found `Integer`
3633

3734
error: aborting due to 3 previous errors
3835

Diff for: tests/ui/impl-trait/bound-normalization-fail.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ LL |
77
LL | Foo(())
88
| ------- return type was inferred to be `Foo<()>` here
99
|
10-
note: expected this to be `()`
10+
note: expected this to be `<T as impl_trait::Trait>::Assoc`
1111
--> $DIR/bound-normalization-fail.rs:14:19
1212
|
1313
LL | type Output = T;
1414
| ^
15-
= note: expected unit type `()`
16-
found associated type `<T as impl_trait::Trait>::Assoc`
15+
= note: expected associated type `<T as impl_trait::Trait>::Assoc`
16+
found unit type `()`
1717
help: consider constraining the associated type `<T as impl_trait::Trait>::Assoc` to `()`
1818
|
1919
LL | fn foo_fail<T: Trait<Assoc = ()>>() -> impl FooLike<Output = T::Assoc> {
@@ -28,13 +28,13 @@ LL |
2828
LL | Foo(())
2929
| ------- return type was inferred to be `Foo<()>` here
3030
|
31-
note: expected this to be `()`
31+
note: expected this to be `<T as lifetimes::Trait<'a>>::Assoc`
3232
--> $DIR/bound-normalization-fail.rs:14:19
3333
|
3434
LL | type Output = T;
3535
| ^
36-
= note: expected unit type `()`
37-
found associated type `<T as lifetimes::Trait<'a>>::Assoc`
36+
= note: expected associated type `<T as lifetimes::Trait<'a>>::Assoc`
37+
found unit type `()`
3838
help: consider constraining the associated type `<T as lifetimes::Trait<'a>>::Assoc` to `()`
3939
|
4040
LL | fn foo2_fail<'a, T: Trait<'a, Assoc = ()>>() -> impl FooLike<Output = T::Assoc> {

Diff for: tests/ui/impl-trait/in-trait/default-body-type-err.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `<&i32 as Deref>::Target == String`
22
--> $DIR/default-body-type-err.rs:4:22
33
|
44
LL | fn lol(&self) -> impl Deref<Target = String> {
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `String`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `String`, found `i32`
66
LL |
77
LL | &1i32
88
| ----- return type was inferred to be `&i32` here

Diff for: tests/ui/impl-trait/issues/issue-78722-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ error[E0271]: expected `{async block@$DIR/issue-78722-2.rs:13:13: 13:18}` to be
1616
--> $DIR/issue-78722-2.rs:11:30
1717
|
1818
LL | fn concrete_use() -> F {
19-
| ^ expected `()`, found `u8`
19+
| ^ expected `u8`, found `()`
2020

2121
error: aborting due to 2 previous errors
2222

Diff for: tests/ui/impl-trait/issues/issue-78722.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ error[E0271]: expected `{async block@$DIR/issue-78722.rs:10:13: 10:18}` to be a
1212
--> $DIR/issue-78722.rs:8:30
1313
|
1414
LL | fn concrete_use() -> F {
15-
| ^ expected `()`, found `u8`
15+
| ^ expected `u8`, found `()`
1616

1717
error: aborting due to 2 previous errors
1818

Diff for: tests/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0271]: type mismatch resolving `<() as Super>::Assoc == ()`
44
LL | fn test() -> impl Test {
55
| ^^^^^^^^^ type mismatch resolving `<() as Super>::Assoc == ()`
66
|
7-
note: expected this to be `u8`
7+
note: expected this to be `()`
88
--> $DIR/projection-mismatch-in-impl-where-clause.rs:6:18
99
|
1010
LL | type Assoc = u8;

Diff for: tests/ui/issues/issue-33941.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ error[E0271]: expected `Iter<'_, _, _>` to be an iterator that yields `&_`, but
2020
--> $DIR/issue-33941.rs:6:14
2121
|
2222
LL | for _ in HashMap::new().iter().cloned() {}
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `(&_, &_)`, found `&_`
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&_`, found `(&_, &_)`
2424
|
25-
= note: expected tuple `(&_, &_)`
26-
found reference `&_`
25+
= note: expected reference `&_`
26+
found tuple `(&_, &_)`
2727
= note: required for `Cloned<std::collections::hash_map::Iter<'_, _, _>>` to implement `Iterator`
2828
= note: required for `Cloned<std::collections::hash_map::Iter<'_, _, _>>` to implement `IntoIterator`
2929

Diff for: tests/ui/issues/issue-67039-unsound-pin-partialeq.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ error[E0271]: type mismatch resolving `<Rc<Apple> as Deref>::Target == Rc<Apple>
22
--> $DIR/issue-67039-unsound-pin-partialeq.rs:25:29
33
|
44
LL | let _ = Pin::new(Apple) == Rc::pin(Apple);
5-
| ^^ expected `Apple`, found `Rc<Apple>`
5+
| ^^ expected `Rc<Apple>`, found `Apple`
66
|
7-
= note: expected struct `Apple`
8-
found struct `Rc<Apple>`
7+
= note: expected struct `Rc<Apple>`
8+
found struct `Apple`
99
= note: required for `Pin<Apple>` to implement `PartialEq<Pin<Rc<Apple>>>`
1010

1111
error: aborting due to 1 previous error

Diff for: tests/ui/lint/issue-106991.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0271]: expected `foo` to be a fn item that returns `i32`, but it returns
22
--> $DIR/issue-106991.rs:5:13
33
|
44
LL | fn bar() -> impl Iterator<Item = i32> {
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `i32`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `()`
66
|
77
= note: required for `Map<std::slice::IterMut<'_, Vec<u8>>, for<'a> fn(&'a mut Vec<u8>) {foo}>` to implement `Iterator`
88

Diff for: tests/ui/suggestions/trait-hidden-method.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ error[E0271]: expected `Box<dyn Iterator>` to be an iterator that yields `u32`,
88
--> $DIR/trait-hidden-method.rs:3:32
99
|
1010
LL | pub fn i_can_has_iterator() -> impl Iterator<Item = u32> {
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found `u32`
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u32`, found associated type
1212
...
1313
LL | Box::new(1..=10) as Box<dyn Iterator>
1414
| ------------------------------------- return type was inferred to be `Box<dyn Iterator>` here
1515
|
16-
= note: expected associated type `<dyn Iterator as Iterator>::Item`
17-
found type `u32`
18-
= help: consider constraining the associated type `<dyn Iterator as Iterator>::Item` to `u32` or calling a method that returns `<dyn Iterator as Iterator>::Item`
16+
= note: expected type `u32`
17+
found associated type `<dyn Iterator as Iterator>::Item`
18+
= help: consider constraining the associated type `<dyn Iterator as Iterator>::Item` to `u32`
1919
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
2020

2121
error: aborting due to 2 previous errors

Diff for: tests/ui/traits/next-solver/async.fail.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ error[E0271]: expected `{async block@$DIR/async.rs:12:17: 12:22}` to be a future
22
--> $DIR/async.rs:12:17
33
|
44
LL | needs_async(async {});
5-
| ----------- ^^^^^^^^ expected `()`, found `i32`
5+
| ----------- ^^^^^^^^ expected `i32`, found `()`
66
| |
77
| required by a bound introduced by this call
88
|
9-
= note: expected unit type `()`
10-
found type `i32`
119
note: required by a bound in `needs_async`
1210
--> $DIR/async.rs:8:31
1311
|

Diff for: tests/ui/traits/next-solver/more-object-bound.stderr

+5-10
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@ error[E0271]: type mismatch resolving `<dyn Trait<A = A, B = B> as SuperTrait>::
22
--> $DIR/more-object-bound.rs:12:5
33
|
44
LL | fn transmute<A, B>(x: A) -> B {
5-
| - -
6-
| | |
7-
| | expected type parameter
8-
| | found type parameter
5+
| - - expected type parameter
6+
| |
97
| found type parameter
10-
| expected type parameter
118
LL | foo::<A, B, dyn Trait<A = A, B = B>>(x)
12-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter `A`, found type parameter `B`
9+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter `B`, found type parameter `A`
1310
|
14-
= note: expected type parameter `A`
15-
found type parameter `B`
16-
= note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound
17-
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
11+
= note: expected type parameter `B`
12+
found type parameter `A`
1813
= note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound
1914
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
2015
= note: required because it appears within the type `dyn Trait<A = A, B = B>`

Diff for: tests/ui/try-block/try-block-bad-type.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ error[E0271]: type mismatch resolving `<Result<i32, i32> as Try>::Output == &str
1515
--> $DIR/try-block-bad-type.rs:12:9
1616
|
1717
LL | ""
18-
| ^^ expected `i32`, found `&str`
18+
| ^^ expected `&str`, found `i32`
1919

2020
error[E0271]: type mismatch resolving `<Result<i32, i32> as Try>::Output == ()`
2121
--> $DIR/try-block-bad-type.rs:15:39
2222
|
2323
LL | let res: Result<i32, i32> = try { };
24-
| ^ expected `i32`, found `()`
24+
| ^ expected `()`, found `i32`
2525

2626
error[E0277]: a `try` block must return `Result` or `Option` (or another type that implements `Try`)
2727
--> $DIR/try-block-bad-type.rs:17:25

Diff for: tests/ui/try-block/try-block-type-error.stderr

+2-7
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@ error[E0271]: type mismatch resolving `<Option<f32> as Try>::Output == {integer}
22
--> $DIR/try-block-type-error.rs:10:9
33
|
44
LL | 42
5-
| ^^ expected `f32`, found integer
6-
|
7-
help: use a float literal
8-
|
9-
LL | 42.0
10-
| ++
5+
| ^^ expected integer, found `f32`
116

127
error[E0271]: type mismatch resolving `<Option<i32> as Try>::Output == ()`
138
--> $DIR/try-block-type-error.rs:16:5
149
|
1510
LL | };
16-
| ^ expected `i32`, found `()`
11+
| ^ expected `()`, found `i32`
1712

1813
error: aborting due to 2 previous errors
1914

Diff for: tests/ui/type-alias-impl-trait/hidden_type_mismatch.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ error[E0271]: type mismatch resolving `<() as Proj>::Assoc == i32`
22
--> $DIR/hidden_type_mismatch.rs:43:9
33
|
44
LL | pub type Sep = impl Sized + std::fmt::Display;
5-
| ------------------------------ the expected opaque type
5+
| ------------------------------ the found opaque type
66
...
77
LL | Bar { inner: 1i32, _marker: () }
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<() as Proj>::Assoc == i32`
99
|
10-
note: expected this to be `Sep`
10+
note: expected this to be `i32`
1111
--> $DIR/hidden_type_mismatch.rs:20:22
1212
|
1313
LL | type Assoc = sus::Sep;
1414
| ^^^^^^^^
15-
= note: expected opaque type `Sep`
16-
found type `i32`
15+
= note: expected type `i32`
16+
found opaque type `Sep`
1717
note: required for `Bar<()>` to implement `Copy`
1818
--> $DIR/hidden_type_mismatch.rs:32:39
1919
|

Diff for: tests/ui/type-alias-impl-trait/issue-94429.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0271]: type mismatch resolving `<{coroutine@$DIR/issue-94429.rs:18:9: 18:
22
--> $DIR/issue-94429.rs:15:26
33
|
44
LL | fn run(&mut self) -> Self::Coro {
5-
| ^^^^^^^^^^ expected integer, found `()`
5+
| ^^^^^^^^^^ expected `()`, found integer
66

77
error: aborting due to 1 previous error
88

0 commit comments

Comments
 (0)