about summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-01-17 12:31:15 +0000
committerbors <bors@rust-lang.org>2017-01-17 12:31:15 +0000
commita167c042abed695a049abf3919ce929765e6cc30 (patch)
treefc768fdc8b7d00c603a0576656cd37bbd524bddd /src/libsyntax/ext
parent0825c96b14f0b5eb59da1c36f70fe410c7c6fce7 (diff)
parent66ef5f2bb55f3204d50b5011e3d15385065834c1 (diff)
Auto merge of #39110 - petrochenkov:sum, r=eddyb
Merge ObjectSum and PolyTraitRef in AST/HIR + some other refactoring

`ObjectSum` and `PolyTraitRef` are the same thing (list of bounds), they exist separately only due to parser quirks. The second commit merges them.

The first commit replaces `Path` with `Ty` in (not yet supported) equality predicates. They are parsed as types anyway and arbitrary types can always be disguised as paths using aliases, so this doesn't add any new functionality.

The third commit uses `Vec` instead of `P<[T]>` in AST. AST is not immutable like HIR and `Vec`s are more convenient for it, unnecessary conversions are also avoided.

The last commit renames `parse_ty_sum` (which is used for parsing types in general) into `parse_ty`, and renames `parse_ty` (which is used restricted contexts where `+` is not permitted due to operator priorities or other reasons) into `parse_ty_no_plus`.

This is the first part of https://github.com/rust-lang/rust/issues/39085#issuecomment-272743755 and https://github.com/rust-lang/rust/issues/39080 focused on data changes and mechanical renaming, I'll submit a PR with parser changes a bit later.

r? @eddyb
Diffstat (limited to 'src/libsyntax/ext')
-rw-r--r--src/libsyntax/ext/build.rs32
-rw-r--r--src/libsyntax/ext/expand.rs2
-rw-r--r--src/libsyntax/ext/quote.rs2
-rw-r--r--src/libsyntax/ext/tt/macro_parser.rs2
4 files changed, 7 insertions, 31 deletions
diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs
index 8c4b56b7fc0..1837fa1e5fe 100644
--- a/src/libsyntax/ext/build.rs
+++ b/src/libsyntax/ext/build.rs
@@ -54,7 +54,6 @@ pub trait AstBuilder {
 
     fn ty(&self, span: Span, ty: ast::TyKind) -> P<ast::Ty>;
     fn ty_path(&self, ast::Path) -> P<ast::Ty>;
-    fn ty_sum(&self, ast::Path, ast::TyParamBounds) -> P<ast::Ty>;
     fn ty_ident(&self, span: Span, idents: ast::Ident) -> P<ast::Ty>;
 
     fn ty_rptr(&self, span: Span,
@@ -68,9 +67,6 @@ pub trait AstBuilder {
     fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty>;
     fn ty_infer(&self, sp: Span) -> P<ast::Ty>;
 
-    fn ty_vars(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> ;
-    fn ty_vars_global(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> ;
-
     fn typaram(&self,
                span: Span,
                id: ast::Ident,
@@ -334,8 +330,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
         } else {
             Some(P(ast::PathParameters::AngleBracketed(ast::AngleBracketedParameterData {
                 lifetimes: lifetimes,
-                types: P::from_vec(types),
-                bindings: P::from_vec(bindings),
+                types: types,
+                bindings: bindings,
             })))
         };
         segments.push(ast::PathSegment { identifier: last_identifier, parameters: parameters });
@@ -370,8 +366,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
         let mut path = trait_path;
         let parameters = ast::AngleBracketedParameterData {
             lifetimes: lifetimes,
-            types: P::from_vec(types),
-            bindings: P::from_vec(bindings),
+            types: types,
+            bindings: bindings,
         };
         path.segments.push(ast::PathSegment {
             identifier: ident,
@@ -403,12 +399,6 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
         self.ty(path.span, ast::TyKind::Path(None, path))
     }
 
-    fn ty_sum(&self, path: ast::Path, bounds: ast::TyParamBounds) -> P<ast::Ty> {
-        self.ty(path.span,
-                ast::TyKind::ObjectSum(self.ty_path(path),
-                                 bounds))
-    }
-
     // Might need to take bounds as an argument in the future, if you ever want
     // to generate a bounded existential trait type.
     fn ty_ident(&self, span: Span, ident: ast::Ident)
@@ -465,20 +455,6 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
         }
     }
 
-    // these are strange, and probably shouldn't be used outside of
-    // pipes. Specifically, the global version possible generates
-    // incorrect code.
-    fn ty_vars(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> {
-        ty_params.iter().map(|p| self.ty_ident(DUMMY_SP, p.ident)).collect()
-    }
-
-    fn ty_vars_global(&self, ty_params: &P<[ast::TyParam]>) -> Vec<P<ast::Ty>> {
-        ty_params
-            .iter()
-            .map(|p| self.ty_path(self.path_global(DUMMY_SP, vec![p.ident])))
-            .collect()
-    }
-
     fn trait_ref(&self, path: ast::Path) -> ast::TraitRef {
         ast::TraitRef {
             path: path,
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index 3a8f9126b49..26e731e1a5e 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -540,7 +540,7 @@ impl<'a> Parser<'a> {
             }
             ExpansionKind::Expr => Expansion::Expr(self.parse_expr()?),
             ExpansionKind::OptExpr => Expansion::OptExpr(Some(self.parse_expr()?)),
-            ExpansionKind::Ty => Expansion::Ty(self.parse_ty()?),
+            ExpansionKind::Ty => Expansion::Ty(self.parse_ty_no_plus()?),
             ExpansionKind::Pat => Expansion::Pat(self.parse_pat()?),
         })
     }
diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs
index d2eb2636e6b..c0cbda4ba12 100644
--- a/src/libsyntax/ext/quote.rs
+++ b/src/libsyntax/ext/quote.rs
@@ -388,7 +388,7 @@ pub fn parse_arm_panic(parser: &mut Parser) -> Arm {
 }
 
 pub fn parse_ty_panic(parser: &mut Parser) -> P<Ty> {
-    panictry!(parser.parse_ty())
+    panictry!(parser.parse_ty_no_plus())
 }
 
 pub fn parse_stmt_panic(parser: &mut Parser) -> Option<Stmt> {
diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs
index 2de31166070..87c8f3efb63 100644
--- a/src/libsyntax/ext/tt/macro_parser.rs
+++ b/src/libsyntax/ext/tt/macro_parser.rs
@@ -522,7 +522,7 @@ fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
         },
         "pat" => token::NtPat(panictry!(p.parse_pat())),
         "expr" => token::NtExpr(panictry!(p.parse_expr())),
-        "ty" => token::NtTy(panictry!(p.parse_ty())),
+        "ty" => token::NtTy(panictry!(p.parse_ty_no_plus())),
         // this could be handled like a token, since it is one
         "ident" => match p.token {
             token::Ident(sn) => {