Skip to content

Commit 28da4ec

Browse files
ericktcatamorphism
authored andcommitted
convert librustc record types to structs
specifically: freevars::freevar_entry ty::{field_ty,AutoAdjustment,AutoRef} mod::{method_param,method_map_entry}
1 parent d5d77b9 commit 28da4ec

File tree

14 files changed

+146
-86
lines changed

14 files changed

+146
-86
lines changed

src/librustc/metadata/decoder.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -930,14 +930,18 @@ fn get_struct_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id)
930930
let item = lookup_item(id, data);
931931
let mut result = ~[];
932932
for reader::tagged_docs(item, tag_item_field) |an_item| {
933-
let f = item_family(an_item);
934-
if f == PublicField || f == PrivateField || f == InheritedField {
935-
let name = item_name(intr, an_item);
936-
let did = item_def_id(an_item, cdata);
937-
let mt = field_mutability(an_item);
938-
result.push({ident: name, id: did, vis:
939-
family_to_visibility(f), mutability: mt});
940-
}
933+
let f = item_family(an_item);
934+
if f == PublicField || f == PrivateField || f == InheritedField {
935+
let name = item_name(intr, an_item);
936+
let did = item_def_id(an_item, cdata);
937+
let mt = field_mutability(an_item);
938+
result.push(ty::field_ty {
939+
ident: name,
940+
id: did, vis:
941+
family_to_visibility(f),
942+
mutability: mt,
943+
});
944+
}
941945
}
942946
result
943947
}

