rustc: Add lint for obsolete attributes

This also moves `#[auto_{en,de}code]` checker from syntax to lint.
This commit is contained in:
klutzy 2013-11-06 12:16:19 +09:00
parent 6ff697d393
commit 1f7bfac9d2
6 changed files with 13 additions and 59 deletions

View File

@ -803,6 +803,11 @@ fn check_heap_item(cx: &Context, it: &ast::item) {
// also make error on obsolete attributes for less confusion.
fn check_item_attribute_usage(cx: &Context, it: &ast::item) {
let crate_attrs = ["crate_type", "link", "feature", "no_uv", "no_main", "no_std"];
let obsolete_attrs = [
("abi", "extern \"abi\" fn"),
("auto_encode", "#[deriving(Encodable)]"),
("auto_decode", "#[deriving(Decodable)]"),
];
for attr in it.attrs.iter() {
let name = attr.node.value.name();
@ -816,6 +821,13 @@ fn check_item_attribute_usage(cx: &Context, it: &ast::item) {
cx.span_lint(attribute_usage, attr.span, msg);
}
}
for &(obs_attr, obs_alter) in obsolete_attrs.iter() {
if name.equiv(&obs_attr) {
cx.span_lint(attribute_usage, attr.span,
format!("obsolete attribute: use `{:s}` instead", obs_alter));
}
}
}
}

View File

@ -365,7 +365,6 @@ fn spawn_process_os(prog: &str, args: &[~str],
use libc::funcs::bsd44::getdtablesize;
mod rustrt {
#[abi = "cdecl"]
extern {
pub fn rust_unset_sigprocmask();
}

View File

@ -1,35 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
/// Deprecated #[auto_encode] and #[auto_decode] syntax extensions
use ast;
use codemap::Span;
use ext::base::*;
pub fn expand_auto_encode(
cx: @ExtCtxt,
span: Span,
_mitem: @ast::MetaItem,
in_items: ~[@ast::item]
) -> ~[@ast::item] {
cx.span_err(span, "`#[auto_encode]` is deprecated, use `#[deriving(Encodable)]` instead");
in_items
}
pub fn expand_auto_decode(
cx: @ExtCtxt,
span: Span,
_mitem: @ast::MetaItem,
in_items: ~[@ast::item]
) -> ~[@ast::item] {
cx.span_err(span, "`#[auto_decode]` is deprecated, use `#[deriving(Decodable)]` instead");
in_items
}

View File

@ -143,7 +143,7 @@ pub enum MacResult {
}
pub enum SyntaxExtension {
// #[auto_encode] and such
// #[deriving] and such
ItemDecorator(ItemDecorator),
// Token-tree expanders
@ -229,12 +229,6 @@ pub fn syntax_expander_table() -> SyntaxEnv {
syntax_expanders.insert(intern(&"format_args"),
builtin_normal_tt_no_ctxt(
ext::format::expand_args));
syntax_expanders.insert(
intern(&"auto_encode"),
@SE(ItemDecorator(ext::auto_encode::expand_auto_encode)));
syntax_expanders.insert(
intern(&"auto_decode"),
@SE(ItemDecorator(ext::auto_encode::expand_auto_decode)));
syntax_expanders.insert(intern(&"env"),
builtin_normal_tt_no_ctxt(
ext::env::expand_env));

View File

@ -83,7 +83,6 @@ pub mod ext {
pub mod concat;
pub mod concat_idents;
pub mod log_syntax;
pub mod auto_encode;
pub mod source_util;
pub mod trace_macros;

View File

@ -1,15 +0,0 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[auto_encode] //~ ERROR: `#[auto_encode]` is deprecated
#[auto_decode] //~ ERROR: `#[auto_decode]` is deprecated
struct A;
fn main() {}