Skip to content

Commit 55082ce

Browse files
committed
Attach TokenStream to ast::Path
1 parent 3815e91 commit 55082ce

File tree

15 files changed

+41
-21
lines changed

15 files changed

+41
-21
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub struct Path {
9696
/// The segments in the path: the things separated by `::`.
9797
/// Global paths begin with `kw::PathRoot`.
9898
pub segments: Vec<PathSegment>,
99+
pub tokens: Option<TokenStream>,
99100
}
100101

101102
impl PartialEq<Symbol> for Path {
@@ -117,7 +118,7 @@ impl Path {
117118
// Convert a span and an identifier to the corresponding
118119
// one-segment path.
119120
pub fn from_ident(ident: Ident) -> Path {
120-
Path { segments: vec![PathSegment::from_ident(ident)], span: ident.span }
121+
Path { segments: vec![PathSegment::from_ident(ident)], span: ident.span, tokens: None }
121122
}
122123

123124
pub fn is_global(&self) -> bool {
@@ -1069,7 +1070,7 @@ pub struct Expr {
10691070

10701071
// `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
10711072
#[cfg(target_arch = "x86_64")]
1072-
rustc_data_structures::static_assert_size!(Expr, 104);
1073+
rustc_data_structures::static_assert_size!(Expr, 112);
10731074

10741075
impl Expr {
10751076
/// Returns `true` if this expression would be valid somewhere that expects a value;

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ impl MetaItem {
415415
}
416416
}
417417
let span = span.with_hi(segments.last().unwrap().ident.span.hi());
418-
Path { span, segments }
418+
Path { span, segments, tokens: None }
419419
}
420420
Some(TokenTree::Token(Token { kind: token::Interpolated(nt), .. })) => match *nt {
421421
token::Nonterminal::NtMeta(ref item) => return item.meta(item.path.span),

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ pub fn noop_visit_ident<T: MutVisitor>(Ident { name: _, span }: &mut Ident, vis:
513513
vis.visit_span(span);
514514
}
515515

516-
pub fn noop_visit_path<T: MutVisitor>(Path { segments, span }: &mut Path, vis: &mut T) {
516+
pub fn noop_visit_path<T: MutVisitor>(Path { segments, span, tokens: _ }: &mut Path, vis: &mut T) {
517517
vis.visit_span(span);
518518
for PathSegment { ident, id, args } in segments {
519519
vis.visit_ident(ident);

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
251251
ItemKind::ExternCrate(orig_name) => hir::ItemKind::ExternCrate(orig_name),
252252
ItemKind::Use(ref use_tree) => {
253253
// Start with an empty prefix.
254-
let prefix = Path { segments: vec![], span: use_tree.span };
254+
let prefix = Path { segments: vec![], span: use_tree.span, tokens: None };
255255

256256
self.lower_use_tree(use_tree, &prefix, id, vis, ident, attrs)
257257
}
@@ -488,7 +488,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
488488
*ident = tree.ident();
489489

490490
// First, apply the prefix to the path.
491-
let mut path = Path { segments, span: path.span };
491+
let mut path = Path { segments, span: path.span, tokens: None };
492492

493493
// Correctly resolve `self` imports.
494494
if path.segments.len() > 1
@@ -540,8 +540,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
540540
hir::ItemKind::Use(path, hir::UseKind::Single)
541541
}
542542
UseTreeKind::Glob => {
543-
let path =
544-
self.lower_path(id, &Path { segments, span: path.span }, ParamMode::Explicit);
543+
let path = self.lower_path(
544+
id,
545+
&Path { segments, span: path.span, tokens: None },
546+
ParamMode::Explicit,
547+
);
545548
hir::ItemKind::Use(path, hir::UseKind::Glob)
546549
}
547550
UseTreeKind::Nested(ref trees) => {
@@ -569,7 +572,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
569572
// for that we return the `{}` import (called the
570573
// `ListStem`).
571574

572-
let prefix = Path { segments, span: prefix.span.to(path.span) };
575+
let prefix = Path { segments, span: prefix.span.to(path.span), tokens: None };
573576

574577
// Add all the nested `PathListItem`s to the HIR.
575578
for &(ref use_tree, id) in trees {

compiler/rustc_expand/src/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'a> ExtCtxt<'a> {
4646
id: ast::DUMMY_NODE_ID,
4747
args,
4848
});
49-
ast::Path { span, segments }
49+
ast::Path { span, segments, tokens: None }
5050
}
5151

5252
pub fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy {

compiler/rustc_expand/src/placeholders.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn placeholder(
1818
) -> AstFragment {
1919
fn mac_placeholder() -> ast::MacCall {
2020
ast::MacCall {
21-
path: ast::Path { span: DUMMY_SP, segments: Vec::new() },
21+
path: ast::Path { span: DUMMY_SP, segments: Vec::new(), tokens: None },
2222
args: P(ast::MacArgs::Empty),
2323
prior_type_ascription: None,
2424
}

compiler/rustc_parse/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ pub fn nt_to_tokenstream(nt: &Nonterminal, sess: &ParseSess, span: Span) -> Toke
278278
Some(tokenstream::TokenTree::token(token::Lifetime(ident.name), ident.span).into())
279279
}
280280
Nonterminal::NtMeta(ref attr) => attr.tokens.clone(),
281+
Nonterminal::NtPath(ref path) => path.tokens.clone(),
281282
Nonterminal::NtTT(ref tt) => Some(tt.clone().into()),
282283
Nonterminal::NtExpr(ref expr) | Nonterminal::NtLiteral(ref expr) => {
283284
if expr.tokens.is_none() {

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ impl<'a> Parser<'a> {
901901
) -> PResult<'a, P<T>> {
902902
self.expect(&token::ModSep)?;
903903

904-
let mut path = ast::Path { segments: Vec::new(), span: DUMMY_SP };
904+
let mut path = ast::Path { segments: Vec::new(), span: DUMMY_SP, tokens: None };
905905
self.parse_path_segments(&mut path.segments, T::PATH_STYLE)?;
906906
path.span = ty_span.to(self.prev_token.span);
907907

compiler/rustc_parse/src/parser/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ impl<'a> Parser<'a> {
787787
fn parse_use_tree(&mut self) -> PResult<'a, UseTree> {
788788
let lo = self.token.span;
789789

790-
let mut prefix = ast::Path { segments: Vec::new(), span: lo.shrink_to_lo() };
790+
let mut prefix = ast::Path { segments: Vec::new(), span: lo.shrink_to_lo(), tokens: None };
791791
let kind = if self.check(&token::OpenDelim(token::Brace))
792792
|| self.check(&token::BinOp(token::Star))
793793
|| self.is_import_coupler()

compiler/rustc_parse/src/parser/nonterminal.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,15 @@ impl<'a> Parser<'a> {
168168
return Err(self.struct_span_err(self.token.span, msg));
169169
}
170170
}
171-
NonterminalKind::Path => token::NtPath(self.parse_path(PathStyle::Type)?),
171+
NonterminalKind::Path => {
172+
let (mut path, tokens) =
173+
self.collect_tokens(|this| this.parse_path(PathStyle::Type))?;
174+
// We have have eaten an NtPath, which could already have tokens
175+
if path.tokens.is_none() {
176+
path.tokens = Some(tokens);
177+
}
178+
token::NtPath(path)
179+
}
172180
NonterminalKind::Meta => {
173181
let (mut attr, tokens) = self.collect_tokens(|this| this.parse_attr_item())?;
174182
// We may have eaten a nonterminal, which could already have tokens

0 commit comments

Comments
 (0)