]> git.lizzy.rs Git - rust.git/commitdiff
Do not interpret mismatches from pretty-printed `$crate` as token stream invalidation
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Mon, 10 Dec 2018 23:26:31 +0000 (02:26 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Wed, 19 Dec 2018 20:17:54 +0000 (23:17 +0300)
src/libsyntax/parse/token.rs
src/libsyntax/tokenstream.rs
src/test/ui/proc-macro/dollar-crate.stderr
src/test/ui/proc-macro/dollar-crate.stdout

index ed7466574596fc586159abdc3d37c78c3783842c..badcc4ed8762d10e63f3492b2a1906417e07ad35 100644 (file)
@@ -633,7 +633,9 @@ pub fn interpolated_to_tokenstream(&self, sess: &ParseSess, span: Span)
             (&Shebang(a), &Shebang(b)) => a == b,
 
             (&Lifetime(a), &Lifetime(b)) => a.name == b.name,
-            (&Ident(a, b), &Ident(c, d)) => a.name == c.name && b == d,
+            (&Ident(a, b), &Ident(c, d)) => b == d && (a.name == c.name ||
+                                                       a.name == keywords::DollarCrate.name() ||
+                                                       c.name == keywords::DollarCrate.name()),
 
             (&Literal(ref a, b), &Literal(ref c, d)) => {
                 b == d && a.probably_equal_for_proc_macro(c)
index c11ef33f931d8ab94a82ba8ceca62795333595f1..013ecd3d343c28c6c0422db40938956421e2e912 100644 (file)
@@ -348,7 +348,9 @@ fn semantic_tree(tree: &TokenTree) -> bool {
                 | TokenTree::Token(_, Token::Semi)
                 // The pretty printer collapses whitespace arbitrarily and can
                 // introduce whitespace from `NoDelim`.
-                | TokenTree::Token(_, Token::Whitespace) => false,
+                | TokenTree::Token(_, Token::Whitespace)
+                // The pretty printer can turn `$crate` into `::crate_name`
+                | TokenTree::Token(_, Token::ModSep) => false,
                 _ => true
             }
         }
index 171562a5aff20520926c7979f93bbad2efb18a1d..75d3e17802ebdfec32d8cd95ca2ec3e86db2a21c 100644 (file)
@@ -2,7 +2,10 @@ error[E0428]: the name `D` is defined multiple times
   --> $DIR/dollar-crate.rs:23:13
    |
 LL |             struct D($crate::S); //~ ERROR the name `D` is defined multiple times
-   |             ^^^^^^^^^^^^^^^^^^^^ `D` redefined here
+   |             ^^^^^^^^^^^^^^^^^^^^
+   |             |
+   |             `D` redefined here
+   |             previous definition of the type `D` here
 ...
 LL |     local!();
    |     --------- in this macro invocation
@@ -13,7 +16,10 @@ error[E0428]: the name `D` is defined multiple times
   --> $DIR/dollar-crate.rs:31:5
    |
 LL |     dollar_crate_external::external!(); //~ ERROR the name `D` is defined multiple times
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `D` redefined here
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |     |
+   |     `D` redefined here
+   |     previous definition of the type `D` here
    |
    = note: `D` must be defined only once in the type namespace of this module
    = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
index 8e254854e32e68ee914bb116e21f96712ed82bab..c47b3603f41c033fc1ac052168b51149322717f1 100644 (file)
@@ -42,80 +42,80 @@ ATTRIBUTE INPUT (PRETTY-PRINTED): struct A(crate::S);
 ATTRIBUTE INPUT: TokenStream [
     Ident {
         ident: "struct",
-        span: #0 bytes(0..0)
+        span: #2 bytes(LO..HI)
     },
     Ident {
         ident: "A",
-        span: #0 bytes(0..0)
+        span: #2 bytes(LO..HI)
     },
     Group {
         delimiter: Parenthesis,
         stream: TokenStream [
             Ident {
-                ident: "crate",
-                span: #0 bytes(0..0)
+                ident: "$crate",
+                span: #2 bytes(LO..HI)
             },
             Punct {
                 ch: ':',
                 spacing: Joint,
-                span: #0 bytes(0..0)
+                span: #2 bytes(LO..HI)
             },
             Punct {
                 ch: ':',
                 spacing: Alone,
-                span: #0 bytes(0..0)
+                span: #2 bytes(LO..HI)
             },
             Ident {
                 ident: "S",
-                span: #0 bytes(0..0)
+                span: #2 bytes(LO..HI)
             }
         ],
-        span: #0 bytes(0..0)
+        span: #2 bytes(LO..HI)
     },
     Punct {
         ch: ';',
         spacing: Alone,
-        span: #0 bytes(0..0)
+        span: #2 bytes(LO..HI)
     }
 ]
 DERIVE INPUT (PRETTY-PRINTED): struct D(crate::S);
 DERIVE INPUT: TokenStream [
     Ident {
         ident: "struct",
-        span: #0 bytes(0..0)
+        span: #2 bytes(LO..HI)
     },
     Ident {
         ident: "D",
-        span: #0 bytes(0..0)
+        span: #2 bytes(LO..HI)
     },
     Group {
         delimiter: Parenthesis,
         stream: TokenStream [
             Ident {
-                ident: "crate",
-                span: #0 bytes(0..0)
+                ident: "$crate",
+                span: #2 bytes(LO..HI)
             },
             Punct {
                 ch: ':',
                 spacing: Joint,
-                span: #0 bytes(0..0)
+                span: #2 bytes(LO..HI)
             },
             Punct {
                 ch: ':',
                 spacing: Alone,
-                span: #0 bytes(0..0)
+                span: #2 bytes(LO..HI)
             },
             Ident {
                 ident: "S",
-                span: #0 bytes(0..0)
+                span: #2 bytes(LO..HI)
             }
         ],
-        span: #0 bytes(0..0)
+        span: #2 bytes(LO..HI)
     },
     Punct {
         ch: ';',
         spacing: Alone,
-        span: #0 bytes(0..0)
+        span: #2 bytes(LO..HI)
     }
 ]
 PROC MACRO INPUT (PRETTY-PRINTED): struct M ( $crate :: S ) ;
@@ -162,99 +162,79 @@ ATTRIBUTE INPUT (PRETTY-PRINTED): struct A(::dollar_crate_external::S);
 ATTRIBUTE INPUT: TokenStream [
     Ident {
         ident: "struct",
-        span: #0 bytes(0..0)
+        span: #10 bytes(LO..HI)
     },
     Ident {
         ident: "A",
-        span: #0 bytes(0..0)
+        span: #10 bytes(LO..HI)
     },
     Group {
         delimiter: Parenthesis,
         stream: TokenStream [
-            Punct {
-                ch: ':',
-                spacing: Joint,
-                span: #0 bytes(0..0)
-            },
-            Punct {
-                ch: ':',
-                spacing: Alone,
-                span: #0 bytes(0..0)
-            },
             Ident {
-                ident: "dollar_crate_external",
-                span: #0 bytes(0..0)
+                ident: "$crate",
+                span: #10 bytes(LO..HI)
             },
             Punct {
                 ch: ':',
                 spacing: Joint,
-                span: #0 bytes(0..0)
+                span: #10 bytes(LO..HI)
             },
             Punct {
                 ch: ':',
                 spacing: Alone,
-                span: #0 bytes(0..0)
+                span: #10 bytes(LO..HI)
             },
             Ident {
                 ident: "S",
-                span: #0 bytes(0..0)
+                span: #10 bytes(LO..HI)
             }
         ],
-        span: #0 bytes(0..0)
+        span: #10 bytes(LO..HI)
     },
     Punct {
         ch: ';',
         spacing: Alone,
-        span: #0 bytes(0..0)
+        span: #10 bytes(LO..HI)
     }
 ]
 DERIVE INPUT (PRETTY-PRINTED): struct D(::dollar_crate_external::S);
 DERIVE INPUT: TokenStream [
     Ident {
         ident: "struct",
-        span: #0 bytes(0..0)
+        span: #10 bytes(LO..HI)
     },
     Ident {
         ident: "D",
-        span: #0 bytes(0..0)
+        span: #10 bytes(LO..HI)
     },
     Group {
         delimiter: Parenthesis,
         stream: TokenStream [
-            Punct {
-                ch: ':',
-                spacing: Joint,
-                span: #0 bytes(0..0)
-            },
-            Punct {
-                ch: ':',
-                spacing: Alone,
-                span: #0 bytes(0..0)
-            },
             Ident {
-                ident: "dollar_crate_external",
-                span: #0 bytes(0..0)
+                ident: "$crate",
+                span: #10 bytes(LO..HI)
             },
             Punct {
                 ch: ':',
                 spacing: Joint,
-                span: #0 bytes(0..0)
+                span: #10 bytes(LO..HI)
             },
             Punct {
                 ch: ':',
                 spacing: Alone,
-                span: #0 bytes(0..0)
+                span: #10 bytes(LO..HI)
             },
             Ident {
                 ident: "S",
-                span: #0 bytes(0..0)
+                span: #10 bytes(LO..HI)
             }
         ],
-        span: #0 bytes(0..0)
+        span: #10 bytes(LO..HI)
     },
     Punct {
         ch: ';',
         spacing: Alone,
-        span: #0 bytes(0..0)
+        span: #10 bytes(LO..HI)
     }
 ]