Skip to content

Commit 99d5f3b

Browse files
Stop inverting expectation in normalization errors
1 parent e7c0d27 commit 99d5f3b

19 files changed

+48
-82
lines changed

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

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

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

13011288
if let Err(new_err) =
1302-
ocx.eq(&obligation.cause, obligation.param_env, expected, actual)
1289+
ocx.eq(&obligation.cause, obligation.param_env, data.term, normalized_term)
13031290
{
13041291
(
13051292
Some((
13061293
data.projection_term,
1307-
is_normalized_term_expected,
1294+
false,
13081295
self.resolve_vars_if_possible(normalized_term),
13091296
data.term,
13101297
)),
@@ -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
true,

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

Lines changed: 4 additions & 6 deletions
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> {

tests/ui/coroutine/type-mismatch-signature-deduction.stderr

Lines changed: 3 additions & 3 deletions
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

tests/ui/diagnostic_namespace/do_not_recommend/as_expression.next.stderr

Lines changed: 1 addition & 4 deletions
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

tests/ui/impl-trait/bound-normalization-fail.stderr

Lines changed: 6 additions & 6 deletions
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> {

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

Lines changed: 1 addition & 1 deletion
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

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

Lines changed: 1 addition & 1 deletion
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

tests/ui/impl-trait/issues/issue-78722.stderr

Lines changed: 1 addition & 1 deletion
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

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

Lines changed: 1 addition & 1 deletion
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;

tests/ui/issues/issue-33941.stderr

Lines changed: 3 additions & 3 deletions
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

0 commit comments

Comments
 (0)