Skip to content

Commit a17234c

Browse files
committed
Add SourceInfo::outermost.
1 parent a0c61a9 commit a17234c

File tree

11 files changed

+45
-53
lines changed

11 files changed

+45
-53
lines changed

src/librustc_middle/mir/mod.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,13 @@ pub struct SourceInfo {
474474
pub scope: SourceScope,
475475
}
476476

477+
impl SourceInfo {
478+
#[inline]
479+
pub fn outermost(span: Span) -> Self {
480+
SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE }
481+
}
482+
}
483+
477484
///////////////////////////////////////////////////////////////////////////
478485
// Borrow kinds
479486

@@ -944,7 +951,7 @@ impl<'tcx> LocalDecl<'tcx> {
944951
mutability,
945952
ty,
946953
user_ty: UserTypeProjections::none(),
947-
source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE },
954+
source_info: SourceInfo::outermost(span),
948955
internal,
949956
local_info: LocalInfo::Other,
950957
is_block_tail: None,
@@ -960,7 +967,7 @@ impl<'tcx> LocalDecl<'tcx> {
960967
mutability: Mutability::Mut,
961968
ty: return_ty,
962969
user_ty: UserTypeProjections::none(),
963-
source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE },
970+
source_info: SourceInfo::outermost(span),
964971
internal: false,
965972
is_block_tail: None,
966973
local_info: LocalInfo::Other,
@@ -1406,10 +1413,7 @@ impl<'tcx> BasicBlockData<'tcx> {
14061413
let mut gap = self.statements.len()..self.statements.len() + extra_stmts;
14071414
self.statements.resize(
14081415
gap.end,
1409-
Statement {
1410-
source_info: SourceInfo { span: DUMMY_SP, scope: OUTERMOST_SOURCE_SCOPE },
1411-
kind: StatementKind::Nop,
1412-
},
1416+
Statement { source_info: SourceInfo::outermost(DUMMY_SP), kind: StatementKind::Nop },
14131417
);
14141418
for (splice_start, new_stmts) in splices.into_iter().rev() {
14151419
let splice_end = splice_start + new_stmts.size_hint().0;

src/librustc_middle/mir/visit.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,10 @@ macro_rules! make_mir_visitor {
242242
) {
243243
let span = body.span;
244244
if let Some(yield_ty) = &$($mutability)? body.yield_ty {
245-
self.visit_ty(yield_ty, TyContext::YieldTy(SourceInfo {
246-
span,
247-
scope: OUTERMOST_SOURCE_SCOPE,
248-
}));
245+
self.visit_ty(
246+
yield_ty,
247+
TyContext::YieldTy(SourceInfo::outermost(span))
248+
);
249249
}
250250

251251
// for best performance, we want to use an iterator rather
@@ -263,10 +263,10 @@ macro_rules! make_mir_visitor {
263263
self.visit_source_scope_data(scope);
264264
}
265265

266-
self.visit_ty(&$($mutability)? body.return_ty(), TyContext::ReturnTy(SourceInfo {
267-
span: body.span,
268-
scope: OUTERMOST_SOURCE_SCOPE,
269-
}));
266+
self.visit_ty(
267+
&$($mutability)? body.return_ty(),
268+
TyContext::ReturnTy(SourceInfo::outermost(body.span))
269+
);
270270

271271
for local in body.local_decls.indices() {
272272
self.visit_local_decl(local, & $($mutability)? body.local_decls[local]);

src/librustc_mir/dataflow/framework/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::dataflow::BottomValue;
1616
/// This is the `Body` that will be used by the `MockAnalysis` below. The shape of its CFG is not
1717
/// important.
1818
fn mock_body() -> mir::Body<'static> {
19-
let source_info = mir::SourceInfo { scope: mir::OUTERMOST_SOURCE_SCOPE, span: DUMMY_SP };
19+
let source_info = mir::SourceInfo::outermost(DUMMY_SP);
2020

2121
let mut blocks = IndexVec::new();
2222
let mut block = |n, kind| {

src/librustc_mir/shim.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,11 @@ enum CallKind {
146146
}
147147

148148
fn temp_decl(mutability: Mutability, ty: Ty<'_>, span: Span) -> LocalDecl<'_> {
149-
let source_info = SourceInfo { scope: OUTERMOST_SOURCE_SCOPE, span };
150149
LocalDecl {
151150
mutability,
152151
ty,
153152
user_ty: UserTypeProjections::none(),
154-
source_info,
153+
source_info: SourceInfo::outermost(span),
155154
internal: false,
156155
local_info: LocalInfo::Other,
157156
is_block_tail: None,
@@ -185,7 +184,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
185184
let sig = tcx.erase_late_bound_regions(&sig);
186185
let span = tcx.def_span(def_id);
187186

188-
let source_info = SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE };
187+
let source_info = SourceInfo::outermost(span);
189188

190189
let return_block = BasicBlock::new(1);
191190
let mut blocks = IndexVec::with_capacity(2);
@@ -374,7 +373,7 @@ impl CloneShimBuilder<'tcx> {
374373
}
375374

376375
fn source_info(&self) -> SourceInfo {
377-
SourceInfo { span: self.span, scope: OUTERMOST_SOURCE_SCOPE }
376+
SourceInfo::outermost(self.span)
378377
}
379378

380379
fn block(
@@ -687,7 +686,7 @@ fn build_call_shim<'tcx>(
687686
debug!("build_call_shim: sig={:?}", sig);
688687

689688
let mut local_decls = local_decls_for_sig(&sig, span);
690-
let source_info = SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE };
689+
let source_info = SourceInfo::outermost(span);
691690

692691
let rcvr_place = || {
693692
assert!(rcvr_adjustment.is_some());
@@ -849,7 +848,7 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> {
849848

850849
let local_decls = local_decls_for_sig(&sig, span);
851850

852-
let source_info = SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE };
851+
let source_info = SourceInfo::outermost(span);
853852

854853
let variant_index = if adt_def.is_enum() {
855854
adt_def.variant_index_with_ctor_id(ctor_id)

src/librustc_mir/transform/add_retag.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,9 @@ impl<'tcx> MirPass<'tcx> for AddRetag {
7777
// PART 1
7878
// Retag arguments at the beginning of the start block.
7979
{
80-
let source_info = SourceInfo {
81-
scope: OUTERMOST_SOURCE_SCOPE,
82-
span, // FIXME: Consider using just the span covering the function
83-
// argument declaration.
84-
};
80+
// FIXME: Consider using just the span covering the function
81+
// argument declaration.
82+
let source_info = SourceInfo::outermost(span);
8583
// Gather all arguments, skip return value.
8684
let places = local_decls
8785
.iter_enumerated()

src/librustc_mir/transform/check_unsafety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
5050
const_context,
5151
min_const_fn,
5252
violations: vec![],
53-
source_info: SourceInfo { span: body.span, scope: OUTERMOST_SOURCE_SCOPE },
53+
source_info: SourceInfo::outermost(body.span),
5454
tcx,
5555
param_env,
5656
used_unsafe: Default::default(),

src/librustc_mir/transform/generator.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ impl TransformVisitor<'tcx> {
261261

262262
let self_place = Place::from(SELF_ARG);
263263
let assign = Statement {
264-
source_info: source_info(body),
264+
source_info: SourceInfo::outermost(body.span),
265265
kind: StatementKind::Assign(box (temp, Rvalue::Discriminant(self_place))),
266266
};
267267
(assign, temp)
@@ -395,7 +395,7 @@ fn replace_local<'tcx>(
395395
body: &mut Body<'tcx>,
396396
tcx: TyCtxt<'tcx>,
397397
) -> Local {
398-
let source_info = source_info(body);
398+
let source_info = SourceInfo::outermost(body.span);
399399
let new_decl = LocalDecl {
400400
mutability: Mutability::Mut,
401401
ty,
@@ -784,7 +784,7 @@ fn insert_switch<'tcx>(
784784
targets: cases.iter().map(|&(_, d)| d).chain(iter::once(default_block)).collect(),
785785
};
786786

787-
let source_info = source_info(body);
787+
let source_info = SourceInfo::outermost(body.span);
788788
body.basic_blocks_mut().raw.insert(
789789
0,
790790
BasicBlockData {
@@ -858,7 +858,7 @@ fn create_generator_drop_shim<'tcx>(
858858
let mut body = body.clone();
859859
body.arg_count = 1; // make sure the resume argument is not included here
860860

861-
let source_info = source_info(&body);
861+
let source_info = SourceInfo::outermost(body.span);
862862

863863
let mut cases = create_cases(&mut body, transform, Operation::Drop);
864864

@@ -922,7 +922,7 @@ fn create_generator_drop_shim<'tcx>(
922922
}
923923

924924
fn insert_term_block<'tcx>(body: &mut Body<'tcx>, kind: TerminatorKind<'tcx>) -> BasicBlock {
925-
let source_info = source_info(body);
925+
let source_info = SourceInfo::outermost(body.span);
926926
body.basic_blocks_mut().push(BasicBlockData {
927927
statements: Vec::new(),
928928
terminator: Some(Terminator { source_info, kind }),
@@ -948,7 +948,7 @@ fn insert_panic_block<'tcx>(
948948
cleanup: None,
949949
};
950950

951-
let source_info = source_info(body);
951+
let source_info = SourceInfo::outermost(body.span);
952952
body.basic_blocks_mut().push(BasicBlockData {
953953
statements: Vec::new(),
954954
terminator: Some(Terminator { source_info, kind: term }),
@@ -1025,7 +1025,7 @@ fn create_generator_resume_function<'tcx>(
10251025

10261026
// Poison the generator when it unwinds
10271027
if can_unwind {
1028-
let source_info = source_info(body);
1028+
let source_info = SourceInfo::outermost(body.span);
10291029
let poison_block = body.basic_blocks_mut().push(BasicBlockData {
10301030
statements: vec![transform.set_discr(VariantIdx::new(POISONED), source_info)],
10311031
terminator: Some(Terminator { source_info, kind: TerminatorKind::Resume }),
@@ -1092,10 +1092,6 @@ fn create_generator_resume_function<'tcx>(
10921092
dump_mir(tcx, None, "generator_resume", &0, source, body, |_, _| Ok(()));
10931093
}
10941094

1095-
fn source_info(body: &Body<'_>) -> SourceInfo {
1096-
SourceInfo { span: body.span, scope: OUTERMOST_SOURCE_SCOPE }
1097-
}
1098-
10991095
fn insert_clean_drop(body: &mut Body<'_>) -> BasicBlock {
11001096
let return_block = insert_term_block(body, TerminatorKind::Return);
11011097

@@ -1104,7 +1100,7 @@ fn insert_clean_drop(body: &mut Body<'_>) -> BasicBlock {
11041100
target: return_block,
11051101
unwind: None,
11061102
};
1107-
let source_info = source_info(body);
1103+
let source_info = SourceInfo::outermost(body.span);
11081104

11091105
// Create a block to destroy an unresumed generators. This can only destroy upvars.
11101106
body.basic_blocks_mut().push(BasicBlockData {
@@ -1135,7 +1131,7 @@ fn create_cases<'tcx>(
11351131
transform: &TransformVisitor<'tcx>,
11361132
operation: Operation,
11371133
) -> Vec<(usize, BasicBlock)> {
1138-
let source_info = source_info(body);
1134+
let source_info = SourceInfo::outermost(body.span);
11391135

11401136
transform
11411137
.suspension_points
@@ -1241,7 +1237,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
12411237
replace_local(resume_local, body.local_decls[resume_local].ty, body, tcx);
12421238

12431239
// When first entering the generator, move the resume argument into its new local.
1244-
let source_info = source_info(body);
1240+
let source_info = SourceInfo::outermost(body.span);
12451241
let stmts = &mut body.basic_blocks_mut()[BasicBlock::new(0)].statements;
12461242
stmts.insert(
12471243
0,

src/librustc_mir/transform/promote_consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
775775
self.promoted.basic_blocks_mut().push(BasicBlockData {
776776
statements: vec![],
777777
terminator: Some(Terminator {
778-
source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE },
778+
source_info: SourceInfo::outermost(span),
779779
kind: TerminatorKind::Return,
780780
}),
781781
is_cleanup: false,
@@ -786,7 +786,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
786786
let last = self.promoted.basic_blocks().last().unwrap();
787787
let data = &mut self.promoted[last];
788788
data.statements.push(Statement {
789-
source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE },
789+
source_info: SourceInfo::outermost(span),
790790
kind: StatementKind::Assign(box (Place::from(dest), rvalue)),
791791
});
792792
}

src/librustc_mir/util/patch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'tcx> MirPatch<'tcx> {
5050
result.new_block(BasicBlockData {
5151
statements: vec![],
5252
terminator: Some(Terminator {
53-
source_info: SourceInfo { span: body.span, scope: OUTERMOST_SOURCE_SCOPE },
53+
source_info: SourceInfo::outermost(body.span),
5454
kind: TerminatorKind::Resume,
5555
}),
5656
is_cleanup: true,

src/librustc_mir_build/build/mod.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -804,10 +804,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
804804
) -> BlockAnd<()> {
805805
// Allocate locals for the function arguments
806806
for &ArgInfo(ty, _, arg_opt, _) in arguments.iter() {
807-
let source_info = SourceInfo {
808-
scope: OUTERMOST_SOURCE_SCOPE,
809-
span: arg_opt.map_or(self.fn_span, |arg| arg.pat.span),
810-
};
807+
let source_info =
808+
SourceInfo::outermost(arg_opt.map_or(self.fn_span, |arg| arg.pat.span));
811809
let arg_local = self.local_decls.push(LocalDecl {
812810
mutability: Mutability::Mut,
813811
ty,
@@ -885,10 +883,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
885883

886884
self.var_debug_info.push(VarDebugInfo {
887885
name,
888-
source_info: SourceInfo {
889-
scope: OUTERMOST_SOURCE_SCOPE,
890-
span: tcx_hir.span(var_id),
891-
},
886+
source_info: SourceInfo::outermost(tcx_hir.span(var_id)),
892887
place: Place {
893888
local: closure_env_arg,
894889
projection: tcx.intern_place_elems(&projs),

src/librustc_mir_build/build/scope.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
989989
let resumeblk = self.cfg.start_new_cleanup_block();
990990
self.cfg.terminate(
991991
resumeblk,
992-
SourceInfo { scope: OUTERMOST_SOURCE_SCOPE, span: self.fn_span },
992+
SourceInfo::outermost(self.fn_span),
993993
TerminatorKind::Resume,
994994
);
995995
self.cached_resume_block = Some(resumeblk);

0 commit comments

Comments
 (0)