Skip to content

Commit 306f81f

Browse files
committed
librustc: Remove mutable fields from the language.
They're still parsed though, to get through bootstrapping.
1 parent b882353 commit 306f81f

File tree

19 files changed

+69
-177
lines changed

19 files changed

+69
-177
lines changed

src/librustc/metadata/decoder.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,6 @@ fn each_reexport(d: ebml::Doc, f: &fn(ebml::Doc) -> bool) {
204204
}
205205
}
206206
207-
fn field_mutability(d: ebml::Doc) -> ast::struct_mutability {
208-
// Use maybe_get_doc in case it's a method
209-
reader::maybe_get_doc(d, tag_struct_mut).map_default(
210-
ast::struct_immutable,
211-
|d| {
212-
match reader::doc_as_u8(*d) as char {
213-
'm' => ast::struct_mutable,
214-
_ => ast::struct_immutable
215-
}
216-
})
217-
}
218-
219207
fn variant_disr_val(d: ebml::Doc) -> Option<int> {
220208
do reader::maybe_get_doc(d, tag_disr_val).chain |val_doc| {
221209
int::parse_bytes(reader::doc_data(val_doc), 10u)
@@ -923,12 +911,10 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id)
923911
if f == PublicField || f == PrivateField || f == InheritedField {
924912
let name = item_name(intr, an_item);
925913
let did = item_def_id(an_item, cdata);
926-
let mt = field_mutability(an_item);
927914
result.push(ty::field_ty {
928915
ident: name,
929916
id: did, vis:
930917
struct_field_family_to_visibility(f),
931-
mutability: mt,
932918
});
933919
}
934920
}
@@ -938,7 +924,6 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id)
938924
ident: special_idents::unnamed_field,
939925
id: did,
940926
vis: ast::inherited,
941-
mutability: ast::struct_immutable,
942927
});
943928
}
944929
result

src/librustc/metadata/encoder.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,6 @@ fn encode_region_param(ecx: @EncodeContext,
119119
}
120120
}
121121

