diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 5abb0ba722e..d6fa74dc3e6 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -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, })) } diff --git a/tests/ui/coroutine/self_referential_gen_block.rs b/tests/ui/coroutine/self_referential_gen_block.rs new file mode 100644 index 00000000000..538d436ed14 --- /dev/null +++ b/tests/ui/coroutine/self_referential_gen_block.rs @@ -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(); +} diff --git a/tests/ui/coroutine/self_referential_gen_block.stderr b/tests/ui/coroutine/self_referential_gen_block.stderr new file mode 100644 index 00000000000..f9cadf8eb04 --- /dev/null +++ b/tests/ui/coroutine/self_referential_gen_block.stderr @@ -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`.