Skip to content

Commit 70b29f7

Browse files
Note closure kind mismatch cause
1 parent 52e2065 commit 70b29f7

File tree

9 files changed

+79
-10
lines changed

9 files changed

+79
-10
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
860860
}
861861
}
862862

863-
err.emit();
864-
return;
863+
err
865864
}
866865

867866
ty::PredicateKind::WellFormed(ty) => {

src/test/ui/closure_context/issue-26046-fn-mut.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ LL | num += 1;
88
...
99
LL | Box::new(closure)
1010
| ----------------- the requirement to implement `Fn` derives from here
11+
|
12+
= note: required for the cast from `[closure@$DIR/issue-26046-fn-mut.rs:4:19: 4:21]` to the object type `dyn Fn()`
1113

1214
error: aborting due to previous error
1315

src/test/ui/closure_context/issue-26046-fn-once.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ LL | vec
88
...
99
LL | Box::new(closure)
1010
| ----------------- the requirement to implement `Fn` derives from here
11+
|
12+
= note: required for the cast from `[closure@$DIR/issue-26046-fn-once.rs:4:19: 4:26]` to the object type `dyn Fn() -> Vec<u8>`
1113

1214
error: aborting due to previous error
1315

src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-array-diagnostics.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ LL | let [_, _s] = s;
77
| - closure is `FnOnce` because it moves the variable `s` out of its environment
88
LL | };
99
LL | expect_fn(c);
10-
| - the requirement to implement `Fn` derives from here
10+
| --------- - the requirement to implement `Fn` derives from here
11+
| |
12+
| required by a bound introduced by this call
13+
|
14+
note: required by a bound in `expect_fn`
15+
--> $DIR/closure-origin-array-diagnostics.rs:5:17
16+
|
17+
LL | fn expect_fn<F: Fn()>(_f: F) {}
18+
| ^^^^ required by this bound in `expect_fn`
1119

1220
error: aborting due to previous error
1321

src/test/ui/closures/2229_closure_analysis/diagnostics/closure-origin-tuple-diagnostics.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ LL | let s = s.1;
77
| --- closure is `FnOnce` because it moves the variable `s.1` out of its environment
88
LL | };
99
LL | expect_fn(c);
10-
| - the requirement to implement `Fn` derives from here
10+
| --------- - the requirement to implement `Fn` derives from here
11+
| |
12+
| required by a bound introduced by this call
13+
|
14+
note: required by a bound in `expect_fn`
15+
--> $DIR/closure-origin-tuple-diagnostics.rs:5:17
16+
|
17+
LL | fn expect_fn<F: Fn()>(_f: F) {}
18+
| ^^^^ required by this bound in `expect_fn`
1119

1220
error: aborting due to previous error
1321

src/test/ui/closures/closure-wrong-kind.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ LL | let closure = |_| foo(x);
66
| |
77
| this closure implements `FnOnce`, not `Fn`
88
LL | bar(closure);
9-
| ------- the requirement to implement `Fn` derives from here
9+
| --- ------- the requirement to implement `Fn` derives from here
10+
| |
11+
| required by a bound introduced by this call
12+
|
13+
note: required by a bound in `bar`
14+
--> $DIR/closure-wrong-kind.rs:6:11
15+
|
16+
LL | fn bar<T: Fn(u32)>(_: T) {}
17+
| ^^^^^^^ required by this bound in `bar`
1018

1119
error: aborting due to previous error
1220

src/test/ui/issues/issue-34349.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ LL | farewell.push_str("!!!");
77
| -------- closure is `FnMut` because it mutates the variable `farewell` here
88
...
99
LL | apply(diary);
10-
| ----- the requirement to implement `Fn` derives from here
10+
| ----- ----- the requirement to implement `Fn` derives from here
11+
| |
12+
| required by a bound introduced by this call
13+
|
14+
note: required by a bound in `apply`
15+
--> $DIR/issue-34349.rs:11:32
16+
|
17+
LL | fn apply<F>(f: F) where F: Fn() {
18+
| ^^^^ required by this bound in `apply`
1119

1220
error: aborting due to previous error
1321

src/test/ui/pattern/move-ref-patterns/move-ref-patterns-closure-captures.stderr

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ LL | drop::<U>(_x1);
88
| --- closure is `FnOnce` because it moves the variable `_x1` out of its environment
99
...
1010
LL | accept_fn_mut(&c1);
11-
| --- the requirement to implement `FnMut` derives from here
11+
| ------------- --- the requirement to implement `FnMut` derives from here
12+
| |
13+
| required by a bound introduced by this call
14+
|
15+
note: required by a bound in `accept_fn_mut`
16+
--> $DIR/move-ref-patterns-closure-captures.rs:4:31
17+
|
18+
LL | fn accept_fn_mut(_: &impl FnMut()) {}
19+
| ^^^^^^^ required by this bound in `accept_fn_mut`
1220

1321
error[E0525]: expected a closure that implements the `Fn` trait, but this closure only implements `FnOnce`
1422
--> $DIR/move-ref-patterns-closure-captures.rs:9:14
@@ -20,7 +28,15 @@ LL | drop::<U>(_x1);
2028
| --- closure is `FnOnce` because it moves the variable `_x1` out of its environment
2129
...
2230
LL | accept_fn(&c1);
23-
| --- the requirement to implement `Fn` derives from here
31+
| --------- --- the requirement to implement `Fn` derives from here
32+
| |
33+
| required by a bound introduced by this call
34+
|
35+
note: required by a bound in `accept_fn`
36+
--> $DIR/move-ref-patterns-closure-captures.rs:5:27
37+
|
38+
LL | fn accept_fn(_: &impl Fn()) {}
39+
| ^^^^ required by this bound in `accept_fn`
2440

2541
error[E0525]: expected a closure that implements the `Fn` trait, but this closure only implements `FnMut`
2642
--> $DIR/move-ref-patterns-closure-captures.rs:20:14
@@ -32,7 +48,15 @@ LL | drop::<&mut U>(_x2);
3248
| --- closure is `FnMut` because it mutates the variable `_x2` here
3349
...
3450
LL | accept_fn(&c2);
35-
| --- the requirement to implement `Fn` derives from here
51+
| --------- --- the requirement to implement `Fn` derives from here
52+
| |
53+
| required by a bound introduced by this call
54+
|
55+
note: required by a bound in `accept_fn`
56+
--> $DIR/move-ref-patterns-closure-captures.rs:5:27
57+
|
58+
LL | fn accept_fn(_: &impl Fn()) {}
59+
| ^^^^ required by this bound in `accept_fn`
3660

3761
error: aborting due to 3 previous errors
3862

src/test/ui/unboxed-closures/unboxed-closures-infer-fn-once-move-from-projection.stderr

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ LL | let c = || drop(y.0);
66
| |
77
| this closure implements `FnOnce`, not `Fn`
88
LL | foo(c);
9-
| - the requirement to implement `Fn` derives from here
9+
| --- - the requirement to implement `Fn` derives from here
10+
| |
11+
| required by a bound introduced by this call
12+
|
13+
note: required by a bound in `foo`
14+
--> $DIR/unboxed-closures-infer-fn-once-move-from-projection.rs:4:14
15+
|
16+
LL | fn foo<F>(f: F)
17+
| --- required by a bound in this
18+
LL | where F: Fn()
19+
| ^^^^ required by this bound in `foo`
1020

1121
error: aborting due to previous error
1222

0 commit comments

Comments
 (0)