Skip to content

Commit

Permalink
Add a lint pass for structural records
Browse files Browse the repository at this point in the history
Closes #3322
  • Loading branch information
catamorphism committed Sep 6, 2012
1 parent 0a852e0 commit 3a34c96
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/rustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ enum lint {
deprecated_mode,
deprecated_pattern,
non_camel_case_types,
structural_records,

managed_heap_memory,
owned_heap_memory,
Expand Down Expand Up @@ -171,6 +172,11 @@ fn get_lint_dict() -> lint_dict {
desc: ~"use of any (~ type or @ type) heap memory",
default: allow}),

(~"structural_records",
@{lint: structural_records,
desc: ~"use of any structural records",
default: allow}),

/* FIXME(#3266)--make liveness warnings lintable
(~"unused_variable",
@{lint: unused_variable,
Expand Down Expand Up @@ -380,6 +386,7 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
check_item_path_statement(cx, i);
check_item_non_camel_case_types(cx, i);
check_item_heap(cx, i);
check_item_structural_records(cx, i);
}

// Take a visitor, and modify it so that it will not proceed past subitems.
Expand Down Expand Up @@ -413,6 +420,23 @@ fn check_item_while_true(cx: ty::ctxt, it: @ast::item) {
visit::visit_item(it, (), visit);
}

fn check_item_structural_records(cx: ty::ctxt, it: @ast::item) {
let visit = item_stopping_visitor(visit::mk_simple_visitor(@{
visit_expr: fn@(e: @ast::expr) {
match e.node {
ast::expr_rec(*) =>
cx.sess.span_lint(
structural_records, e.id, it.id,
e.span,
~"structural records are deprecated"),
_ => ()
}
},
.. *visit::default_simple_visitor()
}));
visit::visit_item(it, (), visit);
}

fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {

fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id,
Expand Down
4 changes: 4 additions & 0 deletions src/test/run-pass/lint-structural-records.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[warn(structural_records)];
fn main() {
let _foo = {x:5};
}

0 comments on commit 3a34c96

Please sign in to comment.