Skip to content

Commit 74a7e8b

Browse files
committed
Auto merge of #26417 - brson:feature-err, r=steveklabnik
It now says '#[feature] may not be used on the stable release channel'. I had to convert this error from a lint to a normal compiler error. I left the lint previously-used for this in place since removing it is a breaking change. It will just go unused until the end of time. Fixes #24125
2 parents 3e4d1b4 + f14a0e2 commit 74a7e8b

File tree

8 files changed

+50
-70
lines changed

8 files changed

+50
-70
lines changed

src/librustc/lint/context.rs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ use self::TargetLint::*;
2828
use middle::privacy::ExportedItems;
2929
use middle::ty::{self, Ty};
3030
use session::{early_error, Session};
31-
use session::config::UnstableFeatures;
3231
use lint::{Level, LevelSource, Lint, LintId, LintArray, LintPass, LintPassObject};
33-
use lint::{Default, CommandLine, Node, Allow, Warn, Deny, Forbid, ReleaseChannel};
32+
use lint::{Default, CommandLine, Node, Allow, Warn, Deny, Forbid};
3433
use lint::builtin;
3534
use util::nodemap::FnvHashMap;
3635

@@ -208,23 +207,6 @@ impl LintStore {
208207
}
209208
}
210209
}
211-
212-
fn maybe_stage_features(&mut self, sess: &Session) {
213-
let lvl = match sess.opts.unstable_features {
214-
UnstableFeatures::Default => return,
215-
UnstableFeatures::Disallow => Forbid,
216-
UnstableFeatures::Cheat => Allow
217-
};
218-
match self.by_name.get("unstable_features") {
219-
Some(&Id(lint_id)) => if self.get_level_source(lint_id).0 != Forbid {
220-
self.set_level(lint_id, (lvl, ReleaseChannel))
221-
},
222-
Some(&Renamed(_, lint_id)) => if self.get_level_source(lint_id).0 != Forbid {
223-
self.set_level(lint_id, (lvl, ReleaseChannel))
224-
},
225-
None => unreachable!()
226-
}
227-
}
228210
}
229211

