1
Fork 0

Revert closure mismatch spans

This commit is contained in:
Michael Goulet 2022-08-16 23:54:54 +00:00
parent 3a1aa3c76e
commit 52e2065ed4
9 changed files with 94 additions and 133 deletions

View file

@ -1630,6 +1630,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{ {
return; return;
} }
// Skip over closure arg mismatch, which has a better heuristic
// to determine what span to point at.
if let traits::FulfillmentErrorCode::CodeSelectionError(
traits::SelectionError::OutputTypeParameterMismatch(_, expected, _),
) = error.code
&& let ty::Closure(..) | ty::Generator(..) = expected.skip_binder().self_ty().kind()
{
return;
}
let Some(unsubstituted_pred) = let Some(unsubstituted_pred) =
self.tcx.predicates_of(def_id).instantiate_identity(self.tcx).predicates.into_iter().nth(idx) else { return; }; self.tcx.predicates_of(def_id).instantiate_identity(self.tcx).predicates.into_iter().nth(idx) else { return; };

View file

@ -1,12 +1,10 @@
error[E0631]: type mismatch in closure arguments error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:2:8 --> $DIR/anonymous-higher-ranked-lifetime.rs:2:5
| |
LL | f1(|_: (), _: ()| {}); LL | f1(|_: (), _: ()| {});
| -- --------------^^^ | ^^ -------------- found signature defined here
| | | | |
| | expected due to this | expected due to this
| | found signature defined here
| required by a bound introduced by this call
| |
= note: expected closure signature `for<'r, 's> fn(&'r (), &'s ()) -> _` = note: expected closure signature `for<'r, 's> fn(&'r (), &'s ()) -> _`
found closure signature `fn((), ()) -> _` found closure signature `fn((), ()) -> _`
@ -17,14 +15,12 @@ LL | fn f1<F>(_: F) where F: Fn(&(), &()) {}
| ^^^^^^^^^^^^ required by this bound in `f1` | ^^^^^^^^^^^^ required by this bound in `f1`
error[E0631]: type mismatch in closure arguments error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:3:8 --> $DIR/anonymous-higher-ranked-lifetime.rs:3:5
| |
LL | f2(|_: (), _: ()| {}); LL | f2(|_: (), _: ()| {});
| -- --------------^^^ | ^^ -------------- found signature defined here
| | | | |
| | expected due to this | expected due to this
| | found signature defined here
| required by a bound introduced by this call
| |
= note: expected closure signature `for<'a, 'r> fn(&'a (), &'r ()) -> _` = note: expected closure signature `for<'a, 'r> fn(&'a (), &'r ()) -> _`
found closure signature `fn((), ()) -> _` found closure signature `fn((), ()) -> _`
@ -35,14 +31,12 @@ LL | fn f2<F>(_: F) where F: for<'a> Fn(&'a (), &()) {}
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `f2` | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `f2`
error[E0631]: type mismatch in closure arguments error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:4:8 --> $DIR/anonymous-higher-ranked-lifetime.rs:4:5
| |
LL | f3(|_: (), _: ()| {}); LL | f3(|_: (), _: ()| {});
| -- --------------^^^ | ^^ -------------- found signature defined here
| | | | |
| | expected due to this | expected due to this
| | found signature defined here
| required by a bound introduced by this call
| |
= note: expected closure signature `for<'r> fn(&(), &'r ()) -> _` = note: expected closure signature `for<'r> fn(&(), &'r ()) -> _`
found closure signature `fn((), ()) -> _` found closure signature `fn((), ()) -> _`
@ -53,14 +47,12 @@ LL | fn f3<'a, F>(_: F) where F: Fn(&'a (), &()) {}
| ^^^^^^^^^^^^^^^ required by this bound in `f3` | ^^^^^^^^^^^^^^^ required by this bound in `f3`
error[E0631]: type mismatch in closure arguments error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:5:8 --> $DIR/anonymous-higher-ranked-lifetime.rs:5:5
| |
LL | f4(|_: (), _: ()| {}); LL | f4(|_: (), _: ()| {});
| -- --------------^^^ | ^^ -------------- found signature defined here
| | | | |
| | expected due to this | expected due to this
| | found signature defined here
| required by a bound introduced by this call
| |
= note: expected closure signature `for<'r, 's> fn(&'s (), &'r ()) -> _` = note: expected closure signature `for<'r, 's> fn(&'s (), &'r ()) -> _`
found closure signature `fn((), ()) -> _` found closure signature `fn((), ()) -> _`
@ -71,14 +63,12 @@ LL | fn f4<F>(_: F) where F: for<'r> Fn(&(), &'r ()) {}
| ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `f4` | ^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `f4`
error[E0631]: type mismatch in closure arguments error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:6:8 --> $DIR/anonymous-higher-ranked-lifetime.rs:6:5
| |
LL | f5(|_: (), _: ()| {}); LL | f5(|_: (), _: ()| {});
| -- --------------^^^ | ^^ -------------- found signature defined here
| | | | |
| | expected due to this | expected due to this
| | found signature defined here
| required by a bound introduced by this call
| |
= note: expected closure signature `for<'r> fn(&'r (), &'r ()) -> _` = note: expected closure signature `for<'r> fn(&'r (), &'r ()) -> _`
found closure signature `fn((), ()) -> _` found closure signature `fn((), ()) -> _`
@ -89,14 +79,12 @@ LL | fn f5<F>(_: F) where F: for<'r> Fn(&'r (), &'r ()) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `f5` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `f5`
error[E0631]: type mismatch in closure arguments error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:7:8 --> $DIR/anonymous-higher-ranked-lifetime.rs:7:5
| |
LL | g1(|_: (), _: ()| {}); LL | g1(|_: (), _: ()| {});
| -- --------------^^^ | ^^ -------------- found signature defined here
| | | | |
| | expected due to this | expected due to this
| | found signature defined here
| required by a bound introduced by this call
| |
= note: expected closure signature `for<'r> fn(&'r (), Box<(dyn for<'r> Fn(&'r ()) + 'static)>) -> _` = note: expected closure signature `for<'r> fn(&'r (), Box<(dyn for<'r> Fn(&'r ()) + 'static)>) -> _`
found closure signature `fn((), ()) -> _` found closure signature `fn((), ()) -> _`
@ -107,14 +95,12 @@ LL | fn g1<F>(_: F) where F: Fn(&(), Box<dyn Fn(&())>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `g1` | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `g1`
error[E0631]: type mismatch in closure arguments error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:8:8 --> $DIR/anonymous-higher-ranked-lifetime.rs:8:5
| |
LL | g2(|_: (), _: ()| {}); LL | g2(|_: (), _: ()| {});
| -- --------------^^^ | ^^ -------------- found signature defined here
| | | | |
| | expected due to this | expected due to this
| | found signature defined here
| required by a bound introduced by this call
| |
= note: expected closure signature `for<'r> fn(&'r (), for<'r> fn(&'r ())) -> _` = note: expected closure signature `for<'r> fn(&'r (), for<'r> fn(&'r ())) -> _`
found closure signature `fn((), ()) -> _` found closure signature `fn((), ()) -> _`
@ -125,14 +111,12 @@ LL | fn g2<F>(_: F) where F: Fn(&(), fn(&())) {}
| ^^^^^^^^^^^^^^^^ required by this bound in `g2` | ^^^^^^^^^^^^^^^^ required by this bound in `g2`
error[E0631]: type mismatch in closure arguments error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:9:8 --> $DIR/anonymous-higher-ranked-lifetime.rs:9:5
| |
LL | g3(|_: (), _: ()| {}); LL | g3(|_: (), _: ()| {});
| -- --------------^^^ | ^^ -------------- found signature defined here
| | | | |
| | expected due to this | expected due to this
| | found signature defined here
| required by a bound introduced by this call
| |
= note: expected closure signature `for<'s> fn(&'s (), Box<(dyn for<'r> Fn(&'r ()) + 'static)>) -> _` = note: expected closure signature `for<'s> fn(&'s (), Box<(dyn for<'r> Fn(&'r ()) + 'static)>) -> _`
found closure signature `fn((), ()) -> _` found closure signature `fn((), ()) -> _`
@ -143,14 +127,12 @@ LL | fn g3<F>(_: F) where F: for<'s> Fn(&'s (), Box<dyn Fn(&())>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `g3` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `g3`
error[E0631]: type mismatch in closure arguments error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:10:8 --> $DIR/anonymous-higher-ranked-lifetime.rs:10:5
| |
LL | g4(|_: (), _: ()| {}); LL | g4(|_: (), _: ()| {});
| -- --------------^^^ | ^^ -------------- found signature defined here
| | | | |
| | expected due to this | expected due to this
| | found signature defined here
| required by a bound introduced by this call
| |
= note: expected closure signature `for<'s> fn(&'s (), for<'r> fn(&'r ())) -> _` = note: expected closure signature `for<'s> fn(&'s (), for<'r> fn(&'r ())) -> _`
found closure signature `fn((), ()) -> _` found closure signature `fn((), ()) -> _`
@ -161,14 +143,12 @@ LL | fn g4<F>(_: F) where F: Fn(&(), for<'r> fn(&'r ())) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `g4` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `g4`
error[E0631]: type mismatch in closure arguments error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:11:8 --> $DIR/anonymous-higher-ranked-lifetime.rs:11:5
| |
LL | h1(|_: (), _: (), _: (), _: ()| {}); LL | h1(|_: (), _: (), _: (), _: ()| {});
| -- ----------------------------^^^ | ^^ ---------------------------- found signature defined here
| | | | |
| | expected due to this | expected due to this
| | found signature defined here
| required by a bound introduced by this call
| |
= note: expected closure signature `for<'r, 's> fn(&'r (), Box<(dyn for<'r> Fn(&'r ()) + 'static)>, &'s (), for<'r, 's> fn(&'r (), &'s ())) -> _` = note: expected closure signature `for<'r, 's> fn(&'r (), Box<(dyn for<'r> Fn(&'r ()) + 'static)>, &'s (), for<'r, 's> fn(&'r (), &'s ())) -> _`
found closure signature `fn((), (), (), ()) -> _` found closure signature `fn((), (), (), ()) -> _`
@ -179,14 +159,12 @@ LL | fn h1<F>(_: F) where F: Fn(&(), Box<dyn Fn(&())>, &(), fn(&(), &())) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `h1` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `h1`
error[E0631]: type mismatch in closure arguments error[E0631]: type mismatch in closure arguments
--> $DIR/anonymous-higher-ranked-lifetime.rs:12:8 --> $DIR/anonymous-higher-ranked-lifetime.rs:12:5
| |
LL | h2(|_: (), _: (), _: (), _: ()| {}); LL | h2(|_: (), _: (), _: (), _: ()| {});
| -- ----------------------------^^^ | ^^ ---------------------------- found signature defined here
| | | | |
| | expected due to this | expected due to this
| | found signature defined here
| required by a bound introduced by this call
| |
= note: expected closure signature `for<'t0, 'r> fn(&'r (), Box<(dyn for<'r> Fn(&'r ()) + 'static)>, &'t0 (), for<'r, 's> fn(&'r (), &'s ())) -> _` = note: expected closure signature `for<'t0, 'r> fn(&'r (), Box<(dyn for<'r> Fn(&'r ()) + 'static)>, &'t0 (), for<'r, 's> fn(&'r (), &'s ())) -> _`
found closure signature `fn((), (), (), ()) -> _` found closure signature `fn((), (), (), ()) -> _`

