Skip to content

Commit e39c3c0

Browse files
committed
Handle restricting closure origin
1 parent b86c5db commit e39c3c0

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

compiler/rustc_typeck/src/check/upvar.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
206206
// If we have an origin, store it.
207207
if let Some(origin) = delegate.current_origin.clone() {
208208
let origin = if self.tcx.features().capture_disjoint_fields {
209-
origin
209+
(origin.0, restrict_capture_precision(origin.1))
210210
} else {
211-
// FIXME(project-rfc-2229#31): Once the changes to support reborrowing are
212-
// made, make sure we are selecting and restricting
213-
// the origin correctly.
214211
(origin.0, Place { projections: vec![], ..origin.1 })
215212
};
216213

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![feature(capture_disjoint_fields)]
2+
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
3+
//~| `#[warn(incomplete_features)]` on by default
4+
//~| see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
5+
6+
// Test that array access is not stored as part of closure kind origin
7+
8+
fn expect_fn<F: Fn()>(_f: F) {}
9+
10+
fn main() {
11+
let s = [format!("s"), format!("s")];
12+
let c = || { //~ ERROR expected a closure that implements the `Fn`
13+
let [_, _s] = s;
14+
};
15+
expect_fn(c);
16+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/closure-origin-array-diagnostics.rs:1:12
3+
|
4+
LL | #![feature(capture_disjoint_fields)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
9+
10+
error[E0525]: expected a closure that implements the `Fn` trait, but this closure only implements `FnOnce`
11+
--> $DIR/closure-origin-array-diagnostics.rs:12:13
12+
|
13+
LL | let c = || {
14+
| ^^ this closure implements `FnOnce`, not `Fn`
15+
LL | let [_, _s] = s;
16+
| - closure is `FnOnce` because it moves the variable `s` out of its environment
17+
LL | };
18+
LL | expect_fn(c);
19+
| --------- the requirement to implement `Fn` derives from here
20+
21+
error: aborting due to previous error; 1 warning emitted
22+
23+
For more information about this error, try `rustc --explain E0525`.

0 commit comments

Comments
 (0)