Handle restricting closure origin
This commit is contained in:
parent
b86c5db96e
commit
e39c3c05a4
|
@ -206,11 +206,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
// If we have an origin, store it.
|
||||
if let Some(origin) = delegate.current_origin.clone() {
|
||||
let origin = if self.tcx.features().capture_disjoint_fields {
|
||||
origin
|
||||
(origin.0, restrict_capture_precision(origin.1))
|
||||
} else {
|
||||
// FIXME(project-rfc-2229#31): Once the changes to support reborrowing are
|
||||
// made, make sure we are selecting and restricting
|
||||
// the origin correctly.
|
||||
(origin.0, Place { projections: vec![], ..origin.1 })
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#![feature(capture_disjoint_fields)]
|
||||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
|
||||
//~| `#[warn(incomplete_features)]` on by default
|
||||
//~| see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
|
||||
|
||||
// Test that array access is not stored as part of closure kind origin
|
||||
|
||||
fn expect_fn<F: Fn()>(_f: F) {}
|
||||
|
||||
fn main() {
|
||||
let s = [format!("s"), format!("s")];
|
||||
let c = || { //~ ERROR expected a closure that implements the `Fn`
|
||||
let [_, _s] = s;
|
||||
};
|
||||
expect_fn(c);
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/closure-origin-array-diagnostics.rs:1:12
|
||||
|
|
||||
LL | #![feature(capture_disjoint_fields)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
|
||||
|
||||
error[E0525]: expected a closure that implements the `Fn` trait, but this closure only implements `FnOnce`
|
||||
--> $DIR/closure-origin-array-diagnostics.rs:12:13
|
||||
|
|
||||
LL | let c = || {
|
||||
| ^^ this closure implements `FnOnce`, not `Fn`
|
||||
LL | let [_, _s] = s;
|
||||
| - closure is `FnOnce` because it moves the variable `s` out of its environment
|
||||
LL | };
|
||||
LL | expect_fn(c);
|
||||
| --------- the requirement to implement `Fn` derives from here
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0525`.
|
Loading…
Reference in New Issue