diff options
| author | bors <bors@rust-lang.org> | 2016-12-23 06:22:45 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-12-23 06:22:45 +0000 |
| commit | 82611a022468bb54476f149a0e77901ed48bcb9a (patch) | |
| tree | 3ff453dfacae27d143767f47ff1c3d5e63576b57 /src/libsyntax/parse | |
| parent | c8e7ec4bfc71db24b4c3cb186480214bdc32a091 (diff) | |
| parent | 8a1acb2c690eeb11b5c3f2a26bf2d68741ed5844 (diff) | |
| download | rust-82611a022468bb54476f149a0e77901ed48bcb9a.tar.gz rust-82611a022468bb54476f149a0e77901ed48bcb9a.zip | |
Auto merge of #38232 - jseyfried:refactor_global_paths, r=nrc
Refactor global paths
This PR removes the field `global: bool` from `ast::Path` and `hir::Path`, instead representing a global path `::foo::bar` as `{{root}}::foo::bar`, where `{{root}}` is a virtual keyword `keywords::CrateRoot`.
Also, fixes #38016.
r? @nrc
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 16 |
2 files changed, 12 insertions, 14 deletions
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index b9e6605639e..24178e1f675 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -633,7 +633,6 @@ mod tests { id: ast::DUMMY_NODE_ID, node: ast::ExprKind::Path(None, ast::Path { span: sp(0, 1), - global: false, segments: vec![Ident::from_str("a").into()], }), span: sp(0, 1), @@ -647,8 +646,9 @@ mod tests { id: ast::DUMMY_NODE_ID, node: ast::ExprKind::Path(None, ast::Path { span: sp(0, 6), - global: true, - segments: vec![Ident::from_str("a").into(), Ident::from_str("b").into()], + segments: vec![ast::PathSegment::crate_root(), + Ident::from_str("a").into(), + Ident::from_str("b").into()] }), span: sp(0, 6), attrs: ThinVec::new(), @@ -757,7 +757,6 @@ mod tests { id: ast::DUMMY_NODE_ID, node:ast::ExprKind::Path(None, ast::Path{ span: sp(7, 8), - global: false, segments: vec![Ident::from_str("d").into()], }), span:sp(7,8), @@ -775,7 +774,6 @@ mod tests { id: ast::DUMMY_NODE_ID, node: ast::ExprKind::Path(None, ast::Path { span:sp(0,1), - global:false, segments: vec![Ident::from_str("b").into()], }), span: sp(0,1), @@ -817,7 +815,6 @@ mod tests { ty: P(ast::Ty{id: ast::DUMMY_NODE_ID, node: ast::TyKind::Path(None, ast::Path{ span:sp(10,13), - global:false, segments: vec![Ident::from_str("i32").into()], }), span:sp(10,13) @@ -860,7 +857,6 @@ mod tests { node: ast::ExprKind::Path(None, ast::Path{ span:sp(17,18), - global:false, segments: vec![Ident::from_str("b").into()], }), span: sp(17,18), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 72462b74e68..cd4f255b5e3 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1614,7 +1614,6 @@ impl<'a> Parser<'a> { } else { ast::Path { span: span, - global: false, segments: vec![] } }; @@ -1658,7 +1657,7 @@ impl<'a> Parser<'a> { // Parse any number of segments and bound sets. A segment is an // identifier followed by an optional lifetime and a set of types. // A bound set is a set of type parameter bounds. - let segments = match mode { + let mut segments = match mode { PathStyle::Type => { self.parse_path_segments_without_colons()? } @@ -1670,13 +1669,16 @@ impl<'a> Parser<'a> { } }; + if is_global { + segments.insert(0, ast::PathSegment::crate_root()); + } + // Assemble the span. let span = mk_sp(lo, self.prev_span.hi); // Assemble the result. Ok(ast::Path { span: span, - global: is_global, segments: segments, }) } @@ -5180,7 +5182,7 @@ impl<'a> Parser<'a> { } else if self.eat_keyword(keywords::Crate) { pub_crate(self) } else { - let path = self.parse_path(PathStyle::Mod)?; + let path = self.parse_path(PathStyle::Mod)?.default_to_global(); self.expect(&token::CloseDelim(token::Paren))?; Ok(Visibility::Restricted { path: P(path), id: ast::DUMMY_NODE_ID }) } @@ -6068,9 +6070,9 @@ impl<'a> Parser<'a> { if self.check(&token::OpenDelim(token::Brace)) || self.check(&token::BinOp(token::Star)) || self.is_import_coupler() { // `{foo, bar}`, `::{foo, bar}`, `*`, or `::*`. + self.eat(&token::ModSep); let prefix = ast::Path { - global: self.eat(&token::ModSep), - segments: Vec::new(), + segments: vec![ast::PathSegment::crate_root()], span: mk_sp(lo, self.span.hi), }; let view_path_kind = if self.eat(&token::BinOp(token::Star)) { @@ -6080,7 +6082,7 @@ impl<'a> Parser<'a> { }; Ok(P(spanned(lo, self.span.hi, view_path_kind))) } else { - let prefix = self.parse_path(PathStyle::Mod)?; + let prefix = self.parse_path(PathStyle::Mod)?.default_to_global(); if self.is_import_coupler() { // `foo::bar::{a, b}` or `foo::bar::*` self.bump(); |
