mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 19:58:32 +00:00
Create a single source scope for promoteds
A promoted inherits all scopes from the parent body. At the same time, almost all statements and terminators inside the promoted body so far refer only to one of those scopes: the outermost one. Instead of inheriting all scopes, inherit only a single scope corresponding to the location of the promoted, making sure that there are no references to other scopes.
This commit is contained in:
parent
5565241f65
commit
db54752082
@ -124,6 +124,15 @@ impl Candidate {
|
|||||||
Candidate::Argument { .. } | Candidate::InlineAsm { .. } => true,
|
Candidate::Argument { .. } | Candidate::InlineAsm { .. } => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn source_info(&self, body: &Body<'_>) -> SourceInfo {
|
||||||
|
match self {
|
||||||
|
Candidate::Ref(location) | Candidate::Repeat(location) => *body.source_info(*location),
|
||||||
|
Candidate::Argument { bb, .. } | Candidate::InlineAsm { bb, .. } => {
|
||||||
|
*body.source_info(body.terminator_loc(*bb))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn args_required_const(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Vec<usize>> {
|
fn args_required_const(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Vec<usize>> {
|
||||||
@ -953,6 +962,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
|
|||||||
from_hir_call,
|
from_hir_call,
|
||||||
fn_span,
|
fn_span,
|
||||||
},
|
},
|
||||||
|
source_info: SourceInfo::outermost(terminator.source_info.span),
|
||||||
..terminator
|
..terminator
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -1163,12 +1173,13 @@ pub fn promote_candidates<'tcx>(
|
|||||||
// Declare return place local so that `mir::Body::new` doesn't complain.
|
// Declare return place local so that `mir::Body::new` doesn't complain.
|
||||||
let initial_locals = iter::once(LocalDecl::new(tcx.types.never, body.span)).collect();
|
let initial_locals = iter::once(LocalDecl::new(tcx.types.never, body.span)).collect();
|
||||||
|
|
||||||
|
let mut scope = body.source_scopes[candidate.source_info(body).scope].clone();
|
||||||
|
scope.parent_scope = None;
|
||||||
|
|
||||||
let mut promoted = Body::new(
|
let mut promoted = Body::new(
|
||||||
body.source, // `promoted` gets filled in below
|
body.source, // `promoted` gets filled in below
|
||||||
IndexVec::new(),
|
IndexVec::new(),
|
||||||
// FIXME: maybe try to filter this to avoid blowing up
|
IndexVec::from_elem_n(scope, 1),
|
||||||
// memory usage?
|
|
||||||
body.source_scopes.clone(),
|
|
||||||
initial_locals,
|
initial_locals,
|
||||||
IndexVec::new(),
|
IndexVec::new(),
|
||||||
0,
|
0,
|
||||||
|
@ -5,8 +5,6 @@ promoted[0] in FOO: &[&i32; 1] = {
|
|||||||
let mut _1: [&i32; 1]; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
let mut _1: [&i32; 1]; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
|
||||||
let mut _2: &i32; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:32: 13:45
|
let mut _2: &i32; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:32: 13:45
|
||||||
let mut _3: &i32; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
|
let mut _3: &i32; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
|
||||||
scope 1 {
|
|
||||||
}
|
|
||||||
|
|
||||||
bb0: {
|
bb0: {
|
||||||
_3 = const {alloc2: &i32}; // scope 0 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
|
_3 = const {alloc2: &i32}; // scope 0 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
|
||||||
|
Loading…
Reference in New Issue
Block a user