@@ -78,13 +78,13 @@ pub struct Mir<'tcx> {
78
78
/// that indexes into this vector.
79
79
basic_blocks : IndexVec < BasicBlock , BasicBlockData < ' tcx > > ,
80
80
81
- /// List of visibility (lexical) scopes; these are referenced by statements
82
- /// and used (eventually) for debuginfo. Indexed by a `VisibilityScope `.
83
- pub visibility_scopes : IndexVec < VisibilityScope , VisibilityScopeData > ,
81
+ /// List of source scopes; these are referenced by statements
82
+ /// and used for debuginfo. Indexed by a `SourceScope `.
83
+ pub source_scopes : IndexVec < SourceScope , SourceScopeData > ,
84
84
85
- /// Crate-local information for each visibility scope, that can't (and
85
+ /// Crate-local information for each source scope, that can't (and
86
86
/// needn't) be tracked across crates.
87
- pub visibility_scope_info : ClearCrossCrate < IndexVec < VisibilityScope , VisibilityScopeInfo > > ,
87
+ pub source_scope_local_data : ClearCrossCrate < IndexVec < SourceScope , SourceScopeLocalData > > ,
88
88
89
89
/// Rvalues promoted from this function, such as borrows of constants.
90
90
/// Each of them is the Mir of a constant with the fn's type parameters
@@ -137,9 +137,9 @@ pub const START_BLOCK: BasicBlock = BasicBlock(0);
137
137
138
138
impl < ' tcx > Mir < ' tcx > {
139
139
pub fn new ( basic_blocks : IndexVec < BasicBlock , BasicBlockData < ' tcx > > ,
140
- visibility_scopes : IndexVec < VisibilityScope , VisibilityScopeData > ,
141
- visibility_scope_info : ClearCrossCrate < IndexVec < VisibilityScope ,
142
- VisibilityScopeInfo > > ,
140
+ source_scopes : IndexVec < SourceScope , SourceScopeData > ,
141
+ source_scope_local_data : ClearCrossCrate < IndexVec < SourceScope ,
142
+ SourceScopeLocalData > > ,
143
143
promoted : IndexVec < Promoted , Mir < ' tcx > > ,
144
144
yield_ty : Option < Ty < ' tcx > > ,
145
145
local_decls : IndexVec < Local , LocalDecl < ' tcx > > ,
@@ -153,8 +153,8 @@ impl<'tcx> Mir<'tcx> {
153
153
154
154
Mir {
155
155
basic_blocks,
156
- visibility_scopes ,
157
- visibility_scope_info ,
156
+ source_scopes ,
157
+ source_scope_local_data ,
158
158
promoted,
159
159
yield_ty,
160
160
generator_drop : None ,
@@ -308,14 +308,6 @@ impl<'tcx> Mir<'tcx> {
308
308
}
309
309
}
310
310
311
- #[ derive( Clone , Debug , RustcEncodable , RustcDecodable ) ]
312
- pub struct VisibilityScopeInfo {
313
- /// A NodeId with lint levels equivalent to this scope's lint levels.
314
- pub lint_root : ast:: NodeId ,
315
- /// The unsafe block that contains this node.
316
- pub safety : Safety ,
317
- }
318
-
319
311
#[ derive( Copy , Clone , Debug , RustcEncodable , RustcDecodable ) ]
320
312
pub enum Safety {
321
313
Safe ,
@@ -329,8 +321,8 @@ pub enum Safety {
329
321
330
322
impl_stable_hash_for ! ( struct Mir <' tcx> {
331
323
basic_blocks,
332
- visibility_scopes ,
333
- visibility_scope_info ,
324
+ source_scopes ,
325
+ source_scope_local_data ,
334
326
promoted,
335
327
yield_ty,
336
328
generator_drop,
@@ -376,8 +368,9 @@ pub struct SourceInfo {
376
368
/// Source span for the AST pertaining to this MIR entity.
377
369
pub span : Span ,
378
370
379
- /// The lexical visibility scope, i.e. which bindings can be seen.
380
- pub scope : VisibilityScope
371
+ /// The source scope, keeping track of which bindings can be
372
+ /// seen by debuginfo, active lint levels, `unsafe {...}`, etc.
373
+ pub scope : SourceScope
381
374
}
382
375
383
376
///////////////////////////////////////////////////////////////////////////
@@ -512,16 +505,13 @@ pub struct LocalDecl<'tcx> {
512
505
/// to generate better debuginfo.
513
506
pub name : Option < Name > ,
514
507
515
- /// Source info of the local.
516
- pub source_info : SourceInfo ,
517
-
518
- /// The *syntactic* visibility scope the local is defined
508
+ /// The *syntactic* (i.e. not visibility) source scope the local is defined
519
509
/// in. If the local was defined in a let-statement, this
520
510
/// is *within* the let-statement, rather than outside
521
511
/// of it.
522
512
///
523
- /// This is needed because visibility scope of locals within a let-statement
524
- /// is weird.
513
+ /// This is needed because the visibility source scope of locals within
514
+ /// a let-statement is weird.
525
515
///
526
516
/// The reason is that we want the local to be *within* the let-statement
527
517
/// for lint purposes, but we want the local to be *after* the let-statement
@@ -566,9 +556,9 @@ pub struct LocalDecl<'tcx> {
566
556
/// `drop(x)`, we want it to refer to `x: u32`.
567
557
///
568
558
/// To allow both uses to work, we need to have more than a single scope
569
- /// for a local. We have the `syntactic_scope ` represent the
559
+ /// for a local. We have the `source_info.scope ` represent the
570
560
/// "syntactic" lint scope (with a variable being under its let
571
- /// block) while the source-info scope represents the "local variable"
561
+ /// block) while the `visibility_scope` represents the "local variable"
572
562
/// scope (where the "rest" of a block is under all prior let-statements).
573
563
///
574
564
/// The end result looks like this:
@@ -580,21 +570,25 @@ pub struct LocalDecl<'tcx> {
580
570
/// │ │{ #[allow(unused_mut] } // this is actually split into 2 scopes
581
571
/// │ │ // in practice because I'm lazy.
582
572
/// │ │
583
- /// │ │← x.syntactic_scope
573
+ /// │ │← x.source_info.scope
584
574
/// │ │← `x.parse().unwrap()`
585
575
/// │ │
586
- /// │ │ │← y.syntactic_scope
576
+ /// │ │ │← y.source_info.scope
587
577
/// │ │
588
578
/// │ │ │{ let y: u32 }
589
579
/// │ │ │
590
- /// │ │ │← y.source_info.scope
580
+ /// │ │ │← y.visibility_scope
591
581
/// │ │ │← `y + 2`
592
582
/// │
593
583
/// │ │{ let x: u32 }
594
- /// │ │← x.source_info.scope
584
+ /// │ │← x.visibility_scope
595
585
/// │ │← `drop(x)` // this accesses `x: u32`
596
586
/// ```
597
- pub syntactic_scope : VisibilityScope ,
587
+ pub source_info : SourceInfo ,
588
+
589
+ /// Source scope within which the local is visible (for debuginfo)
590
+ /// (see `source_info` for more details).
591
+ pub visibility_scope : SourceScope ,
598
592
}
599
593
600
594
impl < ' tcx > LocalDecl < ' tcx > {
@@ -607,9 +601,9 @@ impl<'tcx> LocalDecl<'tcx> {
607
601
name : None ,
608
602
source_info : SourceInfo {
609
603
span,
610
- scope : ARGUMENT_VISIBILITY_SCOPE
604
+ scope : OUTERMOST_SOURCE_SCOPE
611
605
} ,
612
- syntactic_scope : ARGUMENT_VISIBILITY_SCOPE ,
606
+ visibility_scope : OUTERMOST_SOURCE_SCOPE ,
613
607
internal : false ,
614
608
is_user_variable : false
615
609
}
@@ -624,9 +618,9 @@ impl<'tcx> LocalDecl<'tcx> {
624
618
name : None ,
625
619
source_info : SourceInfo {
626
620
span,
627
- scope : ARGUMENT_VISIBILITY_SCOPE
621
+ scope : OUTERMOST_SOURCE_SCOPE
628
622
} ,
629
- syntactic_scope : ARGUMENT_VISIBILITY_SCOPE ,
623
+ visibility_scope : OUTERMOST_SOURCE_SCOPE ,
630
624
internal : true ,
631
625
is_user_variable : false
632
626
}
@@ -642,9 +636,9 @@ impl<'tcx> LocalDecl<'tcx> {
642
636
ty : return_ty,
643
637
source_info : SourceInfo {
644
638
span,
645
- scope : ARGUMENT_VISIBILITY_SCOPE
639
+ scope : OUTERMOST_SOURCE_SCOPE
646
640
} ,
647
- syntactic_scope : ARGUMENT_VISIBILITY_SCOPE ,
641
+ visibility_scope : OUTERMOST_SOURCE_SCOPE ,
648
642
internal : false ,
649
643
name : None , // FIXME maybe we do want some name here?
650
644
is_user_variable : false
@@ -1047,7 +1041,7 @@ impl<'tcx> BasicBlockData<'tcx> {
1047
1041
self . statements . resize ( gap. end , Statement {
1048
1042
source_info : SourceInfo {
1049
1043
span : DUMMY_SP ,
1050
- scope : ARGUMENT_VISIBILITY_SCOPE
1044
+ scope : OUTERMOST_SOURCE_SCOPE
1051
1045
} ,
1052
1046
kind : StatementKind :: Nop
1053
1047
} ) ;
@@ -1501,16 +1495,24 @@ impl<'tcx> Debug for Place<'tcx> {
1501
1495
///////////////////////////////////////////////////////////////////////////
1502
1496
// Scopes
1503
1497
1504
- newtype_index ! ( VisibilityScope
1498
+ newtype_index ! ( SourceScope
1505
1499
{
1506
1500
DEBUG_FORMAT = "scope[{}]" ,
1507
- const ARGUMENT_VISIBILITY_SCOPE = 0 ,
1501
+ const OUTERMOST_SOURCE_SCOPE = 0 ,
1508
1502
} ) ;
1509
1503
1510
1504
#[ derive( Clone , Debug , RustcEncodable , RustcDecodable ) ]
1511
- pub struct VisibilityScopeData {
1505
+ pub struct SourceScopeData {
1512
1506
pub span : Span ,
1513
- pub parent_scope : Option < VisibilityScope > ,
1507
+ pub parent_scope : Option < SourceScope > ,
1508
+ }
1509
+
1510
+ #[ derive( Clone , Debug , RustcEncodable , RustcDecodable ) ]
1511
+ pub struct SourceScopeLocalData {
1512
+ /// A NodeId with lint levels equivalent to this scope's lint levels.
1513
+ pub lint_root : ast:: NodeId ,
1514
+ /// The unsafe block that contains this node.
1515
+ pub safety : Safety ,
1514
1516
}
1515
1517
1516
1518
///////////////////////////////////////////////////////////////////////////
@@ -2153,16 +2155,16 @@ CloneTypeFoldableAndLiftImpls! {
2153
2155
SourceInfo ,
2154
2156
UpvarDecl ,
2155
2157
ValidationOp ,
2156
- VisibilityScopeData ,
2157
- VisibilityScope ,
2158
- VisibilityScopeInfo ,
2158
+ SourceScope ,
2159
+ SourceScopeData ,
2160
+ SourceScopeLocalData ,
2159
2161
}
2160
2162
2161
2163
BraceStructTypeFoldableImpl ! {
2162
2164
impl <' tcx> TypeFoldable <' tcx> for Mir <' tcx> {
2163
2165
basic_blocks,
2164
- visibility_scopes ,
2165
- visibility_scope_info ,
2166
+ source_scopes ,
2167
+ source_scope_local_data ,
2166
2168
promoted,
2167
2169
yield_ty,
2168
2170
generator_drop,
@@ -2190,7 +2192,7 @@ BraceStructTypeFoldableImpl! {
2190
2192
ty,
2191
2193
name,
2192
2194
source_info,
2193
- syntactic_scope ,
2195
+ visibility_scope ,
2194
2196
}
2195
2197
}
2196
2198
0 commit comments