diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-11-06 03:28:09 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-06 03:28:09 +0100 |
| commit | e5da1a12e745e0d92cfae421673faac4fd5e4069 (patch) | |
| tree | 7899e2184908bc21c9eb2b07698513ea1982030c /src/libsyntax_expand | |
| parent | 5c4a595ff09d08c46ee3b23d343da47b0d12243d (diff) | |
| parent | 90f891d8ae9073623769fac18f00c4f1031fcb59 (diff) | |
| download | rust-e5da1a12e745e0d92cfae421673faac4fd5e4069.tar.gz rust-e5da1a12e745e0d92cfae421673faac4fd5e4069.zip | |
Rollup merge of #66054 - petrochenkov:delspan, r=estebank
syntax: Avoid span arithmetic for delimiter tokens The +/-1 logic is from the time where the whole group had a single span and the delimiter spans had to be calculated from it. Now the delimiters have their own spans which are constructed by lexer or proc macro API and can be used directly. If those spans are not perfect, then it should be fixed by tweaking the corresponding lexer logic rather than by trying to add or substract `1` from the span boundaries. Fixes https://github.com/rust-lang/rust/issues/62524 r? @estebank
Diffstat (limited to 'src/libsyntax_expand')
| -rw-r--r-- | src/libsyntax_expand/mbe.rs | 24 | ||||
| -rw-r--r-- | src/libsyntax_expand/mbe/macro_rules.rs | 6 |
2 files changed, 10 insertions, 20 deletions
diff --git a/src/libsyntax_expand/mbe.rs b/src/libsyntax_expand/mbe.rs index d0f790638ef..06e0cde3ad8 100644 --- a/src/libsyntax_expand/mbe.rs +++ b/src/libsyntax_expand/mbe.rs @@ -13,7 +13,7 @@ use syntax::ast; use syntax::parse::token::{self, Token, TokenKind}; use syntax::tokenstream::{DelimSpan}; -use syntax_pos::{BytePos, Span}; +use syntax_pos::Span; use rustc_data_structures::sync::Lrc; @@ -27,23 +27,13 @@ struct Delimited { impl Delimited { /// Returns a `self::TokenTree` with a `Span` corresponding to the opening delimiter. - fn open_tt(&self, span: Span) -> TokenTree { - let open_span = if span.is_dummy() { - span - } else { - span.with_hi(span.lo() + BytePos(self.delim.len() as u32)) - }; - TokenTree::token(token::OpenDelim(self.delim), open_span) + fn open_tt(&self, span: DelimSpan) -> TokenTree { + TokenTree::token(token::OpenDelim(self.delim), span.open) } /// Returns a `self::TokenTree` with a `Span` corresponding to the closing delimiter. - fn close_tt(&self, span: Span) -> TokenTree { - let close_span = if span.is_dummy() { - span - } else { - span.with_lo(span.hi() - BytePos(self.delim.len() as u32)) - }; - TokenTree::token(token::CloseDelim(self.delim), close_span) + fn close_tt(&self, span: DelimSpan) -> TokenTree { + TokenTree::token(token::CloseDelim(self.delim), span.close) } } @@ -138,10 +128,10 @@ impl TokenTree { } (&TokenTree::Delimited(span, ref delimed), _) => { if index == 0 { - return delimed.open_tt(span.open); + return delimed.open_tt(span); } if index == delimed.tts.len() + 1 { - return delimed.close_tt(span.close); + return delimed.close_tt(span); } delimed.tts[index - 1].clone() } diff --git a/src/libsyntax_expand/mbe/macro_rules.rs b/src/libsyntax_expand/mbe/macro_rules.rs index 9a4130b2d8d..bfdc4c52b5a 100644 --- a/src/libsyntax_expand/mbe/macro_rules.rs +++ b/src/libsyntax_expand/mbe/macro_rules.rs @@ -566,7 +566,7 @@ impl FirstSets { } TokenTree::Delimited(span, ref delimited) => { build_recur(sets, &delimited.tts[..]); - first.replace_with(delimited.open_tt(span.open)); + first.replace_with(delimited.open_tt(span)); } TokenTree::Sequence(sp, ref seq_rep) => { let subfirst = build_recur(sets, &seq_rep.tts[..]); @@ -628,7 +628,7 @@ impl FirstSets { return first; } TokenTree::Delimited(span, ref delimited) => { - first.add_one(delimited.open_tt(span.open)); + first.add_one(delimited.open_tt(span)); return first; } TokenTree::Sequence(sp, ref seq_rep) => { @@ -826,7 +826,7 @@ fn check_matcher_core( } } TokenTree::Delimited(span, ref d) => { - let my_suffix = TokenSet::singleton(d.close_tt(span.close)); + let my_suffix = TokenSet::singleton(d.close_tt(span)); check_matcher_core(sess, features, attrs, first_sets, &d.tts, &my_suffix); // don't track non NT tokens last.replace_with_irrelevant(); |
