Skip to content

Commit 8aa7fde

Browse files
committed
more-logical approach for drilling into types
1 parent a411304 commit 8aa7fde

File tree

7 files changed

+690
-533
lines changed

7 files changed

+690
-533
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

+457
Large diffs are not rendered by default.

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+60-479
Large diffs are not rendered by default.

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod _impl;
2+
mod adjust_fulfillment_errors;
23
mod arg_matrix;
34
mod checks;
45
mod suggestions;

src/test/ui/higher-rank-trait-bounds/issue-62203-hrtb-ice.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,14 @@ trait Ty<'a> {
3535
}
3636

3737
fn main() {
38-
let v = Unit2.m(
39-
L {
40-
//~^ ERROR type mismatch
41-
f: |x| {
42-
//~^ ERROR to be a closure that returns `Unit3`, but it returns `Unit4`
43-
drop(x);
44-
Unit4
45-
},
38+
let v = Unit2.m(L {
39+
//~^ ERROR type mismatch
40+
//~| ERROR to be a closure that returns `Unit3`, but it returns `Unit4`
41+
f: |x| {
42+
drop(x);
43+
Unit4
4644
},
47-
);
45+
});
4846
}
4947

5048
impl<'a> Ty<'a> for Unit2 {

src/test/ui/higher-rank-trait-bounds/issue-62203-hrtb-ice.stderr

+23-21
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
error[E0271]: type mismatch resolving `for<'r> <L<[closure@$DIR/issue-62203-hrtb-ice.rs:41:16: 41:19]> as T0<'r, (&'r u8,)>>::O == <_ as Ty<'r>>::V`
2-
--> $DIR/issue-62203-hrtb-ice.rs:39:9
1+
error[E0271]: type mismatch resolving `for<'r> <L<[closure@$DIR/issue-62203-hrtb-ice.rs:41:12: 41:15]> as T0<'r, (&'r u8,)>>::O == <_ as Ty<'r>>::V`
2+
--> $DIR/issue-62203-hrtb-ice.rs:38:21
33
|
4-
LL | let v = Unit2.m(
5-
| - required by a bound introduced by this call
6-
LL | / L {
4+
LL | let v = Unit2.m(L {
5+
| ___________________-_^
6+
| | |
7+
| | required by a bound introduced by this call
78
LL | |
8-
LL | | f: |x| {
99
LL | |
10+
LL | | f: |x| {
1011
... |
11-
LL | | },
1212
LL | | },
13-
| |_________^ type mismatch resolving `for<'r> <L<[closure@$DIR/issue-62203-hrtb-ice.rs:41:16: 41:19]> as T0<'r, (&'r u8,)>>::O == <_ as Ty<'r>>::V`
13+
LL | | });
14+
| |_____^ type mismatch resolving `for<'r> <L<[closure@$DIR/issue-62203-hrtb-ice.rs:41:12: 41:15]> as T0<'r, (&'r u8,)>>::O == <_ as Ty<'r>>::V`
1415
|
1516
note: expected this to be `<_ as Ty<'_>>::V`
1617
--> $DIR/issue-62203-hrtb-ice.rs:21:14
@@ -30,21 +31,22 @@ LL | where
3031
LL | F: for<'r> T0<'r, (<Self as Ty<'r>>::V,), O = <B as Ty<'r>>::V>,
3132
| ^^^^^^^^^^^^^^^^^^^^ required by this bound in `T1::m`
3233

33-
error[E0271]: expected `[[email protected]:41:16]` to be a closure that returns `Unit3`, but it returns `Unit4`
34-
--> $DIR/issue-62203-hrtb-ice.rs:41:16
35-
|
36-
LL | let v = Unit2.m(
37-
| - required by a bound introduced by this call
38-
...
39-
LL | f: |x| {
40-
| ________________^
34+
error[E0271]: expected `[[email protected]:41:12]` to be a closure that returns `Unit3`, but it returns `Unit4`
35+
--> $DIR/issue-62203-hrtb-ice.rs:38:21
36+
|
37+
LL | let v = Unit2.m(L {
38+
| ___________________-_^
39+
| | |
40+
| | required by a bound introduced by this call
41+
LL | |
4142
LL | |
42-
LL | | drop(x);
43-
LL | | Unit4
44-
LL | | },
45-
| |_____________^ expected struct `Unit3`, found struct `Unit4`
43+
LL | | f: |x| {
44+
... |
45+
LL | | },
46+
LL | | });
47+
| |_____^ expected struct `Unit3`, found struct `Unit4`
4648
|
47-
note: required for `L<[closure@$DIR/issue-62203-hrtb-ice.rs:41:16: 41:19]>` to implement `for<'r> T0<'r, (&'r u8,)>`
49+
note: required for `L<[closure@$DIR/issue-62203-hrtb-ice.rs:41:12: 41:15]>` to implement `for<'r> T0<'r, (&'r u8,)>`
4850
--> $DIR/issue-62203-hrtb-ice.rs:17:16
4951
|
5052
LL | impl<'a, A, T> T0<'a, A> for L<T>

src/test/ui/traits/bad-trait-error-span-in-call.rs

+21
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl<X, Y: T3> T2 for GenericBurrito<X, Y> {}
4848
struct NotSpicy;
4949

5050
impl<A: T3, B: T3> T2 for (A, B) {}
51+
impl<A: T2, B: T2> T1 for (A, B) {}
5152

5253
fn want<V: T1>(_x: V) {}
5354

@@ -64,6 +65,12 @@ struct Two<A, B> {
6465

6566
impl<X, Y: T1, Z> T1 for Two<Two<X, Y>, Z> {}
6667

68+
struct DoubleWrapper<T> {
69+
item: Wrapper<T>,
70+
}
71+
72+
impl<T: T1> T1 for DoubleWrapper<T> {}
73+
6774
fn example<Q>(q: Q) {
6875
// In each of the following examples, we expect the error span to point at the 'q' variable,
6976
// since the missing constraint is `Q: T3`.
@@ -89,9 +96,23 @@ fn example<Q>(q: Q) {
8996
//~^ ERROR the trait bound `Q: T3` is not satisfied [E0277]
9097

9198
// Verifies for tuple:
99+
want((3, q));
100+
//~^ ERROR the trait bound `Q: T2` is not satisfied [E0277]
101+
102+
// Verifies for nested tuple:
92103
want(Wrapper { value: (3, q) });
93104
//~^ ERROR the trait bound `Q: T3` is not satisfied [E0277]
94105

106+
// Verifies for nested tuple:
107+
want(((3, q), 5));
108+
//~^ ERROR the trait bound `Q: T3` is not satisfied [E0277]
109+
110+
want(DoubleWrapper { item: Wrapper { value: q } });
111+
//~^ ERROR the trait bound `Q: T1` is not satisfied [E0277]
112+
113+
want(DoubleWrapper { item: Wrapper { value: DoubleWrapper { item: Wrapper { value: q } } } });
114+
//~^ ERROR the trait bound `Q: T1` is not satisfied [E0277]
115+
95116
// Verifies for type alias to struct:
96117
want(Wrapper { value: AliasBurrito { spiciness: q, filling: q } });
97118
//~^ ERROR the trait bound `Q: T3` is not satisfied [E0277]

0 commit comments

Comments
 (0)