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

Drop magic value 3 from code #98235

Merged
merged 1 commit into from
Jun 21, 2022
Merged
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
8 changes: 6 additions & 2 deletions compiler/rustc_mir_transform/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ const RETURNED: usize = GeneratorSubsts::RETURNED;
/// Generator has panicked and is poisoned.
const POISONED: usize = GeneratorSubsts::POISONED;

/// Number of variants to reserve in generator state. Corresponds to
/// `UNRESUMED` (beginning of a generator) and `RETURNED`/`POISONED`
/// (end of a generator) states.
const RESERVED_VARIANTS: usize = 3;

/// A `yield` point in the generator.
struct SuspensionPoint<'tcx> {
/// State discriminant used when suspending or resuming at this point.
Expand Down Expand Up @@ -345,7 +350,7 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> {
data.statements.extend(self.make_state(state_idx, v, source_info));
let state = if let Some((resume, mut resume_arg)) = resume {
// Yield
let state = 3 + self.suspension_points.len();
let state = RESERVED_VARIANTS + self.suspension_points.len();

// The resume arg target location might itself be remapped if its base local is
// live across a yield.
Expand Down Expand Up @@ -792,7 +797,6 @@ fn compute_layout<'tcx>(
// Leave empty variants for the UNRESUMED, RETURNED, and POISONED states.
// In debuginfo, these will correspond to the beginning (UNRESUMED) or end
// (RETURNED, POISONED) of the function.
const RESERVED_VARIANTS: usize = 3;
let body_span = body.source_scopes[OUTERMOST_SOURCE_SCOPE].span;
let mut variant_source_info: IndexVec<VariantIdx, SourceInfo> = [
SourceInfo::outermost(body_span.shrink_to_lo()),
Expand Down