about summary refs log tree commit diff
path: root/src/rustc
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2012-09-05 18:32:01 -0700
committerTim Chevalier <chevalier@alum.wellesley.edu>2012-09-05 18:35:30 -0700
commit3a34c96086e88466e350100af874f07b387a7620 (patch)
treea7e2bcfe2c5dedc569bcddedf7488e704cf0ad1e /src/rustc
parent0a852e0da0503b3abcc2dd0b0858f64e3f4dc6b0 (diff)
downloadrust-3a34c96086e88466e350100af874f07b387a7620.tar.gz
rust-3a34c96086e88466e350100af874f07b387a7620.zip
Add a lint pass for structural records
Closes #3322
Diffstat (limited to 'src/rustc')
-rw-r--r--src/rustc/middle/lint.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/rustc/middle/lint.rs b/src/rustc/middle/lint.rs
index df7fe24b0c2..e38ba74fecf 100644
--- a/src/rustc/middle/lint.rs
+++ b/src/rustc/middle/lint.rs
@@ -53,6 +53,7 @@ enum lint {
     deprecated_mode,
     deprecated_pattern,
     non_camel_case_types,
+    structural_records,
 
     managed_heap_memory,
     owned_heap_memory,
@@ -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,
@@ -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.
@@ -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,