Skip to content

Commit 9da9185

Browse files
committed
syntax: move MethMac to MacImplItem and combine {Provided,Required}Method into MethodTraitItem.
1 parent ce10fa8 commit 9da9185

File tree

37 files changed

+464
-549
lines changed

37 files changed

+464
-549
lines changed

src/librustc/metadata/encoder.rs

+18-21
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
827827
let elem = ast_map::PathName(m.name);
828828
encode_path(rbml_w, impl_path.chain(Some(elem).into_iter()));
829829
if let Some(impl_item) = impl_item_opt {
830-
if let ast::MethodImplItem(ref ast_method) = impl_item.node {
830+
if let ast::MethodImplItem(ref sig, _) = impl_item.node {
831831
encode_attributes(rbml_w, &impl_item.attrs);
832832
let scheme = ty::lookup_item_type(ecx.tcx, m.def_id);
833833
let any_types = !scheme.generics.types.is_empty();
@@ -838,7 +838,7 @@ fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
838838
if !any_types {
839839
encode_symbol(ecx, rbml_w, m.def_id.node);
840840
}
841-
encode_method_argument_names(rbml_w, &ast_method.pe_sig().decl);
841+
encode_method_argument_names(rbml_w, &sig.decl);
842842
}
843843
}
844844

@@ -1362,28 +1362,25 @@ fn encode_info_for_item(ecx: &EncodeContext,
13621362
encode_parent_sort(rbml_w, 't');
13631363

13641364
let trait_item = &*ms[i];
1365-
let encode_trait_item = |rbml_w: &mut Encoder| {
1366-
// If this is a static method, we've already
1367-
// encoded this.
1368-
if is_nonstatic_method {
1369-
// FIXME: I feel like there is something funny
1370-
// going on.
1371-
encode_bounds_and_type_for_item(rbml_w, ecx, item_def_id.def_id().local_id());
1372-
}
1373-
};
13741365
encode_attributes(rbml_w, &trait_item.attrs);
13751366
match trait_item.node {
1376-
ast::RequiredMethod(ref m) => {
1377-
encode_trait_item(rbml_w);
1378-
encode_item_sort(rbml_w, 'r');
1379-
encode_method_argument_names(rbml_w, &*m.decl);
1380-
}
1367+
ast::MethodTraitItem(ref sig, ref body) => {
1368+
// If this is a static method, we've already
1369+
// encoded this.
1370+
if is_nonstatic_method {
1371+
// FIXME: I feel like there is something funny
1372+
// going on.
1373+
encode_bounds_and_type_for_item(rbml_w, ecx,
1374+
item_def_id.def_id().local_id());
1375+
}
13811376

1382-
ast::ProvidedMethod(ref m) => {
1383-
encode_trait_item(rbml_w);
1384-
encode_item_sort(rbml_w, 'p');
1385-
encode_inlined_item(ecx, rbml_w, IITraitItemRef(def_id, trait_item));
1386-
encode_method_argument_names(rbml_w, &*m.pe_sig().decl);
1377+
if body.is_some() {
1378+
encode_item_sort(rbml_w, 'p');
1379+
encode_inlined_item(ecx, rbml_w, IITraitItemRef(def_id, trait_item));
1380+
} else {
1381+
encode_item_sort(rbml_w, 'r');
1382+
}
1383+
encode_method_argument_names(rbml_w, &sig.decl);
13871384
}
13881385

13891386
ast::TypeTraitItem(..) => {

src/librustc/middle/dead.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use util::nodemap::NodeSet;
1818

1919
use std::collections::HashSet;
2020
use syntax::{ast, ast_map, codemap};
21-
use syntax::ast_util::{local_def, is_local, PostExpansionMethod};
21+
use syntax::ast_util::{local_def, is_local};
2222
use syntax::attr::{self, AttrMetaMethods};
2323
use syntax::visit::{self, Visitor};
2424

@@ -353,7 +353,7 @@ impl<'v> Visitor<'v> for LifeSeeder {
353353
ast::ItemTrait(_, _, _, ref trait_items) => {
354354
for trait_item in trait_items {
355355
match trait_item.node {
356-
ast::ProvidedMethod(_) => {
356+
ast::MethodTraitItem(_, Some(_)) => {
357357
if has_allow_dead_code_or_lang_attr(&trait_item.attrs) {
358358
self.worklist.push(trait_item.id);
359359
}
@@ -365,13 +365,14 @@ impl<'v> Visitor<'v> for LifeSeeder {
365365
ast::ItemImpl(_, _, _, ref opt_trait, _, ref impl_items) => {
366366
for impl_item in impl_items {
367367
match impl_item.node {
368-
ast::MethodImplItem(_) => {
368+
ast::MethodImplItem(..) => {
369369
if opt_trait.is_some() ||
370370
has_allow_dead_code_or_lang_attr(&impl_item.attrs) {
371371
self.worklist.push(impl_item.id);
372372
}
373373
}
374374
ast::TypeImplItem(_) => {}
375+
ast::MacImplItem(_) => panic!("unexpanded macro")
375376
}
376377
}
377378
}
@@ -578,10 +579,10 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
578579
// Overwrite so that we don't warn the trait method itself.
579580
fn visit_trait_item(&mut self, trait_method: &ast::TraitItem) {
580581
match trait_method.node {
581-
ast::ProvidedMethod(ref method) => {
582-
visit::walk_block(self, method.pe_body())
582+
ast::MethodTraitItem(_, Some(ref body)) => {
583+
visit::walk_block(self, body)
583584
}
584-
ast::RequiredMethod(_) |
585+
ast::MethodTraitItem(_, None) |
585586
ast::TypeTraitItem(..) => {}
586587
}
587588
}

src/librustc/middle/effect.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use middle::ty::MethodCall;
1818
use util::ppaux;
1919

2020
use syntax::ast;
21-
use syntax::ast_util::PostExpansionMethod;
2221
use syntax::codemap::Span;
2322
use syntax::visit;
2423
use syntax::visit::Visitor;
@@ -90,8 +89,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
9089
let (is_item_fn, is_unsafe_fn) = match fn_kind {
9190
visit::FkItemFn(_, _, fn_style, _) =>
9291
(true, fn_style == ast::Unsafety::Unsafe),
93-
visit::FkMethod(_, method) =>
94-
(true, method.pe_sig().unsafety == ast::Unsafety::Unsafe),
92+
visit::FkMethod(_, sig) =>
93+
(true, sig.unsafety == ast::Unsafety::Unsafe),
9594
_ => (false, false),
9695
};
9796

src/librustc/middle/infer/error_reporting.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ use std::rc::Rc;
8383
use std::string::String;
8484
use syntax::ast;
8585
use syntax::ast_map;
86-
use syntax::ast_util::{name_to_dummy_lifetime, PostExpansionMethod};
86+
use syntax::ast_util::name_to_dummy_lifetime;
8787
use syntax::owned_slice::OwnedSlice;
8888
use syntax::codemap;
8989
use syntax::parse::token;
@@ -848,25 +848,26 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
848848
}
849849
ast_map::NodeImplItem(item) => {
850850
match item.node {
851-
ast::MethodImplItem(ref m) => {
852-
Some((&m.pe_sig().decl,
853-
&m.pe_sig().generics,
854-
m.pe_sig().unsafety,
851+
ast::MethodImplItem(ref sig, _) => {
852+
Some((&sig.decl,
853+
&sig.generics,
854+
sig.unsafety,
855855
item.ident,
856-
Some(&m.pe_sig().explicit_self.node),
856+
Some(&sig.explicit_self.node),
857857
item.span))
858858
}
859859
ast::TypeImplItem(_) => None,
860+
ast::MacImplItem(_) => self.tcx.sess.bug("unexpanded macro")
860861
}
861862
},
862863
ast_map::NodeTraitItem(item) => {
863864
match item.node {
864-
ast::ProvidedMethod(ref m) => {
865-
Some((&m.pe_sig().decl,
866-
&m.pe_sig().generics,
867-
m.pe_sig().unsafety,
865+
ast::MethodTraitItem(ref sig, Some(_)) => {
866+
Some((&sig.decl,
867+
&sig.generics,
868+
sig.unsafety,
868869
item.ident,
869-
Some(&m.pe_sig().explicit_self.node),
870+
Some(&sig.explicit_self.node),
870871
item.span))
871872
}
872873
_ => None
@@ -1731,11 +1732,12 @@ fn lifetimes_in_scope(tcx: &ty::ctxt,
17311732
},
17321733
ast_map::NodeImplItem(ii) => {
17331734
match ii.node {
1734-
ast::MethodImplItem(ref m) => {
1735-
taken.push_all(&m.pe_sig().generics.lifetimes);
1735+
ast::MethodImplItem(ref sig, _) => {
1736+
taken.push_all(&sig.generics.lifetimes);
17361737
Some(ii.id)
17371738
}
17381739
ast::TypeImplItem(_) => None,
1740+
ast::MacImplItem(_) => tcx.sess.bug("unexpanded macro")
17391741
}
17401742
}
17411743
_ => None

src/librustc/middle/reachable.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use std::collections::HashSet;
2525
use syntax::abi;
2626
use syntax::ast;
2727
use syntax::ast_map;
28-
use syntax::ast_util::{is_local, PostExpansionMethod};
28+
use syntax::ast_util::is_local;
2929
use syntax::attr;
3030
use syntax::visit::Visitor;
3131
use syntax::visit;
@@ -53,11 +53,11 @@ fn item_might_be_inlined(item: &ast::Item) -> bool {
5353
}
5454
}
5555

56-
fn method_might_be_inlined(tcx: &ty::ctxt, method: &ast::Method,
56+
fn method_might_be_inlined(tcx: &ty::ctxt, sig: &ast::MethodSig,
5757
impl_item: &ast::ImplItem,
5858
impl_src: ast::DefId) -> bool {
5959
if attr::requests_inline(&impl_item.attrs) ||
60-
generics_require_inlining(&method.pe_sig().generics) {
60+
generics_require_inlining(&sig.generics) {
6161
return true
6262
}
6363
if is_local(impl_src) {
@@ -183,15 +183,14 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
183183
}
184184
Some(ast_map::NodeTraitItem(trait_method)) => {
185185
match trait_method.node {
186-
ast::RequiredMethod(_) => false,
187-
ast::ProvidedMethod(_) => true,
186+
ast::MethodTraitItem(_, ref body) => body.is_some(),
188187
ast::TypeTraitItem(..) => false,
189188
}
190189
}
191190
Some(ast_map::NodeImplItem(impl_item)) => {
192191
match impl_item.node {
193-
ast::MethodImplItem(ref method) => {
194-
if generics_require_inlining(&method.pe_sig().generics) ||
192+
ast::MethodImplItem(ref sig, _) => {
193+
if generics_require_inlining(&sig.generics) ||
195194
attr::requests_inline(&impl_item.attrs) {
196195
true
197196
} else {
@@ -214,6 +213,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
214213
}
215214
}
216215
ast::TypeImplItem(_) => false,
216+
ast::MacImplItem(_) => self.tcx.sess.bug("unexpanded macro")
217217
}
218218
}
219219
Some(_) => false,
@@ -303,24 +303,25 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
303303
}
304304
ast_map::NodeTraitItem(trait_method) => {
305305
match trait_method.node {
306-
ast::RequiredMethod(..) => {
306+
ast::MethodTraitItem(_, None) => {
307307
// Keep going, nothing to get exported
308308
}
309-
ast::ProvidedMethod(ref method) => {
310-
visit::walk_block(self, &*method.pe_body());
309+
ast::MethodTraitItem(_, Some(ref body)) => {
310+
visit::walk_block(self, body);
311311
}
312312
ast::TypeTraitItem(..) => {}
313313
}
314314
}
315315
ast_map::NodeImplItem(impl_item) => {
316316
match impl_item.node {
317-
ast::MethodImplItem(ref method) => {
317+
ast::MethodImplItem(ref sig, ref body) => {
318318
let did = self.tcx.map.get_parent_did(search_item);
319-
if method_might_be_inlined(self.tcx, method, impl_item, did) {
320-
visit::walk_block(self, method.pe_body())
319+
if method_might_be_inlined(self.tcx, sig, impl_item, did) {
320+
visit::walk_block(self, body)
321321
}
322322
}
323323
ast::TypeImplItem(_) => {}
324+
ast::MacImplItem(_) => self.tcx.sess.bug("unexpanded macro")
324325
}
325326
}
326327
// Nothing to recurse on for these

src/librustc/middle/resolve_lifetime.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use middle::subst;
2525
use middle::ty;
2626
use std::fmt;
2727
use syntax::ast;
28-
use syntax::ast_util::PostExpansionMethod;
2928
use syntax::codemap::Span;
3029
use syntax::parse::token::special_idents;
3130
use syntax::parse::token;
@@ -148,8 +147,8 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
148147
visit::walk_fn(this, fk, fd, b, s)
149148
})
150149
}
151-
visit::FkMethod(_, m) => {
152-
self.visit_early_late(subst::FnSpace, &m.pe_sig().generics, |this| {
150+
visit::FkMethod(_, sig) => {
151+
self.visit_early_late(subst::FnSpace, &sig.generics, |this| {
153152
visit::walk_fn(this, fk, fd, b, s)
154153
})
155154
}
@@ -191,9 +190,9 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
191190
}
192191

193192
fn visit_trait_item(&mut self, trait_item: &ast::TraitItem) {
194-
if let ast::RequiredMethod(ref m) = trait_item.node {
193+
if let ast::MethodTraitItem(ref sig, None) = trait_item.node {
195194
self.visit_early_late(
196-
subst::FnSpace, &m.generics,
195+
subst::FnSpace, &sig.generics,
197196
|this| visit::walk_trait_item(this, trait_item))
198197
} else {
199198
visit::walk_trait_item(self, trait_item);

src/librustc/middle/ty.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ use syntax::abi;
8282
use syntax::ast::{CrateNum, DefId, Ident, ItemTrait, LOCAL_CRATE};
8383
use syntax::ast::{MutImmutable, MutMutable, Name, NamedField, NodeId};
8484
use syntax::ast::{StmtExpr, StmtSemi, StructField, UnnamedField, Visibility};
85-
use syntax::ast_util::{self, is_local, lit_is_str, local_def, PostExpansionMethod};
85+
use syntax::ast_util::{self, is_local, lit_is_str, local_def};
8686
use syntax::attr::{self, AttrMetaMethods};
8787
use syntax::codemap::Span;
8888
use syntax::parse::token::{self, InternedString, special_idents};
@@ -2287,7 +2287,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
22872287
match cx.map.find(id) {
22882288
Some(ast_map::NodeImplItem(ref impl_item)) => {
22892289
match impl_item.node {
2290-
ast::MethodImplItem(ref method) => {
2290+
ast::MethodImplItem(_, ref body) => {
22912291
let method_def_id = ast_util::local_def(id);
22922292
match ty::impl_or_trait_item(cx, method_def_id) {
22932293
MethodTraitItem(ref method_ty) => {
@@ -2298,7 +2298,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
22982298
impl_item.span,
22992299
method_generics,
23002300
method_bounds,
2301-
method.pe_body().id)
2301+
body.id)
23022302
}
23032303
TypeTraitItem(_) => {
23042304
cx.sess
@@ -2313,18 +2313,19 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
23132313
can't create a parameter environment \
23142314
for type impl items")
23152315
}
2316+
ast::MacImplItem(_) => cx.sess.bug("unexpanded macro")
23162317
}
23172318
}
23182319
Some(ast_map::NodeTraitItem(trait_item)) => {
23192320
match trait_item.node {
2320-
ast::RequiredMethod(_) => {
2321+
ast::MethodTraitItem(_, None) => {
23212322
cx.sess.span_bug(trait_item.span,
23222323
"ParameterEnvironment::for_item():
23232324
can't create a parameter \
23242325
environment for required trait \
23252326
methods")
23262327
}
2327-
ast::ProvidedMethod(ref method) => {
2328+
ast::MethodTraitItem(_, Some(ref body)) => {
23282329
let method_def_id = ast_util::local_def(id);
23292330
match ty::impl_or_trait_item(cx, method_def_id) {
23302331
MethodTraitItem(ref method_ty) => {
@@ -2335,7 +2336,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
23352336
trait_item.span,
23362337
method_generics,
23372338
method_bounds,
2338-
method.pe_body().id)
2339+
body.id)
23392340
}
23402341
TypeTraitItem(_) => {
23412342
cx.sess
@@ -5082,7 +5083,7 @@ pub fn provided_trait_methods<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)
50825083
if is_local(id) {
50835084
if let ItemTrait(_, _, _, ref ms) = cx.map.expect_item(id.node).node {
50845085
ms.iter().filter_map(|ti| {
5085-
if let ast::ProvidedMethod(_) = ti.node {
5086+
if let ast::MethodTraitItem(_, Some(_)) = ti.node {
50865087
match impl_or_trait_item(cx, ast_util::local_def(ti.id)) {
50875088
MethodTraitItem(m) => Some(m),
50885089
TypeTraitItem(_) => {

src/librustc/util/ppaux.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -829,8 +829,7 @@ impl<'tcx> Repr<'tcx> for ty::TraitDef<'tcx> {
829829
impl<'tcx> Repr<'tcx> for ast::TraitItem {
830830
fn repr(&self, _tcx: &ctxt) -> String {
831831
let kind = match self.node {
832-
ast::RequiredMethod(_) => "RequiredMethod",
833-
ast::ProvidedMethod(_) => "ProvidedMethod",
832+
ast::MethodTraitItem(..) => "MethodTraitItem",
834833
ast::TypeTraitItem(..) => "TypeTraitItem",
835834
};
836835
format!("{}({}, id={})", kind, self.ident, self.id)

0 commit comments

Comments
 (0)