Skip to content

Commit 6223744

Browse files
committed
Prevent generators from being movable
1 parent 4ac25fa commit 6223744

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
715715
body,
716716
fn_decl_span: self.lower_span(span),
717717
fn_arg_span: None,
718-
movability: Some(hir::Movability::Static),
718+
movability: Some(Movability::Movable),
719719
constness: hir::Constness::NotConst,
720720
}))
721721
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// compile-flags: --edition 2024 -Zunstable-options
2+
#![feature(gen_blocks)]
3+
//! This test checks that we don't allow self-referential generators
4+
5+
fn main() {
6+
let mut x = {
7+
let mut x = gen {
8+
let y = 42;
9+
let z = &y; //~ ERROR: borrow may still be in use when coroutine yields
10+
yield 43;
11+
panic!("{z}");
12+
};
13+
x.next();
14+
Box::new(x)
15+
};
16+
x.next();
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0626]: borrow may still be in use when coroutine yields
2+
--> $DIR/self_referential_gen_block.rs:9:21
3+
|
4+
LL | let z = &y;
5+
| ^^
6+
LL | yield 43;
7+
| -------- possible yield occurs here
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0626`.

0 commit comments

Comments
 (0)