View file

@ -1,15 +1,10 @@
error[E0631]: type mismatch in closure arguments error[E0631]: type mismatch in closure arguments
--> $DIR/expect-infer-var-appearing-twice.rs:14:18 --> $DIR/expect-infer-var-appearing-twice.rs:14:5
| |
LL | with_closure(|x: u32, y: i32| { LL | with_closure(|x: u32, y: i32| {
| ------------ ^--------------- | ^^^^^^^^^^^^ ---------------- found signature defined here
| | | | |
| _____|____________found signature defined here | expected due to this
| | |
| | required by a bound introduced by this call
LL | |
LL | | });
| |_____^ expected due to this
| |
= note: expected closure signature `fn(_, _) -> _` = note: expected closure signature `fn(_, _) -> _`
found closure signature `fn(u32, i32) -> _` found closure signature `fn(u32, i32) -> _`

View file

@ -1,12 +1,10 @@
error[E0631]: type mismatch in closure arguments error[E0631]: type mismatch in closure arguments
--> $DIR/E0631.rs:7:9 --> $DIR/E0631.rs:7:5
| |
LL | foo(|_: isize| {}); LL | foo(|_: isize| {});
| --- ----------^^^ | ^^^ ---------- found signature defined here
| | | | |
| | expected due to this | expected due to this
| | found signature defined here
| required by a bound introduced by this call
| |
= note: expected closure signature `fn(usize) -> _` = note: expected closure signature `fn(usize) -> _`
found closure signature `fn(isize) -> _` found closure signature `fn(isize) -> _`
@ -17,14 +15,12 @@ LL | fn foo<F: Fn(usize)>(_: F) {}
| ^^^^^^^^^ required by this bound in `foo` | ^^^^^^^^^ required by this bound in `foo`
error[E0631]: type mismatch in closure arguments error[E0631]: type mismatch in closure arguments
--> $DIR/E0631.rs:8:9 --> $DIR/E0631.rs:8:5
| |
LL | bar(|_: isize| {}); LL | bar(|_: isize| {});
| --- ----------^^^ | ^^^ ---------- found signature defined here
| | | | |
| | expected due to this | expected due to this
| | found signature defined here
| required by a bound introduced by this call
| |
= note: expected closure signature `fn(usize) -> _` = note: expected closure signature `fn(usize) -> _`
found closure signature `fn(isize) -> _` found closure signature `fn(isize) -> _`

View file

@ -46,14 +46,12 @@ LL | [1, 2, 3].sort_by(|tuple, tuple2| panic!());
| ~~~~~~~~~~~~~~~ | ~~~~~~~~~~~~~~~
error[E0593]: closure is expected to take 1 argument, but it takes 0 arguments error[E0593]: closure is expected to take 1 argument, but it takes 0 arguments
--> $DIR/closure-arg-count.rs:13:7 --> $DIR/closure-arg-count.rs:13:5
| |
LL | f(|| panic!()); LL | f(|| panic!());
| - --^^^^^^^^^ | ^ -- takes 0 arguments
| | | | |
| | expected closure that takes 1 argument | expected closure that takes 1 argument
| | takes 0 arguments
| required by a bound introduced by this call
| |
note: required by a bound in `f` note: required by a bound in `f`
--> $DIR/closure-arg-count.rs:3:9 --> $DIR/closure-arg-count.rs:3:9
@ -66,14 +64,12 @@ LL | f(|_| panic!());
| ~~~ | ~~~
error[E0593]: closure is expected to take 1 argument, but it takes 0 arguments error[E0593]: closure is expected to take 1 argument, but it takes 0 arguments
--> $DIR/closure-arg-count.rs:15:9 --> $DIR/closure-arg-count.rs:15:5
| |
LL | f( move || panic!()); LL | f( move || panic!());
| - ----------^^^^^^^^^ | ^ ---------- takes 0 arguments
| | | | |
| | expected closure that takes 1 argument | expected closure that takes 1 argument
| | takes 0 arguments
| required by a bound introduced by this call
| |
note: required by a bound in `f` note: required by a bound in `f`
--> $DIR/closure-arg-count.rs:3:9 --> $DIR/closure-arg-count.rs:3:9
@ -137,14 +133,12 @@ LL | F: FnMut(Self::Item) -> B,
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `map` | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `map`
error[E0593]: closure is expected to take a single 2-tuple as argument, but it takes 3 distinct arguments error[E0593]: closure is expected to take a single 2-tuple as argument, but it takes 3 distinct arguments
--> $DIR/closure-arg-count.rs:27:57 --> $DIR/closure-arg-count.rs:27:53
| |
LL | let bar = |i, x, y| i; LL | let bar = |i, x, y| i;
| --------- takes 3 distinct arguments | --------- takes 3 distinct arguments
LL | let _it = vec![1, 2, 3].into_iter().enumerate().map(bar); LL | let _it = vec![1, 2, 3].into_iter().enumerate().map(bar);
| --- ^^^ expected closure that takes a single 2-tuple as argument | ^^^ expected closure that takes a single 2-tuple as argument
| |
| required by a bound introduced by this call
| |
note: required by a bound in `map` note: required by a bound in `map`
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL

View file

@ -1,12 +1,10 @@
error[E0631]: type mismatch in closure arguments error[E0631]: type mismatch in closure arguments
--> $DIR/closure-arg-type-mismatch.rs:3:18 --> $DIR/closure-arg-type-mismatch.rs:3:14
| |
LL | a.iter().map(|_: (u32, u32)| 45); LL | a.iter().map(|_: (u32, u32)| 45);
| --- ---------------^^^ | ^^^ --------------- found signature defined here
| | | | |
| | expected due to this | expected due to this
| | found signature defined here
| required by a bound introduced by this call
| |
= note: expected closure signature `fn(&(u32, u32)) -> _` = note: expected closure signature `fn(&(u32, u32)) -> _`
found closure signature `fn((u32, u32)) -> _` found closure signature `fn((u32, u32)) -> _`
@ -17,14 +15,12 @@ LL | F: FnMut(Self::Item) -> B,
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `map` | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `map`
error[E0631]: type mismatch in closure arguments error[E0631]: type mismatch in closure arguments
--> $DIR/closure-arg-type-mismatch.rs:4:18 --> $DIR/closure-arg-type-mismatch.rs:4:14
| |
LL | a.iter().map(|_: &(u16, u16)| 45); LL | a.iter().map(|_: &(u16, u16)| 45);
| --- ----------------^^^ | ^^^ ---------------- found signature defined here
| | | | |
| | expected due to this | expected due to this
| | found signature defined here
| required by a bound introduced by this call
| |
= note: expected closure signature `fn(&(u32, u32)) -> _` = note: expected closure signature `fn(&(u32, u32)) -> _`
found closure signature `for<'r> fn(&'r (u16, u16)) -> _` found closure signature `for<'r> fn(&'r (u16, u16)) -> _`
@ -35,14 +31,12 @@ LL | F: FnMut(Self::Item) -> B,
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `map` | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `map`
error[E0631]: type mismatch in closure arguments error[E0631]: type mismatch in closure arguments
--> $DIR/closure-arg-type-mismatch.rs:5:18 --> $DIR/closure-arg-type-mismatch.rs:5:14
| |
LL | a.iter().map(|_: (u16, u16)| 45); LL | a.iter().map(|_: (u16, u16)| 45);
| --- ---------------^^^ | ^^^ --------------- found signature defined here
| | | | |
| | expected due to this | expected due to this
| | found signature defined here
| required by a bound introduced by this call
| |
= note: expected closure signature `fn(&(u32, u32)) -> _` = note: expected closure signature `fn(&(u32, u32)) -> _`
found closure signature `fn((u16, u16)) -> _` found closure signature `fn((u16, u16)) -> _`

View file

@ -1,12 +1,10 @@
error[E0631]: type mismatch in closure arguments error[E0631]: type mismatch in closure arguments
--> $DIR/issue-36053-2.rs:7:39 --> $DIR/issue-36053-2.rs:7:32
| |
LL | once::<&str>("str").fuse().filter(|a: &str| true).count(); LL | once::<&str>("str").fuse().filter(|a: &str| true).count();
| ------ ---------^^^^^ | ^^^^^^ --------- found signature defined here
| | | | |
| | expected due to this | expected due to this
| | found signature defined here
| required by a bound introduced by this call
| |
= note: expected closure signature `for<'r> fn(&'r &str) -> _` = note: expected closure signature `for<'r> fn(&'r &str) -> _`
found closure signature `for<'r> fn(&'r str) -> _` found closure signature `for<'r> fn(&'r str) -> _`

View file

@ -17,6 +17,5 @@ pub fn main() {
//~^ ERROR type mismatch //~^ ERROR type mismatch
//~| NOTE expected due to this //~| NOTE expected due to this
//~| NOTE expected closure signature `fn(isize, _) -> _` //~| NOTE expected closure signature `fn(isize, _) -> _`
//~| NOTE required by a bound introduced by this call
println!("{}", z); println!("{}", z);
} }

View file

@ -1,13 +1,11 @@
error[E0631]: type mismatch in closure arguments error[E0631]: type mismatch in closure arguments
--> $DIR/unboxed-closures-vtable-mismatch.rs:16:24 --> $DIR/unboxed-closures-vtable-mismatch.rs:16:13
| |
LL | let f = to_fn_mut(|x: usize, y: isize| -> isize { (x as isize) + y }); LL | let f = to_fn_mut(|x: usize, y: isize| -> isize { (x as isize) + y });
| ----------------------------- found signature defined here | ----------------------------- found signature defined here
LL | LL |
LL | let z = call_it(3, f); LL | let z = call_it(3, f);
| ------- ^ expected due to this | ^^^^^^^ expected due to this
| |
| required by a bound introduced by this call
| |
= note: expected closure signature `fn(isize, _) -> _` = note: expected closure signature `fn(isize, _) -> _`
found closure signature `fn(usize, _) -> _` found closure signature `fn(usize, _) -> _`