Skip to content

Commit a1637b7

Browse files
authored
Rollup merge of rust-lang#44745 - alexcrichton:no-delim-none, r=estebank
rustc: Don't use DelimToken::None if possible This commit fixes a regression from rust-lang#44601 where lowering attribute to HIR now involves expanding interpolated tokens to their actual tokens. In that commit all interpolated tokens were surrounded with a `DelimToken::None` group of tokens, but this ended up causing regressions like rust-lang#44730 where the various attribute parsers in `syntax/attr.rs` weren't ready to cope with `DelimToken::None`. Instead of fixing the parser in `attr.rs` this commit instead opts to just avoid the `DelimToken::None` in the first place, ensuring that the token stream should look the same as it did before where possible. Closes rust-lang#44730
2 parents 0249406 + 5053442 commit a1637b7

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

src/librustc/hir/lowering.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ use syntax::codemap::{self, respan, Spanned, CompilerDesugaringKind};
6565
use syntax::std_inject;
6666
use syntax::symbol::{Symbol, keywords};
6767
use syntax::tokenstream::{TokenStream, TokenTree, Delimited};
68-
use syntax::parse::token::{Token, DelimToken};
68+
use syntax::parse::token::Token;
6969
use syntax::util::small_vector::SmallVector;
7070
use syntax::visit::{self, Visitor};
7171
use syntax_pos::Span;
@@ -606,10 +606,12 @@ impl<'a> LoweringContext<'a> {
606606
}
607607

608608
fn lower_token_stream(&mut self, tokens: TokenStream) -> TokenStream {
609-
tokens.into_trees().map(|tree| self.lower_token_tree(tree)).collect()
609+
tokens.into_trees()
610+
.flat_map(|tree| self.lower_token_tree(tree).into_trees())
611+
.collect()
610612
}
611613

612-
fn lower_token_tree(&mut self, tree: TokenTree) -> TokenTree {
614+
fn lower_token_tree(&mut self, tree: TokenTree) -> TokenStream {
613615
match tree {
614616
TokenTree::Token(span, token) => {
615617
self.lower_token(token, span)
@@ -618,23 +620,19 @@ impl<'a> LoweringContext<'a> {
618620
TokenTree::Delimited(span, Delimited {
619621
delim: delimited.delim,
620622
tts: self.lower_token_stream(delimited.tts.into()).into(),
621-
})
623+
}).into()
622624
}
623625
}
624626
}
625627

626-
fn lower_token(&mut self, token: Token, span: Span) -> TokenTree {
628+
fn lower_token(&mut self, token: Token, span: Span) -> TokenStream {
627629
match token {
628630
Token::Interpolated(_) => {}
629-
other => return TokenTree::Token(span, other),
631+
other => return TokenTree::Token(span, other).into(),
630632
}
631633

632634
let tts = token.interpolated_to_tokenstream(&self.sess.parse_sess, span);
633-
let tts = self.lower_token_stream(tts);
634-
TokenTree::Delimited(span, Delimited {
635-
delim: DelimToken::NoDelim,
636-
tts: tts.into(),
637-
})
635+
self.lower_token_stream(tts)
638636
}
639637

640638
fn lower_arm(&mut self, arm: &Arm) -> hir::Arm {

src/test/run-pass/issue-44730.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! dox
12+
13+
#![deny(missing_docs)]
14+
15+
macro_rules! doc {
16+
($e:expr) => (
17+
#[doc = $e]
18+
pub struct Foo;
19+
)
20+
}
21+
22+
doc!("a");
23+
24+
fn main() {}

0 commit comments

Comments
 (0)