@@ -90,17 +90,17 @@ pub enum FileName {
9090 /// A macro. This includes the full name of the macro, so that there are no clashes.
9191 Macros ( String ) ,
9292 /// call to `quote!`
93- QuoteExpansion ,
93+ QuoteExpansion ( u64 ) ,
9494 /// Command line
95- Anon ,
95+ Anon ( u64 ) ,
9696 /// Hack in src/libsyntax/parse.rs
9797 /// FIXME(jseyfried)
98- MacroExpansion ,
99- ProcMacroSourceCode ,
98+ MacroExpansion ( u64 ) ,
99+ ProcMacroSourceCode ( u64 ) ,
100100 /// Strings provided as --cfg [cfgspec] stored in a crate_cfg
101- CfgSpec ,
101+ CfgSpec ( u64 ) ,
102102 /// Strings provided as crate attributes in the CLI
103- CliCrateAttr ,
103+ CliCrateAttr ( u64 ) ,
104104 /// Custom sources for explicit parser calls from plugins and drivers
105105 Custom ( String ) ,
106106}
@@ -111,12 +111,13 @@ impl std::fmt::Display for FileName {
111111 match * self {
112112 Real ( ref path) => write ! ( fmt, "{}" , path. display( ) ) ,
113113 Macros ( ref name) => write ! ( fmt, "<{} macros>" , name) ,
114- QuoteExpansion => write ! ( fmt, "<quote expansion>" ) ,
115- MacroExpansion => write ! ( fmt, "<macro expansion>" ) ,
116- Anon => write ! ( fmt, "<anon>" ) ,
117- ProcMacroSourceCode => write ! ( fmt, "<proc-macro source code>" ) ,
118- CfgSpec => write ! ( fmt, "cfgspec" ) ,
119- CliCrateAttr => write ! ( fmt, "<crate attribute>" ) ,
114+ QuoteExpansion ( _) => write ! ( fmt, "<quote expansion>" ) ,
115+ MacroExpansion ( _) => write ! ( fmt, "<macro expansion>" ) ,
116+ Anon ( _) => write ! ( fmt, "<anon>" ) ,
117+ ProcMacroSourceCode ( _) =>
118+ write ! ( fmt, "<proc-macro source code>" ) ,
119+ CfgSpec ( _) => write ! ( fmt, "<cfgspec>" ) ,
120+ CliCrateAttr ( _) => write ! ( fmt, "<crate attribute>" ) ,
120121 Custom ( ref s) => write ! ( fmt, "<{}>" , s) ,
121122 }
122123 }
@@ -135,30 +136,66 @@ impl FileName {
135136 match * self {
136137 Real ( _) => true ,
137138 Macros ( _) |
138- Anon |
139- MacroExpansion |
140- ProcMacroSourceCode |
141- CfgSpec |
142- CliCrateAttr |
139+ Anon ( _ ) |
140+ MacroExpansion ( _ ) |
141+ ProcMacroSourceCode ( _ ) |
142+ CfgSpec ( _ ) |
143+ CliCrateAttr ( _ ) |
143144 Custom ( _) |
144- QuoteExpansion => false ,
145+ QuoteExpansion ( _ ) => false ,
145146 }
146147 }
147148
148149 pub fn is_macros ( & self ) -> bool {
149150 use self :: FileName :: * ;
150151 match * self {
151152 Real ( _) |
152- Anon |
153- MacroExpansion |
154- ProcMacroSourceCode |
155- CfgSpec |
156- CliCrateAttr |
153+ Anon ( _ ) |
154+ MacroExpansion ( _ ) |
155+ ProcMacroSourceCode ( _ ) |
156+ CfgSpec ( _ ) |
157+ CliCrateAttr ( _ ) |
157158 Custom ( _) |
158- QuoteExpansion => false ,
159+ QuoteExpansion ( _ ) => false ,
159160 Macros ( _) => true ,
160161 }
161162 }
163+
164+ pub fn quote_expansion_source_code ( src : & str ) -> FileName {
165+ let mut hasher = StableHasher :: new ( ) ;
166+ src. hash ( & mut hasher) ;
167+ FileName :: QuoteExpansion ( hasher. finish ( ) )
168+ }
169+
170+ pub fn macro_expansion_source_code ( src : & str ) -> FileName {
171+ let mut hasher = StableHasher :: new ( ) ;
172+ src. hash ( & mut hasher) ;
173+ FileName :: MacroExpansion ( hasher. finish ( ) )
174+ }
175+
176+ pub fn anon_source_code ( src : & str ) -> FileName {
177+ let mut hasher = StableHasher :: new ( ) ;
178+ src. hash ( & mut hasher) ;
179+ FileName :: Anon ( hasher. finish ( ) )
180+ }
181+
182+ pub fn proc_macro_source_code ( src : & str ) -> FileName {
183+ let mut hasher = StableHasher :: new ( ) ;
184+ src. hash ( & mut hasher) ;
185+ FileName :: ProcMacroSourceCode ( hasher. finish ( ) )
186+ }
187+
188+ pub fn cfg_spec_source_code ( src : & str ) -> FileName {
189+ let mut hasher = StableHasher :: new ( ) ;
190+ src. hash ( & mut hasher) ;
191+ FileName :: QuoteExpansion ( hasher. finish ( ) )
192+ }
193+
194+ pub fn cli_crate_attr_source_code ( src : & str ) -> FileName {
195+ let mut hasher = StableHasher :: new ( ) ;
196+ src. hash ( & mut hasher) ;
197+ FileName :: CliCrateAttr ( hasher. finish ( ) )
198+ }
162199}
163200
164201/// Spans represent a region of code, used for error reporting. Positions in spans
0 commit comments