122-
fn encode_mutability(ebml_w: &mut writer::Encoder, mt: struct_mutability) {
123-
ebml_w.start_tag(tag_struct_mut);
124-
let val = match mt {
125-
struct_immutable => 'a',
126-
struct_mutable => 'm'
127-
};
128-
ebml_w.writer.write(&[val as u8]);
129-
ebml_w.end_tag();
130-
}
131-
132122
struct entry<T> {
133123
val: T,
134124
pos: uint
@@ -518,13 +508,9 @@ fn encode_info_for_struct(ecx: @EncodeContext,
518508
/* We encode both private and public fields -- need to include
519509
private fields to get the offsets right */
520510
for fields.each |field| {
521-
let (nm, mt, vis) = match field.node.kind {
522-
named_field(nm, mt, vis) => (nm, mt, vis),
523-
unnamed_field => (
524-
special_idents::unnamed_field,
525-
struct_immutable,
526-
inherited
527-
)
511+
let (nm, vis) = match field.node.kind {
512+
named_field(nm, vis) => (nm, vis),
513+
unnamed_field => (special_idents::unnamed_field, inherited)
528514
};
529515

530516
let id = field.node.id;
@@ -537,7 +523,6 @@ fn encode_info_for_struct(ecx: @EncodeContext,
537523
encode_name(ecx, ebml_w, nm);
538524
encode_path(ecx, ebml_w, path, ast_map::path_name(nm));
539525
encode_type(ecx, ebml_w, node_id_to_type(tcx, id));
540-
encode_mutability(ebml_w, mt);
541526
encode_def_id(ebml_w, local_def(id));
542527
ebml_w.end_tag();
543528
}
@@ -828,7 +813,7 @@ fn encode_info_for_item(ecx: @EncodeContext,
828813
needs to know*/
829814
for struct_def.fields.each |f| {
830815
match f.node.kind {
831-
named_field(ident, _, vis) => {
816+
named_field(ident, vis) => {
832817
ebml_w.start_tag(tag_item_field);
833818
encode_struct_field_family(ebml_w, vis);
834819
encode_name(ecx, ebml_w, ident);

src/librustc/middle/lint.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ pub enum lint {
5656
non_camel_case_types,
5757
type_limits,
5858
default_methods,
59-
deprecated_mutable_fields,
6059
unused_unsafe,
6160

6261
managed_heap_memory,
@@ -455,7 +454,6 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
455454
check_item_heap(cx, i);
456455
check_item_type_limits(cx, i);
457456
check_item_default_methods(cx, i);
458-
check_item_deprecated_mutable_fields(cx, i);
459457
check_item_unused_unsafe(cx, i);
460458
check_item_unused_mut(cx, i);
461459
}
@@ -640,28 +638,7 @@ fn check_item_default_methods(cx: ty::ctxt, item: @ast::item) {
640638
}
641639
}
642640

643-
fn check_item_deprecated_mutable_fields(cx: ty::ctxt, item: @ast::item) {
644-
match item.node {
645-
ast::item_struct(struct_def, _) => {
646-
for struct_def.fields.each |field| {
647-
match field.node.kind {
648-
ast::named_field(_, ast::struct_mutable, _) => {
649-
cx.sess.span_lint(deprecated_mutable_fields,
650-
item.id,
651-
item.id,
652-
field.span,
653-
"mutable fields are deprecated");
654-
}
655-
ast::named_field(*) | ast::unnamed_field => {}
656-
}
657-
}
658-
}
659-
_ => {}
660-
}
661-
}
662-
663641
fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {
664-
665642
fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id,
666643
decl: &ast::fn_decl) {
667644
let tys = vec::map(decl.inputs, |a| a.ty );

src/librustc/middle/mem_categorization.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -581,17 +581,7 @@ pub impl mem_categorization_ctxt {
581581
f_name: ast::ident,
582582
f_ty: ty::t,
583583
field_id: ast::node_id) -> cmt {
584-
let f_mutbl = match field_mutbl(self.tcx, base_cmt.ty,
585-
f_name, field_id) {
586-
Some(f_mutbl) => f_mutbl,
587-
None => {
588-
self.tcx.sess.span_bug(
589-
node.span(),
590-
fmt!("Cannot find field `%s` in type `%s`",
591-
*self.tcx.sess.str_of(f_name),
592-
ty_to_str(self.tcx, base_cmt.ty)));
593-
}
594-
};
584+
let f_mutbl = m_imm;
595585
let m = self.inherited_mutability(base_cmt.mutbl, f_mutbl);
596586
let f_interior = interior_field(f_name, f_mutbl);
597587
@cmt_ {
@@ -968,11 +958,7 @@ pub fn field_mutbl(tcx: ty::ctxt,
968958
ty::ty_struct(did, _) => {
969959
for ty::lookup_struct_fields(tcx, did).each |fld| {
970960
if fld.ident == f_name {
971-
let m = match fld.mutability {
972-
ast::struct_mutable => ast::m_mutbl,
973-
ast::struct_immutable => ast::m_imm
974-
};
975-
return Some(m);
961+
return Some(ast::m_imm);
976962
}
977963
}
978964
}
@@ -981,11 +967,7 @@ pub fn field_mutbl(tcx: ty::ctxt,
981967
ast::def_variant(_, variant_id) => {
982968
for ty::lookup_struct_fields(tcx, variant_id).each |fld| {
983969
if fld.ident == f_name {
984-
let m = match fld.mutability {
985-
ast::struct_mutable => ast::m_mutbl,
986-
ast::struct_immutable => ast::m_imm
987-
};
988-
return Some(m);
970+
return Some(ast::m_imm);
989971
}
990972
}
991973
}

src/librustc/middle/region.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -894,17 +894,7 @@ pub fn determine_rp_in_struct_field(
894894
cm: @ast::struct_field,
895895
cx: @mut DetermineRpCtxt,
896896
visitor: visit::vt<@mut DetermineRpCtxt>) {
897-
match cm.node.kind {
898-
ast::named_field(_, ast::struct_mutable, _) => {
899-
do cx.with_ambient_variance(rv_invariant) {
900-
visit::visit_struct_field(cm, cx, visitor);
901-
}
902-
}
903-
ast::named_field(_, ast::struct_immutable, _) |
904-
ast::unnamed_field => {
905-
visit::visit_struct_field(cm, cx, visitor);
906-
}
907-
}
897+
visit::visit_struct_field(cm, cx, visitor);
908898
}
909899

910900
pub fn determine_rp_in_crate(sess: Session,

src/librustc/middle/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4717,7 +4717,7 @@ pub impl Resolver {
47174717
for vec::each(class_def.fields) |field| {
47184718
match field.node.kind {
47194719
unnamed_field => {},
4720-
named_field(ident, _, _) => {
4720+
named_field(ident, _) => {
47214721
if str::eq_slice(*this.session.str_of(ident),
47224722
name) {
47234723
return true

src/librustc/middle/trans/expr.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,14 @@ lvalues are *never* stored by value.
120120
*/
121121

122122
use back::abi;
123-
use lib;
124123
use lib::llvm::{ValueRef, TypeRef, llvm};
124+
use lib;
125125
use metadata::csearch;
126126
use middle::trans::_match;
127127
use middle::trans::adt;
128128
use middle::trans::asm;
129-
use middle::trans::base;
130129
use middle::trans::base::*;
130+
use middle::trans::base;
131131
use middle::trans::build::*;
132132
use middle::trans::callee::DoAutorefArg;
133133
use middle::trans::callee;
@@ -142,8 +142,10 @@ use middle::trans::machine;
142142
use middle::trans::meth;
143143
use middle::trans::tvec;
144144
use middle::trans::type_of;
145+
use middle::ty::struct_fields;
146+
use middle::ty::{AutoDerefRef, AutoAddEnv};
147+
use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowVecRef, AutoBorrowFn};
145148
use middle::ty;
146-
use middle::ty::struct_mutable_fields;
147149
use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowVecRef, AutoBorrowFn,
148150
AutoDerefRef, AutoAddEnv, AutoUnsafe};
149151
use util::common::indenter;
@@ -1107,7 +1109,7 @@ pub fn with_field_tys<R>(tcx: ty::ctxt,
11071109
op: &fn(int, (&[ty::field])) -> R) -> R {
11081110
match ty::get(ty).sty {
11091111
ty::ty_struct(did, ref substs) => {
1110-
op(0, struct_mutable_fields(tcx, did, substs))
1112+
op(0, struct_fields(tcx, did, substs))
11111113
}
11121114

11131115
ty::ty_enum(_, ref substs) => {
@@ -1124,8 +1126,8 @@ pub fn with_field_tys<R>(tcx: ty::ctxt,
11241126
ast::def_variant(enum_id, variant_id) => {
11251127
let variant_info = ty::enum_variant_with_id(
11261128
tcx, enum_id, variant_id);
1127-
op(variant_info.disr_val, struct_mutable_fields(
1128-
tcx, variant_id, substs))
1129+
op(variant_info.disr_val,
1130+
struct_fields(tcx, variant_id, substs))
11291131
}
11301132
_ => {
11311133
tcx.sess.bug(~"resolve didn't map this expr to a \

src/librustc/middle/trans/glue.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,7 @@ pub fn trans_struct_drop(bcx: block,
496496
Call(bcx, dtor_addr, args);
497497

498498
// Drop the fields
499-
let field_tys =
500-
ty::struct_mutable_fields(bcx.tcx(), class_did,
501-
substs);
499+
let field_tys = ty::struct_fields(bcx.tcx(), class_did, substs);
502500
for vec::eachi(field_tys) |i, fld| {
503501
let llfld_a = adt::trans_field_ptr(bcx, repr, v0, 0, i);
504502
bcx = drop_ty(bcx, llfld_a, fld.mt.ty);

src/librustc/middle/ty.rs

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,9 @@ pub enum SelfMode {
106106
}
107107

108108
pub struct field_ty {
109-
ident: ident,
110-
id: def_id,
111-
vis: ast::visibility,
112-
mutability: ast::struct_mutability,
109+
ident: ident,
110+
id: def_id,
111+
vis: ast::visibility,
113112
}
114113

115114
// Contains information needed to resolve types and (in the future) look up
@@ -3987,12 +3986,11 @@ pub fn lookup_struct_field(cx: ctxt,
39873986
fn struct_field_tys(fields: &[@struct_field]) -> ~[field_ty] {
39883987
do fields.map |field| {
39893988
match field.node.kind {
3990-
named_field(ident, mutability, visibility) => {
3989+
named_field(ident, visibility) => {
39913990
field_ty {
39923991
ident: ident,
39933992
id: ast_util::local_def(field.node.id),
39943993
vis: visibility,
3995-
mutability: mutability,
39963994
}
39973995
}
39983996
unnamed_field => {
@@ -4001,51 +3999,22 @@ fn struct_field_tys(fields: &[@struct_field]) -> ~[field_ty] {
40013999
syntax::parse::token::special_idents::unnamed_field,
40024000
id: ast_util::local_def(field.node.id),
40034001
vis: ast::public,
4004-
mutability: ast::struct_immutable,
40054002
}
40064003
}
40074004
}
40084005
}
40094006
}
40104007
4011-
// Return a list of fields corresponding to the struct's items
4012-
// (as if the struct was a record). trans uses this
4013-
// Takes a list of substs with which to instantiate field types
4014-
// Keep in mind that this function reports that all fields are
4015-
// mutable, regardless of how they were declared. It's meant to
4016-
// be used in trans.
4017-
pub fn struct_mutable_fields(cx: ctxt,
4018-
did: ast::def_id,
4019-
substs: &substs)
4020-
-> ~[field] {
4021-
struct_item_fields(cx, did, substs, |_mt| m_mutbl)
4022-
}
4023-
4024-
// Same as struct_mutable_fields, but doesn't change
4025-
// mutability.
4026-
pub fn struct_fields(cx: ctxt,
4027-
did: ast::def_id,
4028-
substs: &substs)
4029-
-> ~[field] {
4030-
struct_item_fields(cx, did, substs, |mt| match mt {
4031-
struct_mutable => m_mutbl,
4032-
struct_immutable => m_imm })
4033-
}
4034-
4035-
4036-
fn struct_item_fields(cx:ctxt,
4037-
did: ast::def_id,
4038-
substs: &substs,
4039-
frob_mutability: &fn(struct_mutability) -> mutability)
4040-
-> ~[field] {
4008+
// Returns a list of fields corresponding to the struct's items. trans uses
4009+
// this. Takes a list of substs with which to instantiate field types.
4010+
pub fn struct_fields(cx: ctxt, did: ast::def_id, substs: &substs)
4011+
-> ~[field] {
40414012
do lookup_struct_fields(cx, did).map |f| {
4042-
// consider all instance vars mut, because the
4043-
// constructor may mutate all vars
40444013
field {
4045-
ident: f.ident,
4014+
ident: f.ident,
40464015
mt: mt {
40474016
ty: lookup_field_type(cx, did, f.id, substs),
4048-
mutbl: frob_mutability(f.mutability)
4017+
mutbl: m_imm
40494018
}
40504019
}
40514020
}

src/librustdoc/extract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ fn structdoc_from_struct(
274274
item: itemdoc,
275275
fields: do struct_def.fields.map |field| {
276276
match field.node.kind {
277-
ast::named_field(ident, _, _) => to_str(ident),
277+
ast::named_field(ident, _) => to_str(ident),
278278
ast::unnamed_field => ~"(unnamed)",
279279
}
280280
},

0 commit comments

Comments
 (0)