Merge pull request #4144 from luqmana/deprecated-attribute

Add deprecated attribute.
This commit is contained in:
Tim Chevalier 2012-12-10 21:16:20 -08:00
commit f675b97ddc
3 changed files with 38 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);

View File

@ -182,7 +182,7 @@ fn find_attrs_by_name(attrs: ~[ast::attribute], name: ~str) ->
return vec::filter_map(attrs, filter);
}
/// Searcha list of meta items and return only those with a specific name
/// Search a list of meta items and return only those with a specific name
fn find_meta_items_by_name(metas: ~[@ast::meta_item], name: ~str) ->
~[@ast::meta_item] {
let filter = fn@(m: &@ast::meta_item) -> Option<@ast::meta_item> {

View File

@ -0,0 +1,10 @@
#[forbid(deprecated_item)];
type Bar = uint;
#[deprecated = "use Bar instead"]
type Foo = int;
fn main() {
let _x: Foo = 21;
}