Skip to content

Commit 52e2065

Browse files
Revert closure mismatch spans
1 parent 3a1aa3c commit 52e2065

File tree

9 files changed

+94
-133
lines changed

9 files changed

+94
-133
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16301630
{
16311631
return;
16321632
}
1633+
// Skip over closure arg mismatch, which has a better heuristic
1634+
// to determine what span to point at.
1635+
if let traits::FulfillmentErrorCode::CodeSelectionError(
1636+
traits::SelectionError::OutputTypeParameterMismatch(_, expected, _),
1637+
) = error.code
1638+
&& let ty::Closure(..) | ty::Generator(..) = expected.skip_binder().self_ty().kind()
1639+
{
1640+
return;
1641+
}
16331642

16341643
let Some(unsubstituted_pred) =
16351644
self.tcx.predicates_of(def_id).instantiate_identity(self.tcx).predicates.into_iter().nth(idx) else { return; };

src/test/ui/anonymous-higher-ranked-lifetime.stderr

Lines changed: 44 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
error[E0631]: type mismatch in closure arguments
2-
--> $DIR/anonymous-higher-ranked-lifetime.rs:2:8
2+
--> $DIR/anonymous-higher-ranked-lifetime.rs:2:5
33
|
44
LL | f1(|_: (), _: ()| {});
5-
| -- --------------^^^
6-
| | |
7-
| | expected due to this
8-
| | found signature defined here
9-
| required by a bound introduced by this call
5+
| ^^ -------------- found signature defined here
6+
| |
7+
| expected due to this
108
|
119
= note: expected closure signature `for<'r, 's> fn(&'r (), &'s ()) -> _`
1210
found closure signature `fn((), ()) -> _`
@@ -17,14 +15,12 @@ LL | fn f1<F>(_: F) where F: Fn(&(), &()) {}
1715
| ^^^^^^^^^^^^ required by this bound in `f1`
1816

1917
error[E0631]: type mismatch in closure arguments
20-
--> $DIR/anonymous-higher-ranked-lifetime.rs:3:8
18+
--> $DIR/anonymous-higher-ranked-lifetime.rs:3:5
2119
|
2220
LL | f2(|_: (), _: ()| {});
23-
| -- --------------^^^
24-
| | |
25-
| | expected due to this
26-
| | found signature defined here
27-
| required by a bound introduced by this call
21+
| ^^ -------------- found signature defined here
22+
| |
23+
| expected due to this
2824
|
2925
= note: expected closure signature `for<'a, 'r> fn(&'a (), &'r ()) -> _`
3026
found closure signature `fn((), ()) -> _`
@@ -35,14 +31,12 @@ LL | fn f2<F>(_: F) where F: for<'a> Fn(&'a (), &()) {}
3531
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `f2`
3632

3733
error[E0631]: type mismatch in closure arguments
38-
--> $DIR/anonymous-higher-ranked-lifetime.rs:4:8
34+
--> $DIR/anonymous-higher-ranked-lifetime.rs:4:5
3935
|
4036
LL | f3(|_: (), _: ()| {});
41-
| -- --------------^^^
42-
| | |
43-
| | expected due to this
44-
| | found signature defined here
45-
| required by a bound introduced by this call
37+
| ^^ -------------- found signature defined here
38+
| |
39+
| expected due to this
4640
|
4741
= note: expected closure signature `for<'r> fn(&(), &'r ()) -> _`
4842
found closure signature `fn((), ()) -> _`
@@ -53,14 +47,12 @@ LL | fn f3<'a, F>(_: F) where F: Fn(&'a (), &()) {}
5347
| ^^^^^^^^^^^^^^^ required by this bound in `f3`
5448

5549
error[E0631]: type mismatch in closure arguments
56-
--> $DIR/anonymous-higher-ranked-lifetime.rs:5:8
50+
--> $DIR/anonymous-higher-ranked-lifetime.rs:5:5
5751
|
5852
LL | f4(|_: (), _: ()| {});
59-
| -- --------------^^^
60-
| | |
61-
| | expected due to this
62-
| | found signature defined here
63-
| required by a bound introduced by this call
53+
| ^^ -------------- found signature defined here
54+
| |
55+
| expected due to this
6456
|
6557
= note: expected closure signature `for<'r, 's> fn(&'s (), &'r ()) -> _`
6658
found closure signature `fn((), ()) -> _`
@@ -71,14 +63,12 @@ LL | fn f4<F>(_: F) where F: for<'r> Fn(&(), &'r ()) {}
7163
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `f4`
7264

