auto merge of #10680 : alexcrichton/rust/relax-feature-gate, r=thestinger

Instead of forcibly always aborting compilation, allow usage of
 #[warn(unknown_features)] and related lint attributes to selectively abort
 compilation. By default, this lint is deny.
This commit is contained in:
bors 2013-11-27 14:17:41 -08:00
commit d662820b29
4 changed files with 34 additions and 5 deletions

View file

@ -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");
}
}
}

View file

@ -59,6 +59,7 @@ use syntax::codemap::Span;
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 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
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 @@ impl<'self> Visitor<()> for Context<'self> {
}
}
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, ());

View file

@ -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

View file

@ -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 <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.
#[deny(unknown_features)];
#[feature(this_is_not_a_feature)]; //~ ERROR: unknown feature
fn main() {}