Skip to content

Add deprecated attribute. #4144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 11, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
10 changes: 10 additions & 0 deletions src/test/compile-fail/lint-deprecated-items.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#[forbid(deprecated_item)];

type Bar = uint;

#[deprecated = "use Bar instead"]
type Foo = int;

fn main() {
let _x: Foo = 21;
}