diff --git a/src/librustc/front/feature_gate.rs b/src/librustc/front/feature_gate.rs index be35a309c44..c175bd3a404 100644 --- a/src/librustc/front/feature_gate.rs +++ b/src/librustc/front/feature_gate.rs @@ -18,6 +18,8 @@ //! Features are enabled in programs via the crate-level attributes of //! #[feature(...)] with a comma-separated list of features. +use middle::lint; + use syntax::ast; use syntax::attr::AttrMetaMethods; use syntax::codemap::Span; @@ -209,7 +211,10 @@ pub fn check_crate(sess: Session, crate: &ast::Crate) { directive not necessary"); } None => { - sess.span_err(mi.span, "unknown feature"); + sess.add_lint(lint::unknown_features, + ast::CRATE_NODE_ID, + mi.span, + ~"unknown feature"); } } } diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 90280292a87..6af07947fde 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -59,6 +59,7 @@ use syntax::codemap; use syntax::parse::token; use syntax::{ast, ast_util, visit}; +use syntax::ast_util::IdVisitingOperation; use syntax::visit::Visitor; #[deriving(Clone, Eq)] @@ -77,6 +78,7 @@ pub enum lint { unused_unsafe, unsafe_block, attribute_usage, + unknown_features, managed_heap_memory, owned_heap_memory, @@ -321,6 +323,13 @@ enum LintSource { desc: "mass-change the level for lints which produce warnings", default: warn }), + + ("unknown_features", + LintSpec { + lint: unknown_features, + desc: "unknown features found in create-level #[feature] directives", + default: deny, + }), ]; /* @@ -1320,7 +1329,7 @@ fn visit_variant(&mut self, v: &ast::variant, g: &ast::Generics, _: ()) { } } -impl<'self> ast_util::IdVisitingOperation for Context<'self> { +impl<'self> IdVisitingOperation for Context<'self> { fn visit_id(&self, id: ast::NodeId) { match self.tcx.sess.lints.pop(&id) { None => {} @@ -1356,6 +1365,7 @@ pub fn check_crate(tcx: ty::ctxt, cx.set_level(lint, level, CommandLine); } cx.with_lint_attrs(crate.attrs, |cx| { + cx.visit_id(ast::CRATE_NODE_ID); cx.visit_ids(|v| { v.visited_outermost = true; visit::walk_crate(v, crate, ()); diff --git a/src/test/compile-fail/gated-bad-feature.rs b/src/test/compile-fail/gated-bad-feature.rs index 0bf2d5ad78b..ed4d32ada09 100644 --- a/src/test/compile-fail/gated-bad-feature.rs +++ b/src/test/compile-fail/gated-bad-feature.rs @@ -13,9 +13,8 @@ foo(bar), foo = "baz" )]; -//~^^^^ ERROR: unknown feature -//~^^^^ ERROR: malformed feature -//~^^^^ ERROR: malformed feature +//~^^^ ERROR: malformed feature +//~^^^ ERROR: malformed feature #[feature]; //~ ERROR: malformed feature #[feature = "foo"]; //~ ERROR: malformed feature diff --git a/src/test/compile-fail/lint-unknown-feature.rs b/src/test/compile-fail/lint-unknown-feature.rs new file mode 100644 index 00000000000..15f446a671c --- /dev/null +++ b/src/test/compile-fail/lint-unknown-feature.rs @@ -0,0 +1,15 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[deny(unknown_features)]; + +#[feature(this_is_not_a_feature)]; //~ ERROR: unknown feature + +fn main() {}