7365
error[E0631]: type mismatch in closure arguments
74-
--> $DIR/anonymous-higher-ranked-lifetime.rs:6:8
66+
--> $DIR/anonymous-higher-ranked-lifetime.rs:6:5
7567
|
7668
LL | f5(|_: (), _: ()| {});
77-
| -- --------------^^^
78-
| | |
79-
| | expected due to this
80-
| | found signature defined here
81-
| required by a bound introduced by this call
69+
| ^^ -------------- found signature defined here
70+
| |
71+
| expected due to this
8272
|
8373
= note: expected closure signature `for<'r> fn(&'r (), &'r ()) -> _`
8474
found closure signature `fn((), ()) -> _`
@@ -89,14 +79,12 @@ LL | fn f5<F>(_: F) where F: for<'r> Fn(&'r (), &'r ()) {}
8979
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `f5`
9080

9181
error[E0631]: type mismatch in closure arguments
92-
--> $DIR/anonymous-higher-ranked-lifetime.rs:7:8
82+
--> $DIR/anonymous-higher-ranked-lifetime.rs:7:5
9383
|
9484
LL | g1(|_: (), _: ()| {});
95-
| -- --------------^^^
96-
| | |
97-
| | expected due to this
98-
| | found signature defined here
99-
| required by a bound introduced by this call
85+
| ^^ -------------- found signature defined here
86+
| |
87+
| expected due to this
10088
|
10189
= note: expected closure signature `for<'r> fn(&'r (), Box<(dyn for<'r> Fn(&'r ()) + 'static)>) -> _`
10290
found closure signature `fn((), ()) -> _`
@@ -107,14 +95,12 @@ LL | fn g1<F>(_: F) where F: Fn(&(), Box<dyn Fn(&())>) {}
10795
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `g1`
10896

10997
error[E0631]: type mismatch in closure arguments
110-
--> $DIR/anonymous-higher-ranked-lifetime.rs:8:8
98+
--> $DIR/anonymous-higher-ranked-lifetime.rs:8:5
11199
|
112100
LL | g2(|_: (), _: ()| {});
113-
| -- --------------^^^
114-
| | |
115-
| | expected due to this
116-
| | found signature defined here
117-
| required by a bound introduced by this call
101+
| ^^ -------------- found signature defined here
102+
| |
103+
| expected due to this
118104
|
119105
= note: expected closure signature `for<'r> fn(&'r (), for<'r> fn(&'r ())) -> _`
120106
found closure signature `fn((), ()) -> _`
@@ -125,14 +111,12 @@ LL | fn g2<F>(_: F) where F: Fn(&(), fn(&())) {}
125111
| ^^^^^^^^^^^^^^^^ required by this bound in `g2`
126112

127113
error[E0631]: type mismatch in closure arguments
128-
--> $DIR/anonymous-higher-ranked-lifetime.rs:9:8
114+
--> $DIR/anonymous-higher-ranked-lifetime.rs:9:5
129115
|
130116
LL | g3(|_: (), _: ()| {});
131-
| -- --------------^^^
132-
| | |
133-
| | expected due to this
134-
| | found signature defined here
135-
| required by a bound introduced by this call
117+
| ^^ -------------- found signature defined here
118+
| |
119+
| expected due to this
136120
|
137121
= note: expected closure signature `for<'s> fn(&'s (), Box<(dyn for<'r> Fn(&'r ()) + 'static)>) -> _`
138122
found closure signature `fn((), ()) -> _`
@@ -143,14 +127,12 @@ LL | fn g3<F>(_: F) where F: for<'s> Fn(&'s (), Box<dyn Fn(&())>) {}
143127
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `g3`
144128

145129
error[E0631]: type mismatch in closure arguments
146-
--> $DIR/anonymous-higher-ranked-lifetime.rs:10:8
130+
--> $DIR/anonymous-higher-ranked-lifetime.rs:10:5
147131
|
148132
LL | g4(|_: (), _: ()| {});
149-
| -- --------------^^^
150-
| | |
151-
| | expected due to this
152-
| | found signature defined here
153-
| required by a bound introduced by this call
133+
| ^^ -------------- found signature defined here
134+
| |
135+
| expected due to this
154136
|
155137
= note: expected closure signature `for<'s> fn(&'s (), for<'r> fn(&'r ())) -> _`
156138
found closure signature `fn((), ()) -> _`
@@ -161,14 +143,12 @@ LL | fn g4<F>(_: F) where F: Fn(&(), for<'r> fn(&'r ())) {}
161143
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `g4`
162144

