Skip to content

Commit dcddfdd

Browse files
committed
librustc: Implement a lint mode for mutable structures; deny by default
1 parent 4b9b328 commit dcddfdd

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/libcore/core.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Implicitly, all crates behave as if they included the following prologue:
5151
#[warn(vecs_implicitly_copyable)];
5252
#[deny(non_camel_case_types)];
5353
#[allow(deprecated_self)];
54+
#[allow(deprecated_mutable_fields)];
5455

5556
/* The Prelude. */
5657

src/librustc/middle/lint.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ pub enum lint {
8181
type_limits,
8282
default_methods,
8383
deprecated_self,
84+
deprecated_mutable_fields,
8485

8586
managed_heap_memory,
8687
owned_heap_memory,
@@ -255,6 +256,13 @@ pub fn get_lint_dict() -> LintDict {
255256
default: warn
256257
}),
257258

259+
(@~"deprecated_mutable_fields",
260+
@LintSpec {
261+
lint: deprecated_mutable_fields,
262+
desc: "deprecated mutable fields in structures",
263+
default: deny
264+
}),
265+
258266
/* FIXME(#3266)--make liveness warnings lintable
259267
(@~"unused_variable",
260268
@LintSpec {
@@ -488,6 +496,7 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
488496
check_item_type_limits(cx, i);
489497
check_item_default_methods(cx, i);
490498
check_item_deprecated_self(cx, i);
499+
check_item_deprecated_mutable_fields(cx, i);
491500
}
492501

493502
// Take a visitor, and modify it so that it will not proceed past subitems.
@@ -705,6 +714,26 @@ fn check_item_deprecated_self(cx: ty::ctxt, item: @ast::item) {
705714
}
706715
}
707716
717+
fn check_item_deprecated_mutable_fields(cx: ty::ctxt, item: @ast::item) {
718+
match item.node {
719+
ast::item_struct(struct_def, _) => {
720+
for struct_def.fields.each |field| {
721+
match field.node.kind {
722+
ast::named_field(_, ast::struct_mutable, _) => {
723+
cx.sess.span_lint(deprecated_mutable_fields,
724+
item.id,
725+
item.id,
726+
field.span,
727+
~"mutable fields are deprecated");
728+
}
729+
ast::named_field(*) | ast::unnamed_field => {}
730+
}
731+
}
732+
}
733+
_ => {}
734+
}
735+
}
736+
708737
fn check_item_structural_records(cx: ty::ctxt, it: @ast::item) {
709738
let visit = item_stopping_visitor(
710739
visit::mk_simple_visitor(@visit::SimpleVisitor {

src/libstd/std.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ not required in or otherwise suitable for the core library.
2929
#[allow(vecs_implicitly_copyable)];
3030
#[deny(non_camel_case_types)];
3131
#[allow(deprecated_self)];
32+
#[allow(deprecated_mutable_fields)];
3233

3334
#[no_core];
3435

0 commit comments

Comments
 (0)