From f61394f0bd9c7d5951d2f70207177ff5a6b038fa Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Thu, 21 Sep 2017 22:18:47 -0400 Subject: [PATCH 01/11] Lifting Generics from MethodSig to TraitItem and ImplItem since we want to support generics in each variant of TraitItem and ImplItem --- src/librustc/hir/lowering.rs | 10 +++---- src/librustc_resolve/lib.rs | 7 +++-- src/librustc_save_analysis/dump_visitor.rs | 9 ++++-- src/librustc_save_analysis/sig.rs | 6 ++-- src/libsyntax/ast.rs | 3 +- src/libsyntax/ext/placeholders.rs | 5 ++-- src/libsyntax/fold.rs | 3 +- src/libsyntax/parse/parser.rs | 32 +++++++++++----------- src/libsyntax/print/pprust.rs | 7 +++-- src/libsyntax/visit.rs | 6 ++-- src/libsyntax_ext/deriving/generic/mod.rs | 3 +- 11 files changed, 51 insertions(+), 40 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 54aecb4b00f..f3363bde6e7 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1548,7 +1548,7 @@ impl<'a> LoweringContext<'a> { } TraitItemKind::Method(ref sig, None) => { let names = this.lower_fn_args_to_names(&sig.decl); - hir::TraitItemKind::Method(this.lower_method_sig(sig), + hir::TraitItemKind::Method(this.lower_method_sig(&i.generics, sig), hir::TraitMethod::Required(names)) } TraitItemKind::Method(ref sig, Some(ref body)) => { @@ -1556,7 +1556,7 @@ impl<'a> LoweringContext<'a> { let body = this.lower_block(body, false); this.expr_block(body, ThinVec::new()) }); - hir::TraitItemKind::Method(this.lower_method_sig(sig), + hir::TraitItemKind::Method(this.lower_method_sig(&i.generics, sig), hir::TraitMethod::Provided(body_id)) } TraitItemKind::Type(ref bounds, ref default) => { @@ -1615,7 +1615,7 @@ impl<'a> LoweringContext<'a> { let body = this.lower_block(body, false); this.expr_block(body, ThinVec::new()) }); - hir::ImplItemKind::Method(this.lower_method_sig(sig), body_id) + hir::ImplItemKind::Method(this.lower_method_sig(&i.generics, sig), body_id) } ImplItemKind::Type(ref ty) => hir::ImplItemKind::Type(this.lower_ty(ty)), ImplItemKind::Macro(..) => panic!("Shouldn't exist any more"), @@ -1727,9 +1727,9 @@ impl<'a> LoweringContext<'a> { }) } - fn lower_method_sig(&mut self, sig: &MethodSig) -> hir::MethodSig { + fn lower_method_sig(&mut self, generics: &Generics, sig: &MethodSig) -> hir::MethodSig { hir::MethodSig { - generics: self.lower_generics(&sig.generics), + generics: self.lower_generics(generics), abi: sig.abi, unsafety: self.lower_unsafety(sig.unsafety), constness: self.lower_constness(sig.constness), diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 4aab43cbec7..8d546a66ef5 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -723,7 +723,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> { ItemRibKind } FnKind::Method(_, sig, _, _) => { - self.visit_generics(&sig.generics); MethodRibKind(!sig.decl.has_self()) } FnKind::Closure(_) => ClosureRibKind(node_id), @@ -1864,6 +1863,7 @@ impl<'a> Resolver<'a> { for trait_item in trait_items { this.check_proc_macro_attrs(&trait_item.attrs); + this.visit_generics(&trait_item.generics); match trait_item.node { TraitItemKind::Const(ref ty, ref default) => { @@ -1880,7 +1880,7 @@ impl<'a> Resolver<'a> { } TraitItemKind::Method(ref sig, _) => { let type_parameters = - HasTypeParameters(&sig.generics, + HasTypeParameters(&trait_item.generics, MethodRibKind(!sig.decl.has_self())); this.with_type_parameter_rib(type_parameters, |this| { visit::walk_trait_item(this, trait_item) @@ -2075,6 +2075,7 @@ impl<'a> Resolver<'a> { this.with_current_self_type(self_type, |this| { for impl_item in impl_items { this.check_proc_macro_attrs(&impl_item.attrs); + this.visit_generics(&impl_item.generics); this.resolve_visibility(&impl_item.vis); match impl_item.node { ImplItemKind::Const(..) => { @@ -2097,7 +2098,7 @@ impl<'a> Resolver<'a> { // We also need a new scope for the method- // specific type parameters. let type_parameters = - HasTypeParameters(&sig.generics, + HasTypeParameters(&impl_item.generics, MethodRibKind(!sig.decl.has_self())); this.with_type_parameter_rib(type_parameters, |this| { visit::walk_impl_item(this, impl_item); diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 3e730cf8365..c57d5305d80 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -354,23 +354,24 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { body: Option<&'l ast::Block>, id: ast::NodeId, name: ast::Ident, + generics: &'l ast::Generics, vis: ast::Visibility, span: Span) { debug!("process_method: {}:{}", id, name); if let Some(mut method_data) = self.save_ctxt.get_method_data(id, name.name, span) { - let sig_str = ::make_signature(&sig.decl, &sig.generics); + let sig_str = ::make_signature(&sig.decl, &generics); if body.is_some() { self.nest_tables(id, |v| { v.process_formals(&sig.decl.inputs, &method_data.qualname) }); } - self.process_generic_params(&sig.generics, span, &method_data.qualname, id); + self.process_generic_params(&generics, span, &method_data.qualname, id); method_data.value = sig_str; - method_data.sig = sig::method_signature(id, name, sig, &self.save_ctxt); + method_data.sig = sig::method_signature(id, name, generics, sig, &self.save_ctxt); self.dumper.dump_def(vis == ast::Visibility::Public, method_data); } @@ -1007,6 +1008,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { body.as_ref().map(|x| &**x), trait_item.id, trait_item.ident, + &trait_item.generics, ast::Visibility::Public, trait_item.span); } @@ -1066,6 +1068,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { Some(body), impl_item.id, impl_item.ident, + &impl_item.generics, impl_item.vis.clone(), impl_item.span); } diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index 47e5ad6c010..88f574d513b 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -77,13 +77,14 @@ pub fn variant_signature(variant: &ast::Variant, scx: &SaveContext) -> Option Option { if !scx.config.signatures { return None; } - make_method_signature(id, ident, m, scx).ok() + make_method_signature(id, ident, generics, m, scx).ok() } pub fn assoc_const_signature(id: NodeId, @@ -895,6 +896,7 @@ fn make_assoc_const_signature(id: NodeId, fn make_method_signature(id: NodeId, ident: ast::Ident, + generics: &ast::Generics, m: &ast::MethodSig, scx: &SaveContext) -> Result { @@ -915,7 +917,7 @@ fn make_method_signature(id: NodeId, let mut sig = name_and_generics(text, 0, - &m.generics, + generics, id, ident, scx)?; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index f445def9e03..b985ac78056 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1178,7 +1178,6 @@ pub struct MethodSig { pub constness: Spanned, pub abi: Abi, pub decl: P, - pub generics: Generics, } /// Represents an item declaration within a trait declaration, @@ -1190,6 +1189,7 @@ pub struct TraitItem { pub id: NodeId, pub ident: Ident, pub attrs: Vec, + pub generics: Generics, pub node: TraitItemKind, pub span: Span, /// See `Item::tokens` for what this is @@ -1211,6 +1211,7 @@ pub struct ImplItem { pub vis: Visibility, pub defaultness: Defaultness, pub attrs: Vec, + pub generics: Generics, pub node: ImplItemKind, pub span: Span, /// See `Item::tokens` for what this is diff --git a/src/libsyntax/ext/placeholders.rs b/src/libsyntax/ext/placeholders.rs index 4fc2b92d3cd..2f5b386346b 100644 --- a/src/libsyntax/ext/placeholders.rs +++ b/src/libsyntax/ext/placeholders.rs @@ -32,6 +32,7 @@ pub fn placeholder(kind: ExpansionKind, id: ast::NodeId) -> Expansion { let ident = keywords::Invalid.ident(); let attrs = Vec::new(); + let generics = ast::Generics::default(); let vis = ast::Visibility::Inherited; let span = DUMMY_SP; let expr_placeholder = || P(ast::Expr { @@ -49,12 +50,12 @@ pub fn placeholder(kind: ExpansionKind, id: ast::NodeId) -> Expansion { tokens: None, }))), ExpansionKind::TraitItems => Expansion::TraitItems(SmallVector::one(ast::TraitItem { - id, span, ident, attrs, + id, span, ident, attrs, generics, node: ast::TraitItemKind::Macro(mac_placeholder()), tokens: None, })), ExpansionKind::ImplItems => Expansion::ImplItems(SmallVector::one(ast::ImplItem { - id, span, ident, vis, attrs, + id, span, ident, vis, attrs, generics, node: ast::ImplItemKind::Macro(mac_placeholder()), defaultness: ast::Defaultness::Final, tokens: None, diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index d7d491db71f..518386a2ad2 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -943,6 +943,7 @@ pub fn noop_fold_trait_item(i: TraitItem, folder: &mut T) id: folder.new_id(i.id), ident: folder.fold_ident(i.ident), attrs: fold_attrs(i.attrs, folder), + generics: folder.fold_generics(i.generics), node: match i.node { TraitItemKind::Const(ty, default) => { TraitItemKind::Const(folder.fold_ty(ty), @@ -972,6 +973,7 @@ pub fn noop_fold_impl_item(i: ImplItem, folder: &mut T) vis: folder.fold_vis(i.vis), ident: folder.fold_ident(i.ident), attrs: fold_attrs(i.attrs, folder), + generics: folder.fold_generics(i.generics), defaultness: i.defaultness, node: match i.node { ast::ImplItemKind::Const(ty, expr) => { @@ -1074,7 +1076,6 @@ pub fn noop_fold_foreign_item(ni: ForeignItem, folder: &mut T) -> For pub fn noop_fold_method_sig(sig: MethodSig, folder: &mut T) -> MethodSig { MethodSig { - generics: folder.fold_generics(sig.generics), abi: sig.abi, unsafety: sig.unsafety, constness: sig.constness, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8fd2bad4e44..b0ed4c4e0ee 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1287,10 +1287,10 @@ impl<'a> Parser<'a> { mut attrs: Vec) -> 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,7 @@ 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::ImplItemKind)> { + -> PResult<'a, (Ident, Vec, ast::Generics, ast::ImplItemKind)> { // code copied from parse_macro_use_or_failure... abstraction! if self.token.is_path_start() { // Method macro. @@ -5013,7 +5014,7 @@ 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 +5023,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, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 02f871c58c7..b9a7fa04a06 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1525,6 +1525,7 @@ impl<'a> State<'a> { pub fn print_method_sig(&mut self, ident: ast::Ident, + generics: &ast::Generics, m: &ast::MethodSig, vis: &ast::Visibility) -> io::Result<()> { @@ -1533,7 +1534,7 @@ impl<'a> State<'a> { m.constness.node, m.abi, Some(ident), - &m.generics, + &generics, vis) } @@ -1553,7 +1554,7 @@ impl<'a> State<'a> { if body.is_some() { self.head("")?; } - self.print_method_sig(ti.ident, sig, &ast::Visibility::Inherited)?; + self.print_method_sig(ti.ident, &ti.generics, sig, &ast::Visibility::Inherited)?; if let Some(ref body) = *body { self.nbsp()?; self.print_block_with_attrs(body, &ti.attrs)?; @@ -1592,7 +1593,7 @@ impl<'a> State<'a> { } ast::ImplItemKind::Method(ref sig, ref body) => { self.head("")?; - self.print_method_sig(ii.ident, sig, &ii.vis)?; + self.print_method_sig(ii.ident, &ii.generics, sig, &ii.vis)?; self.nbsp()?; self.print_block_with_attrs(body, &ii.attrs)?; } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 521c6030eba..e74296c06a9 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -543,8 +543,7 @@ pub fn walk_fn<'a, V>(visitor: &mut V, kind: FnKind<'a>, declaration: &'a FnDecl walk_fn_decl(visitor, declaration); visitor.visit_block(body); } - FnKind::Method(_, sig, _, body) => { - visitor.visit_generics(&sig.generics); + FnKind::Method(_, _, _, body) => { walk_fn_decl(visitor, declaration); visitor.visit_block(body); } @@ -558,13 +557,13 @@ pub fn walk_fn<'a, V>(visitor: &mut V, kind: FnKind<'a>, declaration: &'a FnDecl pub fn walk_trait_item<'a, V: Visitor<'a>>(visitor: &mut V, trait_item: &'a TraitItem) { visitor.visit_ident(trait_item.span, trait_item.ident); walk_list!(visitor, visit_attribute, &trait_item.attrs); + visitor.visit_generics(&trait_item.generics); match trait_item.node { TraitItemKind::Const(ref ty, ref default) => { visitor.visit_ty(ty); walk_list!(visitor, visit_expr, default); } TraitItemKind::Method(ref sig, None) => { - visitor.visit_generics(&sig.generics); walk_fn_decl(visitor, &sig.decl); } TraitItemKind::Method(ref sig, Some(ref body)) => { @@ -585,6 +584,7 @@ pub fn walk_impl_item<'a, V: Visitor<'a>>(visitor: &mut V, impl_item: &'a ImplIt visitor.visit_vis(&impl_item.vis); visitor.visit_ident(impl_item.span, impl_item.ident); walk_list!(visitor, visit_attribute, &impl_item.attrs); + visitor.visit_generics(&impl_item.generics); match impl_item.node { ImplItemKind::Const(ref ty, ref expr) => { visitor.visit_ty(ty); diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 5c1ca19d635..18897047538 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -506,6 +506,7 @@ impl<'a> TraitDef<'a> { vis: ast::Visibility::Inherited, defaultness: ast::Defaultness::Final, attrs: Vec::new(), + generics: Generics::default(), node: ast::ImplItemKind::Type(type_def.to_ty(cx, self.span, type_ident, generics)), tokens: None, } @@ -921,12 +922,12 @@ impl<'a> MethodDef<'a> { ast::ImplItem { id: ast::DUMMY_NODE_ID, attrs: self.attributes.clone(), + generics: fn_generics, span: trait_.span, vis: ast::Visibility::Inherited, defaultness: ast::Defaultness::Final, ident: method_ident, node: ast::ImplItemKind::Method(ast::MethodSig { - generics: fn_generics, abi, unsafety, constness: From e03447dae36022a0155718a8b089fed1204ac39a Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Thu, 21 Sep 2017 22:22:33 -0400 Subject: [PATCH 02/11] Fixed tidy errors --- src/libsyntax/parse/parser.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index b0ed4c4e0ee..07fa2a4d1a7 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4987,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::Generics, ast::ImplItemKind)> { + -> PResult<'a, (Ident, Vec, ast::Generics, + ast::ImplItemKind)> { // code copied from parse_macro_use_or_failure... abstraction! if self.token.is_path_start() { // Method macro. @@ -5014,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::Generics::default(), 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()?; From 892e4689efb163ab220ee353b15b70833b9baeb0 Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Mon, 25 Sep 2017 12:23:43 -0400 Subject: [PATCH 03/11] Removed redundant generics visits --- src/librustc_resolve/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 8d546a66ef5..2e5c9e35346 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1863,7 +1863,6 @@ impl<'a> Resolver<'a> { for trait_item in trait_items { this.check_proc_macro_attrs(&trait_item.attrs); - this.visit_generics(&trait_item.generics); match trait_item.node { TraitItemKind::Const(ref ty, ref default) => { @@ -2075,7 +2074,6 @@ impl<'a> Resolver<'a> { this.with_current_self_type(self_type, |this| { for impl_item in impl_items { this.check_proc_macro_attrs(&impl_item.attrs); - this.visit_generics(&impl_item.generics); this.resolve_visibility(&impl_item.vis); match impl_item.node { ImplItemKind::Const(..) => { From bb301446050900f2e9bbb0d465fd8615fbd0e7e6 Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Mon, 25 Sep 2017 17:24:20 -0400 Subject: [PATCH 04/11] Lifted generics into TraitItem and ImplItem from MethodSig -- HIR now matches AST --- src/librustc/hir/intravisit.rs | 8 ++-- src/librustc/hir/lowering.rs | 11 ++--- src/librustc/hir/mod.rs | 3 +- src/librustc/hir/print.rs | 9 ++-- src/librustc/ich/impls_hir.rs | 7 +++- src/librustc/middle/reachable.rs | 11 +++-- src/librustc/middle/resolve_lifetime.rs | 4 +- src/librustc_typeck/check/compare_method.rs | 14 +++---- src/librustc_typeck/collect.rs | 46 ++++----------------- 9 files changed, 42 insertions(+), 71 deletions(-) diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 1755b3bca05..d99d7cd897b 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -780,9 +780,7 @@ pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V, function_kind: FnKind<' FnKind::ItemFn(_, generics, ..) => { visitor.visit_generics(generics); } - FnKind::Method(_, sig, ..) => { - visitor.visit_generics(&sig.generics); - } + FnKind::Method(..) | FnKind::Closure(_) => {} } } @@ -802,6 +800,7 @@ pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V, pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v TraitItem) { visitor.visit_name(trait_item.span, trait_item.name); walk_list!(visitor, visit_attribute, &trait_item.attrs); + visitor.visit_generics(&trait_item.generics); match trait_item.node { TraitItemKind::Const(ref ty, default) => { visitor.visit_id(trait_item.id); @@ -810,7 +809,6 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai } TraitItemKind::Method(ref sig, TraitMethod::Required(ref names)) => { visitor.visit_id(trait_item.id); - visitor.visit_generics(&sig.generics); visitor.visit_fn_decl(&sig.decl); for name in names { visitor.visit_name(name.span, name.node); @@ -852,6 +850,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt ref vis, ref defaultness, ref attrs, + ref generics, ref node, span } = *impl_item; @@ -860,6 +859,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt visitor.visit_vis(vis); visitor.visit_defaultness(defaultness); walk_list!(visitor, visit_attribute, attrs); + visitor.visit_generics(generics); match *node { ImplItemKind::Const(ref ty, body) => { visitor.visit_id(impl_item.id); diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index f3363bde6e7..81da69a575c 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1539,6 +1539,7 @@ impl<'a> LoweringContext<'a> { hir_id, name: this.lower_ident(i.ident), attrs: this.lower_attrs(&i.attrs), + generics: this.lower_generics(&i.generics), node: match i.node { TraitItemKind::Const(ref ty, ref default) => { hir::TraitItemKind::Const(this.lower_ty(ty), @@ -1548,7 +1549,7 @@ impl<'a> LoweringContext<'a> { } TraitItemKind::Method(ref sig, None) => { let names = this.lower_fn_args_to_names(&sig.decl); - hir::TraitItemKind::Method(this.lower_method_sig(&i.generics, sig), + hir::TraitItemKind::Method(this.lower_method_sig(sig), hir::TraitMethod::Required(names)) } TraitItemKind::Method(ref sig, Some(ref body)) => { @@ -1556,7 +1557,7 @@ impl<'a> LoweringContext<'a> { let body = this.lower_block(body, false); this.expr_block(body, ThinVec::new()) }); - hir::TraitItemKind::Method(this.lower_method_sig(&i.generics, sig), + hir::TraitItemKind::Method(this.lower_method_sig(sig), hir::TraitMethod::Provided(body_id)) } TraitItemKind::Type(ref bounds, ref default) => { @@ -1603,6 +1604,7 @@ impl<'a> LoweringContext<'a> { hir_id, name: this.lower_ident(i.ident), attrs: this.lower_attrs(&i.attrs), + generics: this.lower_generics(&i.generics), vis: this.lower_visibility(&i.vis, None), defaultness: this.lower_defaultness(i.defaultness, true /* [1] */), node: match i.node { @@ -1615,7 +1617,7 @@ impl<'a> LoweringContext<'a> { let body = this.lower_block(body, false); this.expr_block(body, ThinVec::new()) }); - hir::ImplItemKind::Method(this.lower_method_sig(&i.generics, sig), body_id) + hir::ImplItemKind::Method(this.lower_method_sig(sig), body_id) } ImplItemKind::Type(ref ty) => hir::ImplItemKind::Type(this.lower_ty(ty)), ImplItemKind::Macro(..) => panic!("Shouldn't exist any more"), @@ -1727,9 +1729,8 @@ impl<'a> LoweringContext<'a> { }) } - fn lower_method_sig(&mut self, generics: &Generics, sig: &MethodSig) -> hir::MethodSig { + fn lower_method_sig(&mut self, sig: &MethodSig) -> hir::MethodSig { hir::MethodSig { - generics: self.lower_generics(generics), abi: sig.abi, unsafety: self.lower_unsafety(sig.unsafety), constness: self.lower_constness(sig.constness), diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 5ad0ff04c1b..fb3fc8a2da4 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1295,7 +1295,6 @@ pub struct MethodSig { pub constness: Constness, pub abi: Abi, pub decl: P, - pub generics: Generics, } // The bodies for items are stored "out of line", in a separate @@ -1316,6 +1315,7 @@ pub struct TraitItem { pub name: Name, pub hir_id: HirId, pub attrs: HirVec, + pub generics: Generics, pub node: TraitItemKind, pub span: Span, } @@ -1360,6 +1360,7 @@ pub struct ImplItem { pub vis: Visibility, pub defaultness: Defaultness, pub attrs: HirVec, + pub generics: Generics, pub node: ImplItemKind, pub span: Span, } diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 7287e599b29..4eee9cbfc2d 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -880,6 +880,7 @@ impl<'a> State<'a> { pub fn print_method_sig(&mut self, name: ast::Name, m: &hir::MethodSig, + generics: &hir::Generics, vis: &hir::Visibility, arg_names: &[Spanned], body_id: Option) @@ -889,7 +890,7 @@ impl<'a> State<'a> { m.constness, m.abi, Some(name), - &m.generics, + generics, vis, arg_names, body_id) @@ -905,12 +906,12 @@ impl<'a> State<'a> { self.print_associated_const(ti.name, &ty, default, &hir::Inherited)?; } hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Required(ref arg_names)) => { - self.print_method_sig(ti.name, sig, &hir::Inherited, arg_names, None)?; + self.print_method_sig(ti.name, sig, &ti.generics, &hir::Inherited, arg_names, None)?; self.s.word(";")?; } hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => { self.head("")?; - self.print_method_sig(ti.name, sig, &hir::Inherited, &[], Some(body))?; + self.print_method_sig(ti.name, sig, &ti.generics, &hir::Inherited, &[], Some(body))?; self.nbsp()?; self.end()?; // need to close a box self.end()?; // need to close a box @@ -938,7 +939,7 @@ impl<'a> State<'a> { } hir::ImplItemKind::Method(ref sig, body) => { self.head("")?; - self.print_method_sig(ii.name, sig, &ii.vis, &[], Some(body))?; + self.print_method_sig(ii.name, sig, &ii.generics, &ii.vis, &[], Some(body))?; self.nbsp()?; self.end()?; // need to close a box self.end()?; // need to close a box diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index c0fae8bf8bd..994f0bd16b1 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -232,8 +232,7 @@ impl_stable_hash_for!(struct hir::MethodSig { unsafety, constness, abi, - decl, - generics + decl }); impl_stable_hash_for!(struct hir::TypeBinding { @@ -709,6 +708,7 @@ impl<'gcx> HashStable> for hir::TraitItem { hir_id: _, name, ref attrs, + ref generics, ref node, span } = *self; @@ -716,6 +716,7 @@ impl<'gcx> HashStable> for hir::TraitItem { hcx.hash_hir_item_like(attrs, |hcx| { name.hash_stable(hcx, hasher); attrs.hash_stable(hcx, hasher); + generics.hash_stable(hcx, hasher); node.hash_stable(hcx, hasher); span.hash_stable(hcx, hasher); }); @@ -744,6 +745,7 @@ impl<'gcx> HashStable> for hir::ImplItem { ref vis, defaultness, ref attrs, + ref generics, ref node, span } = *self; @@ -753,6 +755,7 @@ impl<'gcx> HashStable> for hir::ImplItem { vis.hash_stable(hcx, hasher); defaultness.hash_stable(hcx, hasher); attrs.hash_stable(hcx, hasher); + generics.hash_stable(hcx, hasher); node.hash_stable(hcx, hasher); span.hash_stable(hcx, hasher); }); diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index bb6213cb5fa..2037bc01a5b 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -58,11 +58,10 @@ fn item_might_be_inlined(item: &hir::Item) -> bool { } fn method_might_be_inlined<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - sig: &hir::MethodSig, impl_item: &hir::ImplItem, impl_src: DefId) -> bool { if attr::requests_inline(&impl_item.attrs) || - generics_require_inlining(&sig.generics) { + generics_require_inlining(&impl_item.generics) { return true } if let Some(impl_node_id) = tcx.hir.as_local_node_id(impl_src) { @@ -176,8 +175,8 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { Some(hir_map::NodeImplItem(impl_item)) => { match impl_item.node { hir::ImplItemKind::Const(..) => true, - hir::ImplItemKind::Method(ref sig, _) => { - if generics_require_inlining(&sig.generics) || + hir::ImplItemKind::Method(..) => { + if generics_require_inlining(&impl_item.generics) || attr::requests_inline(&impl_item.attrs) { true } else { @@ -293,9 +292,9 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { hir::ImplItemKind::Const(_, body) => { self.visit_nested_body(body); } - hir::ImplItemKind::Method(ref sig, body) => { + hir::ImplItemKind::Method(_, body) => { let did = self.tcx.hir.get_parent_did(search_item); - if method_might_be_inlined(self.tcx, sig, impl_item, did) { + if method_might_be_inlined(self.tcx, impl_item, did) { self.visit_nested_body(body) } } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index d0c5460fa97..dc912f1c1b6 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -412,7 +412,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { if let hir::TraitItemKind::Method(ref sig, _) = trait_item.node { self.visit_early_late( Some(self.hir_map.get_parent(trait_item.id)), - &sig.decl, &sig.generics, + &sig.decl, &trait_item.generics, |this| intravisit::walk_trait_item(this, trait_item)) } else { intravisit::walk_trait_item(self, trait_item); @@ -423,7 +423,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { if let hir::ImplItemKind::Method(ref sig, _) = impl_item.node { self.visit_early_late( Some(self.hir_map.get_parent(impl_item.id)), - &sig.decl, &sig.generics, + &sig.decl, &impl_item.generics, |this| intravisit::walk_impl_item(this, impl_item)) } else { intravisit::walk_impl_item(self, impl_item); diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index b21d4888612..554a858bcc1 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -568,15 +568,11 @@ fn compare_number_of_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let num_trait_m_type_params = trait_m_generics.types.len(); if num_impl_m_type_params != num_trait_m_type_params { let impl_m_node_id = tcx.hir.as_local_node_id(impl_m.def_id).unwrap(); - let span = match tcx.hir.expect_impl_item(impl_m_node_id).node { - ImplItemKind::Method(ref impl_m_sig, _) => { - if impl_m_sig.generics.is_parameterized() { - impl_m_sig.generics.span - } else { - impl_m_span - } - } - _ => bug!("{:?} is not a method", impl_m), + let impl_m_item = tcx.hir.expect_impl_item(impl_m_node_id); + let span = if impl_m_item.generics.is_parameterized() { + impl_m_item.generics.span + } else { + impl_m_span }; let mut err = struct_span_err!(tcx.sess, diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index a5b3f8cb806..68ba1b4c44c 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -261,19 +261,9 @@ fn type_param_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let item_node_id = tcx.hir.as_local_node_id(item_def_id).unwrap(); let ast_generics = match tcx.hir.get(item_node_id) { - NodeTraitItem(item) => { - match item.node { - TraitItemKind::Method(ref sig, _) => &sig.generics, - _ => return result - } - } + NodeTraitItem(item) => &item.generics, - NodeImplItem(item) => { - match item.node { - ImplItemKind::Method(ref sig, _) => &sig.generics, - _ => return result - } - } + NodeImplItem(item) => &item.generics, NodeItem(item) => { match item.node { @@ -818,12 +808,12 @@ fn has_late_bound_regions<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, match node { hir_map::NodeTraitItem(item) => match item.node { hir::TraitItemKind::Method(ref sig, _) => - has_late_bound_regions(tcx, &sig.generics, &sig.decl), + has_late_bound_regions(tcx, &item.generics, &sig.decl), _ => None, }, hir_map::NodeImplItem(item) => match item.node { hir::ImplItemKind::Method(ref sig, _) => - has_late_bound_regions(tcx, &sig.generics, &sig.decl), + has_late_bound_regions(tcx, &item.generics, &sig.decl), _ => None, }, hir_map::NodeForeignItem(item) => match item.node { @@ -881,19 +871,9 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let no_generics = hir::Generics::empty(); let ast_generics = match node { - NodeTraitItem(item) => { - match item.node { - TraitItemKind::Method(ref sig, _) => &sig.generics, - _ => &no_generics - } - } + NodeTraitItem(item) => &item.generics, - NodeImplItem(item) => { - match item.node { - ImplItemKind::Method(ref sig, _) => &sig.generics, - _ => &no_generics - } - } + NodeImplItem(item) => &item.generics, NodeItem(item) => { match item.node { @@ -1353,19 +1333,9 @@ fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let icx = ItemCtxt::new(tcx, def_id); let no_generics = hir::Generics::empty(); let ast_generics = match node { - NodeTraitItem(item) => { - match item.node { - TraitItemKind::Method(ref sig, _) => &sig.generics, - _ => &no_generics - } - } + NodeTraitItem(item) => &item.generics, - NodeImplItem(item) => { - match item.node { - ImplItemKind::Method(ref sig, _) => &sig.generics, - _ => &no_generics - } - } + NodeImplItem(item) => &item.generics, NodeItem(item) => { match item.node { From 2095ac1e2714f5fa8f25de1e8574dd541514277c Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Mon, 25 Sep 2017 18:36:28 -0400 Subject: [PATCH 05/11] Fixed tidy errors --- src/librustc/hir/print.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 4eee9cbfc2d..b4614873550 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -906,12 +906,14 @@ impl<'a> State<'a> { self.print_associated_const(ti.name, &ty, default, &hir::Inherited)?; } hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Required(ref arg_names)) => { - self.print_method_sig(ti.name, sig, &ti.generics, &hir::Inherited, arg_names, None)?; + self.print_method_sig(ti.name, sig, &ti.generics, &hir::Inherited, arg_names, + None)?; self.s.word(";")?; } hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => { self.head("")?; - self.print_method_sig(ti.name, sig, &ti.generics, &hir::Inherited, &[], Some(body))?; + self.print_method_sig(ti.name, sig, &ti.generics, &hir::Inherited, &[], + Some(body))?; self.nbsp()?; self.end()?; // need to close a box self.end()?; // need to close a box From b43db76d36d6205ebaf5b2b6c260ac23f74733dc Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Tue, 26 Sep 2017 01:17:04 -0400 Subject: [PATCH 06/11] Fixing rustdoc --- src/librustdoc/clean/mod.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index e217978648e..63e3c7edb95 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1140,13 +1140,13 @@ pub struct Method { pub abi: Abi, } -impl<'a> Clean for (&'a hir::MethodSig, hir::BodyId) { +impl<'a> Clean for (&'a hir::MethodSig, &'a hir::Generics, hir::BodyId) { fn clean(&self, cx: &DocContext) -> Method { Method { - generics: self.0.generics.clean(cx), + generics: self.1.clean(cx), unsafety: self.0.unsafety, constness: self.0.constness, - decl: (&*self.0.decl, self.1).clean(cx), + decl: (&*self.0.decl, self.2).clean(cx), abi: self.0.abi } } @@ -1379,13 +1379,13 @@ impl Clean for hir::TraitItem { default.map(|e| print_const_expr(cx, e))) } hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => { - MethodItem((sig, body).clean(cx)) + MethodItem((sig, &self.generics, body).clean(cx)) } hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Required(ref names)) => { TyMethodItem(TyMethod { unsafety: sig.unsafety.clone(), decl: (&*sig.decl, &names[..]).clean(cx), - generics: sig.generics.clean(cx), + generics: self.generics.clean(cx), abi: sig.abi }) } @@ -1414,7 +1414,7 @@ impl Clean for hir::ImplItem { Some(print_const_expr(cx, expr))) } hir::ImplItemKind::Method(ref sig, body) => { - MethodItem((sig, body).clean(cx)) + MethodItem((sig, &self.generics, body).clean(cx)) } hir::ImplItemKind::Type(ref ty) => TypedefItem(Typedef { type_: ty.clean(cx), From 86ae34900f68903006913f374a7860e25c502057 Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Tue, 10 Oct 2017 16:38:43 -0400 Subject: [PATCH 07/11] Updated to latest rustfmt-nightly --- src/Cargo.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Cargo.lock b/src/Cargo.lock index 328ce353e2a..0b708dc7cc8 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -1358,10 +1358,10 @@ dependencies = [ "rls-rustc 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rls-vfs 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "rustfmt-nightly 0.2.7", - "serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rustfmt-nightly 0.2.8", + "serde 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1840,7 +1840,7 @@ dependencies = [ [[package]] name = "rustfmt-nightly" -version = "0.2.7" +version = "0.2.8" dependencies = [ "diff 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", From 14c426da99b06c35aa820b2d6845134d09dbe2c3 Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Tue, 10 Oct 2017 17:56:24 -0400 Subject: [PATCH 08/11] Removed Generics from FnKind::ItemFn in libsyntax --- src/librustc_resolve/lib.rs | 3 +-- src/libsyntax/feature_gate.rs | 4 ++-- src/libsyntax/visit.rs | 8 ++++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 2e5c9e35346..88404953266 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -718,8 +718,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> { _: Span, node_id: NodeId) { let rib_kind = match function_kind { - FnKind::ItemFn(_, generics, ..) => { - self.visit_generics(generics); + FnKind::ItemFn(..) => { ItemRibKind } FnKind::Method(_, sig, _, _) => { diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 9060a613bc1..326f8cef6b3 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1526,7 +1526,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { span: Span, _node_id: NodeId) { // check for const fn declarations - if let FnKind::ItemFn(_, _, _, Spanned { node: ast::Constness::Const, .. }, _, _, _) = + if let FnKind::ItemFn(_, _, Spanned { node: ast::Constness::Const, .. }, _, _, _) = fn_kind { gate_feature_post!(&self, const_fn, span, "const fn is unstable"); } @@ -1536,7 +1536,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { // point. match fn_kind { - FnKind::ItemFn(_, _, _, _, abi, _, _) | + FnKind::ItemFn(_, _, _, abi, _, _) | FnKind::Method(_, &ast::MethodSig { abi, .. }, _, _) => { self.check_abi(abi, span); } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index e74296c06a9..078a63cba20 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -31,7 +31,7 @@ use codemap::Spanned; #[derive(Copy, Clone, PartialEq, Eq)] pub enum FnKind<'a> { /// fn foo() or extern "Abi" fn foo() - ItemFn(Ident, &'a Generics, Unsafety, Spanned, Abi, &'a Visibility, &'a Block), + ItemFn(Ident, Unsafety, Spanned, Abi, &'a Visibility, &'a Block), /// fn foo(&self) Method(Ident, &'a MethodSig, Option<&'a Visibility>, &'a Block), @@ -247,7 +247,8 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { visitor.visit_expr(expr); } ItemKind::Fn(ref declaration, unsafety, constness, abi, ref generics, ref body) => { - visitor.visit_fn(FnKind::ItemFn(item.ident, generics, unsafety, + visitor.visit_generics(generics); + visitor.visit_fn(FnKind::ItemFn(item.ident, unsafety, constness, abi, &item.vis, body), declaration, item.span, @@ -538,8 +539,7 @@ pub fn walk_fn<'a, V>(visitor: &mut V, kind: FnKind<'a>, declaration: &'a FnDecl where V: Visitor<'a>, { match kind { - FnKind::ItemFn(_, generics, _, _, _, _, body) => { - visitor.visit_generics(generics); + FnKind::ItemFn(_, _, _, _, _, body) => { walk_fn_decl(visitor, declaration); visitor.visit_block(body); } From 693687187e48b687dd158ad7f52eab7a744918d8 Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Wed, 11 Oct 2017 02:35:48 -0400 Subject: [PATCH 09/11] Revert "Updated to latest rustfmt-nightly" This reverts commit a49157dc30bf7a163200b10d63a71b005a1376e3. --- src/Cargo.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Cargo.lock b/src/Cargo.lock index 0b708dc7cc8..328ce353e2a 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -1358,10 +1358,10 @@ dependencies = [ "rls-rustc 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rls-vfs 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "rustfmt-nightly 0.2.8", - "serde 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rustfmt-nightly 0.2.7", + "serde 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1840,7 +1840,7 @@ dependencies = [ [[package]] name = "rustfmt-nightly" -version = "0.2.8" +version = "0.2.7" dependencies = [ "diff 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", From 60bff8ce93d2b43a8d53ffc4454e58f53e012475 Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Tue, 17 Oct 2017 22:15:34 -0400 Subject: [PATCH 10/11] Marking the tools as broken --- src/tools/toolstate.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tools/toolstate.toml b/src/tools/toolstate.toml index e62597c5216..9dd420c1458 100644 --- a/src/tools/toolstate.toml +++ b/src/tools/toolstate.toml @@ -26,10 +26,10 @@ miri = "Broken" # ping @Manishearth @llogiq @mcarton @oli-obk -clippy = "Compiling" +clippy = "Broken" # ping @nrc -rls = "Testing" +rls = "Broken" # ping @nrc -rustfmt = "Testing" +rustfmt = "Broken" From 4b0f004e3ddd4421153fd3a0a85343652aa864ce Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 23 Oct 2017 16:18:00 -0400 Subject: [PATCH 11/11] update inherent_impls tests Now that we are visiting things in a different order during lowering, adding parameters winds up affecting the HirIds assigned to thinks in the method body, whereas it didn't before. We could fix this by reordering the order in which we visit `generics` during lowering, but this feels very fragile. Seems better to just let typeck tables be dirty here. --- src/test/incremental/hashes/inherent_impls.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/test/incremental/hashes/inherent_impls.rs b/src/test/incremental/hashes/inherent_impls.rs index 5067b571ee6..9351a4b05f1 100644 --- a/src/test/incremental/hashes/inherent_impls.rs +++ b/src/test/incremental/hashes/inherent_impls.rs @@ -370,9 +370,7 @@ impl Foo { #[rustc_metadata_clean(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] impl Foo { - // FIXME(michaelwoerister): This is curious but an unused lifetime parameter doesn't seem to - // show up in any of the derived data structures. - #[rustc_clean(cfg="cfail2", except="Hir,HirBody")] + #[rustc_clean(cfg="cfail2", except="Hir,HirBody,TypeckTables")] #[rustc_clean(cfg="cfail3")] #[rustc_metadata_clean(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] @@ -395,7 +393,7 @@ impl Foo { impl Foo { #[rustc_clean( cfg="cfail2", - except="Hir,HirBody,GenericsOfItem,PredicatesOfItem,TypeOfItem", + except="Hir,HirBody,GenericsOfItem,PredicatesOfItem,TypeOfItem,TypeckTables", )] #[rustc_clean(cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] @@ -441,7 +439,8 @@ impl Foo { #[rustc_metadata_clean(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] impl Foo { - #[rustc_clean(cfg="cfail2", except="Hir,HirBody,GenericsOfItem,PredicatesOfItem,TypeOfItem")] + #[rustc_clean(cfg="cfail2", except="Hir,HirBody,GenericsOfItem,PredicatesOfItem,\ + TypeOfItem,TypeckTables")] #[rustc_clean(cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] @@ -462,7 +461,7 @@ impl Foo { #[rustc_metadata_clean(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] impl Foo { - #[rustc_clean(cfg="cfail2", except="Hir,HirBody,PredicatesOfItem")] + #[rustc_clean(cfg="cfail2", except="Hir,HirBody,PredicatesOfItem,TypeckTables")] #[rustc_clean(cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")]