Skip to content

Commit 7fef397

Browse files
Make get_lints be a static function
This moves from calling get_lints on instantiated pass objects to the raw object
1 parent 68c07db commit 7fef397

File tree

8 files changed

+42
-57
lines changed

8 files changed

+42
-57
lines changed

src/librustc/lint/context.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::hir::intravisit as hir_visit;
2222
use crate::hir::intravisit::Visitor;
2323
use crate::hir::map::{definitions::DisambiguatedDefPathData, DefPathData};
2424
use crate::lint::{EarlyLintPass, LateLintPass, EarlyLintPassObject, LateLintPassObject};
25-
use crate::lint::{LintArray, Level, Lint, LintId, LintPass, LintBuffer};
25+
use crate::lint::{Level, Lint, LintId, LintPass, LintBuffer};
2626
use crate::lint::builtin::BuiltinLintDiagnostics;
2727
use crate::lint::levels::{LintLevelSets, LintLevelsBuilder};
2828
use crate::middle::privacy::AccessLevels;
@@ -1307,10 +1307,6 @@ impl LintPass for LateLintPassObjects<'_> {
13071307
fn name(&self) -> &'static str {
13081308
panic!()
13091309
}
1310-
1311-
fn get_lints(&self) -> LintArray {
1312-
panic!()
1313-
}
13141310
}
13151311

13161312
macro_rules! expand_late_lint_pass_impl_methods {
@@ -1477,10 +1473,6 @@ impl LintPass for EarlyLintPassObjects<'_> {
14771473
fn name(&self) -> &'static str {
14781474
panic!()
14791475
}
1480-
1481-
fn get_lints(&self) -> LintArray {
1482-
panic!()
1483-
}
14841476
}
14851477

14861478
macro_rules! expand_early_lint_pass_impl_methods {

src/librustc/lint/mod.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,6 @@ pub type LintArray = Vec<&'static Lint>;
178178

179179
pub trait LintPass {
180180
fn name(&self) -> &'static str;
181-
182-
/// Gets descriptions of the lints this `LintPass` object can emit.
183-
///
184-
/// N.B., there is no enforcement that the object only emits lints it registered.
185-
/// And some `rustc` internal `LintPass`es register lints to be emitted by other
186-
/// parts of the compiler. If you want enforced access restrictions for your
187-
/// `Lint`, make it a private `static` item in its own module.
188-
fn get_lints(&self) -> LintArray;
189181
}
190182

191183
/// Implements `LintPass for $name` with the given list of `Lint` statics.
@@ -194,7 +186,9 @@ macro_rules! impl_lint_pass {
194186
($name:ident => [$($lint:expr),* $(,)?]) => {
195187
impl LintPass for $name {
196188
fn name(&self) -> &'static str { stringify!($name) }
197-
fn get_lints(&self) -> LintArray { $crate::lint_array!($($lint),*) }
189+
}
190+
impl $name {
191+
pub fn get_lints() -> LintArray { $crate::lint_array!($($lint),*) }
198192
}
199193
};
200194
}
@@ -332,6 +326,12 @@ macro_rules! declare_combined_late_lint_pass {
332326
$($passes: $constructor,)*
333327
}
334328
}
329+
330+
$v fn get_lints() -> LintArray {
331+
let mut lints = Vec::new();
332+
$(lints.extend_from_slice(&$passes::get_lints());)*
333+
lints
334+
}
335335
}
336336

337337
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for $name {
@@ -342,12 +342,6 @@ macro_rules! declare_combined_late_lint_pass {
342342
fn name(&self) -> &'static str {
343343
panic!()
344344
}
345-
346-
fn get_lints(&self) -> LintArray {
347-
let mut lints = Vec::new();
348-
$(lints.extend_from_slice(&self.$passes.get_lints());)*
349-
lints
350-
}
351345
}
352346
)
353347
}
@@ -459,6 +453,12 @@ macro_rules! declare_combined_early_lint_pass {
459453
$($passes: $constructor,)*
460454
}
461455
}
456+
457+
$v fn get_lints() -> LintArray {
458+
let mut lints = Vec::new();
459+
$(lints.extend_from_slice(&$passes::get_lints());)*
460+
lints
461+
}
462462
}
463463

464464
impl EarlyLintPass for $name {
@@ -469,12 +469,6 @@ macro_rules! declare_combined_early_lint_pass {
469469
fn name(&self) -> &'static str {
470470
panic!()
471471
}
472-
473-
fn get_lints(&self) -> LintArray {
474-
let mut lints = Vec::new();
475-
$(lints.extend_from_slice(&self.$passes.get_lints());)*
476-
lints
477-
}
478472
}
479473
)
480474
}

src/librustc_interface/passes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,19 +291,19 @@ pub fn register_plugins<'a>(
291291
syntax_exts,
292292
early_lint_passes,
293293
late_lint_passes,
294+
lints,
294295
lint_groups,
295296
llvm_passes,
296297
attributes,
297298
..
298299
} = registry;
299300

300301
let mut ls = sess.lint_store.borrow_mut();
302+
ls.register_lints(&lints);
301303
for pass in early_lint_passes {
302-
ls.register_lints(&pass.get_lints());
303304
ls.register_early_pass(pass);
304305
}
305306
for pass in late_lint_passes {
306-
ls.register_lints(&pass.get_lints());
307307
ls.register_late_pass(pass);
308308
}
309309

src/librustc_lint/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,17 @@ pub fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool)
204204
}
205205

206206
macro_rules! register_pass {
207-
($method:ident, $constructor:expr) => (
207+
($method:ident, $ty:ident, $constructor:expr) => (
208208
let obj = box $constructor;
209-
store.register_lints(&obj.get_lints());
209+
store.register_lints(&$ty::get_lints());
210210
store.$method(obj);
211211
)
212212
}
213213

214214
macro_rules! register_passes {
215215
($method:ident, [$($passes:ident: $constructor:expr,)*]) => (
216216
$(
217-
register_pass!($method, $constructor);
217+
register_pass!($method, $passes, $constructor);
218218
)*
219219
)
220220
}
@@ -225,10 +225,10 @@ pub fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool)
225225
late_lint_passes!(register_passes, register_late_pass);
226226
late_lint_mod_passes!(register_passes, register_late_mod_pass);
227227
} else {
228-
store.register_lints(&BuiltinCombinedPreExpansionLintPass::new().get_lints());
229-
store.register_lints(&BuiltinCombinedEarlyLintPass::new().get_lints());
230-
store.register_lints(&BuiltinCombinedModuleLateLintPass::new().get_lints());
231-
store.register_lints(&BuiltinCombinedLateLintPass::new().get_lints());
228+
store.register_lints(&BuiltinCombinedPreExpansionLintPass::get_lints());
229+
store.register_lints(&BuiltinCombinedEarlyLintPass::get_lints());
230+
store.register_lints(&BuiltinCombinedModuleLateLintPass::get_lints());
231+
store.register_lints(&BuiltinCombinedLateLintPass::get_lints());
232232
}
233233

234234
add_lint_group!("nonstandard_style",
@@ -486,11 +486,11 @@ pub fn register_builtins(store: &mut lint::LintStore, no_interleave_lints: bool)
486486
}
487487

