about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-11-26 14:55:06 -0800
committerAlex Crichton <alex@alexcrichton.com>2013-11-27 09:54:30 -0800
commita9bd049fc09445a20ab8a9283a24f1074403d061 (patch)
treeeb356b4d583646f03ff9fb9abf8cf317c2a34fb2
parente9a1869a5f4164d5311963b1b25b05f003d43699 (diff)
downloadrust-a9bd049fc09445a20ab8a9283a24f1074403d061.tar.gz
rust-a9bd049fc09445a20ab8a9283a24f1074403d061.zip
Relax restrictions on unknown feature directives
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.
-rw-r--r--src/librustc/front/feature_gate.rs7
-rw-r--r--src/librustc/middle/lint.rs12
-rw-r--r--src/test/compile-fail/gated-bad-feature.rs5
-rw-r--r--src/test/compile-fail/lint-unknown-feature.rs15
4 files changed, 34 insertions, 5 deletions
diff --git a/src/librustc/front/feature_gate.rs b/src/librustc/front/feature_gate.rs
index 6103312bc78..99cd0136749 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;
@@ -197,7 +199,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 38b7bc0875b..15fc34c0798 100644
--- a/src/librustc/middle/lint.rs
+++ b/src/librustc/middle/lint.rs
@@ -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,
+    }),
 ];
 
 /*
@@ -1319,7 +1328,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 => {}
@@ -1355,6 +1364,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 <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() {}