Rollup merge of #46800 - estebank:expected-closure-def-span, r=arielb1

Rework expected closure error

* point at def span
* add label to primary span
* use `span_label`s instead of `span_note`s
This commit is contained in:
Guillaume Gomez 2017-12-18 23:08:33 +01:00 committed by GitHub
commit 6cc58b3fe8
4 changed files with 23 additions and 36 deletions

View file

@ -1,20 +1,13 @@
error[E0525]: expected a closure that implements the `Fn` trait, but this closure only implements `FnMut`
--> $DIR/issue-26046-fn-mut.rs:14:19
|
14 | let closure = || { //~ ERROR expected a closure that
| ___________________^
15 | | num += 1;
16 | | };
| |_____^
17 |
18 | Box::new(closure)
| ----------------- the requirement to implement `Fn` derives from here
|
note: closure is `FnMut` because it mutates the variable `num` here
--> $DIR/issue-26046-fn-mut.rs:15:9
|
14 | let closure = || { //~ ERROR expected a closure that
| ^^ this closure implements `FnMut`, not `Fn`
15 | num += 1;
| ^^^
| --- closure is `FnMut` because it mutates the variable `num` here
...
18 | Box::new(closure)
| ----------------- the requirement to implement `Fn` derives from here
error: aborting due to previous error

View file

@ -1,20 +1,13 @@
error[E0525]: expected a closure that implements the `Fn` trait, but this closure only implements `FnOnce`
--> $DIR/issue-26046-fn-once.rs:14:19
|
14 | let closure = move || { //~ ERROR expected a closure
| ___________________^
15 | | vec
16 | | };
| |_____^
17 |
18 | Box::new(closure)
| ----------------- the requirement to implement `Fn` derives from here
|
note: closure is `FnOnce` because it moves the variable `vec` out of its environment
--> $DIR/issue-26046-fn-once.rs:15:9
|
14 | let closure = move || { //~ ERROR expected a closure
| ^^^^^^^ this closure implements `FnOnce`, not `Fn`
15 | vec
| ^^^
| --- closure is `FnOnce` because it moves the variable `vec` out of its environment
...
18 | Box::new(closure)
| ----------------- the requirement to implement `Fn` derives from here
error: aborting due to previous error

View file

@ -2,15 +2,12 @@ error[E0525]: expected a closure that implements the `Fn` trait, but this closur
--> $DIR/unboxed-closures-infer-fn-once-move-from-projection.rs:24:13
|
24 | let c = || drop(y.0); //~ ERROR expected a closure that implements the `Fn` trait
| ^^^^^^^^^^^^
| ^^^^^^^^-^^^
| | |
| | closure is `FnOnce` because it moves the variable `y` out of its environment
| this closure implements `FnOnce`, not `Fn`
25 | foo(c);
| --- the requirement to implement `Fn` derives from here
|
note: closure is `FnOnce` because it moves the variable `y` out of its environment
--> $DIR/unboxed-closures-infer-fn-once-move-from-projection.rs:24:21
|
24 | let c = || drop(y.0); //~ ERROR expected a closure that implements the `Fn` trait
| ^
error: aborting due to previous error