163145
error[E0631]: type mismatch in closure arguments
164-
--> $DIR/anonymous-higher-ranked-lifetime.rs:11:8
146+
--> $DIR/anonymous-higher-ranked-lifetime.rs:11:5
165147
|
166148
LL | h1(|_: (), _: (), _: (), _: ()| {});
167-
| -- ----------------------------^^^
168-
| | |
169-
| | expected due to this
170-
| | found signature defined here
171-
| required by a bound introduced by this call
149+
| ^^ ---------------------------- found signature defined here
150+
| |
151+
| expected due to this
172152
|
173153
= note: expected closure signature `for<'r, 's> fn(&'r (), Box<(dyn for<'r> Fn(&'r ()) + 'static)>, &'s (), for<'r, 's> fn(&'r (), &'s ())) -> _`
174154
found closure signature `fn((), (), (), ()) -> _`
@@ -179,14 +159,12 @@ LL | fn h1<F>(_: F) where F: Fn(&(), Box<dyn Fn(&())>, &(), fn(&(), &())) {}
179159
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `h1`
180160

181161
error[E0631]: type mismatch in closure arguments
182-
--> $DIR/anonymous-higher-ranked-lifetime.rs:12:8
162+
--> $DIR/anonymous-higher-ranked-lifetime.rs:12:5
183163
|
184164
LL | h2(|_: (), _: (), _: (), _: ()| {});
185-
| -- ----------------------------^^^
186-
| | |
187-
| | expected due to this
188-
| | found signature defined here
189-
| required by a bound introduced by this call
165+
| ^^ ---------------------------- found signature defined here
166+
| |
167+
| expected due to this
190168
|
191169
= note: expected closure signature `for<'t0, 'r> fn(&'r (), Box<(dyn for<'r> Fn(&'r ()) + 'static)>, &'t0 (), for<'r, 's> fn(&'r (), &'s ())) -> _`
192170
found closure signature `fn((), (), (), ()) -> _`

