Skip to content

Commit ebfa2ab

Browse files
authored
Small style improvements
1 parent 1e21b3c commit ebfa2ab

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

compiler/rustc_expand/src/mbe/macro_parser.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
//! eof: [a $( a )* a b ·]
7171
//! ```
7272
73-
use rustc_errors::ErrorGuaranteed;
7473
pub(crate) use NamedMatch::*;
7574
pub(crate) use ParseResult::*;
7675

@@ -79,6 +78,7 @@ use crate::mbe::{macro_rules::Tracker, KleeneOp, TokenTree};
7978
use rustc_ast::token::{self, DocComment, Nonterminal, NonterminalKind, Token};
8079
use rustc_data_structures::fx::FxHashMap;
8180
use rustc_data_structures::sync::Lrc;
81+
use rustc_errors::ErrorGuaranteed;
8282
use rustc_lint_defs::pluralize;
8383
use rustc_parse::parser::{NtOrTt, Parser};
8484
use rustc_span::symbol::Ident;
@@ -96,7 +96,7 @@ use std::collections::hash_map::Entry::{Occupied, Vacant};
9696
///
9797
/// This means a matcher can be represented by `&[MatcherLoc]`, and traversal mostly involves
9898
/// simply incrementing the current matcher position index by one.
99-
#[derive(Debug, Clone, PartialEq)]
99+
#[derive(Debug)]
100100
pub(crate) enum MatcherLoc {
101101
Token {
102102
token: Token,

compiler/rustc_expand/src/mbe/macro_rules.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -210,18 +210,18 @@ fn trace_macros_note(cx_expansions: &mut FxIndexMap<Span, Vec<String>>, sp: Span
210210
}
211211

212212
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.
214214
fn before_match_loc(&mut self, parser: &TtParser, matcher: &'matcher MatcherLoc);
215215

216216
/// 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`).
218218
fn after_arm(&mut self, result: &NamedParseResult);
219219

220-
/// For tracing
220+
/// For tracing.
221221
fn description() -> &'static str;
222222
}
223223

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.
225225
struct NoopTracker;
226226

227227
impl<'matcher> Tracker<'matcher> for NoopTracker {
@@ -256,7 +256,7 @@ fn expand_macro<'cx>(
256256
trace_macros_note(&mut cx.expansions, sp, msg);
257257
}
258258

259-
// Track nothing for the best performance
259+
// Track nothing for the best performance.
260260
let try_success_result = try_match_macro(sess, name, &arg, lhses, &mut NoopTracker);
261261

262262
match try_success_result {
@@ -326,7 +326,7 @@ fn expand_macro<'cx>(
326326
}
327327
}
328328

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.
330330
let mut tracker = CollectTrackerAndEmitter::new(cx, sp);
331331

332332
let try_success_result = try_match_macro(sess, name, &arg, lhses, &mut tracker);
@@ -378,7 +378,7 @@ fn expand_macro<'cx>(
378378
DummyResult::any(sp)
379379
}
380380

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.
382382
struct CollectTrackerAndEmitter<'a, 'cx> {
383383
cx: &'a mut ExtCtxt<'cx>,
384384
/// Which arm's failure should we report? (the one furthest along)
@@ -427,7 +427,7 @@ enum CanRetry {
427427
No(ErrorGuaranteed),
428428
}
429429

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,
431431
/// and nothing if it failed. On failure, it's the callers job to use `track` accordingly to record all errors
432432
/// correctly.
433433
#[instrument(level = "debug", skip(sess, arg, lhses, track), fields(tracking = %T::description()))]
@@ -485,15 +485,16 @@ fn try_match_macro<'matcher, T: Tracker<'matcher>>(
485485
}
486486
Failure(_, _) => {
487487
trace!("Failed to match arm, trying the next one");
488-
// Try the next arm
488+
// Try the next arm.
489489
}
490490
Error(_, _) => {
491491
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.
493493
return Err(CanRetry::Yes);
494494
}
495495
ErrorReported(guarantee) => {
496496
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.
497498
return Err(CanRetry::No(guarantee));
498499
}
499500
}

0 commit comments

Comments
 (0)