1
Fork 0

Give each PathSegment a NodeId

This commit is contained in:
Nick Cameron 2018-08-31 12:01:26 +12:00
parent 8ec22e7ec7
commit fc67d8fac4
4 changed files with 19 additions and 7 deletions

View file

@ -129,6 +129,8 @@ pub struct PathSegment {
/// The identifier portion of this path segment.
pub ident: Ident,
pub id: NodeId,
/// Type/lifetime parameters attached to this path. They come in
/// two flavors: `Path<A,B,C>` and `Path(A,B) -> C`.
/// `None` means that no parameter list is supplied (`Path`),
@ -140,10 +142,14 @@ pub struct PathSegment {
impl PathSegment {
pub fn from_ident(ident: Ident) -> Self {
PathSegment { ident, args: None }
PathSegment { ident, id: DUMMY_NODE_ID, args: None }
}
pub fn crate_root(span: Span) -> Self {
PathSegment::from_ident(Ident::new(keywords::CrateRoot.name(), span))
PathSegment {
ident: Ident::new(keywords::CrateRoot.name(), span),
id: CRATE_NODE_ID,
args: None,
}
}
}

View file

@ -329,7 +329,11 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
} else {
None
};
segments.push(ast::PathSegment { ident: last_ident.with_span_pos(span), args });
segments.push(ast::PathSegment {
ident: last_ident.with_span_pos(span),
id: ast::DUMMY_NODE_ID,
args,
});
let mut path = ast::Path { span, segments };
if global {
if let Some(seg) = path.make_root() {
@ -366,7 +370,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
} else {
None
};
path.segments.push(ast::PathSegment { ident, args });
path.segments.push(ast::PathSegment { ident, id: ast::DUMMY_NODE_ID, args });
(ast::QSelf {
ty: self_type,

View file

@ -468,8 +468,9 @@ pub fn noop_fold_usize<T: Folder>(i: usize, _: &mut T) -> usize {
pub fn noop_fold_path<T: Folder>(Path { segments, span }: Path, fld: &mut T) -> Path {
Path {
segments: segments.move_map(|PathSegment { ident, args }| PathSegment {
segments: segments.move_map(|PathSegment { ident, id, args }| PathSegment {
ident: fld.fold_ident(ident),
id: fld.new_id(id),
args: args.map(|args| args.map(|args| fld.fold_generic_args(args))),
}),
span: fld.new_span(span)
@ -1234,6 +1235,7 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span, attrs}: Expr, folder: &mu
ExprKind::MethodCall(
PathSegment {
ident: folder.fold_ident(seg.ident),
id: folder.new_id(seg.id),
args: seg.args.map(|args| {
args.map(|args| folder.fold_generic_args(args))
}),

View file

@ -2134,10 +2134,10 @@ impl<'a> Parser<'a> {
ParenthesisedArgs { inputs, output, span }.into()
};
PathSegment { ident, args }
PathSegment { ident, args, id: ast::DUMMY_NODE_ID }
} else {
// Generic arguments are not found.
PathSegment::from_ident(ident)
PathSegment::from_ident(ident,)
})
}