Prevent generators from being movable
This commit is contained in:
parent
4ac25faf9f
commit
6223744078
@ -715,7 +715,7 @@ pub(super) fn make_gen_expr(
|
||||
body,
|
||||
fn_decl_span: self.lower_span(span),
|
||||
fn_arg_span: None,
|
||||
movability: Some(hir::Movability::Static),
|
||||
movability: Some(Movability::Movable),
|
||||
constness: hir::Constness::NotConst,
|
||||
}))
|
||||
}
|
||||
|
17
tests/ui/coroutine/self_referential_gen_block.rs
Normal file
17
tests/ui/coroutine/self_referential_gen_block.rs
Normal file
@ -0,0 +1,17 @@
|
||||
// compile-flags: --edition 2024 -Zunstable-options
|
||||
#![feature(gen_blocks)]
|
||||
//! This test checks that we don't allow self-referential generators
|
||||
|
||||
fn main() {
|
||||
let mut x = {
|
||||
let mut x = gen {
|
||||
let y = 42;
|
||||
let z = &y; //~ ERROR: borrow may still be in use when coroutine yields
|
||||
yield 43;
|
||||
panic!("{z}");
|
||||
};
|
||||
x.next();
|
||||
Box::new(x)
|
||||
};
|
||||
x.next();
|
||||
}
|
11
tests/ui/coroutine/self_referential_gen_block.stderr
Normal file
11
tests/ui/coroutine/self_referential_gen_block.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
error[E0626]: borrow may still be in use when coroutine yields
|
||||
--> $DIR/self_referential_gen_block.rs:9:21
|
||||
|
|
||||
LL | let z = &y;
|
||||
| ^^
|
||||
LL | yield 43;
|
||||
| -------- possible yield occurs here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0626`.
|
Loading…
Reference in New Issue
Block a user