src/librustc/middle/astencode.rs

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -448,16 +448,20 @@ impl ast::def: tr {
448448

449449
impl ty::AutoAdjustment: tr {
450450
fn tr(xcx: extended_decode_ctxt) -> ty::AutoAdjustment {
451-
{autoderefs: self.autoderefs,
452-
autoref: self.autoref.map(|ar| ar.tr(xcx))}
451+
ty::AutoAdjustment {
452+
autoderefs: self.autoderefs,
453+
autoref: self.autoref.map(|ar| ar.tr(xcx)),
454+
}
453455
}
454456
}
455457

456458
impl ty::AutoRef: tr {
457459
fn tr(xcx: extended_decode_ctxt) -> ty::AutoRef {
458-
{kind: self.kind,
459-
region: self.region.tr(xcx),
460-
mutbl: self.mutbl}
460+
ty::AutoRef {
461+
kind: self.kind,
462+
region: self.region.tr(xcx),
463+
mutbl: self.mutbl,
464+
}
461465
}
462466
}
463467

@@ -503,7 +507,10 @@ impl reader::Decoder: ebml_decoder_helper {
503507

504508
impl freevar_entry: tr {
505509
fn tr(xcx: extended_decode_ctxt) -> freevar_entry {
506-
{def: self.def.tr(xcx), span: self.span.tr(xcx)}
510+
freevar_entry {
511+
def: self.def.tr(xcx),
512+
span: self.span.tr(xcx),
513+
}
507514
}
508515
}
509516

@@ -533,21 +540,20 @@ fn encode_method_map_entry(ecx: @e::encode_ctxt,
533540
impl reader::Decoder: read_method_map_entry_helper {
534541
fn read_method_map_entry(xcx: extended_decode_ctxt) -> method_map_entry {
535542
do self.read_rec {
536-
{self_arg:
537-
self.read_field(~"self_arg", 0u, || {
538-
self.read_arg(xcx)
539-
}),
540-
explicit_self:
541-
self.read_field(~"explicit_self", 2u, || {
543+
method_map_entry {
544+
self_arg: self.read_field(~"self_arg", 0u, || {
545+
self.read_arg(xcx)
546+
}),
547+
explicit_self: self.read_field(~"explicit_self", 2u, || {
542548
let self_type: ast::self_ty_ = Decodable::decode(&self);
543549
self_type
544-
}),
545-
origin:
546-
self.read_field(~"origin", 1u, || {
547-
let method_origin: method_origin =
548-
Decodable::decode(&self);
549-
method_origin.tr(xcx)
550-
})}
550+
}),
551+
origin: self.read_field(~"origin", 1u, || {
552+
let method_origin: method_origin =
553+
Decodable::decode(&self);
554+
method_origin.tr(xcx)
555+
}),
556+
}
551557
}
552558
}
553559
}
@@ -559,7 +565,12 @@ impl method_origin: tr {
559565
typeck::method_static(did.tr(xcx))
560566
}
561567
typeck::method_param(ref mp) => {
562-
typeck::method_param({trait_id:(*mp).trait_id.tr(xcx),.. (*mp)})
568+
typeck::method_param(
569+
typeck::method_param {
570+
trait_id: mp.trait_id.tr(xcx),
571+
.. *mp
572+
}
573+
)
563574
}
564575
typeck::method_trait(did, m, vstore) => {
565576
typeck::method_trait(did.tr(xcx), m, vstore)

src/librustc/middle/freevars.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ export has_freevars;
3434
// (The def_upvar will already have been stripped).
3535
#[auto_encode]
3636
#[auto_decode]
37-
type freevar_entry = {
37+
struct freevar_entry {
3838
def: ast::def, //< The variable being accessed free.
3939
span: span //< First span where it is accessed (there can be multiple)
40-
};
40+
}
4141
type freevar_info = @~[@freevar_entry];
4242
type freevar_map = HashMap<ast::node_id, freevar_info>;
4343

@@ -79,7 +79,10 @@ fn collect_freevars(def_map: resolve::DefMap, blk: ast::blk)
7979
if i == depth { // Made it to end of loop
8080
let dnum = ast_util::def_id_of_def(def).node;
8181
if !seen.contains_key(dnum) {
82-
refs.push(@{def:def, span:expr.span});
82+
refs.push(@freevar_entry {
83+
def: def,
84+
span: expr.span,
85+
});
8386
seen.insert(dnum, ());
8487
}
8588
}

src/librustc/middle/privacy.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
132132
// XXX: External crates.
133133
}
134134
}
135-
method_param({trait_id: trait_id, method_num: method_num, _}) |
135+
method_param(method_param {
136+
trait_id: trait_id,
137+
method_num: method_num,
138+
_
139+
}) |
136140
method_trait(trait_id, method_num, _) |
137141
method_self(trait_id, method_num) => {
138142
if trait_id.crate == local_crate {

src/librustc/middle/trans/meth.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,12 @@ fn trans_method_callee(bcx: block, callee_id: ast::node_id,
209209
})
210210
}
211211
}
212-
typeck::method_param({trait_id:trait_id, method_num:off,
213-
param_num:p, bound_num:b}) => {
212+
typeck::method_param(typeck::method_param {
213+
trait_id: trait_id,
214+
method_num: off,
215+
param_num: p,
216+
bound_num: b
217+
}) => {
214218
match bcx.fcx.param_substs {
215219
Some(ref substs) => {
216220
let vtbl = base::find_vtable(bcx.tcx(), substs, p, b);

src/librustc/middle/trans/reachable.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,21 @@ fn traverse_inline_body(cx: ctx, body: blk) {
182182
}
183183
expr_field(_, _, _) => {
184184
match cx.method_map.find(e.id) {
185-
Some({origin: typeck::method_static(did), _}) => {
185+
Some(typeck::method_map_entry {
186+
origin: typeck::method_static(did),
187+
_
188+
}) => {
186189
traverse_def_id(cx, did);
187190
}
188191
_ => ()
189192
}
190193
}
191194
expr_method_call(*) => {
192195
match cx.method_map.find(e.id) {
193-
Some({origin: typeck::method_static(did), _}) => {
196+
Some(typeck::method_map_entry {
197+
origin: typeck::method_static(did),
198+
_
199+
}) => {
194200
traverse_def_id(cx, did);
195201
}
196202
Some(_) => {}

src/librustc/middle/trans/type_use.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,10 @@ fn mark_for_method_call(cx: ctx, e_id: node_id, callee_id: node_id) {
233233
}
234234
}
235235
}
236-
typeck::method_param({param_num: param, _}) => {
236+
typeck::method_param(typeck::method_param {
237+
param_num: param,
238+
_
239+
}) => {
237240
cx.uses[param] |= use_tydesc;
238241
}
239242
typeck::method_trait(*) | typeck::method_self(*) => (),

src/librustc/middle/ty.rs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,12 @@ enum vstore {
272272
vstore_slice(Region)
273273
}
274274

275-
type field_ty = {
275+
struct field_ty {
276276
ident: ident,
277277
id: def_id,
278278
vis: ast::visibility,
279-
mutability: ast::struct_mutability
280-
};
279+
mutability: ast::struct_mutability,
280+
}
281281

282282
/// How an lvalue is to be used.
283283
#[auto_encode]
@@ -356,18 +356,18 @@ impl region_variance : cmp::Eq {
356356

357357
#[auto_encode]
358358
#[auto_decode]
359-
pub type AutoAdjustment = {
359+
pub struct AutoAdjustment {
360360
autoderefs: uint,
361361
autoref: Option<AutoRef>
362-
};
362+
}
363363

364364
#[auto_encode]
365365
#[auto_decode]
366-
pub type AutoRef = {
366+
pub struct AutoRef {
367367
kind: AutoRefKind,
368368
region: Region,
369369
mutbl: ast::mutability
370-
};
370+
}
371371

372372
#[auto_encode]
373373
#[auto_decode]
@@ -3086,8 +3086,9 @@ fn method_call_bounds(tcx: ctxt, method_map: typeck::method_map,
30863086
// and then the method bounds themselves...
30873087
ty::lookup_item_type(tcx, did).bounds
30883088
}
3089-
typeck::method_param({trait_id:trt_id,
3090-
method_num:n_mth, _}) |
3089+
typeck::method_param(typeck::method_param {
3090+
trait_id: trt_id,
3091+
method_num: n_mth, _}) |
30913092
typeck::method_trait(trt_id, n_mth, _) |
30923093
typeck::method_self(trt_id, n_mth) => {
30933094
// ...trait methods bounds, in contrast, include only the
@@ -4075,25 +4076,27 @@ pure fn is_public(f: field_ty) -> bool {
40754076
}
40764077

40774078
fn struct_field_tys(fields: ~[@struct_field]) -> ~[field_ty] {
4078-
let mut rslt = ~[];
4079-
for fields.each |field| {
4079+
do fields.map |field| {
40804080
match field.node.kind {
40814081
named_field(ident, mutability, visibility) => {
4082-
rslt.push({ident: ident,
4083-
id: ast_util::local_def(field.node.id),
4084-
vis: visibility,
4085-
mutability: mutability});
4082+
field_ty {
4083+
ident: ident,
4084+
id: ast_util::local_def(field.node.id),
4085+
vis: visibility,
4086+
mutability: mutability,
4087+
}
40864088
}
40874089
unnamed_field => {
4088-
rslt.push({ident:
4089-
syntax::parse::token::special_idents::unnamed_field,
4090-
id: ast_util::local_def(field.node.id),
4091-
vis: ast::public,
4092-
mutability: ast::struct_immutable});
4090+
field_ty {
4091+
ident:
4092+
syntax::parse::token::special_idents::unnamed_field,
4093+
id: ast_util::local_def(field.node.id),
4094+
vis: ast::public,
4095+
mutability: ast::struct_immutable,
4096+
}
40934097
}
4094-
}
4098+
}
40954099
}
4096-
rslt
40974100
}
40984101

40994102
// Return a list of fields corresponding to the struct's items

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

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,13 @@ impl LookupContext {
455455
explicit_self: method.self_ty,
456456
num_method_tps: method.tps.len(),
457457
self_mode: get_mode_from_self_type(method.self_ty),
458-
origin: method_param({trait_id:init_trait_id,
459-
method_num:pos,
460-
param_num:param_ty.idx,
461-
bound_num:this_bound_idx})
458+
origin: method_param(
459+
method_param {
460+
trait_id: init_trait_id,
461+
method_num: pos,
462+
param_num: param_ty.idx,
463+
bound_num: this_bound_idx,
464+
})
462465
};
463466

464467
debug!("pushing inherent candidate for param: %?", cand);
@@ -834,10 +837,14 @@ impl LookupContext {
834837
Some(move mme) => {
835838
self.fcx.write_adjustment(
836839
self.self_expr.id,
837-
@{autoderefs: autoderefs,
838-
autoref: Some({kind: kind,
839-
region: region,
840-
mutbl: *mutbl})});
840+
@ty::AutoAdjustment {
841+
autoderefs: autoderefs,
842+
autoref: Some(ty::AutoRef {
843+
kind: kind,
844+
region: region,
845+
mutbl: *mutbl,
846+
}),
847+
});
841848
return Some(mme);
842849
}
843850
}
@@ -1004,10 +1011,14 @@ impl LookupContext {
10041011
};
10051012

10061013
self.fcx.write_ty_substs(self.callee_id, fty, all_substs);
1007-
return {self_arg: {mode: ast::expl(candidate.self_mode),
1008-
ty: candidate.rcvr_ty},
1009-
explicit_self: candidate.explicit_self,
1010-
origin: candidate.origin};
1014+
method_map_entry {
1015+
self_arg: {
1016+
mode: ast::expl(candidate.self_mode),
1017+
ty: candidate.rcvr_ty,
1018+
},
1019+
explicit_self: candidate.explicit_self,
1020+
origin: candidate.origin,
1021+
}
10111022
}
10121023

10131024
fn enforce_trait_instance_limitations(&self,
@@ -1050,7 +1061,7 @@ impl LookupContext {
10501061
method_static(method_id) | method_self(method_id, _) => {
10511062
bad = self.tcx().destructors.contains_key(method_id);
10521063
}
1053-
method_param({trait_id: trait_id, _}) |
1064+
method_param(method_param { trait_id: trait_id, _ }) |
10541065
method_trait(trait_id, _, _) => {
10551066
bad = self.tcx().destructor_for_type.contains_key(trait_id);
10561067
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,10 @@ impl @fn_ctxt {
730730

731731
fn write_autoderef_adjustment(node_id: ast::node_id, derefs: uint) {
732732
if derefs == 0 { return; }
733-
self.write_adjustment(node_id, @{autoderefs: derefs, autoref: None});
733+
self.write_adjustment(
734+
node_id,
735+
@ty::AutoAdjustment { autoderefs: derefs, autoref: None }
736+
);
734737
}
735738

736739
fn write_adjustment(node_id: ast::node_id, adj: @ty::AutoAdjustment) {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ fn constrain_auto_ref(
324324

325325
let adjustment = rcx.fcx.inh.adjustments.find(expr.id);
326326
let region = match adjustment {
327-
Some(@{autoref: Some(ref auto_ref), _}) => auto_ref.region,
327+
Some(@ty::AutoAdjustment { autoref: Some(ref auto_ref), _ }) => {
328+
auto_ref.region
329+
},
328330
_ => { return; }
329331
};
330332

0 commit comments

Comments
 (0)