Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 13c9a98

Browse files
committed
Auto merge of rust-lang#134862 - compiler-errors:builtin-passes-that-dont-need-to-run, r=<try>
Filter out builtin lint passes that don't need to be run r? `@ghost`
2 parents ceb0441 + 7d164e8 commit 13c9a98

File tree

10 files changed

+63
-62
lines changed

10 files changed

+63
-62
lines changed

compiler/rustc_lint/src/late.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,12 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
307307
// `check_foo` method in `$methods` within this pass simply calls `check_foo`
308308
// once per `$pass`. Compare with `declare_combined_late_lint_pass`, which is
309309
// similar, but combines lint passes at compile time.
310-
struct RuntimeCombinedLateLintPass<'a, 'tcx> {
311-
passes: &'a mut [LateLintPassObject<'tcx>],
310+
pub struct RuntimeCombinedLateLintPass<'tcx> {
311+
pub passes: Vec<LateLintPassObject<'tcx>>,
312312
}
313313

314314
#[allow(rustc::lint_pass_impl_without_macro)]
315-
impl LintPass for RuntimeCombinedLateLintPass<'_, '_> {
315+
impl LintPass for RuntimeCombinedLateLintPass<'_> {
316316
fn name(&self) -> &'static str {
317317
panic!()
318318
}
@@ -323,7 +323,7 @@ impl LintPass for RuntimeCombinedLateLintPass<'_, '_> {
323323

324324
macro_rules! impl_late_lint_pass {
325325
([], [$($(#[$attr:meta])* fn $f:ident($($param:ident: $arg:ty),*);)*]) => {
326-
impl<'tcx> LateLintPass<'tcx> for RuntimeCombinedLateLintPass<'_, 'tcx> {
326+
impl<'tcx> LateLintPass<'tcx> for RuntimeCombinedLateLintPass<'tcx> {
327327
$(fn $f(&mut self, context: &LateContext<'tcx>, $($param: $arg),*) {
328328
for pass in self.passes.iter_mut() {
329329
pass.$f(context, $($param),*);
@@ -360,14 +360,14 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
360360
late_lint_mod_inner(tcx, module_def_id, context, builtin_lints);
361361
} else {
362362
let builtin_lints = Box::new(builtin_lints) as Box<dyn LateLintPass<'tcx>>;
363-
let mut binding = store
363+
let passes = store
364364
.late_module_passes
365365
.iter()
366366
.map(|mk_pass| (mk_pass)(tcx))
367367
.chain(std::iter::once(builtin_lints))
368368
.collect::<Vec<_>>();
369369

370-
let pass = RuntimeCombinedLateLintPass { passes: binding.as_mut_slice() };
370+
let pass = RuntimeCombinedLateLintPass { passes };
371371
late_lint_mod_inner(tcx, module_def_id, context, pass);
372372
}
373373
}
@@ -398,10 +398,10 @@ fn late_lint_mod_inner<'tcx, T: LateLintPass<'tcx>>(
398398

399399
fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
400400
// Note: `passes` is often empty.
401-
let passes: Vec<_> =
401+
let unfiltered_passes: Vec<_> =
402402
unerased_lint_store(tcx.sess).late_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();
403403

404-
if passes.is_empty() {
404+
if unfiltered_passes.is_empty() {
405405
return;
406406
}
407407

@@ -418,7 +418,7 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
418418

419419
let lints_that_dont_need_to_run = tcx.lints_that_dont_need_to_run(());
420420

421-
let mut filtered_passes: Vec<Box<dyn LateLintPass<'tcx>>> = passes
421+
let mut passes: Vec<Box<dyn LateLintPass<'tcx>>> = unfiltered_passes
422422
.into_iter()
423423
.filter(|pass| {
424424
let lints = (**pass).get_lints();
@@ -429,8 +429,8 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
429429
})
430430
.collect();
431431

432-
filtered_passes.push(Box::new(HardwiredLints));
433-
let pass = RuntimeCombinedLateLintPass { passes: &mut filtered_passes[..] };
432+
passes.push(Box::new(HardwiredLints));
433+
let pass = RuntimeCombinedLateLintPass { passes };
434434
late_lint_crate_inner(tcx, context, pass);
435435
}
436436

compiler/rustc_lint/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ pub use context::{
129129
CheckLintNameResult, EarlyContext, FindLintError, LateContext, LintContext, LintStore,
130130
};
131131
pub use early::{EarlyCheckNode, check_ast_node};
132-
pub use late::{check_crate, late_lint_mod, unerased_lint_store};
132+
pub use late::{RuntimeCombinedLateLintPass, check_crate, late_lint_mod, unerased_lint_store};
133133
pub use passes::{EarlyLintPass, LateLintPass};
134134
pub use rustc_session::lint::Level::{self, *};
135135
pub use rustc_session::lint::{
@@ -146,7 +146,7 @@ pub fn provide(providers: &mut Providers) {
146146
}
147147

148148
fn lint_mod(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
149-
late_lint_mod(tcx, module_def_id, BuiltinCombinedModuleLateLintPass::new());
149+
late_lint_mod(tcx, module_def_id, BuiltinCombinedModuleLateLintPass::new(tcx));
150150
}
151151

152152
early_lint_methods!(

compiler/rustc_lint/src/passes.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,11 @@ late_lint_methods!(declare_late_lint_pass, []);
7272

7373
impl LateLintPass<'_> for HardwiredLints {}
7474

75-
#[macro_export]
76-
macro_rules! expand_combined_late_lint_pass_method {
77-
([$($pass:ident),*], $self: ident, $name: ident, $params:tt) => ({
78-
$($self.$pass.$name $params;)*
79-
})
80-
}
81-
8275
#[macro_export]
8376
macro_rules! expand_combined_late_lint_pass_methods {
8477
($passes:tt, [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
8578
$(fn $name(&mut self, context: &$crate::LateContext<'tcx>, $($param: $arg),*) {
86-
$crate::expand_combined_late_lint_pass_method!($passes, self, $name, (context, $($param),*));
79+
self.inner.$name(context$(, $param)*);
8780
})*
8881
)
8982
}
@@ -97,15 +90,23 @@ macro_rules! expand_combined_late_lint_pass_methods {
9790
macro_rules! declare_combined_late_lint_pass {
9891
([$v:vis $name:ident, [$($pass:ident: $constructor:expr,)*]], $methods:tt) => (
9992
#[allow(non_snake_case)]
100-
$v struct $name {
101-
$($pass: $pass,)*
93+
$v struct $name<'tcx> {
94+
inner: RuntimeCombinedLateLintPass<'tcx>,
10295
}
10396

104-
impl $name {
105-
$v fn new() -> Self {
106-
Self {
107-
$($pass: $constructor,)*
108-
}
97+
impl<'tcx> $name<'tcx> {
98+
$v fn new(tcx: TyCtxt<'tcx>) -> Self {
99+
let lints_that_dont_need_to_run = tcx.lints_that_dont_need_to_run(());
100+
let mut passes = vec![];
101+
$(passes.push(Box::new($constructor) as Box<dyn LateLintPass<'tcx>>);)*
102+
passes.retain(|pass| {
103+
let lints = (**pass).get_lints();
104+
// Lintless passes are always in
105+
lints.is_empty() ||
106+
// If the pass doesn't have a single needed lint, omit it
107+
!lints.iter().all(|lint| lints_that_dont_need_to_run.contains(&LintId::of(lint)))
108+
});
109+
$name { inner: RuntimeCombinedLateLintPass { passes } }
109110
}
110111

111112
$v fn get_lints() -> $crate::LintVec {
@@ -115,12 +116,12 @@ macro_rules! declare_combined_late_lint_pass {
115116
}
116117
}
117118

118-
impl<'tcx> $crate::LateLintPass<'tcx> for $name {
119+
impl<'tcx> $crate::LateLintPass<'tcx> for $name<'tcx> {
119120
$crate::expand_combined_late_lint_pass_methods!([$($pass),*], $methods);
120121
}
121122

122123
#[allow(rustc::lint_pass_impl_without_macro)]
123-
impl $crate::LintPass for $name {
124+
impl $crate::LintPass for $name<'_> {
124125
fn name(&self) -> &'static str {
125126
panic!()
126127
}

tests/ui/print_type_sizes/multiple_types.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ pub enum Enum {
1111
Small(SevenBytes),
1212
Large(FiftyBytes),
1313
}
14+
15+
fn main() {
16+
let x = Enum::Small(SevenBytes([0; 7]));
17+
let x = Enum::Large(FiftyBytes([0; 50]));
18+
}

tests/ui/print_type_sizes/padding.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,9 @@ enum E2 {
2626
A(i8, i32),
2727
B(S),
2828
}
29+
30+
fn main() {
31+
let s = S { a: true, b: true, g: 0 };
32+
let e1 = E1::A(0, 0);
33+
let e2 = E2::A(0, 0);
34+
}

tests/ui/print_type_sizes/repr-align.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,14 @@ pub struct S {
3030
c: A,
3131
d: i8,
3232
}
33+
34+
fn main() {
35+
let s = S {
36+
a: 0,
37+
b: 0,
38+
c: A(0),
39+
d: 0,
40+
};
41+
42+
let e = E::A(0);
43+
}

tests/ui/print_type_sizes/repr_int_c.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ enum Repru8 {
1717
A(u16),
1818
B,
1919
}
20+
21+
fn main() {
22+
let c = ReprCu8::A(0);
23+
let r = Repru8::A(0);
24+
}

tests/ui/print_type_sizes/variants.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ pub enum Enum {
1616
Small(SevenBytes),
1717
Large(FiftyBytes),
1818
}
19+
20+
fn main() {
21+
let x = Enum::Small(SevenBytes([0; 7]));
22+
let x = Enum::Large(FiftyBytes([0; 50]));
23+
}

tests/ui/traits/solver-cycles/129541-recursive-enum-and-array-impl.rs

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/ui/traits/solver-cycles/129541-recursive-enum-and-array-impl.stderr

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)