Skip to content

Commit 9849182

Browse files
committed
syntax: move indirection around {Trait,Impl}Item, from within.
1 parent f899513 commit 9849182

File tree

31 files changed

+274
-362
lines changed

31 files changed

+274
-362
lines changed

src/librustc/metadata/encoder.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ fn encode_info_for_associated_type(ecx: &EncodeContext,
851851
associated_type: &ty::AssociatedType,
852852
impl_path: PathElems,
853853
parent_id: NodeId,
854-
typedef_opt: Option<P<ast::Typedef>>) {
854+
typedef_opt: Option<&ast::Typedef>) {
855855
debug!("encode_info_for_associated_type({:?},{:?})",
856856
associated_type.def_id,
857857
token::get_name(associated_type.name));
@@ -873,13 +873,9 @@ fn encode_info_for_associated_type(ecx: &EncodeContext,
873873
let elem = ast_map::PathName(associated_type.name);
874874
encode_path(rbml_w, impl_path.chain(Some(elem).into_iter()));
875875

876-
match typedef_opt {
877-
None => {}
878-
Some(typedef) => {
879-
encode_attributes(rbml_w, &typedef.attrs);
880-
encode_type(ecx, rbml_w, ty::node_id_to_type(ecx.tcx,
881-
typedef.id));
882-
}
876+
if let Some(typedef) = typedef_opt {
877+
encode_attributes(rbml_w, &typedef.attrs);
878+
encode_type(ecx, rbml_w, ty::node_id_to_type(ecx.tcx, typedef.id));
883879
}
884880

885881
rbml_w.end_tag();
@@ -1226,7 +1222,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
12261222
let num_implemented_methods = ast_items.len();
12271223
for (i, &trait_item_def_id) in items.iter().enumerate() {
12281224
let ast_item = if i < num_implemented_methods {
1229-
Some(&ast_items[i])
1225+
Some(&*ast_items[i])
12301226
} else {
12311227
None
12321228
};
@@ -1265,7 +1261,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
12651261
&**associated_type,
12661262
path.clone(),
12671263
item.id,
1268-
Some((*typedef).clone()))
1264+
Some(typedef))
12691265
}
12701266
(ty::TypeTraitItem(ref associated_type), _) => {
12711267
encode_info_for_associated_type(ecx,
@@ -1387,7 +1383,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
13871383

13881384
encode_parent_sort(rbml_w, 't');
13891385

1390-
let trait_item = &ms[i];
1386+
let trait_item = &*ms[i];
13911387
let encode_trait_item = |rbml_w: &mut Encoder| {
13921388
// If this is a static method, we've already
13931389
// encoded this.
@@ -1397,23 +1393,23 @@ fn encode_info_for_item(ecx: &EncodeContext,
13971393
encode_bounds_and_type_for_item(rbml_w, ecx, item_def_id.def_id().local_id());
13981394
}
13991395
};
1400-
match trait_item {
1401-
&ast::RequiredMethod(ref m) => {
1396+
match *trait_item {
1397+
ast::RequiredMethod(ref m) => {
14021398
encode_attributes(rbml_w, &m.attrs);
14031399
encode_trait_item(rbml_w);
14041400
encode_item_sort(rbml_w, 'r');
14051401
encode_method_argument_names(rbml_w, &*m.decl);
14061402
}
14071403

1408-
&ast::ProvidedMethod(ref m) => {
1404+
ast::ProvidedMethod(ref m) => {
14091405
encode_attributes(rbml_w, &m.attrs);
14101406
encode_trait_item(rbml_w);
14111407
encode_item_sort(rbml_w, 'p');
14121408
encode_inlined_item(ecx, rbml_w, IITraitItemRef(def_id, trait_item));
14131409
encode_method_argument_names(rbml_w, &*m.pe_fn_decl());
14141410
}
14151411

1416-
&ast::TypeTraitItem(ref associated_type) => {
1412+
ast::TypeTraitItem(ref associated_type) => {
14171413
encode_attributes(rbml_w,
14181414
&associated_type.attrs);
14191415
encode_item_sort(rbml_w, 't');

src/librustc/middle/astencode.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,9 @@ fn simplify_ast(ii: e::InlinedItemRef) -> ast::InlinedItem {
425425
}
426426
ast::TypeTraitItem(ref associated_type) => {
427427
ast::TypeTraitItem(
428-
P(fold::noop_fold_associated_type(
429-
(**associated_type).clone(),
430-
&mut fld)))
428+
fold::noop_fold_associated_type(
429+
(*associated_type).clone(),
430+
&mut fld))
431431
}
432432
})
433433
}
@@ -441,7 +441,7 @@ fn simplify_ast(ii: e::InlinedItemRef) -> ast::InlinedItem {
441441
}
442442
ast::TypeImplItem(ref td) => {
443443
ast::TypeImplItem(
444-
P(fold::noop_fold_typedef((**td).clone(), &mut fld)))
444+
fold::noop_fold_typedef((*td).clone(), &mut fld))
445445
}
446446
})
447447
}

src/librustc/middle/dead.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ impl<'v> Visitor<'v> for LifeSeeder {
357357
}
358358
ast::ItemImpl(_, _, _, Some(ref _trait_ref), _, ref impl_items) => {
359359
for impl_item in impl_items {
360-
match *impl_item {
360+
match **impl_item {
361361
ast::MethodImplItem(ref method) => {
362362
self.worklist.push(method.id);
363363
}
@@ -586,7 +586,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
586586
ast::ProvidedMethod(ref method) => {
587587
visit::walk_block(self, &*method.pe_body())
588588
}
589-
ast::RequiredMethod(_) => {}
589+
ast::RequiredMethod(_) |
590590
ast::TypeTraitItem(_) => {}
591591
}
592592
}

src/librustc/middle/reachable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
315315
match *impl_item {
316316
ast::MethodImplItem(ref method) => {
317317
let did = self.tcx.map.get_parent_did(search_item);
318-
if method_might_be_inlined(self.tcx, &**method, did) {
318+
if method_might_be_inlined(self.tcx, method, did) {
319319
visit::walk_block(self, method.pe_body())
320320
}
321321
}

src/librustc/middle/stability.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ use syntax::codemap::{Span, DUMMY_SP};
2222
use syntax::{attr, visit};
2323
use syntax::ast;
2424
use syntax::ast::{Attribute, Block, Crate, DefId, FnDecl, NodeId, Variant};
25-
use syntax::ast::{Item, RequiredMethod, ProvidedMethod, TraitItem};
26-
use syntax::ast::{TypeMethod, Method, Generics, StructField, TypeTraitItem};
25+
use syntax::ast::{Item, TypeMethod, Method, Generics, StructField};
2726
use syntax::ast_util::is_local;
2827
use syntax::attr::{Stability, AttrMetaMethods};
2928
use syntax::visit::{FnKind, FkMethod, Visitor};
@@ -134,19 +133,20 @@ impl<'a, 'v> Visitor<'v> for Annotator<'a> {
134133
// a stability attribute, so we don't recurse.
135134
}
136135

137-
fn visit_trait_item(&mut self, t: &TraitItem) {
136+
fn visit_trait_item(&mut self, t: &ast::TraitItem) {
138137
let (id, attrs, sp) = match *t {
139-
RequiredMethod(TypeMethod {id, ref attrs, span, ..}) => (id, attrs, span),
138+
ast::RequiredMethod(TypeMethod {id, ref attrs, span, ..}) => (id, attrs, span),
140139

141140
// work around lack of pattern matching for @ types
142-
ProvidedMethod(ref method) => {
143-
match **method {
141+
ast::ProvidedMethod(ref method) => {
142+
match *method {
144143
Method {ref attrs, id, span, ..} => (id, attrs, span),
145144
}
146145
}
147146

148-
TypeTraitItem(ref typedef) => (typedef.ty_param.id, &typedef.attrs,
149-
typedef.ty_param.span),
147+
ast::TypeTraitItem(ref typedef) => {
148+
(typedef.ty_param.id, &typedef.attrs, typedef.ty_param.span)
149+
}
150150
};
151151
self.annotate(id, true, attrs, sp, |v| visit::walk_trait_item(v, t), true);
152152
}
@@ -335,7 +335,7 @@ pub fn check_item(tcx: &ty::ctxt, item: &ast::Item, warn_about_defns: bool,
335335
let trait_items = ty::trait_items(tcx, trait_did);
336336

337337
for impl_item in impl_items {
338-
let (ident, span) = match *impl_item {
338+
let (ident, span) = match **impl_item {
339339
ast::MethodImplItem(ref method) => {
340340
(match method.node {
341341
ast::MethDecl(ident, _, _, _, _, _, _, _) => ident,

src/librustc/middle/ty.rs

+15-31
Original file line numberDiff line numberDiff line change
@@ -5080,39 +5080,23 @@ pub fn provided_source(cx: &ctxt, id: ast::DefId) -> Option<ast::DefId> {
50805080
pub fn provided_trait_methods<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)
50815081
-> Vec<Rc<Method<'tcx>>> {
50825082
if is_local(id) {
5083-
match cx.map.find(id.node) {
5084-
Some(ast_map::NodeItem(item)) => {
5085-
match item.node {
5086-
ItemTrait(_, _, _, ref ms) => {
5087-
let (_, p) =
5088-
ast_util::split_trait_methods(&ms[..]);
5089-
p.iter()
5090-
.map(|m| {
5091-
match impl_or_trait_item(
5092-
cx,
5093-
ast_util::local_def(m.id)) {
5094-
MethodTraitItem(m) => m,
5095-
TypeTraitItem(_) => {
5096-
cx.sess.bug("provided_trait_methods(): \
5097-
split_trait_methods() put \
5098-
associated types in the \
5099-
provided method bucket?!")
5100-
}
5101-
}
5102-
}).collect()
5103-
}
5104-
_ => {
5105-
cx.sess.bug(&format!("provided_trait_methods: `{:?}` is \
5106-
not a trait",
5107-
id))
5083+
if let ItemTrait(_, _, _, ref ms) = cx.map.expect_item(id.node).node {
5084+
ms.iter().filter_map(|ti| {
5085+
if let ast::ProvidedMethod(ref m) = **ti {
5086+
match impl_or_trait_item(cx, ast_util::local_def(m.id)) {
5087+
MethodTraitItem(m) => Some(m),
5088+
TypeTraitItem(_) => {
5089+
cx.sess.bug("provided_trait_methods(): \
5090+
associated type found from \
5091+
looking up ProvidedMethod?!")
5092+
}
51085093
}
5094+
} else {
5095+
None
51095096
}
5110-
}
5111-
_ => {
5112-
cx.sess.bug(&format!("provided_trait_methods: `{:?}` is not a \
5113-
trait",
5114-
id))
5115-
}
5097+
}).collect()
5098+
} else {
5099+
cx.sess.bug(&format!("provided_trait_methods: `{:?}` is not a trait", id))
51165100
}
51175101
} else {
51185102
csearch::get_provided_trait_methods(cx, id)

src/librustc_privacy/lib.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'v> Visitor<'v> for ParentVisitor {
9494
// private.
9595
ast::ItemTrait(_, _, _, ref methods) if item.vis != ast::Public => {
9696
for m in methods {
97-
match *m {
97+
match **m {
9898
ast::ProvidedMethod(ref m) => {
9999
self.parents.insert(m.id, item.id);
100100
}
@@ -280,7 +280,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
280280

281281
if public_ty || public_trait {
282282
for impl_item in impl_items {
283-
match *impl_item {
283+
match **impl_item {
284284
ast::MethodImplItem(ref method) => {
285285
let meth_public =
286286
match method.pe_explicit_self().node {
@@ -301,7 +301,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
301301
// is public
302302
ast::ItemTrait(_, _, _, ref methods) if public_first => {
303303
for method in methods {
304-
match *method {
304+
match **method {
305305
ast::ProvidedMethod(ref m) => {
306306
debug!("provided {}", m.id);
307307
self.exported_items.insert(m.id);
@@ -1088,7 +1088,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
10881088
"visibility qualifiers have no effect on trait \
10891089
impls");
10901090
for impl_item in impl_items {
1091-
match *impl_item {
1091+
match **impl_item {
10921092
ast::MethodImplItem(ref m) => {
10931093
check_inherited(m.span, m.pe_vis(), "");
10941094
}
@@ -1123,7 +1123,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
11231123

11241124
ast::ItemTrait(_, _, _, ref methods) => {
11251125
for m in methods {
1126-
match *m {
1126+
match **m {
11271127
ast::ProvidedMethod(ref m) => {
11281128
check_inherited(m.span, m.pe_vis(),
11291129
"unnecessary visibility");
@@ -1165,7 +1165,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
11651165
match item.node {
11661166
ast::ItemImpl(_, _, _, _, _, ref impl_items) => {
11671167
for impl_item in impl_items {
1168-
match *impl_item {
1168+
match **impl_item {
11691169
ast::MethodImplItem(ref m) => {
11701170
check_inherited(tcx, m.span, m.pe_vis());
11711171
}
@@ -1188,7 +1188,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
11881188

11891189
ast::ItemTrait(_, _, _, ref methods) => {
11901190
for m in methods {
1191-
match *m {
1191+
match **m {
11921192
ast::RequiredMethod(..) => {}
11931193
ast::ProvidedMethod(ref m) => check_inherited(tcx, m.span,
11941194
m.pe_vis()),
@@ -1352,7 +1352,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
13521352
trait_ref.is_some() ||
13531353
impl_items.iter()
13541354
.any(|impl_item| {
1355-
match *impl_item {
1355+
match **impl_item {
13561356
ast::MethodImplItem(ref m) => {
13571357
self.exported_items.contains(&m.id)
13581358
}
@@ -1369,9 +1369,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
13691369
match *trait_ref {
13701370
None => {
13711371
for impl_item in impl_items {
1372-
match *impl_item {
1372+
match **impl_item {
13731373
ast::MethodImplItem(ref method) => {
1374-
visit::walk_method_helper(self, &**method)
1374+
visit::walk_method_helper(self, method)
13751375
}
13761376
ast::TypeImplItem(_) => {}
13771377
}
@@ -1395,7 +1395,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
13951395

13961396
// Those in 3. are warned with this call.
13971397
for impl_item in impl_items {
1398-
match *impl_item {
1398+
match **impl_item {
13991399
ast::MethodImplItem(..) => {},
14001400
ast::TypeImplItem(ref typedef) => {
14011401
self.visit_ty(&typedef.typ);
@@ -1409,14 +1409,14 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
14091409
// methods will be visible as `Public::foo`.
14101410
let mut found_pub_static = false;
14111411
for impl_item in impl_items {
1412-
match *impl_item {
1412+
match **impl_item {
14131413
ast::MethodImplItem(ref method) => {
14141414
if method.pe_explicit_self().node ==
14151415
ast::SelfStatic &&
14161416
self.exported_items
14171417
.contains(&method.id) {
14181418
found_pub_static = true;
1419-
visit::walk_method_helper(self, &**method);
1419+
visit::walk_method_helper(self, method);
14201420
}
14211421
}
14221422
ast::TypeImplItem(_) => {}

src/librustc_resolve/build_reduced_graph.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use syntax::ast::UnnamedField;
4848
use syntax::ast::{Variant, ViewPathGlob, ViewPathList, ViewPathSimple};
4949
use syntax::ast::{Visibility};
5050
use syntax::ast;
51-
use syntax::ast_util::{self, local_def};
51+
use syntax::ast_util::{self, local_def, PostExpansionMethod};
5252
use syntax::attr::AttrMetaMethods;
5353
use syntax::parse::token::{self, special_idents};
5454
use syntax::codemap::{Span, DUMMY_SP};
@@ -525,28 +525,32 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
525525

526526
// Add the names of all the items to the trait info.
527527
for trait_item in items {
528-
let (name, trait_item_id) = match *trait_item {
528+
let (name, trait_item_id) = match **trait_item {
529529
ast::RequiredMethod(_) |
530530
ast::ProvidedMethod(_) => {
531-
let ty_m = ast_util::trait_item_to_ty_method(trait_item);
532-
533-
let name = ty_m.ident.name;
531+
let (id, name, span) = match **trait_item {
532+
ast::RequiredMethod(ref m) => {
533+
(m.id, m.ident.name, m.span)
534+
}
535+
ast::ProvidedMethod(ref m) => {
536+
(m.id, m.pe_ident().name, m.span)
537+
}
538+
_ => unreachable!()
539+
};
534540

535541
// Add it as a name in the trait module.
536-
let def = DefMethod(local_def(ty_m.id),
542+
let def = DefMethod(local_def(id),
537543
FromTrait(local_def(item.id)));
538544

539545
let method_name_bindings =
540546
self.add_child(name,
541547
&module_parent,
542548
ForbidDuplicateTypesAndValues,
543-
ty_m.span);
549+
span);
544550
// NB: not IMPORTABLE
545-
method_name_bindings.define_value(def,
546-
ty_m.span,
547-
PUBLIC);
551+
method_name_bindings.define_value(def, span, PUBLIC);
548552

549-
(name, local_def(ty_m.id))
553+
(name, local_def(id))
550554
}
551555
ast::TypeTraitItem(ref associated_type) => {
552556
let def = DefAssociatedTy(local_def(item.id),

0 commit comments

Comments
 (0)