diff options
| author | bors <bors@rust-lang.org> | 2017-10-24 01:20:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-10-24 01:20:09 +0000 |
| commit | 336624735c696fe3c15b64db83f19e9ce4665d06 (patch) | |
| tree | 2f141291475025b0200376e3695fc7e3c4d372b7 /src/libsyntax/parse | |
| parent | 4c053db233d69519b548e5b8ed7192d0783e582a (diff) | |
| parent | 4b0f004e3ddd4421153fd3a0a85343652aa864ce (diff) | |
| download | rust-336624735c696fe3c15b64db83f19e9ce4665d06.tar.gz rust-336624735c696fe3c15b64db83f19e9ce4665d06.zip | |
Auto merge of #44766 - sunjay:lift_generics, r=nikomatsakis
Move Generics from MethodSig to TraitItem and ImplItem As part of `rust-impl-period/WG-compiler-traits`, we want to "lift" `Generics` from `MethodSig` into `TraitItem` and `ImplItem`. This is in preparation for adding associated type generics. (https://github.com/rust-lang/rust/issues/44265#issuecomment-331172238) Currently this change is only made in the AST. In the future, it may also impact the HIR. (Still discussing) To understand this PR, it's probably best to start from the changes to `ast.rs` and then work your way to the other files to understand the far reaching effects of this change. r? @nikomatsakis
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8fd2bad4e44..07fa2a4d1a7 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1287,10 +1287,10 @@ impl<'a> Parser<'a> { mut attrs: Vec<Attribute>) -> PResult<'a, TraitItem> { let lo = self.span; - let (name, node) = if self.eat_keyword(keywords::Type) { + let (name, node, generics) = if self.eat_keyword(keywords::Type) { let TyParam {ident, bounds, default, ..} = self.parse_ty_param(vec![])?; self.expect(&token::Semi)?; - (ident, TraitItemKind::Type(bounds, default)) + (ident, TraitItemKind::Type(bounds, default), ast::Generics::default()) } else if self.is_const_item() { self.expect_keyword(keywords::Const)?; let ident = self.parse_ident()?; @@ -1305,7 +1305,7 @@ impl<'a> Parser<'a> { self.expect(&token::Semi)?; None }; - (ident, TraitItemKind::Const(ty, default)) + (ident, TraitItemKind::Const(ty, default), ast::Generics::default()) } else if self.token.is_path_start() { // trait item macro. // code copied from parse_macro_use_or_failure... abstraction! @@ -1328,7 +1328,7 @@ impl<'a> Parser<'a> { } let mac = respan(lo.to(self.prev_span), Mac_ { path: pth, tts: tts }); - (keywords::Invalid.ident(), ast::TraitItemKind::Macro(mac)) + (keywords::Invalid.ident(), ast::TraitItemKind::Macro(mac), ast::Generics::default()) } else { let (constness, unsafety, abi) = self.parse_fn_front_matter()?; @@ -1341,13 +1341,12 @@ impl<'a> Parser<'a> { // definition... p.parse_arg_general(false) })?; - generics.where_clause = self.parse_where_clause()?; + let sig = ast::MethodSig { unsafety, constness, decl: d, - generics, abi, }; @@ -1370,13 +1369,14 @@ impl<'a> Parser<'a> { return Err(self.fatal(&format!("expected `;` or `{{`, found `{}`", token_str))); } }; - (ident, ast::TraitItemKind::Method(sig, body)) + (ident, ast::TraitItemKind::Method(sig, body), generics) }; Ok(TraitItem { id: ast::DUMMY_NODE_ID, ident: name, attrs, + generics, node, span: lo.to(self.prev_span), tokens: None, @@ -4901,12 +4901,12 @@ impl<'a> Parser<'a> { let lo = self.span; let vis = self.parse_visibility(false)?; let defaultness = self.parse_defaultness()?; - let (name, node) = if self.eat_keyword(keywords::Type) { + let (name, node, generics) = if self.eat_keyword(keywords::Type) { let name = self.parse_ident()?; self.expect(&token::Eq)?; let typ = self.parse_ty()?; self.expect(&token::Semi)?; - (name, ast::ImplItemKind::Type(typ)) + (name, ast::ImplItemKind::Type(typ), ast::Generics::default()) } else if self.is_const_item() { self.expect_keyword(keywords::Const)?; let name = self.parse_ident()?; @@ -4915,11 +4915,11 @@ impl<'a> Parser<'a> { self.expect(&token::Eq)?; let expr = self.parse_expr()?; self.expect(&token::Semi)?; - (name, ast::ImplItemKind::Const(typ, expr)) + (name, ast::ImplItemKind::Const(typ, expr), ast::Generics::default()) } else { - let (name, inner_attrs, node) = self.parse_impl_method(&vis, at_end)?; + let (name, inner_attrs, generics, node) = self.parse_impl_method(&vis, at_end)?; attrs.extend(inner_attrs); - (name, node) + (name, node, generics) }; Ok(ImplItem { @@ -4929,6 +4929,7 @@ impl<'a> Parser<'a> { vis, defaultness, attrs, + generics, node, tokens: None, }) @@ -4986,7 +4987,8 @@ impl<'a> Parser<'a> { /// Parse a method or a macro invocation in a trait impl. fn parse_impl_method(&mut self, vis: &Visibility, at_end: &mut bool) - -> PResult<'a, (Ident, Vec<ast::Attribute>, ast::ImplItemKind)> { + -> PResult<'a, (Ident, Vec<ast::Attribute>, ast::Generics, + ast::ImplItemKind)> { // code copied from parse_macro_use_or_failure... abstraction! if self.token.is_path_start() { // Method macro. @@ -5013,7 +5015,8 @@ impl<'a> Parser<'a> { } let mac = respan(lo.to(self.prev_span), Mac_ { path: pth, tts: tts }); - Ok((keywords::Invalid.ident(), vec![], ast::ImplItemKind::Macro(mac))) + Ok((keywords::Invalid.ident(), vec![], ast::Generics::default(), + ast::ImplItemKind::Macro(mac))) } else { let (constness, unsafety, abi) = self.parse_fn_front_matter()?; let ident = self.parse_ident()?; @@ -5022,8 +5025,7 @@ impl<'a> Parser<'a> { generics.where_clause = self.parse_where_clause()?; *at_end = true; let (inner_attrs, body) = self.parse_inner_attrs_and_block()?; - Ok((ident, inner_attrs, ast::ImplItemKind::Method(ast::MethodSig { - generics, + Ok((ident, inner_attrs, generics, ast::ImplItemKind::Method(ast::MethodSig { abi, unsafety, constness, |
