Take lint passes as constructor functions
This commit is contained in:
parent
7fef39791a
commit
24545128eb
@ -168,20 +168,20 @@ impl LintStore {
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn register_early_pass(&mut self, pass: EarlyLintPassObject) {
|
||||
self.early_passes.as_mut().unwrap().push(pass);
|
||||
pub fn register_early_pass(&mut self, pass: fn() -> EarlyLintPassObject) {
|
||||
self.early_passes.as_mut().unwrap().push((pass)());
|
||||
}
|
||||
|
||||
pub fn register_pre_expansion_pass(&mut self, pass: EarlyLintPassObject) {
|
||||
self.pre_expansion_passes.as_mut().unwrap().push(pass);
|
||||
pub fn register_pre_expansion_pass(&mut self, pass: fn() -> EarlyLintPassObject) {
|
||||
self.pre_expansion_passes.as_mut().unwrap().push((pass)());
|
||||
}
|
||||
|
||||
pub fn register_late_pass(&mut self, pass: LateLintPassObject) {
|
||||
self.late_passes.lock().as_mut().unwrap().push(pass);
|
||||
pub fn register_late_pass(&mut self, pass: fn() -> LateLintPassObject) {
|
||||
self.late_passes.lock().as_mut().unwrap().push((pass)());
|
||||
}
|
||||
|
||||
pub fn register_late_mod_pass(&mut self, pass: LateLintPassObject) {
|
||||
self.late_module_passes.push(pass);
|
||||
pub fn register_late_mod_pass(&mut self, pass: fn() -> LateLintPassObject) {
|
||||
self.late_module_passes.push((pass)());
|
||||
}
|
||||
|
||||
// Helper method for register_early/late_pass
|
||||
|
@ -205,9 +205,8 @@ pub fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool)
|
||||
|
||||
macro_rules! register_pass {
|
||||
($method:ident, $ty:ident, $constructor:expr) => (
|
||||
let obj = box $constructor;
|
||||
store.register_lints(&$ty::get_lints());
|
||||
store.$method(obj);
|
||||
store.$method(|| box $constructor);
|
||||
)
|
||||
}
|
||||
|
||||
@ -487,11 +486,11 @@ pub fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool)
|
||||
|
||||
pub fn register_internals(store: &mut lint::LintStore) {
|
||||
store.register_lints(&DefaultHashTypes::get_lints());
|
||||
store.register_early_pass(box DefaultHashTypes::new());
|
||||
store.register_early_pass(|| box DefaultHashTypes::new());
|
||||
store.register_lints(&LintPassImpl::get_lints());
|
||||
store.register_early_pass(box LintPassImpl);
|
||||
store.register_early_pass(|| box LintPassImpl);
|
||||
store.register_lints(&TyTyKind::get_lints());
|
||||
store.register_late_pass(box TyTyKind);
|
||||
store.register_late_pass(|| box TyTyKind);
|
||||
store.register_group(
|
||||
false,
|
||||
"rustc::internal",
|
||||
|
@ -36,10 +36,10 @@ pub struct Registry<'a> {
|
||||
pub syntax_exts: Vec<NamedSyntaxExtension>,
|
||||
|
||||
#[doc(hidden)]
|
||||
pub early_lint_passes: Vec<EarlyLintPassObject>,
|
||||
pub early_lint_passes: Vec<fn() -> EarlyLintPassObject>,
|
||||
|
||||
#[doc(hidden)]
|
||||
pub late_lint_passes: Vec<LateLintPassObject>,
|
||||
pub late_lint_passes: Vec<fn() -> LateLintPassObject>,
|
||||
|
||||
#[doc(hidden)]
|
||||
pub lints: Vec<&'static Lint>,
|
||||
@ -109,12 +109,12 @@ impl<'a> Registry<'a> {
|
||||
}
|
||||
|
||||
/// Register a compiler lint pass.
|
||||
pub fn register_early_lint_pass(&mut self, lint_pass: EarlyLintPassObject) {
|
||||
pub fn register_early_lint_pass(&mut self, lint_pass: fn() -> EarlyLintPassObject) {
|
||||
self.early_lint_passes.push(lint_pass);
|
||||
}
|
||||
|
||||
/// Register a compiler lint pass.
|
||||
pub fn register_late_lint_pass(&mut self, lint_pass: LateLintPassObject) {
|
||||
pub fn register_late_lint_pass(&mut self, lint_pass: fn() -> LateLintPassObject) {
|
||||
self.late_lint_passes.push(lint_pass);
|
||||
}
|
||||
/// Register a lint group.
|
||||
|
@ -32,5 +32,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||
|
||||
#[plugin_registrar]
|
||||
pub fn plugin_registrar(reg: &mut Registry) {
|
||||
reg.register_late_lint_pass(box Pass);
|
||||
reg.register_lint(&[&CRATE_NOT_OKAY]);
|
||||
reg.register_late_lint_pass(|| box Pass);
|
||||
}
|
||||
|
@ -23,3 +23,4 @@ LL | custom_lint_pass_macro!();
|
||||
= help: try using `declare_lint_pass!` or `impl_lint_pass!` instead
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user