488488
pub fn register_internals(store: &mut lint::LintStore) {
489-
store.register_lints(&DefaultHashTypes::new().get_lints());
489+
store.register_lints(&DefaultHashTypes::get_lints());
490490
store.register_early_pass(box DefaultHashTypes::new());
491-
store.register_lints(&LintPassImpl.get_lints());
491+
store.register_lints(&LintPassImpl::get_lints());
492492
store.register_early_pass(box LintPassImpl);
493-
store.register_lints(&TyTyKind.get_lints());
493+
store.register_lints(&TyTyKind::get_lints());
494494
store.register_late_pass(box TyTyKind);
495495
store.register_group(
496496
false,

src/librustc_plugin/registry.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ pub struct Registry<'a> {
4141
#[doc(hidden)]
4242
pub late_lint_passes: Vec<LateLintPassObject>,
4343

44+
#[doc(hidden)]
45+
pub lints: Vec<&'static Lint>,
46+
4447
#[doc(hidden)]
4548
pub lint_groups: FxHashMap<&'static str, (Vec<LintId>, Option<&'static str>)>,
4649

@@ -59,6 +62,7 @@ impl<'a> Registry<'a> {
5962
args_hidden: None,
6063
krate_span,
6164
syntax_exts: vec![],
65+
lints: vec![],
6266
early_lint_passes: vec![],
6367
late_lint_passes: vec![],
6468
lint_groups: FxHashMap::default(),
@@ -99,6 +103,11 @@ impl<'a> Registry<'a> {
99103
self.register_syntax_extension(Symbol::intern(name), ext);
100104
}
101105

106+
/// Register a compiler lint pass.
107+
pub fn register_lints(&mut self, lints: &[&'static Lint]) {
108+
self.lints.extend(lints);
109+
}
110+
102111
/// Register a compiler lint pass.
103112
pub fn register_early_lint_pass(&mut self, lint_pass: EarlyLintPassObject) {
104113
self.early_lint_passes.push(lint_pass);

src/librustdoc/core.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc::hir::HirId;
55
use rustc::middle::cstore::CrateStore;
66
use rustc::middle::privacy::AccessLevels;
77
use rustc::ty::{Ty, TyCtxt};
8-
use rustc::lint::{self, LintPass};
8+
use rustc::lint;
99
use rustc::session::config::ErrorOutputType;
1010
use rustc::session::DiagnosticOutput;
1111
use rustc::util::nodemap::{FxHashMap, FxHashSet};
@@ -273,10 +273,9 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
273273
whitelisted_lints.extend(lint_opts.iter().map(|(lint, _)| lint).cloned());
274274

275275
let lints = || {
276-
lint::builtin::HardwiredLints
277-
.get_lints()
276+
lint::builtin::HardwiredLints::get_lints()
278277
.into_iter()
279-
.chain(rustc_lint::SoftLints.get_lints().into_iter())
278+
.chain(rustc_lint::SoftLints::get_lints().into_iter())
280279
};
281280

282281
let lint_opts = lints().filter_map(|lint| {

src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
extern crate rustc;
77

88
use rustc::lint::{LintArray, LintPass};
9-
use rustc::{declare_lint, declare_lint_pass, impl_lint_pass, lint_array};
9+
use rustc::{declare_lint, declare_lint_pass, impl_lint_pass};
1010

1111
declare_lint! {
1212
pub TEST_LINT,
@@ -17,10 +17,6 @@ declare_lint! {
1717
struct Foo;
1818

1919
impl LintPass for Foo { //~ERROR implementing `LintPass` by hand
20-
fn get_lints(&self) -> LintArray {
21-
lint_array!(TEST_LINT)
22-
}
23-
2420
fn name(&self) -> &'static str {
2521
"Foo"
2622
}
@@ -31,10 +27,6 @@ macro_rules! custom_lint_pass_macro {
3127
struct Custom;
3228

3329
impl LintPass for Custom { //~ERROR implementing `LintPass` by hand
34-
fn get_lints(&self) -> LintArray {
35-
lint_array!(TEST_LINT)
36-
}
37-
3830
fn name(&self) -> &'static str {
3931
"Custom"
4032
}

src/test/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.stderr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | #![deny(rustc::lint_pass_impl_without_macro)]
1212
= help: try using `declare_lint_pass!` or `impl_lint_pass!` instead
1313

1414
error: implementing `LintPass` by hand
15-
--> $DIR/lint_pass_impl_without_macro.rs:33:14
15+
--> $DIR/lint_pass_impl_without_macro.rs:29:14
1616
|
1717
LL | impl LintPass for Custom {
1818
| ^^^^^^^^
@@ -23,4 +23,3 @@ LL | custom_lint_pass_macro!();
2323
= help: try using `declare_lint_pass!` or `impl_lint_pass!` instead
2424

2525
error: aborting due to 2 previous errors
26-

0 commit comments

Comments
 (0)