Skip to content

Commit 3a31f06

Browse files
committed
Address review comments
1 parent ff40e37 commit 3a31f06

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

src/libsyntax/ext/tt/macro_rules.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt<'_>,
130130
}
131131

132132
// Which arm's failure should we report? (the one furthest along)
133-
let mut best_fail_spot = DUMMY_SP;
134-
let mut best_fail_tok = None;
135-
let mut best_fail_text = None;
133+
let mut best_failure: Option<(Token, &str)> = None;
136134

137135
for (i, lhs) in lhses.iter().enumerate() { // try each arm's matchers
138136
let lhs_tt = match *lhs {
@@ -190,21 +188,20 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt<'_>,
190188
arm_span,
191189
})
192190
}
193-
Failure(token, msg) => if token.span.lo() >= best_fail_spot.lo() {
194-
best_fail_spot = token.span;
195-
best_fail_tok = Some(token.kind);
196-
best_fail_text = Some(msg);
197-
},
191+
Failure(token, msg) => match best_failure {
192+
Some((ref best_token, _)) if best_token.span.lo() >= token.span.lo() => {}
193+
_ => best_failure = Some((token, msg))
194+
}
198195
Error(err_sp, ref msg) => {
199196
cx.span_fatal(err_sp.substitute_dummy(sp), &msg[..])
200197
}
201198
}
202199
}
203200

204-
let best_fail_msg = parse_failure_msg(best_fail_tok.expect("ran no matchers"));
205-
let span = best_fail_spot.substitute_dummy(sp);
206-
let mut err = cx.struct_span_err(span, &best_fail_msg);
207-
err.span_label(span, best_fail_text.unwrap_or(&best_fail_msg));
201+
let (token, label) = best_failure.expect("ran no matchers");
202+
let span = token.span.substitute_dummy(sp);
203+
let mut err = cx.struct_span_err(span, &parse_failure_msg(token.kind));
204+
err.span_label(span, label);
208205
if let Some(sp) = def_span {
209206
if cx.source_map().span_to_filename(sp).is_real() && !sp.is_dummy() {
210207
err.span_label(cx.source_map().def_span(sp), "when calling this macro");

src/libsyntax/mut_visit.rs

+2
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,8 @@ pub fn noop_visit_token<T: MutVisitor>(t: &mut Token, vis: &mut T) {
604604
let mut ident = Ident::new(*name, *span);
605605
vis.visit_ident(&mut ident);
606606
*name = ident.name;
607+
*span = ident.span;
608+
return; // avoid visiting the span for the second time
607609
}
608610
token::Interpolated(nt) => {
609611
let mut nt = Lrc::make_mut(nt);

src/libsyntax/parse/parser.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,17 @@ enum PrevTokenKind {
197197
#[derive(Clone)]
198198
pub struct Parser<'a> {
199199
pub sess: &'a ParseSess,
200-
/// The current token.
200+
/// The current normalized token.
201+
/// "Normalized" means that some interpolated tokens
202+
/// (`$i: ident` and `$l: lifetime` meta-variables) are replaced
203+
/// with non-interpolated identifier and lifetime tokens they refer to.
204+
/// Perhaps the normalized / non-normalized setup can be simplified somehow.
201205
pub token: Token,
202-
/// The span of the previous token.
206+
/// Span of the current non-normalized token.
203207
meta_var_span: Option<Span>,
204-
/// The span of the previous token.
208+
/// Span of the previous non-normalized token.
205209
pub prev_span: Span,
206-
/// The previous token kind.
210+
/// Kind of the previous normalized token (in simplified form).
207211
prev_token_kind: PrevTokenKind,
208212
restrictions: Restrictions,
209213
/// Used to determine the path to externally loaded source files.

0 commit comments

Comments
 (0)