提交 748eccd4 编写于 作者: M Mark Rousskov

Lints being from a plugin is dependent on the lint, not the registration

上级 2121b047
......@@ -50,7 +50,7 @@
pub struct LintStore {
/// Registered lints. The bool is true if the lint was
/// added by a plugin.
lints: Vec<(&'static Lint, bool)>,
lints: Vec<&'static Lint>,
/// Trait objects for each lint pass.
/// This is only `None` while performing a lint pass.
......@@ -152,7 +152,7 @@ pub fn new() -> LintStore {
}
}
pub fn get_lints<'t>(&'t self) -> &'t [(&'static Lint, bool)] {
pub fn get_lints<'t>(&'t self) -> &'t [&'static Lint] {
&self.lints
}
......@@ -169,10 +169,9 @@ pub fn get_lint_groups<'t>(&'t self) -> Vec<(&'static str, Vec<LintId>, bool)> {
}
pub fn register_early_pass(&mut self,
from_plugin: bool,
register_only: bool,
pass: EarlyLintPassObject) {
self.push_lints(from_plugin, &pass.get_lints());
self.push_lints(&pass.get_lints());
if !register_only {
self.early_passes.as_mut().unwrap().push(pass);
}
......@@ -180,22 +179,20 @@ pub fn register_early_pass(&mut self,
pub fn register_pre_expansion_pass(
&mut self,
from_plugin: bool,
register_only: bool,
pass: EarlyLintPassObject,
) {
self.push_lints(from_plugin, &pass.get_lints());
self.push_lints(&pass.get_lints());
if !register_only {
self.pre_expansion_passes.as_mut().unwrap().push(pass);
}
}
pub fn register_late_pass(&mut self,
from_plugin: bool,
register_only: bool,
per_module: bool,
pass: LateLintPassObject) {
self.push_lints(from_plugin, &pass.get_lints());
self.push_lints(&pass.get_lints());
if !register_only {
if per_module {
self.late_module_passes.push(pass);
......@@ -206,9 +203,9 @@ pub fn register_late_pass(&mut self,
}
// Helper method for register_early/late_pass
fn push_lints(&mut self, from_plugin: bool, lints: &[&'static Lint]) {
fn push_lints(&mut self, lints: &[&'static Lint]) {
for lint in lints {
self.lints.push((lint, from_plugin));
self.lints.push(lint);
let id = LintId::of(lint);
if self.by_name.insert(lint.name_lower(), Id(id)).is_some() {
......
......@@ -76,6 +76,8 @@ pub struct Lint {
/// `true` if this lint is reported even inside expansions of external macros.
pub report_in_external_macro: bool,
pub is_plugin: bool,
}
impl Lint {
......@@ -117,6 +119,7 @@ pub fn default_level(&self, session: &Session) -> Level {
desc: $desc,
edition_lint_opts: None,
report_in_external_macro: $external,
is_plugin: false,
};
);
($vis: vis $NAME: ident, $Level: ident, $desc: expr,
......@@ -128,6 +131,7 @@ pub fn default_level(&self, session: &Session) -> Level {
desc: $desc,
edition_lint_opts: Some(($lint_edition, $crate::lint::Level::$edition_level)),
report_in_external_macro: false,
is_plugin: false,
};
);
}
......@@ -156,6 +160,7 @@ pub fn default_level(&self, session: &Session) -> Level {
desc: $desc,
edition_lint_opts: None,
report_in_external_macro: $external,
is_plugin: true,
};
);
}
......
......@@ -835,8 +835,7 @@ fn describe_lints(sess: &Session, lint_store: &lint::LintStore, loaded_plugins:
");
fn sort_lints(sess: &Session, lints: Vec<(&'static Lint, bool)>) -> Vec<&'static Lint> {
let mut lints: Vec<_> = lints.into_iter().map(|(x, _)| x).collect();
fn sort_lints(sess: &Session, mut lints: Vec<&'static Lint>) -> Vec<&'static Lint> {
// The sort doesn't case-fold but it's doubtful we care.
lints.sort_by_cached_key(|x: &&Lint| (x.default_level(sess), x.name));
lints
......@@ -852,7 +851,7 @@ fn sort_lint_groups(lints: Vec<(&'static str, Vec<lint::LintId>, bool)>)
let (plugin, builtin): (Vec<_>, _) = lint_store.get_lints()
.iter()
.cloned()
.partition(|&(_, p)| p);
.partition(|&lint| lint.is_plugin);
let plugin = sort_lints(sess, plugin);
let builtin = sort_lints(sess, builtin);
......
......@@ -299,10 +299,10 @@ pub fn register_plugins<'a>(
let mut ls = sess.lint_store.borrow_mut();
for pass in early_lint_passes {
ls.register_early_pass(true, false, pass);
ls.register_early_pass(false, pass);
}
for pass in late_lint_passes {
ls.register_late_pass(true, false, false, pass);
ls.register_late_pass(false, false, pass);
}
for (name, (to, deprecated_name)) in lint_groups {
......
......@@ -205,7 +205,7 @@ pub fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool)
macro_rules! register_pass {
($method:ident, $constructor:expr, [$($args:expr),*]) => (
store.$method(false, false, $($args,)* box $constructor);
store.$method(false, $($args,)* box $constructor);
)
}
......@@ -224,16 +224,15 @@ pub fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool)
late_lint_mod_passes!(register_passes, [register_late_pass, [true]]);
} else {
store.register_pre_expansion_pass(
false,
true,
box BuiltinCombinedPreExpansionLintPass::new()
);
store.register_early_pass(false, true, box BuiltinCombinedEarlyLintPass::new());
store.register_early_pass(true, box BuiltinCombinedEarlyLintPass::new());
store.register_late_pass(
false, true, true, box BuiltinCombinedModuleLateLintPass::new()
true, true, box BuiltinCombinedModuleLateLintPass::new()
);
store.register_late_pass(
false, true, false, box BuiltinCombinedLateLintPass::new()
true, false, box BuiltinCombinedLateLintPass::new()
);
}
......@@ -492,9 +491,9 @@ pub fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool)
}
pub fn register_internals(store: &mut lint::LintStore) {
store.register_early_pass(false, false, box DefaultHashTypes::new());
store.register_early_pass(false, false, box LintPassImpl);
store.register_late_pass(false, false, false, box TyTyKind);
store.register_early_pass(false, box DefaultHashTypes::new());
store.register_early_pass(false, box LintPassImpl);
store.register_late_pass(false, false, box TyTyKind);
store.register_group(
false,
"rustc::internal",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册