-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add functionality for epoch lints; add epoch lint for dyn-trait #48461
Changes from all commits
d9438c3
da9dc05
3eeabe7
bd29696
63168f7
177271f
dd67fe1
0cb3672
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,8 @@ use errors::{DiagnosticBuilder, DiagnosticId}; | |
use hir::def_id::{CrateNum, LOCAL_CRATE}; | ||
use hir::intravisit::{self, FnKind}; | ||
use hir; | ||
use session::{Session, DiagnosticMessageId}; | ||
use lint::builtin::BuiltinLintDiagnostics; | ||
use session::{config, Session, DiagnosticMessageId}; | ||
use std::hash; | ||
use syntax::ast; | ||
use syntax::codemap::MultiSpan; | ||
|
@@ -74,25 +75,46 @@ pub struct Lint { | |
/// | ||
/// e.g. "imports that are never used" | ||
pub desc: &'static str, | ||
|
||
/// Deny lint after this epoch | ||
pub epoch_deny: Option<config::Epoch>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Further down you state that the lint should be removed after the epoch, here it seems to suggest it should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is this? It used to say this, but that changed. This specific lint becomes Deny in Rust2018. Other lints may wish to disappear entirely because they are no longer lints. |
||
} | ||
|
||
impl Lint { | ||
/// Get the lint's name, with ASCII letters converted to lowercase. | ||
pub fn name_lower(&self) -> String { | ||
self.name.to_ascii_lowercase() | ||
} | ||
|
||
pub fn default_level(&self, session: &Session) -> Level { | ||
if let Some(epoch_deny) = self.epoch_deny { | ||
if session.epoch() >= epoch_deny { | ||
return Level::Deny | ||
} | ||
} | ||
self.default_level | ||
} | ||
} | ||
|
||
/// Declare a static item of type `&'static Lint`. | ||
#[macro_export] | ||
macro_rules! declare_lint { | ||
($vis: vis $NAME: ident, $Level: ident, $desc: expr, $epoch: expr) => ( | ||
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint { | ||
name: stringify!($NAME), | ||
default_level: $crate::lint::$Level, | ||
desc: $desc, | ||
epoch_deny: Some($epoch) | ||
}; | ||
); | ||
($vis: vis $NAME: ident, $Level: ident, $desc: expr) => ( | ||
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint { | ||
name: stringify!($NAME), | ||
default_level: $crate::lint::$Level, | ||
desc: $desc | ||
desc: $desc, | ||
epoch_deny: None, | ||
}; | ||
) | ||
); | ||
} | ||
|
||
/// Declare a static `LintArray` and return it as an expression. | ||
|
@@ -304,7 +326,7 @@ impl LintId { | |
/// Setting for how to handle a lint. | ||
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)] | ||
pub enum Level { | ||
Allow, Warn, Deny, Forbid | ||
Allow, Warn, Deny, Forbid, | ||
} | ||
|
||
impl_stable_hash_for!(enum self::Level { | ||
|
@@ -378,12 +400,14 @@ impl LintBuffer { | |
lint: &'static Lint, | ||
id: ast::NodeId, | ||
sp: MultiSpan, | ||
msg: &str) { | ||
msg: &str, | ||
diagnostic: BuiltinLintDiagnostics) { | ||
let early_lint = BufferedEarlyLint { | ||
lint_id: LintId::of(lint), | ||
ast_id: id, | ||
span: sp, | ||
msg: msg.to_string(), | ||
diagnostic | ||
}; | ||
let arr = self.map.entry(id).or_insert(Vec::new()); | ||
if !arr.contains(&early_lint) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment plz
"Create a lint group for each epoch corresponding to the future compatibility warnings targeting that epoch"
(Do you think that this ought to include the lints for "all previous epochs", since they are additive?)
(Also, are these lint groups insta-stable?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could. I think having them separate is cleaner, Rust doesn't do well with overlapping lint groups.
Rust lint stability is a very low bar, you just need to not remove the lint (aside from
register_removed_lint()
or whatever it's called). I think it's fine to insta-stable lint groups.