Skip to content

Commit 3a34c96

Browse files
committed
Add a lint pass for structural records
Closes #3322
1 parent 0a852e0 commit 3a34c96

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/rustc/middle/lint.rs

+24
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ enum lint {
5353
deprecated_mode,
5454
deprecated_pattern,
5555
non_camel_case_types,
56+
structural_records,
5657

5758
managed_heap_memory,
5859
owned_heap_memory,
@@ -171,6 +172,11 @@ fn get_lint_dict() -> lint_dict {
171172
desc: ~"use of any (~ type or @ type) heap memory",
172173
default: allow}),
173174

175+
(~"structural_records",
176+
@{lint: structural_records,
177+
desc: ~"use of any structural records",
178+
default: allow}),
179+
174180
/* FIXME(#3266)--make liveness warnings lintable
175181
(~"unused_variable",
176182
@{lint: unused_variable,
@@ -380,6 +386,7 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
380386
check_item_path_statement(cx, i);
381387
check_item_non_camel_case_types(cx, i);
382388
check_item_heap(cx, i);
389+
check_item_structural_records(cx, i);
383390
}
384391

385392
// 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) {
413420
visit::visit_item(it, (), visit);
414421
}
415422

423+
fn check_item_structural_records(cx: ty::ctxt, it: @ast::item) {
424+
let visit = item_stopping_visitor(visit::mk_simple_visitor(@{
425+
visit_expr: fn@(e: @ast::expr) {
426+
match e.node {
427+
ast::expr_rec(*) =>
428+
cx.sess.span_lint(
429+
structural_records, e.id, it.id,
430+
e.span,
431+
~"structural records are deprecated"),
432+
_ => ()
433+
}
434+
},
435+
.. *visit::default_simple_visitor()
436+
}));
437+
visit::visit_item(it, (), visit);
438+
}
439+
416440
fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {
417441

418442
fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[warn(structural_records)];
2+
fn main() {
3+
let _foo = {x:5};
4+
}

0 commit comments

Comments
 (0)