Split out just registration to separate function

This commit is contained in:
Mark Rousskov 2019-10-07 17:21:50 -04:00
parent b060f3b84d
commit e1079c82be
3 changed files with 30 additions and 44 deletions

View file

@ -168,42 +168,28 @@ impl LintStore {
.collect()
}
pub fn register_early_pass(&mut self,
register_only: bool,
pass: EarlyLintPassObject) {
self.push_lints(&pass.get_lints());
if !register_only {
self.early_passes.as_mut().unwrap().push(pass);
}
pub fn register_early_pass(&mut self, pass: EarlyLintPassObject) {
self.register_lints(&pass.get_lints());
self.early_passes.as_mut().unwrap().push(pass);
}
pub fn register_pre_expansion_pass(
&mut self,
register_only: bool,
pass: EarlyLintPassObject,
) {
self.push_lints(&pass.get_lints());
if !register_only {
self.pre_expansion_passes.as_mut().unwrap().push(pass);
}
pub fn register_pre_expansion_pass(&mut self, pass: EarlyLintPassObject) {
self.register_lints(&pass.get_lints());
self.pre_expansion_passes.as_mut().unwrap().push(pass);
}
pub fn register_late_pass(&mut self, register_only: bool, pass: LateLintPassObject) {
self.push_lints(&pass.get_lints());
if !register_only {
self.late_passes.lock().as_mut().unwrap().push(pass);
}
pub fn register_late_pass(&mut self, pass: LateLintPassObject) {
self.register_lints(&pass.get_lints());
self.late_passes.lock().as_mut().unwrap().push(pass);
}
pub fn register_late_mod_pass(&mut self, register_only: bool, pass: LateLintPassObject) {
self.push_lints(&pass.get_lints());
if !register_only {
self.late_module_passes.push(pass);
}
pub fn register_late_mod_pass(&mut self, pass: LateLintPassObject) {
self.register_lints(&pass.get_lints());
self.late_module_passes.push(pass);
}
// Helper method for register_early/late_pass
fn push_lints(&mut self, lints: &[&'static Lint]) {
pub fn register_lints(&mut self, lints: &[&'static Lint]) {
for lint in lints {
self.lints.push(lint);

View file

@ -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(false, pass);
ls.register_early_pass(pass);
}
for pass in late_lint_passes {
ls.register_late_pass(false, pass);
ls.register_late_pass(pass);
}
for (name, (to, deprecated_name)) in lint_groups {

View file

@ -204,29 +204,29 @@ 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, $($args,)* box $constructor);
($method:ident, $constructor:expr) => (
store.$method(box $constructor);
)
}
macro_rules! register_passes {
([$method:ident, $args:tt], [$($passes:ident: $constructor:expr,)*]) => (
($method:ident, [$($passes:ident: $constructor:expr,)*]) => (
$(
register_pass!($method, $constructor, $args);
register_pass!($method, $constructor);
)*
)
}
if no_interleave_lints {
pre_expansion_lint_passes!(register_passes, [register_pre_expansion_pass, []]);
early_lint_passes!(register_passes, [register_early_pass, []]);
late_lint_passes!(register_passes, [register_late_pass, []]);
late_lint_mod_passes!(register_passes, [register_late_mod_pass, []]);
pre_expansion_lint_passes!(register_passes, register_pre_expansion_pass);
early_lint_passes!(register_passes, register_early_pass);
late_lint_passes!(register_passes, register_late_pass);
late_lint_mod_passes!(register_passes, register_late_mod_pass);
} else {
store.register_pre_expansion_pass(true, box BuiltinCombinedPreExpansionLintPass::new());
store.register_early_pass(true, box BuiltinCombinedEarlyLintPass::new());
store.register_late_mod_pass(true, box BuiltinCombinedModuleLateLintPass::new());
store.register_late_pass(true, box BuiltinCombinedLateLintPass::new());
store.register_lints(&BuiltinCombinedPreExpansionLintPass::new().get_lints());
store.register_lints(&BuiltinCombinedEarlyLintPass::new().get_lints());
store.register_lints(&BuiltinCombinedModuleLateLintPass::new().get_lints());
store.register_lints(&BuiltinCombinedLateLintPass::new().get_lints());
}
add_lint_group!("nonstandard_style",
@ -484,9 +484,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, box DefaultHashTypes::new());
store.register_early_pass(false, box LintPassImpl);
store.register_late_pass(false, box TyTyKind);
store.register_early_pass(box DefaultHashTypes::new());
store.register_early_pass(box LintPassImpl);
store.register_late_pass(box TyTyKind);
store.register_group(
false,
"rustc::internal",