mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Note closure captures when reporting deferred cast to fn ptr failed
This commit is contained in:
parent
20f23abbec
commit
b7495b401c
@ -495,6 +495,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
||||
err.span_label(self.span, "invalid cast");
|
||||
}
|
||||
|
||||
fcx.suggest_no_capture_closure(&mut err, self.cast_ty, self.expr_ty);
|
||||
self.try_suggest_collection_to_bool(fcx, &mut err);
|
||||
|
||||
err.emit();
|
||||
|
@ -3,6 +3,12 @@ error[E0605]: non-primitive cast: `{closure@$DIR/closure-no-fn-3.rs:6:28: 6:30}`
|
||||
|
|
||||
LL | let baz: fn() -> u8 = (|| { b }) as fn() -> u8;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast
|
||||
|
|
||||
note: closures can only be coerced to `fn` types if they do not capture any variables
|
||||
--> $DIR/closure-no-fn-3.rs:6:33
|
||||
|
|
||||
LL | let baz: fn() -> u8 = (|| { b }) as fn() -> u8;
|
||||
| ^ `b` captured here
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user