syntax: move MethMac to MacImplItem and combine {Provided,Required}Method into MethodTraitItem.

This commit is contained in:
Eduard Burtescu 2015-03-11 23:38:58 +02:00
parent ce10fa8d12
commit 9da918548d
37 changed files with 466 additions and 551 deletions

View file

@ -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();
@ -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);
}
}
@ -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(..) => {

View file

@ -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};
@ -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);
}
@ -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")
}
}
}
@ -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(..) => {}
}
}

View file

@ -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;
@ -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),
};

View file

@ -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;
@ -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
@ -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

View file

@ -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;
@ -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) {
@ -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 {
@ -214,6 +213,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
}
}
ast::TypeImplItem(_) => false,
ast::MacImplItem(_) => self.tcx.sess.bug("unexpanded macro")
}
}
Some(_) => false,
@ -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

View file

@ -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;
@ -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)
})
}
@ -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);

View file

@ -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};
@ -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) => {
@ -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
@ -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) => {
@ -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
@ -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(_) => {

View file

@ -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)