Skip to content

Commit a9bd049

Browse files
committed
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.
1 parent e9a1869 commit a9bd049

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

src/librustc/front/feature_gate.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
//! Features are enabled in programs via the crate-level attributes of
1919
//! #[feature(...)] with a comma-separated list of features.
2020
21+
use middle::lint;
22+
2123
use syntax::ast;
2224
use syntax::attr::AttrMetaMethods;
2325
use syntax::codemap::Span;
@@ -197,7 +199,10 @@ pub fn check_crate(sess: Session, crate: &ast::Crate) {
197199
directive not necessary");
198200
}
199201
None => {
200-
sess.span_err(mi.span, "unknown feature");
202+
sess.add_lint(lint::unknown_features,
203+
ast::CRATE_NODE_ID,
204+
mi.span,
205+
~"unknown feature");
201206
}
202207
}
203208
}

src/librustc/middle/lint.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ use syntax::codemap::Span;
5959
use syntax::codemap;
6060
use syntax::parse::token;
6161
use syntax::{ast, ast_util, visit};
62+
use syntax::ast_util::IdVisitingOperation;
6263
use syntax::visit::Visitor;
6364

6465
#[deriving(Clone, Eq)]
@@ -77,6 +78,7 @@ pub enum lint {
7778
unused_unsafe,
7879
unsafe_block,
7980
attribute_usage,
81+
unknown_features,
8082

8183
managed_heap_memory,
8284
owned_heap_memory,
@@ -321,6 +323,13 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
321323
desc: "mass-change the level for lints which produce warnings",
322324
default: warn
323325
}),
326+
327+
("unknown_features",
328+
LintSpec {
329+
lint: unknown_features,
330+
desc: "unknown features found in create-level #[feature] directives",
331+
default: deny,
332+
}),
324333
];
325334

326335
/*
@@ -1319,7 +1328,7 @@ impl<'self> Visitor<()> for Context<'self> {
13191328
}
13201329
}
13211330

1322-
impl<'self> ast_util::IdVisitingOperation for Context<'self> {
1331+
impl<'self> IdVisitingOperation for Context<'self> {
13231332
fn visit_id(&self, id: ast::NodeId) {
13241333
match self.tcx.sess.lints.pop(&id) {
13251334
None => {}
@@ -1355,6 +1364,7 @@ pub fn check_crate(tcx: ty::ctxt,
13551364
cx.set_level(lint, level, CommandLine);
13561365
}
13571366
cx.with_lint_attrs(crate.attrs, |cx| {
1367+
cx.visit_id(ast::CRATE_NODE_ID);
13581368
cx.visit_ids(|v| {
13591369
v.visited_outermost = true;
13601370
visit::walk_crate(v, crate, ());

src/test/compile-fail/gated-bad-feature.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
foo(bar),
1414
foo = "baz"
1515
)];
16-
//~^^^^ ERROR: unknown feature
17-
//~^^^^ ERROR: malformed feature
18-
//~^^^^ ERROR: malformed feature
16+
//~^^^ ERROR: malformed feature
17+
//~^^^ ERROR: malformed feature
1918

2019
#[feature]; //~ ERROR: malformed feature
2120
#[feature = "foo"]; //~ ERROR: malformed feature
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[deny(unknown_features)];
12+
13+
#[feature(this_is_not_a_feature)]; //~ ERROR: unknown feature
14+
15+
fn main() {}

0 commit comments

Comments
 (0)