Skip to content

Commit 729708d

Browse files
committed
rustc: rename ty::method to ty::Method and add ctor
1 parent 18f6a51 commit 729708d

File tree

9 files changed

+108
-76
lines changed

9 files changed

+108
-76
lines changed

src/librustc/metadata/csearch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use syntax::ast_map;
2222
use syntax::diagnostic::expect;
2323

2424
pub struct ProvidedTraitMethodInfo {
25-
ty: ty::method,
25+
ty: ty::Method,
2626
def_id: ast::def_id
2727
}
2828

@@ -129,7 +129,7 @@ pub fn get_impls_for_mod(cstore: @mut cstore::CStore, def: ast::def_id,
129129
}
130130

131131
pub fn get_method(tcx: ty::ctxt,
132-
def: ast::def_id) -> ty::method
132+
def: ast::def_id) -> ty::Method
133133
{
134134
let cdata = cstore::get_crate_data(tcx.cstore, def.crate);
135135
decoder::get_method(tcx.cstore.intr, cdata, def.node, tcx)

src/librustc/metadata/decoder.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ pub fn get_method_name_and_explicit_self(
760760
}
761761

762762
pub fn get_method(intr: @ident_interner, cdata: cmd, id: ast::node_id,
763-
tcx: ty::ctxt) -> ty::method
763+
tcx: ty::ctxt) -> ty::Method
764764
{
765765
let method_doc = lookup_item(id, cdata.data);
766766
let def_id = item_def_id(method_doc, cdata);
@@ -771,18 +771,19 @@ pub fn get_method(intr: @ident_interner, cdata: cmd, id: ast::node_id,
771771
let fty = doc_method_fty(method_doc, tcx, cdata);
772772
let vis = item_visibility(method_doc);
773773
let explicit_self = get_explicit_self(method_doc);
774-
ty::method {
775-
ident: name,
776-
generics: ty::Generics {
774+
775+
ty::Method::new(
776+
name,
777+
ty::Generics {
777778
type_param_defs: type_param_defs,
778779
region_param: None
779780
},
780-
transformed_self_ty: transformed_self_ty,
781-
fty: fty,
782-
explicit_self: explicit_self,
783-
vis: vis,
784-
def_id: def_id
785-
}
781+
transformed_self_ty,
782+
fty,
783+
explicit_self,
784+
vis,
785+
def_id
786+
)
786787
}
787788

788789
pub fn get_trait_method_def_ids(cdata: cmd,
@@ -824,18 +825,19 @@ pub fn get_provided_trait_methods(intr: @ident_interner, cdata: cmd,
824825

825826
let transformed_self_ty = doc_transformed_self_ty(mth, tcx, cdata);
826827
let explicit_self = get_explicit_self(mth);
827-
let ty_method = ty::method {
828-
ident: name,
829-
generics: ty::Generics {
828+
829+
let ty_method = ty::Method::new(
830+
name,
831+
ty::Generics {
830832
type_param_defs: type_param_defs,
831833
region_param: None
832834
},
833-
transformed_self_ty: transformed_self_ty,
834-
fty: fty,
835-
explicit_self: explicit_self,
836-
vis: ast::public,
837-
def_id: did
838-
};
835+
transformed_self_ty,
836+
fty,
837+
explicit_self,
838+
ast::public,
839+
did
840+
);
839841
let provided_trait_method_info = ProvidedTraitMethodInfo {
840842
ty: ty_method,
841843
def_id: did

src/librustc/metadata/encoder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ fn encode_path(ecx: @EncodeContext,
366366
fn encode_reexported_static_method(ecx: @EncodeContext,
367367
ebml_w: &mut writer::Encoder,
368368
exp: &middle::resolve::Export2,
369-
m: @ty::method) {
369+
m: @ty::Method) {
370370
debug!("(encode static trait method) reexport '%s::%s'",
371371
*exp.name, *ecx.tcx.sess.str_of(m.ident));
372372
ebml_w.start_tag(tag_items_data_item_reexport);
@@ -625,7 +625,7 @@ fn encode_info_for_struct_ctor(ecx: @EncodeContext,
625625

626626
fn encode_method_ty_fields(ecx: @EncodeContext,
627627
ebml_w: &mut writer::Encoder,
628-
method_ty: &ty::method) {
628+
method_ty: &ty::Method) {
629629
encode_def_id(ebml_w, method_ty.def_id);
630630
encode_name(ecx, ebml_w, method_ty.ident);
631631
encode_ty_type_param_defs(ebml_w, ecx,
@@ -652,7 +652,7 @@ fn encode_info_for_method(ecx: @EncodeContext,
652652
ebml_w.start_tag(tag_items_data_item);
653653

654654
let method_def_id = local_def(m.id);
655-
let method_ty: @ty::method = ty::method(ecx.tcx, method_def_id);
655+
let method_ty = ty::method(ecx.tcx, method_def_id);
656656
encode_method_ty_fields(ecx, ebml_w, method_ty);
657657

658658
match m.explicit_self.node {
@@ -948,7 +948,7 @@ fn encode_info_for_item(ecx: @EncodeContext,
948948
for ty::trait_method_def_ids(tcx, local_def(item.id)).eachi |i, &method_def_id| {
949949
assert!(method_def_id.crate == ast::local_crate);
950950

951-
let method_ty: @ty::method = ty::method(tcx, method_def_id);
951+
let method_ty = ty::method(tcx, method_def_id);
952952

953953
index.push(entry {val: method_def_id.node, pos: ebml_w.writer.tell()});
954954

src/librustc/middle/trans/reflect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use syntax::parse::token::special_idents;
3535

3636
pub struct Reflector {
3737
visitor_val: ValueRef,
38-
visitor_methods: @~[@ty::method],
38+
visitor_methods: @~[@ty::Method],
3939
final_bcx: block,
4040
tydesc_ty: TypeRef,
4141
bcx: block

src/librustc/middle/ty.rs

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub struct field {
5353
mt: mt
5454
}
5555

56-
pub struct method {
56+
pub struct Method {
5757
ident: ast::ident,
5858
generics: ty::Generics,
5959
transformed_self_ty: Option<ty::t>,
@@ -63,6 +63,33 @@ pub struct method {
6363
def_id: ast::def_id
6464
}
6565

66+
pub impl Method {
67+
fn new(ident: ast::ident,
68+
generics: ty::Generics,
69+
transformed_self_ty: Option<ty::t>,
70+
fty: BareFnTy,
71+
explicit_self: ast::explicit_self_,
72+
vis: ast::visibility,
73+
def_id: ast::def_id) -> Method {
74+
// Check the invariants.
75+
if explicit_self == ast::sty_static {
76+
assert!(transformed_self_ty.is_none());
77+
} else {
78+
assert!(transformed_self_ty.is_some());
79+
}
80+
81+
Method {
82+
ident: ident,
83+
generics: generics,
84+
transformed_self_ty: transformed_self_ty,
85+
fty: fty,
86+
explicit_self: explicit_self,
87+
vis: vis,
88+
def_id: def_id
89+
}
90+
}
91+
}
92+
6693
#[deriving(Eq)]
6794
pub struct mt {
6895
ty: t,
@@ -254,13 +281,13 @@ struct ctxt_ {
254281
node_type_substs: @mut HashMap<node_id, ~[t]>,
255282

256283
// Maps from a method to the method "descriptor"
257-
methods: @mut HashMap<def_id, @method>,
284+
methods: @mut HashMap<def_id, @Method>,
258285

259286
// Maps from a trait def-id to a list of the def-ids of its methods
260287
trait_method_def_ids: @mut HashMap<def_id, @~[def_id]>,
261288

262289
// A cache for the trait_methods() routine
263-
trait_methods_cache: @mut HashMap<def_id, @~[@method]>,
290+
trait_methods_cache: @mut HashMap<def_id, @~[@Method]>,
264291

265292
trait_refs: @mut HashMap<node_id, @TraitRef>,
266293
trait_defs: @mut HashMap<def_id, @TraitDef>,
@@ -3498,7 +3525,7 @@ pub fn field_idx_strict(tcx: ty::ctxt, id: ast::ident, fields: &[field])
34983525
fields.map(|f| tcx.sess.str_of(f.ident))));
34993526
}
35003527

3501-
pub fn method_idx(id: ast::ident, meths: &[@method]) -> Option<uint> {
3528+
pub fn method_idx(id: ast::ident, meths: &[@Method]) -> Option<uint> {
35023529
vec::position(meths, |m| m.ident == id)
35033530
}
35043531

@@ -3822,12 +3849,12 @@ fn lookup_locally_or_in_crate_store<V:Copy>(
38223849
return v;
38233850
}
38243851

3825-
pub fn trait_method(cx: ctxt, trait_did: ast::def_id, idx: uint) -> @method {
3852+
pub fn trait_method(cx: ctxt, trait_did: ast::def_id, idx: uint) -> @Method {
38263853
let method_def_id = ty::trait_method_def_ids(cx, trait_did)[idx];
38273854
ty::method(cx, method_def_id)
38283855
}
38293856

3830-
pub fn trait_methods(cx: ctxt, trait_did: ast::def_id) -> @~[@method] {
3857+
pub fn trait_methods(cx: ctxt, trait_did: ast::def_id) -> @~[@Method] {
38313858
match cx.trait_methods_cache.find(&trait_did) {
38323859
Some(&methods) => methods,
38333860
None => {
@@ -3839,7 +3866,7 @@ pub fn trait_methods(cx: ctxt, trait_did: ast::def_id) -> @~[@method] {
38393866
}
38403867
}
38413868

3842-
pub fn method(cx: ctxt, id: ast::def_id) -> @method {
3869+
pub fn method(cx: ctxt, id: ast::def_id) -> @Method {
38433870
lookup_locally_or_in_crate_store(
38443871
"methods", id, cx.methods,
38453872
|| @csearch::get_method(cx, id))

src/librustc/middle/typeck/check/method.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub struct LookupContext<'self> {
170170
pub struct Candidate {
171171
rcvr_ty: ty::t,
172172
rcvr_substs: ty::substs,
173-
method_ty: @ty::method,
173+
method_ty: @ty::Method,
174174
origin: method_origin,
175175
}
176176

@@ -469,7 +469,7 @@ pub impl<'self> LookupContext<'self> {
469469
did: def_id,
470470
substs: &ty::substs) {
471471
struct MethodInfo {
472-
method_ty: @ty::method,
472+
method_ty: @ty::Method,
473473
trait_def_id: ast::def_id,
474474
index: uint
475475
}

src/librustc/middle/typeck/coherence.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ pub impl CoherenceChecker {
527527
#[cfg(stage0)]
528528
fn each_provided_trait_method(&self,
529529
trait_did: ast::def_id,
530-
f: &fn(x: @ty::method) -> bool) {
530+
f: &fn(@ty::Method) -> bool) {
531531
// Make a list of all the names of the provided methods.
532532
// XXX: This is horrible.
533533
let mut provided_method_idents = HashSet::new();
@@ -547,7 +547,7 @@ pub impl CoherenceChecker {
547547
#[cfg(not(stage0))]
548548
fn each_provided_trait_method(&self,
549549
trait_did: ast::def_id,
550-
f: &fn(x: @ty::method) -> bool) -> bool {
550+
f: &fn(x: @ty::Method) -> bool) -> bool {
551551
// Make a list of all the names of the provided methods.
552552
// XXX: This is horrible.
553553
let mut provided_method_idents = HashSet::new();
@@ -1073,7 +1073,7 @@ fn subst_receiver_types_in_method_ty(
10731073
impl_id: ast::node_id,
10741074
trait_ref: &ty::TraitRef,
10751075
new_def_id: ast::def_id,
1076-
method: &ty::method) -> ty::method
1076+
method: &ty::Method) -> ty::Method
10771077
{
10781078
/*!
10791079
* Substitutes the values for the receiver's type parameters
@@ -1117,19 +1117,22 @@ fn subst_receiver_types_in_method_ty(
11171117
tps: combined_tps
11181118
};
11191119

1120-
ty::method {
1121-
ident: method.ident,
1120+
ty::Method::new(
1121+
method.ident,
1122+
1123+
// method types *can* appear in the generic bounds
1124+
method.generics.subst(tcx, &combined_substs),
11221125

11231126
// method tps cannot appear in the self_ty, so use `substs` from trait ref
1124-
transformed_self_ty: method.transformed_self_ty.subst(tcx, &trait_ref.substs),
1125-
1126-
// method types *can* appear in the generic bounds or the fty
1127-
generics: method.generics.subst(tcx, &combined_substs),
1128-
fty: method.fty.subst(tcx, &combined_substs),
1129-
explicit_self: method.explicit_self,
1130-
vis: method.vis,
1131-
def_id: new_def_id
1132-
}
1127+
method.transformed_self_ty.subst(tcx, &trait_ref.substs),
1128+
1129+
// method types *can* appear in the fty
1130+
method.fty.subst(tcx, &combined_substs),
1131+
1132+
method.explicit_self,
1133+
method.vis,
1134+
new_def_id
1135+
)
11331136
}
11341137

11351138
pub fn check_coherence(crate_context: @mut CrateCtxt, crate: @crate) {

0 commit comments

Comments
 (0)