Skip to content

Commit 68e7282

Browse files
authored
Rollup merge of rust-lang#48801 - Manishearth:epoch-features, r=nikomatsakis
Add functionality for gating feature flags on epochs ; rejigger epoch lints fixes rust-lang#48794 r? @nikomatsakis
2 parents b0bc601 + a08cfc4 commit 68e7282

File tree

14 files changed

+328
-263
lines changed

14 files changed

+328
-263
lines changed

src/librustc/lint/builtin.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use errors::DiagnosticBuilder;
1818
use lint::{LintPass, LateLintPass, LintArray};
1919
use session::Session;
20-
use session::config::Epoch;
2120
use syntax::codemap::Span;
2221

2322
declare_lint! {
@@ -264,9 +263,8 @@ declare_lint! {
264263

265264
declare_lint! {
266265
pub BARE_TRAIT_OBJECT,
267-
Warn,
268-
"suggest using `dyn Trait` for trait objects",
269-
Epoch::Epoch2018
266+
Allow,
267+
"suggest using `dyn Trait` for trait objects"
270268
}
271269

272270
declare_lint! {

src/librustc/lint/context.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use util::nodemap::FxHashMap;
4242
use std::default::Default as StdDefault;
4343
use std::cell::{Ref, RefCell};
4444
use syntax::ast;
45+
use syntax::epoch;
4546
use syntax_pos::{MultiSpan, Span};
4647
use errors::DiagnosticBuilder;
4748
use hir;
@@ -105,7 +106,7 @@ pub struct FutureIncompatibleInfo {
105106
pub reference: &'static str,
106107
/// If this is an epoch fixing lint, the epoch in which
107108
/// this lint becomes obsolete
108-
pub epoch: Option<config::Epoch>,
109+
pub epoch: Option<epoch::Epoch>,
109110
}
110111

111112
/// The target of the `by_name` map, which accounts for renaming/deprecation.
@@ -201,7 +202,7 @@ impl LintStore {
201202
sess: Option<&Session>,
202203
lints: Vec<FutureIncompatibleInfo>) {
203204

204-
for epoch in config::ALL_EPOCHS {
205+
for epoch in epoch::ALL_EPOCHS {
205206
let lints = lints.iter().filter(|f| f.epoch == Some(*epoch)).map(|f| f.id)
206207
.collect::<Vec<_>>();
207208
if !lints.is_empty() {

src/librustc/lint/mod.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ use hir::def_id::{CrateNum, LOCAL_CRATE};
3838
use hir::intravisit::{self, FnKind};
3939
use hir;
4040
use lint::builtin::BuiltinLintDiagnostics;
41-
use session::{config, Session, DiagnosticMessageId};
41+
use session::{Session, DiagnosticMessageId};
4242
use std::hash;
4343
use syntax::ast;
4444
use syntax::codemap::MultiSpan;
45+
use syntax::epoch::Epoch;
4546
use syntax::symbol::Symbol;
4647
use syntax::visit as ast_visit;
4748
use syntax_pos::Span;
@@ -77,7 +78,7 @@ pub struct Lint {
7778
pub desc: &'static str,
7879

7980
/// Deny lint after this epoch
80-
pub epoch_deny: Option<config::Epoch>,
81+
pub epoch_deny: Option<Epoch>,
8182
}
8283

8384
impl Lint {
@@ -492,9 +493,14 @@ pub fn struct_lint_level<'a>(sess: &'a Session,
492493
// Check for future incompatibility lints and issue a stronger warning.
493494
let lints = sess.lint_store.borrow();
494495
if let Some(future_incompatible) = lints.future_incompatible(LintId::of(lint)) {
496+
let future = if let Some(epoch) = future_incompatible.epoch {
497+
format!("the {} epoch", epoch)
498+
} else {
499+
"a future release".to_owned()
500+
};
495501
let explanation = format!("this was previously accepted by the compiler \
496502
but is being phased out; \
497-
it will become a hard error in a future release!");
503+
it will become a hard error in {}!", future);
498504
let citation = format!("for more information, see {}",
499505
future_incompatible.reference);
500506
err.warn(&explanation);

src/librustc/session/config.rs

+3-54
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use middle::cstore;
2828

2929
use syntax::ast::{self, IntTy, UintTy};
3030
use syntax::codemap::{FileName, FilePathMapping};
31+
use syntax::epoch::Epoch;
3132
use syntax::parse::token;
3233
use syntax::parse;
3334
use syntax::symbol::Symbol;
@@ -111,59 +112,6 @@ pub enum OutputType {
111112
DepInfo,
112113
}
113114

114-
/// The epoch of the compiler (RFC 2052)
115-
#[derive(Clone, Copy, Hash, PartialOrd, Ord, Eq, PartialEq, Debug)]
116-
#[non_exhaustive]
117-
pub enum Epoch {
118-
// epochs must be kept in order, newest to oldest
119-
/// The 2015 epoch
120-
Epoch2015,
121-
/// The 2018 epoch
122-
Epoch2018,
123-
// when adding new epochs, be sure to update:
124-
//
125-
// - the list in the `parse_epoch` static
126-
// - the match in the `parse_epoch` function
127-
// - add a `rust_####()` function to the session
128-
// - update the enum in Cargo's sources as well
129-
//
130-
// When -Zepoch becomes --epoch, there will
131-
// also be a check for the epoch being nightly-only
132-
// somewhere. That will need to be updated
133-
// whenever we're stabilizing/introducing a new epoch
134-
// as well as changing the default Cargo template.
135-
}
136-
137-
pub const ALL_EPOCHS: &[Epoch] = &[Epoch::Epoch2015, Epoch::Epoch2018];
138-
139-
impl ToString for Epoch {
140-
fn to_string(&self) -> String {
141-
match *self {
142-
Epoch::Epoch2015 => "2015".into(),
143-
Epoch::Epoch2018 => "2018".into(),
144-
}
145-
}
146-
}
147-
148-
impl Epoch {
149-
pub fn lint_name(&self) -> &'static str {
150-
match *self {
151-
Epoch::Epoch2015 => "epoch_2015",
152-
Epoch::Epoch2018 => "epoch_2018",
153-
}
154-
}
155-
}
156-
157-
impl str::FromStr for Epoch {
158-
type Err = ();
159-
fn from_str(s: &str) -> Result<Self, ()> {
160-
match s {
161-
"2015" => Ok(Epoch::Epoch2015),
162-
"2018" => Ok(Epoch::Epoch2018),
163-
_ => Err(()),
164-
}
165-
}
166-
}
167115

168116
impl_stable_hash_for!(enum self::OutputType {
169117
Bitcode,
@@ -829,9 +777,10 @@ macro_rules! options {
829777

830778
#[allow(dead_code)]
831779
mod $mod_set {
832-
use super::{$struct_name, Passes, SomePasses, AllPasses, Sanitizer, Lto, Epoch};
780+
use super::{$struct_name, Passes, SomePasses, AllPasses, Sanitizer, Lto};
833781
use rustc_back::{LinkerFlavor, PanicStrategy, RelroLevel};
834782
use std::path::PathBuf;
783+
use syntax::epoch::Epoch;
835784

836785
$(
837786
pub fn $opt(cg: &mut $struct_name, v: Option<&str>) -> bool {

src/librustc/session/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use lint::builtin::BuiltinLintDiagnostics;
2020
use middle::allocator::AllocatorKind;
2121
use middle::dependency_format;
2222
use session::search_paths::PathKind;
23-
use session::config::{DebugInfoLevel, Epoch, OutputType};
23+
use session::config::{DebugInfoLevel, OutputType};
2424
use ty::tls;
2525
use util::nodemap::{FxHashMap, FxHashSet};
2626
use util::common::{duration_to_secs_str, ErrorReported};
@@ -30,6 +30,7 @@ use rustc_data_structures::sync::Lrc;
3030
use syntax::ast::NodeId;
3131
use errors::{self, DiagnosticBuilder, DiagnosticId};
3232
use errors::emitter::{Emitter, EmitterWriter};
33+
use syntax::epoch::Epoch;
3334
use syntax::json::JsonEmitter;
3435
use syntax::feature_gate;
3536
use syntax::symbol::Symbol;

src/librustc_driver/driver.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,9 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
647647
{
648648
let time_passes = sess.time_passes();
649649

650-
let (mut krate, features) = syntax::config::features(krate, &sess.parse_sess, sess.opts.test);
650+
let (mut krate, features) = syntax::config::features(krate, &sess.parse_sess,
651+
sess.opts.test,
652+
sess.opts.debugging_opts.epoch);
651653
// these need to be set "early" so that expansion sees `quote` if enabled.
652654
sess.init_features(features);
653655

src/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnionsWithDropFields {
12631263
pub struct UnreachablePub;
12641264

12651265
declare_lint! {
1266-
UNREACHABLE_PUB,
1266+
pub UNREACHABLE_PUB,
12671267
Allow,
12681268
"`pub` items not reachable from crate root"
12691269
}

src/librustc_lint/lib.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ extern crate rustc_mir;
4343
extern crate syntax_pos;
4444

4545
use rustc::lint;
46+
use rustc::lint::builtin::BARE_TRAIT_OBJECT;
4647
use rustc::session;
4748
use rustc::util;
4849

4950
use session::Session;
51+
use syntax::epoch::Epoch;
5052
use lint::LintId;
5153
use lint::FutureIncompatibleInfo;
5254

@@ -176,6 +178,11 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
176178
UNUSED_FEATURES,
177179
UNUSED_PARENS);
178180

181+
add_lint_group!(sess,
182+
"rust_2018_idioms",
183+
BARE_TRAIT_OBJECT,
184+
UNREACHABLE_PUB);
185+
179186
// Guidelines for creating a future incompatibility lint:
180187
//
181188
// - Create a lint defaulting to warn as normal, with ideally the same error
@@ -274,13 +281,8 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
274281
FutureIncompatibleInfo {
275282
id: LintId::of(TYVAR_BEHIND_RAW_POINTER),
276283
reference: "issue #46906 <https://github.com/rust-lang/rust/issues/46906>",
277-
epoch: None,
278-
},
279-
FutureIncompatibleInfo {
280-
id: LintId::of(lint::builtin::BARE_TRAIT_OBJECT),
281-
reference: "issue #48457 <https://github.com/rust-lang/rust/issues/48457>",
282-
epoch: Some(session::config::Epoch::Epoch2018),
283-
}
284+
epoch: Some(Epoch::Epoch2018),
285+
}
284286
]);
285287

286288
// Register renamed and removed lints

src/libsyntax/config.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use feature_gate::{feature_err, EXPLAIN_STMT_ATTR_SYNTAX, Features, get_features
1313
use {fold, attr};
1414
use ast;
1515
use codemap::Spanned;
16+
use epoch::Epoch;
1617
use parse::{token, ParseSess};
1718

1819
use ptr::P;
@@ -26,7 +27,7 @@ pub struct StripUnconfigured<'a> {
2627
}
2728

2829
// `cfg_attr`-process the crate's attributes and compute the crate's features.
29-
pub fn features(mut krate: ast::Crate, sess: &ParseSess, should_test: bool)
30+
pub fn features(mut krate: ast::Crate, sess: &ParseSess, should_test: bool, epoch: Epoch)
3031
-> (ast::Crate, Features) {
3132
let features;
3233
{
@@ -46,7 +47,7 @@ pub fn features(mut krate: ast::Crate, sess: &ParseSess, should_test: bool)
4647
return (krate, Features::new());
4748
}
4849

49-
features = get_features(&sess.span_diagnostic, &krate.attrs);
50+
features = get_features(&sess.span_diagnostic, &krate.attrs, epoch);
5051

5152
// Avoid reconfiguring malformed `cfg_attr`s
5253
if err_count == sess.span_diagnostic.err_count() {

src/libsyntax/epoch.rs

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2018 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+
use std::fmt;
12+
use std::str::FromStr;
13+
14+
/// The epoch of the compiler (RFC 2052)
15+
#[derive(Clone, Copy, Hash, PartialOrd, Ord, Eq, PartialEq, Debug)]
16+
#[non_exhaustive]
17+
pub enum Epoch {
18+
// epochs must be kept in order, newest to oldest
19+
20+
/// The 2015 epoch
21+
Epoch2015,
22+
/// The 2018 epoch
23+
Epoch2018,
24+
25+
// when adding new epochs, be sure to update:
26+
//
27+
// - the list in the `parse_epoch` static in librustc::session::config
28+
// - add a `rust_####()` function to the session
29+
// - update the enum in Cargo's sources as well
30+
//
31+
// When -Zepoch becomes --epoch, there will
32+
// also be a check for the epoch being nightly-only
33+
// somewhere. That will need to be updated
34+
// whenever we're stabilizing/introducing a new epoch
35+
// as well as changing the default Cargo template.
36+
}
37+
38+
// must be in order from oldest to newest
39+
pub const ALL_EPOCHS: &[Epoch] = &[Epoch::Epoch2015, Epoch::Epoch2018];
40+
41+
impl fmt::Display for Epoch {
42+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
43+
let s = match *self {
44+
Epoch::Epoch2015 => "2015",
45+
Epoch::Epoch2018 => "2018",
46+
};
47+
write!(f, "{}", s)
48+
}
49+
}
50+
51+
impl Epoch {
52+
pub fn lint_name(&self) -> &'static str {
53+
match *self {
54+
Epoch::Epoch2015 => "epoch_2015",
55+
Epoch::Epoch2018 => "epoch_2018",
56+
}
57+
}
58+
}
59+
60+
impl FromStr for Epoch {
61+
type Err = ();
62+
fn from_str(s: &str) -> Result<Self, ()> {
63+
match s {
64+
"2015" => Ok(Epoch::Epoch2015),
65+
"2018" => Ok(Epoch::Epoch2018),
66+
_ => Err(())
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)