Make get_lints be a static function
This moves from calling get_lints on instantiated pass objects to the raw object
This commit is contained in:
parent
68c07db80a
commit
7fef39791a
8 changed files with 42 additions and 57 deletions
|
@ -22,7 +22,7 @@ use crate::hir::intravisit as hir_visit;
|
|||
use crate::hir::intravisit::Visitor;
|
||||
use crate::hir::map::{definitions::DisambiguatedDefPathData, DefPathData};
|
||||
use crate::lint::{EarlyLintPass, LateLintPass, EarlyLintPassObject, LateLintPassObject};
|
||||
use crate::lint::{LintArray, Level, Lint, LintId, LintPass, LintBuffer};
|
||||
use crate::lint::{Level, Lint, LintId, LintPass, LintBuffer};
|
||||
use crate::lint::builtin::BuiltinLintDiagnostics;
|
||||
use crate::lint::levels::{LintLevelSets, LintLevelsBuilder};
|
||||
use crate::middle::privacy::AccessLevels;
|
||||
|
@ -1307,10 +1307,6 @@ impl LintPass for LateLintPassObjects<'_> {
|
|||
fn name(&self) -> &'static str {
|
||||
panic!()
|
||||
}
|
||||
|
||||
fn get_lints(&self) -> LintArray {
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! expand_late_lint_pass_impl_methods {
|
||||
|
@ -1477,10 +1473,6 @@ impl LintPass for EarlyLintPassObjects<'_> {
|
|||
fn name(&self) -> &'static str {
|
||||
panic!()
|
||||
}
|
||||
|
||||
fn get_lints(&self) -> LintArray {
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! expand_early_lint_pass_impl_methods {
|
||||
|
|
|
@ -178,14 +178,6 @@ pub type LintArray = Vec<&'static Lint>;
|
|||
|
||||
pub trait LintPass {
|
||||
fn name(&self) -> &'static str;
|
||||
|
||||
/// Gets descriptions of the lints this `LintPass` object can emit.
|
||||
///
|
||||
/// N.B., there is no enforcement that the object only emits lints it registered.
|
||||
/// And some `rustc` internal `LintPass`es register lints to be emitted by other
|
||||
/// parts of the compiler. If you want enforced access restrictions for your
|
||||
/// `Lint`, make it a private `static` item in its own module.
|
||||
fn get_lints(&self) -> LintArray;
|
||||
}
|
||||
|
||||
/// Implements `LintPass for $name` with the given list of `Lint` statics.
|
||||
|
@ -194,7 +186,9 @@ macro_rules! impl_lint_pass {
|
|||
($name:ident => [$($lint:expr),* $(,)?]) => {
|
||||
impl LintPass for $name {
|
||||
fn name(&self) -> &'static str { stringify!($name) }
|
||||
fn get_lints(&self) -> LintArray { $crate::lint_array!($($lint),*) }
|
||||
}
|
||||
impl $name {
|
||||
pub fn get_lints() -> LintArray { $crate::lint_array!($($lint),*) }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -332,6 +326,12 @@ macro_rules! declare_combined_late_lint_pass {
|
|||
$($passes: $constructor,)*
|
||||
}
|
||||
}
|
||||
|
||||
$v fn get_lints() -> LintArray {
|
||||
let mut lints = Vec::new();
|
||||
$(lints.extend_from_slice(&$passes::get_lints());)*
|
||||
lints
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for $name {
|
||||
|
@ -342,12 +342,6 @@ macro_rules! declare_combined_late_lint_pass {
|
|||
fn name(&self) -> &'static str {
|
||||
panic!()
|
||||
}
|
||||
|
||||
fn get_lints(&self) -> LintArray {
|
||||
let mut lints = Vec::new();
|
||||
$(lints.extend_from_slice(&self.$passes.get_lints());)*
|
||||
lints
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -459,6 +453,12 @@ macro_rules! declare_combined_early_lint_pass {
|
|||
$($passes: $constructor,)*
|
||||
}
|
||||
}
|
||||
|
||||
$v fn get_lints() -> LintArray {
|
||||
let mut lints = Vec::new();
|
||||
$(lints.extend_from_slice(&$passes::get_lints());)*
|
||||
lints
|
||||
}
|
||||
}
|
||||
|
||||
impl EarlyLintPass for $name {
|
||||
|
@ -469,12 +469,6 @@ macro_rules! declare_combined_early_lint_pass {
|
|||
fn name(&self) -> &'static str {
|
||||
panic!()
|
||||
}
|
||||
|
||||
fn get_lints(&self) -> LintArray {
|
||||
let mut lints = Vec::new();
|
||||
$(lints.extend_from_slice(&self.$passes.get_lints());)*
|
||||
lints
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
@ -291,6 +291,7 @@ pub fn register_plugins<'a>(
|
|||
syntax_exts,
|
||||
early_lint_passes,
|
||||
late_lint_passes,
|
||||
lints,
|
||||
lint_groups,
|
||||
llvm_passes,
|
||||
attributes,
|
||||
|
@ -298,12 +299,11 @@ pub fn register_plugins<'a>(
|
|||
} = registry;
|
||||
|
||||
let mut ls = sess.lint_store.borrow_mut();
|
||||
ls.register_lints(&lints);
|
||||
for pass in early_lint_passes {
|
||||
ls.register_lints(&pass.get_lints());
|
||||
ls.register_early_pass(pass);
|
||||
}
|
||||
for pass in late_lint_passes {
|
||||
ls.register_lints(&pass.get_lints());
|
||||
ls.register_late_pass(pass);
|
||||
}
|
||||
|
||||
|
|
|
@ -204,9 +204,9 @@ pub fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool)
|
|||
}
|
||||
|
||||
macro_rules! register_pass {
|
||||
($method:ident, $constructor:expr) => (
|
||||
($method:ident, $ty:ident, $constructor:expr) => (
|
||||
let obj = box $constructor;
|
||||
store.register_lints(&obj.get_lints());
|
||||
store.register_lints(&$ty::get_lints());
|
||||
store.$method(obj);
|
||||
)
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ pub fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool)
|
|||
macro_rules! register_passes {
|
||||
($method:ident, [$($passes:ident: $constructor:expr,)*]) => (
|
||||
$(
|
||||
register_pass!($method, $constructor);
|
||||
register_pass!($method, $passes, $constructor);
|
||||
)*
|
||||
)
|
||||
}
|
||||
|
@ -225,10 +225,10 @@ pub fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool)
|
|||
late_lint_passes!(register_passes, register_late_pass);
|
||||
late_lint_mod_passes!(register_passes, register_late_mod_pass);
|
||||
} else {
|
||||
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());
|
||||
store.register_lints(&BuiltinCombinedPreExpansionLintPass::get_lints());
|
||||
store.register_lints(&BuiltinCombinedEarlyLintPass::get_lints());
|
||||
store.register_lints(&BuiltinCombinedModuleLateLintPass::get_lints());
|
||||
store.register_lints(&BuiltinCombinedLateLintPass::get_lints());
|
||||
}
|
||||
|
||||
add_lint_group!("nonstandard_style",
|
||||
|
@ -486,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::new().get_lints());
|
||||
store.register_lints(&DefaultHashTypes::get_lints());
|
||||
store.register_early_pass(box DefaultHashTypes::new());
|
||||
store.register_lints(&LintPassImpl.get_lints());
|
||||
store.register_lints(&LintPassImpl::get_lints());
|
||||
store.register_early_pass(box LintPassImpl);
|
||||
store.register_lints(&TyTyKind.get_lints());
|
||||
store.register_lints(&TyTyKind::get_lints());
|
||||
store.register_late_pass(box TyTyKind);
|
||||
store.register_group(
|
||||
false,
|
||||
|
|
|
@ -41,6 +41,9 @@ pub struct Registry<'a> {
|
|||
#[doc(hidden)]
|
||||
pub late_lint_passes: Vec<LateLintPassObject>,
|
||||
|
||||
#[doc(hidden)]
|
||||
pub lints: Vec<&'static Lint>,
|
||||
|
||||
#[doc(hidden)]
|
||||
pub lint_groups: FxHashMap<&'static str, (Vec<LintId>, Option<&'static str>)>,
|
||||
|
||||
|
@ -59,6 +62,7 @@ impl<'a> Registry<'a> {
|
|||
args_hidden: None,
|
||||
krate_span,
|
||||
syntax_exts: vec![],
|
||||
lints: vec![],
|
||||
early_lint_passes: vec![],
|
||||
late_lint_passes: vec![],
|
||||
lint_groups: FxHashMap::default(),
|
||||
|
@ -99,6 +103,11 @@ impl<'a> Registry<'a> {
|
|||
self.register_syntax_extension(Symbol::intern(name), ext);
|
||||
}
|
||||
|
||||
/// Register a compiler lint pass.
|
||||
pub fn register_lints(&mut self, lints: &[&'static Lint]) {
|
||||
self.lints.extend(lints);
|
||||
}
|
||||
|
||||
/// Register a compiler lint pass.
|
||||
pub fn register_early_lint_pass(&mut self, lint_pass: EarlyLintPassObject) {
|
||||
self.early_lint_passes.push(lint_pass);
|
||||
|
|
|
@ -5,7 +5,7 @@ use rustc::hir::HirId;
|
|||
use rustc::middle::cstore::CrateStore;
|
||||
use rustc::middle::privacy::AccessLevels;
|
||||
use rustc::ty::{Ty, TyCtxt};
|
||||
use rustc::lint::{self, LintPass};
|
||||
use rustc::lint;
|
||||
use rustc::session::config::ErrorOutputType;
|
||||
use rustc::session::DiagnosticOutput;
|
||||
use rustc::util::nodemap::{FxHashMap, FxHashSet};
|
||||
|
@ -273,10 +273,9 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
|
|||
whitelisted_lints.extend(lint_opts.iter().map(|(lint, _)| lint).cloned());
|
||||
|
||||
let lints = || {
|
||||
lint::builtin::HardwiredLints
|
||||
.get_lints()
|
||||
lint::builtin::HardwiredLints::get_lints()
|
||||
.into_iter()
|
||||
.chain(rustc_lint::SoftLints.get_lints().into_iter())
|
||||
.chain(rustc_lint::SoftLints::get_lints().into_iter())
|
||||
};
|
||||
|
||||
let lint_opts = lints().filter_map(|lint| {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
extern crate rustc;
|
||||
|
||||
use rustc::lint::{LintArray, LintPass};
|
||||
use rustc::{declare_lint, declare_lint_pass, impl_lint_pass, lint_array};
|
||||
use rustc::{declare_lint, declare_lint_pass, impl_lint_pass};
|
||||
|
||||
declare_lint! {
|
||||
pub TEST_LINT,
|
||||
|
@ -17,10 +17,6 @@ declare_lint! {
|
|||
struct Foo;
|
||||
|
||||
impl LintPass for Foo { //~ERROR implementing `LintPass` by hand
|
||||
fn get_lints(&self) -> LintArray {
|
||||
lint_array!(TEST_LINT)
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
"Foo"
|
||||
}
|
||||
|
@ -31,10 +27,6 @@ macro_rules! custom_lint_pass_macro {
|
|||
struct Custom;
|
||||
|
||||
impl LintPass for Custom { //~ERROR implementing `LintPass` by hand
|
||||
fn get_lints(&self) -> LintArray {
|
||||
lint_array!(TEST_LINT)
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
"Custom"
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ LL | #![deny(rustc::lint_pass_impl_without_macro)]
|
|||
= help: try using `declare_lint_pass!` or `impl_lint_pass!` instead
|
||||
|
||||
error: implementing `LintPass` by hand
|
||||
--> $DIR/lint_pass_impl_without_macro.rs:33:14
|
||||
--> $DIR/lint_pass_impl_without_macro.rs:29:14
|
||||
|
|
||||
LL | impl LintPass for Custom {
|
||||
| ^^^^^^^^
|
||||
|
@ -23,4 +23,3 @@ LL | custom_lint_pass_macro!();
|
|||
= help: try using `declare_lint_pass!` or `impl_lint_pass!` instead
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue