@@ -59,6 +59,9 @@ pub struct Mark(u32);
5959#[ derive( Debug ) ]
6060struct MarkData {
6161 parent : Mark ,
62+ /// Each mark should have an associated expansion info, but sometimes there's a delay between
63+ /// creation of a mark and obtaining its info (e.g. macros are collected first and then
64+ /// resolved later), so we use an `Option` here.
6265 expn_info : Option < ExpnInfo > ,
6366}
6467
@@ -155,11 +158,11 @@ crate struct HygieneData {
155158}
156159
157160impl HygieneData {
158- crate fn new ( ) -> Self {
161+ crate fn new ( edition : Edition ) -> Self {
159162 HygieneData {
160163 marks : vec ! [ MarkData {
161164 parent: Mark :: root( ) ,
162- expn_info: None ,
165+ expn_info: Some ( ExpnInfo :: default ( ExpnKind :: Root , DUMMY_SP , edition ) ) ,
163166 } ] ,
164167 syntax_contexts : vec ! [ SyntaxContextData {
165168 outer_mark: Mark :: root( ) ,
@@ -183,7 +186,15 @@ impl HygieneData {
183186 }
184187
185188 fn expn_info ( & self , mark : Mark ) -> Option < & ExpnInfo > {
186- self . marks [ mark. 0 as usize ] . expn_info . as_ref ( )
189+ if mark != Mark :: root ( ) {
190+ Some ( self . marks [ mark. 0 as usize ] . expn_info . as_ref ( )
191+ . expect ( "no expansion info for a mark" ) )
192+ } else {
193+ // FIXME: Some code relies on `expn_info().is_none()` meaning "no expansion".
194+ // Introduce a method for checking for "no expansion" instead and always return
195+ // `ExpnInfo` from this function instead of the `Option`.
196+ None
197+ }
187198 }
188199
189200 fn is_descendant_of ( & self , mut mark : Mark , ancestor : Mark ) -> bool {
@@ -670,6 +681,8 @@ impl ExpnInfo {
670681/// Expansion kind.
671682#[ derive( Clone , Debug , RustcEncodable , RustcDecodable ) ]
672683pub enum ExpnKind {
684+ /// No expansion, aka root expansion. Only `Mark::root()` has this kind.
685+ Root ,
673686 /// Expansion produced by a macro.
674687 /// FIXME: Some code injected by the compiler before HIR lowering also gets this kind.
675688 Macro ( MacroKind , Symbol ) ,
@@ -680,6 +693,7 @@ pub enum ExpnKind {
680693impl ExpnKind {
681694 pub fn descr ( & self ) -> Symbol {
682695 match * self {
696+ ExpnKind :: Root => kw:: PathRoot ,
683697 ExpnKind :: Macro ( _, descr) => descr,
684698 ExpnKind :: Desugaring ( kind) => Symbol :: intern ( kind. descr ( ) ) ,
685699 }
0 commit comments