230212
/// Context for lint checking.
@@ -308,7 +290,6 @@ pub fn raw_emit_lint(sess: &Session, lint: &'static Lint,
308290

309291
let name = lint.name_lower();
310292
let mut def = None;
311-
let mut note = None;
312293
let msg = match source {
313294
Default => {
314295
format!("{}, #[{}({})] on by default", msg,
@@ -325,12 +306,6 @@ pub fn raw_emit_lint(sess: &Session, lint: &'static Lint,
325306
def = Some(src);
326307
msg.to_string()
327308
}
328-
ReleaseChannel => {
329-
let release_channel = option_env!("CFG_RELEASE_CHANNEL").unwrap_or("(unknown)");
330-
note = Some(format!("this feature may not be used in the {} release channel",
331-
release_channel));
332-
msg.to_string()
333-
}
334309
};
335310

336311
// For purposes of printing, we can treat forbid as deny.
@@ -344,10 +319,6 @@ pub fn raw_emit_lint(sess: &Session, lint: &'static Lint,
344319
_ => sess.bug("impossible level in raw_emit_lint"),
345320
}
346321

347-
if let Some(note) = note {
348-
sess.note(&note[..]);
349-
}
350-
351322
if let Some(span) = def {
352323
sess.span_note(span, "lint level defined here");
353324
}
@@ -689,9 +660,6 @@ impl LintPass for GatherNodeLevels {
689660
pub fn check_crate(tcx: &ty::ctxt,
690661
exported_items: &ExportedItems) {
691662

692-
// If this is a feature-staged build of rustc then flip several lints to 'forbid'
693-
tcx.sess.lint_store.borrow_mut().maybe_stage_features(&tcx.sess);
694-
695663
let krate = tcx.map.krate();
696664
let mut cx = Context::new(tcx, krate, exported_items);
697665

src/librustc/lint/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,6 @@ pub enum LintSource {
247247

248248
/// Lint level was set by a command-line flag.
249249
CommandLine,
250-
251-
/// Lint level was set by the release channel.
252-
ReleaseChannel
253250
}
254251

255252
pub type LevelSource = (Level, LintSource);

src/librustc/session/config.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use syntax::attr::AttrMetaMethods;
3232
use syntax::diagnostic::{ColorConfig, Auto, Always, Never, SpanHandler};
3333
use syntax::parse;
3434
use syntax::parse::token::InternedString;
35+
use syntax::feature_gate::UnstableFeatures;
3536

3637
use getopts;
3738
use std::collections::HashMap;
@@ -119,21 +120,6 @@ pub struct Options {
119120
pub unstable_features: UnstableFeatures
120121
}
121122

122-
#[derive(Clone, Copy)]
123-
pub enum UnstableFeatures {
124-
/// Hard errors for unstable features are active, as on
125-
/// beta/stable channels.
126-
Disallow,
127-
/// Use the default lint levels
128-
Default,
129-
/// Errors are bypassed for bootstrapping. This is required any time
130-
/// during the build that feature-related lints are set to warn or above
131-
/// because the build turns on warnings-as-errors and uses lots of unstable
132-
/// features. As a result, this this is always required for building Rust
133-
/// itself.
134-
Cheat
135-
}
136-
137123
#[derive(Clone, PartialEq, Eq)]
138124
pub enum PrintRequest {
139125
FileNames,
@@ -1074,7 +1060,7 @@ pub fn get_unstable_features_setting() -> UnstableFeatures {
10741060
match (disable_unstable_features, bootstrap_secret_key, bootstrap_provided_key) {
10751061
(_, Some(ref s), Some(ref p)) if s == p => UnstableFeatures::Cheat,
10761062
(true, _, _) => UnstableFeatures::Disallow,
1077-
(false, _, _) => UnstableFeatures::Default
1063+
(false, _, _) => UnstableFeatures::Allow
10781064
}
10791065
}
10801066

src/librustc_driver/driver.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,8 @@ pub fn phase_2_configure_and_expand(sess: &Session,
528528
let features =
529529
syntax::feature_gate::check_crate(sess.codemap(),
530530
&sess.parse_sess.span_diagnostic,
531-
&krate, &attributes);
531+
&krate, &attributes,
532+
sess.opts.unstable_features);
532533
*sess.features.borrow_mut() = features;
533534
sess.abort_if_errors();
534535
});
@@ -558,7 +559,8 @@ pub fn phase_2_configure_and_expand(sess: &Session,
558559
let features =
559560
syntax::feature_gate::check_crate(sess.codemap(),
560561
&sess.parse_sess.span_diagnostic,
561-
&krate, &attributes);
562+
&krate, &attributes,
563+
sess.opts.unstable_features);
562564
*sess.features.borrow_mut() = features;
563565
sess.abort_if_errors();
564566
});

src/librustc_driver/test.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use syntax::codemap;
3535
use syntax::codemap::{Span, CodeMap, DUMMY_SP};
3636
use syntax::diagnostic::{Level, RenderSpan, Bug, Fatal, Error, Warning, Note, Help};
3737
use syntax::parse::token;
38+
use syntax::feature_gate::UnstableFeatures;
3839

3940
struct Env<'a, 'tcx: 'a> {
4041
infcx: &'a infer::InferCtxt<'a, 'tcx>,
@@ -102,6 +103,7 @@ fn test_env<F>(source_string: &str,
102103
let mut options =
103104
config::basic_options();
104105
options.debugging_opts.verbose = true;
106+
options.unstable_features = UnstableFeatures::Allow;
105107
let codemap =
106108
CodeMap::new();
107109
let diagnostic_handler =

src/librustc_lint/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2213,7 +2213,7 @@ pub struct UnstableFeatures;
22132213
declare_lint! {
22142214
UNSTABLE_FEATURES,
22152215
Allow,
2216-
"enabling unstable features"
2216+
"enabling unstable features (deprecated. do not use)"
22172217
}
22182218

22192219
impl LintPass for UnstableFeatures {

src/librustdoc/core.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ pub use self::MaybeTyped::*;
1212
use rustc_lint;
1313
use rustc_driver::driver;
1414
use rustc::session::{self, config};
15-
use rustc::session::config::UnstableFeatures;
1615
use rustc::middle::{privacy, ty};
1716
use rustc::ast_map;
1817
use rustc::lint;
1918
use rustc_trans::back::link;
2019
use rustc_resolve as resolve;
2120

2221
use syntax::{ast, codemap, diagnostic};
22+
use syntax::feature_gate::UnstableFeatures;
2323

2424
use std::cell::{RefCell, Cell};
2525
use std::collections::{HashMap, HashSet};
@@ -106,7 +106,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
106106
target_triple: triple.unwrap_or(config::host_triple().to_string()),
107107
cfg: config::parse_cfgspecs(cfgs),
108108
// Ensure that rustdoc works even if rustc is feature-staged
109-
unstable_features: UnstableFeatures::Default,
109+
unstable_features: UnstableFeatures::Allow,
110110
..config::basic_options().clone()
111111
};
112112

src/libsyntax/feature_gate.rs

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -430,18 +430,6 @@ pub fn emit_feature_err(diag: &SpanHandler, feature: &str, span: Span, explain:
430430
feature));
431431
}
432432

433-
pub fn emit_feature_warn(diag: &SpanHandler, feature: &str, span: Span, explain: &str) {
434-
diag.span_warn(span, explain);
435-
436-
// #23973: do not suggest `#![feature(...)]` if we are in beta/stable
437-
if option_env!("CFG_DISABLE_UNSTABLE_FEATURES").is_some() { return; }
438-
if diag.handler.can_emit_warnings {
439-
diag.fileline_help(span, &format!("add #![feature({})] to the \
440-
crate attributes to silence this warning",
441-
feature));
442-
}
443-
}
444-
445433
pub const EXPLAIN_ASM: &'static str =
446434
"inline assembly is not stable enough for use and is subject to change";
447435

@@ -811,9 +799,46 @@ pub fn check_crate_macros(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast:
811799
}
812800

813801
pub fn check_crate(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::Crate,
814-
plugin_attributes: &[(String, AttributeType)]) -> Features
802+
plugin_attributes: &[(String, AttributeType)],
803+
unstable: UnstableFeatures) -> Features
815804
{
805+
maybe_stage_features(span_handler, krate, unstable);
806+
816807
check_crate_inner(cm, span_handler, krate, plugin_attributes,
817808
|ctx, krate| visit::walk_crate(&mut PostExpansionVisitor { context: ctx },
818809
krate))
819810
}
811+
812+
#[derive(Clone, Copy)]
813+
pub enum UnstableFeatures {
814+
/// Hard errors for unstable features are active, as on
815+
/// beta/stable channels.
816+
Disallow,
817+
/// Allow features to me activated, as on nightly.
818+
Allow,
819+
/// Errors are bypassed for bootstrapping. This is required any time
820+
/// during the build that feature-related lints are set to warn or above
821+
/// because the build turns on warnings-as-errors and uses lots of unstable
822+
/// features. As a result, this this is always required for building Rust
823+
/// itself.
824+
Cheat
825+
}
826+
827+
fn maybe_stage_features(span_handler: &SpanHandler, krate: &ast::Crate,
828+
unstable: UnstableFeatures) {
829+
let allow_features = match unstable {
830+
UnstableFeatures::Allow => true,
831+
UnstableFeatures::Disallow => false,
832+
UnstableFeatures::Cheat => true
833+
};
834+
if !allow_features {
835+
for attr in &krate.attrs {
836+
if attr.check_name("feature") {
837+
let release_channel = option_env!("CFG_RELEASE_CHANNEL").unwrap_or("(unknown)");
838+
let ref msg = format!("#[feature] may not be used on the {} release channel",
839+
release_channel);
840+
span_handler.span_err(attr.span, msg);
841+
}
842+
}
843+
}
844+
}

0 commit comments

Comments
 (0)