Skip to content

Commit

Permalink
syntax: move MethMac to MacImplItem and combine {Provided,Required}Me…
Browse files Browse the repository at this point in the history
…thod into MethodTraitItem.
  • Loading branch information
eddyb committed Mar 11, 2015
1 parent ce10fa8 commit 9da9185
Show file tree
Hide file tree
Showing 37 changed files with 464 additions and 549 deletions.
39 changes: 18 additions & 21 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
let elem = ast_map::PathName(m.name);
encode_path(rbml_w, impl_path.chain(Some(elem).into_iter()));
if let Some(impl_item) = impl_item_opt {
if let ast::MethodImplItem(ref ast_method) = impl_item.node {
if let ast::MethodImplItem(ref sig, _) = impl_item.node {
encode_attributes(rbml_w, &impl_item.attrs);
let scheme = ty::lookup_item_type(ecx.tcx, m.def_id);
let any_types = !scheme.generics.types.is_empty();
Expand All @@ -838,7 +838,7 @@ fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
if !any_types {
encode_symbol(ecx, rbml_w, m.def_id.node);
}
encode_method_argument_names(rbml_w, &ast_method.pe_sig().decl);
encode_method_argument_names(rbml_w, &sig.decl);
}
}

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

let trait_item = &*ms[i];
let encode_trait_item = |rbml_w: &mut Encoder| {
// If this is a static method, we've already
// encoded this.
if is_nonstatic_method {
// FIXME: I feel like there is something funny
// going on.
encode_bounds_and_type_for_item(rbml_w, ecx, item_def_id.def_id().local_id());
}
};
encode_attributes(rbml_w, &trait_item.attrs);
match trait_item.node {
ast::RequiredMethod(ref m) => {
encode_trait_item(rbml_w);
encode_item_sort(rbml_w, 'r');
encode_method_argument_names(rbml_w, &*m.decl);
}
ast::MethodTraitItem(ref sig, ref body) => {
// If this is a static method, we've already
// encoded this.
if is_nonstatic_method {
// FIXME: I feel like there is something funny
// going on.
encode_bounds_and_type_for_item(rbml_w, ecx,
item_def_id.def_id().local_id());
}

ast::ProvidedMethod(ref m) => {
encode_trait_item(rbml_w);
encode_item_sort(rbml_w, 'p');
encode_inlined_item(ecx, rbml_w, IITraitItemRef(def_id, trait_item));
encode_method_argument_names(rbml_w, &*m.pe_sig().decl);
if body.is_some() {
encode_item_sort(rbml_w, 'p');
encode_inlined_item(ecx, rbml_w, IITraitItemRef(def_id, trait_item));
} else {
encode_item_sort(rbml_w, 'r');
}
encode_method_argument_names(rbml_w, &sig.decl);
}

ast::TypeTraitItem(..) => {
Expand Down
13 changes: 7 additions & 6 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use util::nodemap::NodeSet;

use std::collections::HashSet;
use syntax::{ast, ast_map, codemap};
use syntax::ast_util::{local_def, is_local, PostExpansionMethod};
use syntax::ast_util::{local_def, is_local};
use syntax::attr::{self, AttrMetaMethods};
use syntax::visit::{self, Visitor};

Expand Down Expand Up @@ -353,7 +353,7 @@ impl<'v> Visitor<'v> for LifeSeeder {
ast::ItemTrait(_, _, _, ref trait_items) => {
for trait_item in trait_items {
match trait_item.node {
ast::ProvidedMethod(_) => {
ast::MethodTraitItem(_, Some(_)) => {
if has_allow_dead_code_or_lang_attr(&trait_item.attrs) {
self.worklist.push(trait_item.id);
}
Expand All @@ -365,13 +365,14 @@ impl<'v> Visitor<'v> for LifeSeeder {
ast::ItemImpl(_, _, _, ref opt_trait, _, ref impl_items) => {
for impl_item in impl_items {
match impl_item.node {
ast::MethodImplItem(_) => {
ast::MethodImplItem(..) => {
if opt_trait.is_some() ||
has_allow_dead_code_or_lang_attr(&impl_item.attrs) {
self.worklist.push(impl_item.id);
}
}
ast::TypeImplItem(_) => {}
ast::MacImplItem(_) => panic!("unexpanded macro")
}
}
}
Expand Down Expand Up @@ -578,10 +579,10 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
// Overwrite so that we don't warn the trait method itself.
fn visit_trait_item(&mut self, trait_method: &ast::TraitItem) {
match trait_method.node {
ast::ProvidedMethod(ref method) => {
visit::walk_block(self, method.pe_body())
ast::MethodTraitItem(_, Some(ref body)) => {
visit::walk_block(self, body)
}
ast::RequiredMethod(_) |
ast::MethodTraitItem(_, None) |
ast::TypeTraitItem(..) => {}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use middle::ty::MethodCall;
use util::ppaux;

use syntax::ast;
use syntax::ast_util::PostExpansionMethod;
use syntax::codemap::Span;
use syntax::visit;
use syntax::visit::Visitor;
Expand Down Expand Up @@ -90,8 +89,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
let (is_item_fn, is_unsafe_fn) = match fn_kind {
visit::FkItemFn(_, _, fn_style, _) =>
(true, fn_style == ast::Unsafety::Unsafe),
visit::FkMethod(_, method) =>
(true, method.pe_sig().unsafety == ast::Unsafety::Unsafe),
visit::FkMethod(_, sig) =>
(true, sig.unsafety == ast::Unsafety::Unsafe),
_ => (false, false),
};

Expand Down
28 changes: 15 additions & 13 deletions src/librustc/middle/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ use std::rc::Rc;
use std::string::String;
use syntax::ast;
use syntax::ast_map;
use syntax::ast_util::{name_to_dummy_lifetime, PostExpansionMethod};
use syntax::ast_util::name_to_dummy_lifetime;
use syntax::owned_slice::OwnedSlice;
use syntax::codemap;
use syntax::parse::token;
Expand Down Expand Up @@ -848,25 +848,26 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
}
ast_map::NodeImplItem(item) => {
match item.node {
ast::MethodImplItem(ref m) => {
Some((&m.pe_sig().decl,
&m.pe_sig().generics,
m.pe_sig().unsafety,
ast::MethodImplItem(ref sig, _) => {
Some((&sig.decl,
&sig.generics,
sig.unsafety,
item.ident,
Some(&m.pe_sig().explicit_self.node),
Some(&sig.explicit_self.node),
item.span))
}
ast::TypeImplItem(_) => None,
ast::MacImplItem(_) => self.tcx.sess.bug("unexpanded macro")
}
},
ast_map::NodeTraitItem(item) => {
match item.node {
ast::ProvidedMethod(ref m) => {
Some((&m.pe_sig().decl,
&m.pe_sig().generics,
m.pe_sig().unsafety,
ast::MethodTraitItem(ref sig, Some(_)) => {
Some((&sig.decl,
&sig.generics,
sig.unsafety,
item.ident,
Some(&m.pe_sig().explicit_self.node),
Some(&sig.explicit_self.node),
item.span))
}
_ => None
Expand Down Expand Up @@ -1731,11 +1732,12 @@ fn lifetimes_in_scope(tcx: &ty::ctxt,
},
ast_map::NodeImplItem(ii) => {
match ii.node {
ast::MethodImplItem(ref m) => {
taken.push_all(&m.pe_sig().generics.lifetimes);
ast::MethodImplItem(ref sig, _) => {
taken.push_all(&sig.generics.lifetimes);
Some(ii.id)
}
ast::TypeImplItem(_) => None,
ast::MacImplItem(_) => tcx.sess.bug("unexpanded macro")
}
}
_ => None
Expand Down
27 changes: 14 additions & 13 deletions src/librustc/middle/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::collections::HashSet;
use syntax::abi;
use syntax::ast;
use syntax::ast_map;
use syntax::ast_util::{is_local, PostExpansionMethod};
use syntax::ast_util::is_local;
use syntax::attr;
use syntax::visit::Visitor;
use syntax::visit;
Expand Down Expand Up @@ -53,11 +53,11 @@ fn item_might_be_inlined(item: &ast::Item) -> bool {
}
}

fn method_might_be_inlined(tcx: &ty::ctxt, method: &ast::Method,
fn method_might_be_inlined(tcx: &ty::ctxt, sig: &ast::MethodSig,
impl_item: &ast::ImplItem,
impl_src: ast::DefId) -> bool {
if attr::requests_inline(&impl_item.attrs) ||
generics_require_inlining(&method.pe_sig().generics) {
generics_require_inlining(&sig.generics) {
return true
}
if is_local(impl_src) {
Expand Down Expand Up @@ -183,15 +183,14 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
}
Some(ast_map::NodeTraitItem(trait_method)) => {
match trait_method.node {
ast::RequiredMethod(_) => false,
ast::ProvidedMethod(_) => true,
ast::MethodTraitItem(_, ref body) => body.is_some(),
ast::TypeTraitItem(..) => false,
}
}
Some(ast_map::NodeImplItem(impl_item)) => {
match impl_item.node {
ast::MethodImplItem(ref method) => {
if generics_require_inlining(&method.pe_sig().generics) ||
ast::MethodImplItem(ref sig, _) => {
if generics_require_inlining(&sig.generics) ||
attr::requests_inline(&impl_item.attrs) {
true
} else {
Expand All @@ -214,6 +213,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
}
}
ast::TypeImplItem(_) => false,
ast::MacImplItem(_) => self.tcx.sess.bug("unexpanded macro")
}
}
Some(_) => false,
Expand Down Expand Up @@ -303,24 +303,25 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
}
ast_map::NodeTraitItem(trait_method) => {
match trait_method.node {
ast::RequiredMethod(..) => {
ast::MethodTraitItem(_, None) => {
// Keep going, nothing to get exported
}
ast::ProvidedMethod(ref method) => {
visit::walk_block(self, &*method.pe_body());
ast::MethodTraitItem(_, Some(ref body)) => {
visit::walk_block(self, body);
}
ast::TypeTraitItem(..) => {}
}
}
ast_map::NodeImplItem(impl_item) => {
match impl_item.node {
ast::MethodImplItem(ref method) => {
ast::MethodImplItem(ref sig, ref body) => {
let did = self.tcx.map.get_parent_did(search_item);
if method_might_be_inlined(self.tcx, method, impl_item, did) {
visit::walk_block(self, method.pe_body())
if method_might_be_inlined(self.tcx, sig, impl_item, did) {
visit::walk_block(self, body)
}
}
ast::TypeImplItem(_) => {}
ast::MacImplItem(_) => self.tcx.sess.bug("unexpanded macro")
}
}
// Nothing to recurse on for these
Expand Down
9 changes: 4 additions & 5 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use middle::subst;
use middle::ty;
use std::fmt;
use syntax::ast;
use syntax::ast_util::PostExpansionMethod;
use syntax::codemap::Span;
use syntax::parse::token::special_idents;
use syntax::parse::token;
Expand Down Expand Up @@ -148,8 +147,8 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
visit::walk_fn(this, fk, fd, b, s)
})
}
visit::FkMethod(_, m) => {
self.visit_early_late(subst::FnSpace, &m.pe_sig().generics, |this| {
visit::FkMethod(_, sig) => {
self.visit_early_late(subst::FnSpace, &sig.generics, |this| {
visit::walk_fn(this, fk, fd, b, s)
})
}
Expand Down Expand Up @@ -191,9 +190,9 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
}

fn visit_trait_item(&mut self, trait_item: &ast::TraitItem) {
if let ast::RequiredMethod(ref m) = trait_item.node {
if let ast::MethodTraitItem(ref sig, None) = trait_item.node {
self.visit_early_late(
subst::FnSpace, &m.generics,
subst::FnSpace, &sig.generics,
|this| visit::walk_trait_item(this, trait_item))
} else {
visit::walk_trait_item(self, trait_item);
Expand Down
15 changes: 8 additions & 7 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ use syntax::abi;
use syntax::ast::{CrateNum, DefId, Ident, ItemTrait, LOCAL_CRATE};
use syntax::ast::{MutImmutable, MutMutable, Name, NamedField, NodeId};
use syntax::ast::{StmtExpr, StmtSemi, StructField, UnnamedField, Visibility};
use syntax::ast_util::{self, is_local, lit_is_str, local_def, PostExpansionMethod};
use syntax::ast_util::{self, is_local, lit_is_str, local_def};
use syntax::attr::{self, AttrMetaMethods};
use syntax::codemap::Span;
use syntax::parse::token::{self, InternedString, special_idents};
Expand Down Expand Up @@ -2287,7 +2287,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
match cx.map.find(id) {
Some(ast_map::NodeImplItem(ref impl_item)) => {
match impl_item.node {
ast::MethodImplItem(ref method) => {
ast::MethodImplItem(_, ref body) => {
let method_def_id = ast_util::local_def(id);
match ty::impl_or_trait_item(cx, method_def_id) {
MethodTraitItem(ref method_ty) => {
Expand All @@ -2298,7 +2298,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
impl_item.span,
method_generics,
method_bounds,
method.pe_body().id)
body.id)
}
TypeTraitItem(_) => {
cx.sess
Expand All @@ -2313,18 +2313,19 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
can't create a parameter environment \
for type impl items")
}
ast::MacImplItem(_) => cx.sess.bug("unexpanded macro")
}
}
Some(ast_map::NodeTraitItem(trait_item)) => {
match trait_item.node {
ast::RequiredMethod(_) => {
ast::MethodTraitItem(_, None) => {
cx.sess.span_bug(trait_item.span,
"ParameterEnvironment::for_item():
can't create a parameter \
environment for required trait \
methods")
}
ast::ProvidedMethod(ref method) => {
ast::MethodTraitItem(_, Some(ref body)) => {
let method_def_id = ast_util::local_def(id);
match ty::impl_or_trait_item(cx, method_def_id) {
MethodTraitItem(ref method_ty) => {
Expand All @@ -2335,7 +2336,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
trait_item.span,
method_generics,
method_bounds,
method.pe_body().id)
body.id)
}
TypeTraitItem(_) => {
cx.sess
Expand Down Expand Up @@ -5082,7 +5083,7 @@ pub fn provided_trait_methods<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)
if is_local(id) {
if let ItemTrait(_, _, _, ref ms) = cx.map.expect_item(id.node).node {
ms.iter().filter_map(|ti| {
if let ast::ProvidedMethod(_) = ti.node {
if let ast::MethodTraitItem(_, Some(_)) = ti.node {
match impl_or_trait_item(cx, ast_util::local_def(ti.id)) {
MethodTraitItem(m) => Some(m),
TypeTraitItem(_) => {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,8 +829,7 @@ impl<'tcx> Repr<'tcx> for ty::TraitDef<'tcx> {
impl<'tcx> Repr<'tcx> for ast::TraitItem {
fn repr(&self, _tcx: &ctxt) -> String {
let kind = match self.node {
ast::RequiredMethod(_) => "RequiredMethod",
ast::ProvidedMethod(_) => "ProvidedMethod",
ast::MethodTraitItem(..) => "MethodTraitItem",
ast::TypeTraitItem(..) => "TypeTraitItem",
};
format!("{}({}, id={})", kind, self.ident, self.id)
Expand Down
Loading

0 comments on commit 9da9185

Please sign in to comment.