@@ -210,18 +210,18 @@ fn trace_macros_note(cx_expansions: &mut FxIndexMap<Span, Vec<String>>, sp: Span
210
210
}
211
211
212
212
pub ( super ) trait Tracker < ' matcher > {
213
- /// This is called before trying to match next MatcherLoc on the current token
213
+ /// This is called before trying to match next MatcherLoc on the current token.
214
214
fn before_match_loc ( & mut self , parser : & TtParser , matcher : & ' matcher MatcherLoc ) ;
215
215
216
216
/// This is called after an arm has been parsed, either successfully or unsuccessfully. When this is called,
217
- /// `before_match_loc` was called at least once (with a `MatcherLoc::Eof`)
217
+ /// `before_match_loc` was called at least once (with a `MatcherLoc::Eof`).
218
218
fn after_arm ( & mut self , result : & NamedParseResult ) ;
219
219
220
- /// For tracing
220
+ /// For tracing.
221
221
fn description ( ) -> & ' static str ;
222
222
}
223
223
224
- /// A noop tracker that is used in the hot path of the expansion, has zero overhead thanks to monomorphization
224
+ /// A noop tracker that is used in the hot path of the expansion, has zero overhead thanks to monomorphization.
225
225
struct NoopTracker ;
226
226
227
227
impl < ' matcher > Tracker < ' matcher > for NoopTracker {
@@ -256,7 +256,7 @@ fn expand_macro<'cx>(
256
256
trace_macros_note ( & mut cx. expansions , sp, msg) ;
257
257
}
258
258
259
- // Track nothing for the best performance
259
+ // Track nothing for the best performance.
260
260
let try_success_result = try_match_macro ( sess, name, & arg, lhses, & mut NoopTracker ) ;
261
261
262
262
match try_success_result {
@@ -326,7 +326,7 @@ fn expand_macro<'cx>(
326
326
}
327
327
}
328
328
329
- // An error occured , try the expansion again, tracking the expansion closely for better diagnostics
329
+ // An error occurred , try the expansion again, tracking the expansion closely for better diagnostics.
330
330
let mut tracker = CollectTrackerAndEmitter :: new ( cx, sp) ;
331
331
332
332
let try_success_result = try_match_macro ( sess, name, & arg, lhses, & mut tracker) ;
@@ -378,7 +378,7 @@ fn expand_macro<'cx>(
378
378
DummyResult :: any ( sp)
379
379
}
380
380
381
- /// The tracker used for the slow error path that collects useful info for diagnostics
381
+ /// The tracker used for the slow error path that collects useful info for diagnostics.
382
382
struct CollectTrackerAndEmitter < ' a , ' cx > {
383
383
cx : & ' a mut ExtCtxt < ' cx > ,
384
384
/// Which arm's failure should we report? (the one furthest along)
@@ -427,7 +427,7 @@ enum CanRetry {
427
427
No ( ErrorGuaranteed ) ,
428
428
}
429
429
430
- /// Try expanding the macro. Returns the index of the sucessful arm and its named_matches if it was successful,
430
+ /// Try expanding the macro. Returns the index of the successful arm and its named_matches if it was successful,
431
431
/// and nothing if it failed. On failure, it's the callers job to use `track` accordingly to record all errors
432
432
/// correctly.
433
433
#[ instrument( level = "debug" , skip( sess, arg, lhses, track) , fields( tracking = %T :: description( ) ) ) ]
@@ -485,15 +485,16 @@ fn try_match_macro<'matcher, T: Tracker<'matcher>>(
485
485
}
486
486
Failure ( _, _) => {
487
487
trace ! ( "Failed to match arm, trying the next one" ) ;
488
- // Try the next arm
488
+ // Try the next arm.
489
489
}
490
490
Error ( _, _) => {
491
491
debug ! ( "Fatal error occurred during matching" ) ;
492
- // We haven't emitted an error yet
492
+ // We haven't emitted an error yet, so we can retry.
493
493
return Err ( CanRetry :: Yes ) ;
494
494
}
495
495
ErrorReported ( guarantee) => {
496
496
debug ! ( "Fatal error occurred and was reported during matching" ) ;
497
+ // An error has been reported already, we cannot retry as that would cause duplicate errors.
497
498
return Err ( CanRetry :: No ( guarantee) ) ;
498
499
}
499
500
}
0 commit comments