@@ -90,17 +90,17 @@ pub enum FileName {
90
90
/// A macro. This includes the full name of the macro, so that there are no clashes.
91
91
Macros ( String ) ,
92
92
/// call to `quote!`
93
- QuoteExpansion ,
93
+ QuoteExpansion ( u64 ) ,
94
94
/// Command line
95
- Anon ,
95
+ Anon ( u64 ) ,
96
96
/// Hack in src/libsyntax/parse.rs
97
97
/// FIXME(jseyfried)
98
- MacroExpansion ,
99
- ProcMacroSourceCode ,
98
+ MacroExpansion ( u64 ) ,
99
+ ProcMacroSourceCode ( u64 ) ,
100
100
/// Strings provided as --cfg [cfgspec] stored in a crate_cfg
101
- CfgSpec ,
101
+ CfgSpec ( u64 ) ,
102
102
/// Strings provided as crate attributes in the CLI
103
- CliCrateAttr ,
103
+ CliCrateAttr ( u64 ) ,
104
104
/// Custom sources for explicit parser calls from plugins and drivers
105
105
Custom ( String ) ,
106
106
}
@@ -111,12 +111,13 @@ impl std::fmt::Display for FileName {
111
111
match * self {
112
112
Real ( ref path) => write ! ( fmt, "{}" , path. display( ) ) ,
113
113
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>" ) ,
120
121
Custom ( ref s) => write ! ( fmt, "<{}>" , s) ,
121
122
}
122
123
}
@@ -135,30 +136,66 @@ impl FileName {
135
136
match * self {
136
137
Real ( _) => true ,
137
138
Macros ( _) |
138
- Anon |
139
- MacroExpansion |
140
- ProcMacroSourceCode |
141
- CfgSpec |
142
- CliCrateAttr |
139
+ Anon ( _ ) |
140
+ MacroExpansion ( _ ) |
141
+ ProcMacroSourceCode ( _ ) |
142
+ CfgSpec ( _ ) |
143
+ CliCrateAttr ( _ ) |
143
144
Custom ( _) |
144
- QuoteExpansion => false ,
145
+ QuoteExpansion ( _ ) => false ,
145
146
}
146
147
}
147
148
148
149
pub fn is_macros ( & self ) -> bool {
149
150
use self :: FileName :: * ;
150
151
match * self {
151
152
Real ( _) |
152
- Anon |
153
- MacroExpansion |
154
- ProcMacroSourceCode |
155
- CfgSpec |
156
- CliCrateAttr |
153
+ Anon ( _ ) |
154
+ MacroExpansion ( _ ) |
155
+ ProcMacroSourceCode ( _ ) |
156
+ CfgSpec ( _ ) |
157
+ CliCrateAttr ( _ ) |
157
158
Custom ( _) |
158
- QuoteExpansion => false ,
159
+ QuoteExpansion ( _ ) => false ,
159
160
Macros ( _) => true ,
160
161
}
161
162
}
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
+ }
162
199
}
163
200
164
201
/// Spans represent a region of code, used for error reporting. Positions in spans
0 commit comments