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

Reset qualifs when a storage of a local ends #90168

Merged
merged 1 commit into from
Oct 23, 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
11 changes: 10 additions & 1 deletion compiler/rustc_const_eval/src/transform/check_consts/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use rustc_index::bit_set::BitSet;
use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::{self, BasicBlock, Local, Location};
use rustc_middle::mir::{self, BasicBlock, Local, Location, Statement, StatementKind};

use std::marker::PhantomData;

Expand Down Expand Up @@ -120,6 +120,15 @@ where
self.super_assign(place, rvalue, location);
}

fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
match statement.kind {
StatementKind::StorageDead(local) => {
self.qualifs_per_local.remove(local);
}
_ => self.super_statement(statement, location),
}
}

fn visit_terminator(&mut self, terminator: &mir::Terminator<'tcx>, location: Location) {
// The effect of assignment to the return place in `TerminatorKind::Call` is not applied
// here; that occurs in `apply_call_return_effect`.
Expand Down
20 changes: 20 additions & 0 deletions src/test/ui/consts/promoted-storage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Check that storage statements reset local qualification.
// check-pass
use std::cell::Cell;

const C: Option<Cell<u32>> = {
let mut c = None;
let mut i = 0;
while i == 0 {
let mut x = None;
c = x;
x = Some(Cell::new(0));
let _ = x;
i += 1;
}
c
};

fn main() {
let _: &'static _ = &C;
}