about summary refs log tree commit diff
path: root/compiler/rustc_parse
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2020-09-10 16:20:05 -0400
committerAaron Hill <aa1ronham@gmail.com>2020-09-10 16:20:05 -0400
commit283d4c4d148c8c53a8b197c4ff0a9f79a1690eb2 (patch)
treedde142ec298203e3bcd27687af7974f4634f345b /compiler/rustc_parse
parent8c35a9279ca50d3e5a6f33d80a7191454fd89cbe (diff)
downloadrust-283d4c4d148c8c53a8b197c4ff0a9f79a1690eb2.tar.gz
rust-283d4c4d148c8c53a8b197c4ff0a9f79a1690eb2.zip
Ignore `|` and `+` tokens during proc-macro pretty-print check
Fixes #76182

This is an alternative to PR #76188

These tokens are not preserved in the AST in certain cases
(e.g. a leading `|` in a pattern or a trailing `+` in a trait bound).

This PR ignores them entirely during the pretty-print/reparse check
to avoid spuriously using the re-parsed tokenstream.
Diffstat (limited to 'compiler/rustc_parse')
-rw-r--r--compiler/rustc_parse/src/lib.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs
index e7fd74f551a..0f6a111ad70 100644
--- a/compiler/rustc_parse/src/lib.rs
+++ b/compiler/rustc_parse/src/lib.rs
@@ -353,6 +353,12 @@ pub fn tokenstream_probably_equal_for_proc_macro(
                 | token::CloseDelim(DelimToken::NoDelim)
                 // The pretty printer collapses many semicolons into one.
                 | token::Semi
+                // We don't preserve leading `|` tokens in patterns, so
+                // we ignore them entirely
+                | token::BinOp(token::BinOpToken::Or)
+                // We don't preserve trailing '+' tokens in trait bounds,
+                // so we ignore them entirely
+                | token::BinOp(token::BinOpToken::Plus)
                 // The pretty printer can turn `$crate` into `::crate_name`
                 | token::ModSep = token.kind {
                 return false;