@@ -78,13 +78,13 @@ pub struct Mir<'tcx> {
7878 /// that indexes into this vector.
7979 basic_blocks : IndexVec < BasicBlock , BasicBlockData < ' tcx > > ,
8080
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 > ,
8484
85- /// Crate-local information for each visibility scope, that can't (and
85+ /// Crate-local information for each source scope, that can't (and
8686 /// 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 > > ,
8888
8989 /// Rvalues promoted from this function, such as borrows of constants.
9090 /// 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);
137137
138138impl < ' tcx > Mir < ' tcx > {
139139 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 > > ,
143143 promoted : IndexVec < Promoted , Mir < ' tcx > > ,
144144 yield_ty : Option < Ty < ' tcx > > ,
145145 local_decls : IndexVec < Local , LocalDecl < ' tcx > > ,
@@ -153,8 +153,8 @@ impl<'tcx> Mir<'tcx> {
153153
154154 Mir {
155155 basic_blocks,
156- visibility_scopes ,
157- visibility_scope_info ,
156+ source_scopes ,
157+ source_scope_local_data ,
158158 promoted,
159159 yield_ty,
160160 generator_drop : None ,
@@ -308,14 +308,6 @@ impl<'tcx> Mir<'tcx> {
308308 }
309309}
310310
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-
319311#[ derive( Copy , Clone , Debug , RustcEncodable , RustcDecodable ) ]
320312pub enum Safety {
321313 Safe ,
@@ -329,8 +321,8 @@ pub enum Safety {
329321
330322impl_stable_hash_for ! ( struct Mir <' tcx> {
331323 basic_blocks,
332- visibility_scopes ,
333- visibility_scope_info ,
324+ source_scopes ,
325+ source_scope_local_data ,
334326 promoted,
335327 yield_ty,
336328 generator_drop,
@@ -376,8 +368,9 @@ pub struct SourceInfo {
376368 /// Source span for the AST pertaining to this MIR entity.
377369 pub span : Span ,
378370
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
381374}
382375
383376///////////////////////////////////////////////////////////////////////////
@@ -512,16 +505,13 @@ pub struct LocalDecl<'tcx> {
512505 /// to generate better debuginfo.
513506 pub name : Option < Name > ,
514507
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
519509 /// in. If the local was defined in a let-statement, this
520510 /// is *within* the let-statement, rather than outside
521511 /// of it.
522512 ///
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.
525515 ///
526516 /// The reason is that we want the local to be *within* the let-statement
527517 /// for lint purposes, but we want the local to be *after* the let-statement
@@ -566,9 +556,9 @@ pub struct LocalDecl<'tcx> {
566556 /// `drop(x)`, we want it to refer to `x: u32`.
567557 ///
568558 /// 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
570560 /// "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"
572562 /// scope (where the "rest" of a block is under all prior let-statements).
573563 ///
574564 /// The end result looks like this:
@@ -580,21 +570,25 @@ pub struct LocalDecl<'tcx> {
580570 /// │ │{ #[allow(unused_mut] } // this is actually split into 2 scopes
581571 /// │ │ // in practice because I'm lazy.
582572 /// │ │
583- /// │ │← x.syntactic_scope
573+ /// │ │← x.source_info.scope
584574 /// │ │← `x.parse().unwrap()`
585575 /// │ │
586- /// │ │ │← y.syntactic_scope
576+ /// │ │ │← y.source_info.scope
587577 /// │ │
588578 /// │ │ │{ let y: u32 }
589579 /// │ │ │
590- /// │ │ │← y.source_info.scope
580+ /// │ │ │← y.visibility_scope
591581 /// │ │ │← `y + 2`
592582 /// │
593583 /// │ │{ let x: u32 }
594- /// │ │← x.source_info.scope
584+ /// │ │← x.visibility_scope
595585 /// │ │← `drop(x)` // this accesses `x: u32`
596586 /// ```
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 ,
598592}
599593
600594impl < ' tcx > LocalDecl < ' tcx > {
@@ -607,9 +601,9 @@ impl<'tcx> LocalDecl<'tcx> {
607601 name : None ,
608602 source_info : SourceInfo {
609603 span,
610- scope : ARGUMENT_VISIBILITY_SCOPE
604+ scope : OUTERMOST_SOURCE_SCOPE
611605 } ,
612- syntactic_scope : ARGUMENT_VISIBILITY_SCOPE ,
606+ visibility_scope : OUTERMOST_SOURCE_SCOPE ,
613607 internal : false ,
614608 is_user_variable : false
615609 }
@@ -624,9 +618,9 @@ impl<'tcx> LocalDecl<'tcx> {
624618 name : None ,
625619 source_info : SourceInfo {
626620 span,
627- scope : ARGUMENT_VISIBILITY_SCOPE
621+ scope : OUTERMOST_SOURCE_SCOPE
628622 } ,
629- syntactic_scope : ARGUMENT_VISIBILITY_SCOPE ,
623+ visibility_scope : OUTERMOST_SOURCE_SCOPE ,
630624 internal : true ,
631625 is_user_variable : false
632626 }
@@ -642,9 +636,9 @@ impl<'tcx> LocalDecl<'tcx> {
642636 ty : return_ty,
643637 source_info : SourceInfo {
644638 span,
645- scope : ARGUMENT_VISIBILITY_SCOPE
639+ scope : OUTERMOST_SOURCE_SCOPE
646640 } ,
647- syntactic_scope : ARGUMENT_VISIBILITY_SCOPE ,
641+ visibility_scope : OUTERMOST_SOURCE_SCOPE ,
648642 internal : false ,
649643 name : None , // FIXME maybe we do want some name here?
650644 is_user_variable : false
@@ -1047,7 +1041,7 @@ impl<'tcx> BasicBlockData<'tcx> {
10471041 self . statements . resize ( gap. end , Statement {
10481042 source_info : SourceInfo {
10491043 span : DUMMY_SP ,
1050- scope : ARGUMENT_VISIBILITY_SCOPE
1044+ scope : OUTERMOST_SOURCE_SCOPE
10511045 } ,
10521046 kind : StatementKind :: Nop
10531047 } ) ;
@@ -1501,16 +1495,24 @@ impl<'tcx> Debug for Place<'tcx> {
15011495///////////////////////////////////////////////////////////////////////////
15021496// Scopes
15031497
1504- newtype_index ! ( VisibilityScope
1498+ newtype_index ! ( SourceScope
15051499 {
15061500 DEBUG_FORMAT = "scope[{}]" ,
1507- const ARGUMENT_VISIBILITY_SCOPE = 0 ,
1501+ const OUTERMOST_SOURCE_SCOPE = 0 ,
15081502 } ) ;
15091503
15101504#[ derive( Clone , Debug , RustcEncodable , RustcDecodable ) ]
1511- pub struct VisibilityScopeData {
1505+ pub struct SourceScopeData {
15121506 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 ,
15141516}
15151517
15161518///////////////////////////////////////////////////////////////////////////
@@ -2153,16 +2155,16 @@ CloneTypeFoldableAndLiftImpls! {
21532155 SourceInfo ,
21542156 UpvarDecl ,
21552157 ValidationOp ,
2156- VisibilityScopeData ,
2157- VisibilityScope ,
2158- VisibilityScopeInfo ,
2158+ SourceScope ,
2159+ SourceScopeData ,
2160+ SourceScopeLocalData ,
21592161}
21602162
21612163BraceStructTypeFoldableImpl ! {
21622164 impl <' tcx> TypeFoldable <' tcx> for Mir <' tcx> {
21632165 basic_blocks,
2164- visibility_scopes ,
2165- visibility_scope_info ,
2166+ source_scopes ,
2167+ source_scope_local_data ,
21662168 promoted,
21672169 yield_ty,
21682170 generator_drop,
@@ -2190,7 +2192,7 @@ BraceStructTypeFoldableImpl! {
21902192 ty,
21912193 name,
21922194 source_info,
2193- syntactic_scope ,
2195+ visibility_scope ,
21942196 }
21952197}
21962198
0 commit comments