src/test/ui/closure-expected-type/expect-infer-var-appearing-twice.stderr

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
error[E0631]: type mismatch in closure arguments
2-
--> $DIR/expect-infer-var-appearing-twice.rs:14:18
2+
--> $DIR/expect-infer-var-appearing-twice.rs:14:5
33
|
4-
LL | with_closure(|x: u32, y: i32| {
5-
| ------------ ^---------------
6-
| | |
7-
| _____|____________found signature defined here
8-
| | |
9-
| | required by a bound introduced by this call
10-
LL | |
11-
LL | | });
12-
| |_____^ expected due to this
4+
LL | with_closure(|x: u32, y: i32| {
5+
| ^^^^^^^^^^^^ ---------------- found signature defined here
6+
| |
7+
| expected due to this
138
|
149
= note: expected closure signature `fn(_, _) -> _`
1510
found closure signature `fn(u32, i32) -> _`

src/test/ui/mismatched_types/E0631.stderr

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
error[E0631]: type mismatch in closure arguments
2-
--> $DIR/E0631.rs:7:9
2+
--> $DIR/E0631.rs:7:5
33
|
44
LL | foo(|_: isize| {});
5-
| --- ----------^^^
6-
| | |
7-
| | expected due to this
8-
| | found signature defined here
9-
| required by a bound introduced by this call
5+
| ^^^ ---------- found signature defined here
6+
| |
7+
| expected due to this
108
|
119
= note: expected closure signature `fn(usize) -> _`
1210
found closure signature `fn(isize) -> _`
@@ -17,14 +15,12 @@ LL | fn foo<F: Fn(usize)>(_: F) {}
1715
| ^^^^^^^^^ required by this bound in `foo`
1816

1917
error[E0631]: type mismatch in closure arguments
20-
--> $DIR/E0631.rs:8:9
18+
--> $DIR/E0631.rs:8:5
2119
|
2220
LL | bar(|_: isize| {});
23-
| --- ----------^^^
24-
| | |
25-
| | expected due to this
26-
| | found signature defined here
27-
| required by a bound introduced by this call
21+
| ^^^ ---------- found signature defined here
22+
| |
23+
| expected due to this
2824
|
2925
= note: expected closure signature `fn(usize) -> _`
3026
found closure signature `fn(isize) -> _`

src/test/ui/mismatched_types/closure-arg-count.stderr

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,12 @@ LL | [1, 2, 3].sort_by(|tuple, tuple2| panic!());
4646
| ~~~~~~~~~~~~~~~
4747

4848
error[E0593]: closure is expected to take 1 argument, but it takes 0 arguments
49-
--> $DIR/closure-arg-count.rs:13:7
49+
--> $DIR/closure-arg-count.rs:13:5
5050
|
5151
LL | f(|| panic!());
52-
| - --^^^^^^^^^
53-
| | |
54-
| | expected closure that takes 1 argument
55-
| | takes 0 arguments
56-
| required by a bound introduced by this call
52+
| ^ -- takes 0 arguments
53+
| |
54+
| expected closure that takes 1 argument
5755
|
5856
note: required by a bound in `f`
5957
--> $DIR/closure-arg-count.rs:3:9
@@ -66,14 +64,12 @@ LL | f(|_| panic!());
6664
| ~~~
6765

6866
error[E0593]: closure is expected to take 1 argument, but it takes 0 arguments
69-
--> $DIR/closure-arg-count.rs:15:9
67+
--> $DIR/closure-arg-count.rs:15:5
7068
|
7169
LL | f( move || panic!());
72-
| - ----------^^^^^^^^^
73-
| | |
74-
| | expected closure that takes 1 argument
75-
| | takes 0 arguments
76-
| required by a bound introduced by this call
70+
| ^ ---------- takes 0 arguments
71+
| |
72+
| expected closure that takes 1 argument
7773
|
7874
note: required by a bound in `f`
7975
--> $DIR/closure-arg-count.rs:3:9
@@ -137,14 +133,12 @@ LL | F: FnMut(Self::Item) -> B,
137133
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `map`
138134

139135
error[E0593]: closure is expected to take a single 2-tuple as argument, but it takes 3 distinct arguments
140-
--> $DIR/closure-arg-count.rs:27:57
136+
--> $DIR/closure-arg-count.rs:27:53
141137
|
142138
LL | let bar = |i, x, y| i;
143139
| --------- takes 3 distinct arguments
144140
LL | let _it = vec![1, 2, 3].into_iter().enumerate().map(bar);
145-
| --- ^^^ expected closure that takes a single 2-tuple as argument
146-
| |
147-
| required by a bound introduced by this call
141+
| ^^^ expected closure that takes a single 2-tuple as argument
148142
|
149143
note: required by a bound in `map`
150144
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL

src/test/ui/mismatched_types/closure-arg-type-mismatch.stderr

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
error[E0631]: type mismatch in closure arguments
2-
--> $DIR/closure-arg-type-mismatch.rs:3:18
2+
--> $DIR/closure-arg-type-mismatch.rs:3:14
33
|
44
LL | a.iter().map(|_: (u32, u32)| 45);
5-
| --- ---------------^^^
6-
| | |
7-
| | expected due to this
8-
| | found signature defined here
9-
| required by a bound introduced by this call
5+
| ^^^ --------------- found signature defined here
6+
| |
7+
| expected due to this
108
|
119
= note: expected closure signature `fn(&(u32, u32)) -> _`
1210
found closure signature `fn((u32, u32)) -> _`
@@ -17,14 +15,12 @@ LL | F: FnMut(Self::Item) -> B,
1715
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `map`
1816

1917
error[E0631]: type mismatch in closure arguments
20-
--> $DIR/closure-arg-type-mismatch.rs:4:18
18+
--> $DIR/closure-arg-type-mismatch.rs:4:14
2119
|
2220
LL | a.iter().map(|_: &(u16, u16)| 45);
23-
| --- ----------------^^^
24-
| | |
25-
| | expected due to this
26-
| | found signature defined here
27-
| required by a bound introduced by this call
21+
| ^^^ ---------------- found signature defined here
22+
| |
23+
| expected due to this
2824
|
2925
= note: expected closure signature `fn(&(u32, u32)) -> _`
3026
found closure signature `for<'r> fn(&'r (u16, u16)) -> _`
@@ -35,14 +31,12 @@ LL | F: FnMut(Self::Item) -> B,
3531
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `map`
3632

3733
error[E0631]: type mismatch in closure arguments
38-
--> $DIR/closure-arg-type-mismatch.rs:5:18
34+
--> $DIR/closure-arg-type-mismatch.rs:5:14
3935
|
4036
LL | a.iter().map(|_: (u16, u16)| 45);
41-
| --- ---------------^^^
42-
| | |
43-
| | expected due to this
44-
| | found signature defined here
45-
| required by a bound introduced by this call
37+
| ^^^ --------------- found signature defined here
38+
| |
39+
| expected due to this
4640
|
4741
= note: expected closure signature `fn(&(u32, u32)) -> _`
4842
found closure signature `fn((u16, u16)) -> _`

0 commit comments

Comments
 (0)