Skip to content

Commit da9dc05

Browse files
committed
Allow future-incompat lints to mention an epoch
1 parent d9438c3 commit da9dc05

File tree

9 files changed

+101
-29
lines changed

9 files changed

+101
-29
lines changed

src/librustc/lint/context.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ pub struct BufferedEarlyLint {
9999
/// guidelines.
100100
pub struct FutureIncompatibleInfo {
101101
pub id: LintId,
102-
pub reference: &'static str // e.g., a URL for an issue/PR/RFC or error code
102+
/// e.g., a URL for an issue/PR/RFC or error code
103+
pub reference: &'static str,
104+
/// If this is an epoch fixing lint, the epoch in which
105+
/// this lint becomes obsolete
106+
pub epoch: Option<config::Epoch>,
103107
}
104108

105109
/// The target of the `by_name` map, which accounts for renaming/deprecation.
@@ -194,11 +198,24 @@ impl LintStore {
194198
pub fn register_future_incompatible(&mut self,
195199
sess: Option<&Session>,
196200
lints: Vec<FutureIncompatibleInfo>) {
197-
let ids = lints.iter().map(|f| f.id).collect();
198-
self.register_group(sess, false, "future_incompatible", ids);
199-
for info in lints {
200-
self.future_incompatible.insert(info.id, info);
201+
202+
for epoch in config::ALL_EPOCHS {
203+
let lints = lints.iter().filter(|f| f.epoch == Some(*epoch)).map(|f| f.id)
204+
.collect::<Vec<_>>();
205+
if !lints.is_empty() {
206+
self.register_group(sess, false, epoch.lint_name(), lints)
207+
}
208+
}
209+
210+
let mut future_incompatible = vec![];
211+
for lint in lints {
212+
future_incompatible.push(lint.id);
213+
self.future_incompatible.insert(lint.id, lint);
201214
}
215+
216+
self.register_group(sess, false, "future_incompatible", future_incompatible);
217+
218+
202219
}
203220

204221
pub fn future_incompatible(&self, id: LintId) -> Option<&FutureIncompatibleInfo> {

src/librustc/lint/levels.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,15 @@ impl LintLevelSets {
8989
fn get_lint_level(&self,
9090
lint: &'static Lint,
9191
idx: u32,
92-
aux: Option<&FxHashMap<LintId, (Level, LintSource)>>)
92+
aux: Option<&FxHashMap<LintId, (Level, LintSource)>>,
93+
sess: &Session)
9394
-> (Level, LintSource)
9495
{
9596
let (level, mut src) = self.get_lint_id_level(LintId::of(lint), idx, aux);
9697

9798
// If `level` is none then we actually assume the default level for this
9899
// lint.
99-
let mut level = level.unwrap_or(lint.default_level);
100+
let mut level = level.unwrap_or(lint.default_level(sess));
100101

101102
// If we're about to issue a warning, check at the last minute for any
102103
// directives against the warnings "lint". If, for example, there's an
@@ -235,7 +236,8 @@ impl<'a> LintLevelsBuilder<'a> {
235236
let lint = builtin::RENAMED_AND_REMOVED_LINTS;
236237
let (level, src) = self.sets.get_lint_level(lint,
237238
self.cur,
238-
Some(&specs));
239+
Some(&specs),
240+
&sess);
239241
lint::struct_lint_level(self.sess,
240242
lint,
241243
level,
@@ -248,7 +250,8 @@ impl<'a> LintLevelsBuilder<'a> {
248250
let lint = builtin::UNKNOWN_LINTS;
249251
let (level, src) = self.sets.get_lint_level(lint,
250252
self.cur,
251-
Some(&specs));
253+
Some(&specs),
254+
self.sess);
252255
let msg = format!("unknown lint: `{}`", name);
253256
let mut db = lint::struct_lint_level(self.sess,
254257
lint,
@@ -342,7 +345,7 @@ impl<'a> LintLevelsBuilder<'a> {
342345
msg: &str)
343346
-> DiagnosticBuilder<'a>
344347
{
345-
let (level, src) = self.sets.get_lint_level(lint, self.cur, None);
348+
let (level, src) = self.sets.get_lint_level(lint, self.cur, None, self.sess);
346349
lint::struct_lint_level(self.sess, lint, level, src, span, msg)
347350
}
348351

@@ -377,11 +380,11 @@ impl LintLevelMap {
377380
/// If the `id` was not previously registered, returns `None`. If `None` is
378381
/// returned then the parent of `id` should be acquired and this function
379382
/// should be called again.
380-
pub fn level_and_source(&self, lint: &'static Lint, id: HirId)
383+
pub fn level_and_source(&self, lint: &'static Lint, id: HirId, session: &Session)
381384
-> Option<(Level, LintSource)>
382385
{
383386
self.id_to_set.get(&id).map(|idx| {
384-
self.sets.get_lint_level(lint, *idx, None)
387+
self.sets.get_lint_level(lint, *idx, None, session)
385388
})
386389
}
387390

src/librustc/lint/mod.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use errors::{DiagnosticBuilder, DiagnosticId};
3737
use hir::def_id::{CrateNum, LOCAL_CRATE};
3838
use hir::intravisit::{self, FnKind};
3939
use hir;
40-
use session::{Session, DiagnosticMessageId};
40+
use session::{config, Session, DiagnosticMessageId};
4141
use std::hash;
4242
use syntax::ast;
4343
use syntax::codemap::MultiSpan;
@@ -74,25 +74,46 @@ pub struct Lint {
7474
///
7575
/// e.g. "imports that are never used"
7676
pub desc: &'static str,
77+
78+
/// Deny lint after this epoch
79+
pub epoch_deny: Option<config::Epoch>,
7780
}
7881

7982
impl Lint {
8083
/// Get the lint's name, with ASCII letters converted to lowercase.
8184
pub fn name_lower(&self) -> String {
8285
self.name.to_ascii_lowercase()
8386
}
87+
88+
pub fn default_level(&self, session: &Session) -> Level {
89+
if let Some(epoch_deny) = self.epoch_deny {
90+
if session.epoch() >= epoch_deny {
91+
return Level::Deny
92+
}
93+
}
94+
self.default_level
95+
}
8496
}
8597

8698
/// Declare a static item of type `&'static Lint`.
8799
#[macro_export]
88100
macro_rules! declare_lint {
101+
($vis: vis $NAME: ident, $Level: ident, $desc: expr, $epoch: expr) => (
102+
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
103+
name: stringify!($NAME),
104+
default_level: $crate::lint::$Level,
105+
desc: $desc,
106+
epoch_deny: Some($epoch)
107+
};
108+
);
89109
($vis: vis $NAME: ident, $Level: ident, $desc: expr) => (
90110
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
91111
name: stringify!($NAME),
92112
default_level: $crate::lint::$Level,
93-
desc: $desc
113+
desc: $desc,
114+
epoch_deny: None,
94115
};
95-
)
116+
);
96117
}
97118

98119
/// Declare a static `LintArray` and return it as an expression.
@@ -304,7 +325,7 @@ impl LintId {
304325
/// Setting for how to handle a lint.
305326
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
306327
pub enum Level {
307-
Allow, Warn, Deny, Forbid
328+
Allow, Warn, Deny, Forbid,
308329
}
309330

310331
impl_stable_hash_for!(enum self::Level {

src/librustc/session/config.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub enum OutputType {
113113
}
114114

115115
/// The epoch of the compiler (RFC 2052)
116-
#[derive(Clone, Copy, Hash, PartialOrd, Ord, Eq, PartialEq)]
116+
#[derive(Clone, Copy, Hash, PartialOrd, Ord, Eq, PartialEq, Debug)]
117117
#[non_exhaustive]
118118
pub enum Epoch {
119119
// epochs must be kept in order, newest to oldest
@@ -148,6 +148,15 @@ impl ToString for Epoch {
148148
}
149149
}
150150

151+
impl Epoch {
152+
pub fn lint_name(&self) -> &'static str {
153+
match *self {
154+
Epoch::Epoch2015 => "epoch_2015",
155+
Epoch::Epoch2018 => "epoch_2018",
156+
}
157+
}
158+
}
159+
151160
impl str::FromStr for Epoch {
152161
type Err = ();
153162
fn from_str(s: &str) -> Result<Self, ()> {

src/librustc/session/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,10 @@ impl Session {
869869
pub fn rust_2018(&self) -> bool {
870870
self.opts.debugging_opts.epoch >= Epoch::Epoch2018
871871
}
872+
873+
pub fn epoch(&self) -> Epoch {
874+
self.opts.debugging_opts.epoch
875+
}
872876
}
873877

874878
pub fn build_session(sopts: config::Options,

src/librustc/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2234,7 +2234,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
22342234
let sets = self.lint_levels(LOCAL_CRATE);
22352235
loop {
22362236
let hir_id = self.hir.definitions().node_to_hir_id(id);
2237-
if let Some(pair) = sets.level_and_source(lint, hir_id) {
2237+
if let Some(pair) = sets.level_and_source(lint, hir_id, self.sess) {
22382238
return pair
22392239
}
22402240
let next = self.hir.get_parent_node(id);

src/librustc_driver/driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ pub fn phase_2_configure_and_expand_inner<'a, F>(sess: &'a Session,
735735

736736
// Lint plugins are registered; now we can process command line flags.
737737
if sess.opts.describe_lints {
738-
super::describe_lints(&sess.lint_store.borrow(), true);
738+
super::describe_lints(&sess, &sess.lint_store.borrow(), true);
739739
return Err(CompileIncomplete::Stopped);
740740
}
741741

src/librustc_driver/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -774,15 +774,15 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
774774
-> Option<(Input, Option<PathBuf>)> {
775775
match matches.free.len() {
776776
0 => {
777+
let mut sess = build_session(sopts.clone(),
778+
None,
779+
descriptions.clone());
777780
if sopts.describe_lints {
778781
let mut ls = lint::LintStore::new();
779-
rustc_lint::register_builtins(&mut ls, None);
780-
describe_lints(&ls, false);
782+
rustc_lint::register_builtins(&mut ls, Some(&sess));
783+
describe_lints(&sess, &ls, false);
781784
return None;
782785
}
783-
let mut sess = build_session(sopts.clone(),
784-
None,
785-
descriptions.clone());
786786
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
787787
let mut cfg = config::build_configuration(&sess, cfg.clone());
788788
let trans = get_trans(&sess);
@@ -1121,7 +1121,7 @@ fn usage(verbose: bool, include_unstable_options: bool) {
11211121
verbose_help);
11221122
}
11231123

1124-
fn describe_lints(lint_store: &lint::LintStore, loaded_plugins: bool) {
1124+
fn describe_lints(sess: &Session, lint_store: &lint::LintStore, loaded_plugins: bool) {
11251125
println!("
11261126
Available lint options:
11271127
-W <foo> Warn about <foo>
@@ -1133,10 +1133,10 @@ Available lint options:
11331133
11341134
");
11351135

1136-
fn sort_lints(lints: Vec<(&'static Lint, bool)>) -> Vec<&'static Lint> {
1136+
fn sort_lints(sess: &Session, lints: Vec<(&'static Lint, bool)>) -> Vec<&'static Lint> {
11371137
let mut lints: Vec<_> = lints.into_iter().map(|(x, _)| x).collect();
11381138
lints.sort_by(|x: &&Lint, y: &&Lint| {
1139-
match x.default_level.cmp(&y.default_level) {
1139+
match x.default_level(sess).cmp(&y.default_level(sess)) {
11401140
// The sort doesn't case-fold but it's doubtful we care.
11411141
Equal => x.name.cmp(y.name),
11421142
r => r,
@@ -1159,8 +1159,8 @@ Available lint options:
11591159
.iter()
11601160
.cloned()
11611161
.partition(|&(_, p)| p);
1162-
let plugin = sort_lints(plugin);
1163-
let builtin = sort_lints(builtin);
1162+
let plugin = sort_lints(sess, plugin);
1163+
let builtin = sort_lints(sess, builtin);
11641164

11651165
let (plugin_groups, builtin_groups): (Vec<_>, _) = lint_store.get_lint_groups()
11661166
.iter()

src/librustc_lint/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,74 +185,92 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
185185
FutureIncompatibleInfo {
186186
id: LintId::of(PRIVATE_IN_PUBLIC),
187187
reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
188+
epoch: None,
188189
},
189190
FutureIncompatibleInfo {
190191
id: LintId::of(PUB_USE_OF_PRIVATE_EXTERN_CRATE),
191192
reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
193+
epoch: None,
192194
},
193195
FutureIncompatibleInfo {
194196
id: LintId::of(PATTERNS_IN_FNS_WITHOUT_BODY),
195197
reference: "issue #35203 <https://github.com/rust-lang/rust/issues/35203>",
198+
epoch: None,
196199
},
197200
FutureIncompatibleInfo {
198201
id: LintId::of(SAFE_EXTERN_STATICS),
199202
reference: "issue #36247 <https://github.com/rust-lang/rust/issues/36247>",
203+
epoch: None,
200204
},
201205
FutureIncompatibleInfo {
202206
id: LintId::of(INVALID_TYPE_PARAM_DEFAULT),
203207
reference: "issue #36887 <https://github.com/rust-lang/rust/issues/36887>",
208+
epoch: None,
204209
},
205210
FutureIncompatibleInfo {
206211
id: LintId::of(LEGACY_DIRECTORY_OWNERSHIP),
207212
reference: "issue #37872 <https://github.com/rust-lang/rust/issues/37872>",
213+
epoch: None,
208214
},
209215
FutureIncompatibleInfo {
210216
id: LintId::of(LEGACY_IMPORTS),
211217
reference: "issue #38260 <https://github.com/rust-lang/rust/issues/38260>",
218+
epoch: None,
212219
},
213220
FutureIncompatibleInfo {
214221
id: LintId::of(LEGACY_CONSTRUCTOR_VISIBILITY),
215222
reference: "issue #39207 <https://github.com/rust-lang/rust/issues/39207>",
223+
epoch: None,
216224
},
217225
FutureIncompatibleInfo {
218226
id: LintId::of(RESOLVE_TRAIT_ON_DEFAULTED_UNIT),
219227
reference: "issue #39216 <https://github.com/rust-lang/rust/issues/39216>",
228+
epoch: None,
220229
},
221230
FutureIncompatibleInfo {
222231
id: LintId::of(MISSING_FRAGMENT_SPECIFIER),
223232
reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>",
233+
epoch: None,
224234
},
225235
FutureIncompatibleInfo {
226236
id: LintId::of(ILLEGAL_FLOATING_POINT_LITERAL_PATTERN),
227237
reference: "issue #41620 <https://github.com/rust-lang/rust/issues/41620>",
238+
epoch: None,
228239
},
229240
FutureIncompatibleInfo {
230241
id: LintId::of(ANONYMOUS_PARAMETERS),
231242
reference: "issue #41686 <https://github.com/rust-lang/rust/issues/41686>",
243+
epoch: None,
232244
},
233245
FutureIncompatibleInfo {
234246
id: LintId::of(PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES),
235247
reference: "issue #42238 <https://github.com/rust-lang/rust/issues/42238>",
248+
epoch: None,
236249
},
237250
FutureIncompatibleInfo {
238251
id: LintId::of(LATE_BOUND_LIFETIME_ARGUMENTS),
239252
reference: "issue #42868 <https://github.com/rust-lang/rust/issues/42868>",
253+
epoch: None,
240254
},
241255
FutureIncompatibleInfo {
242256
id: LintId::of(SAFE_PACKED_BORROWS),
243257
reference: "issue #46043 <https://github.com/rust-lang/rust/issues/46043>",
258+
epoch: None,
244259
},
245260
FutureIncompatibleInfo {
246261
id: LintId::of(INCOHERENT_FUNDAMENTAL_IMPLS),
247262
reference: "issue #46205 <https://github.com/rust-lang/rust/issues/46205>",
263+
epoch: None,
248264
},
249265
FutureIncompatibleInfo {
250266
id: LintId::of(COERCE_NEVER),
251267
reference: "issue #46325 <https://github.com/rust-lang/rust/issues/46325>",
268+
epoch: None,
252269
},
253270
FutureIncompatibleInfo {
254271
id: LintId::of(TYVAR_BEHIND_RAW_POINTER),
255272
reference: "issue #46906 <https://github.com/rust-lang/rust/issues/46906>",
273+
epoch: None,
256274
},
257275
]);
258276

0 commit comments

Comments
 (0)