Add deprecated attribute.

This commit is contained in:
Luqman Aden
2012-12-09 02:26:12 -05:00
parent 42f8a3366a
commit 4b4c8331bb
2 changed files with 28 additions and 1 deletions

View File

@@ -60,6 +60,7 @@ enum lint {
unrecognized_lint,
non_implicitly_copyable_typarams,
vecs_implicitly_copyable,
deprecated_item,
deprecated_mode,
deprecated_pattern,
non_camel_case_types,
@@ -157,6 +158,11 @@ fn get_lint_dict() -> lint_dict {
desc: ~"implicit copies of non implicitly copyable data",
default: warn}),
(~"deprecated_item",
@{lint: deprecated_item,
desc: ~"warn about items marked deprecated",
default: warn}),
(~"deprecated_mode",
@{lint: deprecated_mode,
desc: ~"warn about deprecated uses of modes",
@@ -412,6 +418,7 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
check_item_non_camel_case_types(cx, i);
check_item_heap(cx, i);
check_item_structural_records(cx, i);
check_item_deprecated(cx, i);
check_item_deprecated_modes(cx, i);
check_item_type_limits(cx, i);
}
@@ -767,6 +774,26 @@ fn check_item_non_camel_case_types(cx: ty::ctxt, it: @ast::item) {
}
}
fn check_item_deprecated(tcx: ty::ctxt, it: @ast::item) {
let at = attr::find_attrs_by_name(it.attrs, ~"deprecated");
if at.is_not_empty() {
for at.each |attr| {
let fmt = match attr.node.value.node {
ast::meta_name_value(_, ref l) =>
match l.node {
ast::lit_str(ref reason) =>
fmt!("deprecated: %s", **reason),
_ => ~"item is deprecated"
},
_ => ~"item is deprecated"
};
tcx.sess.span_lint(deprecated_item, it.id, it.id, it.span,
fmt);
}
}
}
fn check_fn(tcx: ty::ctxt, fk: visit::fn_kind, decl: ast::fn_decl,
_body: ast::blk, span: span, id: ast::node_id) {
debug!("lint check_fn fk=%? id=%?", fk, id);