Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebase resume argument projections during state transform #89321

Merged
merged 1 commit into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions compiler/rustc_mir_transform/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,16 @@ impl MutVisitor<'tcx> for TransformVisitor<'tcx> {
let source_info = data.terminator().source_info;
// We must assign the value first in case it gets declared dead below
data.statements.extend(self.make_state(state_idx, v, source_info));
let state = if let Some((resume, resume_arg)) = resume {
let state = if let Some((resume, mut resume_arg)) = resume {
// Yield
let state = 3 + self.suspension_points.len();

// The resume arg target location might itself be remapped if its base local is
// live across a yield.
let resume_arg =
if let Some(&(ty, variant, idx)) = self.remap.get(&resume_arg.local) {
self.make_field(variant, idx, ty)
replace_base(&mut resume_arg, self.make_field(variant, idx, ty), self.tcx);
resume_arg
} else {
resume_arg
};
Expand Down
10 changes: 8 additions & 2 deletions src/test/ui/generator/yield-in-box.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// run-pass

// Test that box-statements with yields in them work.

#![feature(generators, box_syntax)]
#![feature(generators, box_syntax, generator_trait)]
use std::pin::Pin;
use std::ops::Generator;
use std::ops::GeneratorState;

fn main() {
let x = 0i32;
Expand All @@ -15,4 +17,8 @@ fn main() {
_t => {}
}
};

let mut g = |_| box yield;
assert_eq!(Pin::new(&mut g).resume(1), GeneratorState::Yielded(()));
assert_eq!(Pin::new(&mut g).resume(2), GeneratorState::Complete(box 2));
}
2 changes: 1 addition & 1 deletion src/test/ui/generator/yield-in-box.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: unused generator that must be used
--> $DIR/yield-in-box.rs:9:5
--> $DIR/yield-in-box.rs:11:5
|
LL | / || {
LL | | let y = 2u32;
Expand Down