]> git.lizzy.rs Git - rust.git/commitdiff
Address review comments
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Wed, 5 Jun 2019 19:04:52 +0000 (22:04 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Thu, 6 Jun 2019 11:04:33 +0000 (14:04 +0300)
src/libsyntax/ext/tt/macro_rules.rs
src/libsyntax/mut_visit.rs
src/libsyntax/parse/parser.rs

index d25339a78f43c1f56bd243b6dabf6326c264f4e0..7ab51c1eb20c9468d87a42f7ab3fc74fe2446fd2 100644 (file)
@@ -130,9 +130,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt<'_>,
     }
 
     // Which arm's failure should we report? (the one furthest along)
-    let mut best_fail_spot = DUMMY_SP;
-    let mut best_fail_tok = None;
-    let mut best_fail_text = None;
+    let mut best_failure: Option<(Token, &str)> = None;
 
     for (i, lhs) in lhses.iter().enumerate() { // try each arm's matchers
         let lhs_tt = match *lhs {
@@ -190,21 +188,20 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt<'_>,
                     arm_span,
                 })
             }
-            Failure(token, msg) => if token.span.lo() >= best_fail_spot.lo() {
-                best_fail_spot = token.span;
-                best_fail_tok = Some(token.kind);
-                best_fail_text = Some(msg);
-            },
+            Failure(token, msg) => match best_failure {
+                Some((ref best_token, _)) if best_token.span.lo() >= token.span.lo() => {}
+                _ => best_failure = Some((token, msg))
+            }
             Error(err_sp, ref msg) => {
                 cx.span_fatal(err_sp.substitute_dummy(sp), &msg[..])
             }
         }
     }
 
-    let best_fail_msg = parse_failure_msg(best_fail_tok.expect("ran no matchers"));
-    let span = best_fail_spot.substitute_dummy(sp);
-    let mut err = cx.struct_span_err(span, &best_fail_msg);
-    err.span_label(span, best_fail_text.unwrap_or(&best_fail_msg));
+    let (token, label) = best_failure.expect("ran no matchers");
+    let span = token.span.substitute_dummy(sp);
+    let mut err = cx.struct_span_err(span, &parse_failure_msg(token.kind));
+    err.span_label(span, label);
     if let Some(sp) = def_span {
         if cx.source_map().span_to_filename(sp).is_real() && !sp.is_dummy() {
             err.span_label(cx.source_map().def_span(sp), "when calling this macro");
index 4d7f0a97b0fa55ec0daf368c6e85f1ece4b1c11d..d2a614c4a54ac320a803a6aa84c62ee7de43124d 100644 (file)
@@ -604,6 +604,8 @@ pub fn noop_visit_token<T: MutVisitor>(t: &mut Token, vis: &mut T) {
             let mut ident = Ident::new(*name, *span);
             vis.visit_ident(&mut ident);
             *name = ident.name;
+            *span = ident.span;
+            return; // avoid visiting the span for the second time
         }
         token::Interpolated(nt) => {
             let mut nt = Lrc::make_mut(nt);
index 51bfe3527cf4dfa099e875aba1c75a69dc8170d4..43e7c9330e418ead1b52b47b1d22de011e33bcc6 100644 (file)
@@ -197,13 +197,17 @@ enum PrevTokenKind {
 #[derive(Clone)]
 pub struct Parser<'a> {
     pub sess: &'a ParseSess,
-    /// The current token.
+    /// The current normalized token.
+    /// "Normalized" means that some interpolated tokens
+    /// (`$i: ident` and `$l: lifetime` meta-variables) are replaced
+    /// with non-interpolated identifier and lifetime tokens they refer to.
+    /// Perhaps the normalized / non-normalized setup can be simplified somehow.
     pub token: Token,
-    /// The span of the previous token.
+    /// Span of the current non-normalized token.
     meta_var_span: Option<Span>,
-    /// The span of the previous token.
+    /// Span of the previous non-normalized token.
     pub prev_span: Span,
-    /// The previous token kind.
+    /// Kind of the previous normalized token (in simplified form).
     prev_token_kind: PrevTokenKind,
     restrictions: Restrictions,
     /// Used to determine the path to externally loaded source files.