Skip to content

Commit 756bbec

Browse files
committed
Auto merge of #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 0b63477 + e4b3df9 commit 756bbec

File tree

11 files changed

+86
-47
lines changed

11 files changed

+86
-47
lines changed

compiler/rustc_index/src/idx.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,15 @@ impl Idx for u32 {
4343
self as usize
4444
}
4545
}
46+
47+
impl Idx for u8 {
48+
#[inline]
49+
fn new(idx: usize) -> Self {
50+
assert!(idx <= u8::MAX as usize);
51+
idx as u8
52+
}
53+
#[inline]
54+
fn index(self) -> usize {
55+
self as usize
56+
}
57+
}

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+
struct RuntimeCombinedLateLintPass<'tcx> {
311+
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#![feature(if_let_guard)]
3131
#![feature(iter_order_by)]
3232
#![feature(let_chains)]
33+
#![feature(macro_metavar_expr)]
3334
#![feature(rustc_attrs)]
3435
#![feature(rustdoc_internals)]
3536
#![feature(trait_upcasting)]
@@ -146,7 +147,7 @@ pub fn provide(providers: &mut Providers) {
146147
}
147148

148149
fn lint_mod(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
149-
late_lint_mod(tcx, module_def_id, BuiltinCombinedModuleLateLintPass::new());
150+
late_lint_mod(tcx, module_def_id, BuiltinCombinedModuleLateLintPass::new(tcx));
150151
}
151152

152153
early_lint_methods!(

compiler/rustc_lint/src/passes.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ impl LateLintPass<'_> for HardwiredLints {}
7575
#[macro_export]
7676
macro_rules! expand_combined_late_lint_pass_method {
7777
([$($pass:ident),*], $self: ident, $name: ident, $params:tt) => ({
78-
$($self.$pass.$name $params;)*
78+
$(
79+
if $self.enabled_passes.contains(EnabledPasses::$pass as u8) {
80+
$self.$pass.$name $params;
81+
}
82+
)*
7983
})
8084
}
8185

@@ -96,15 +100,37 @@ macro_rules! expand_combined_late_lint_pass_methods {
96100
#[macro_export]
97101
macro_rules! declare_combined_late_lint_pass {
98102
([$v:vis $name:ident, [$($pass:ident: $constructor:expr,)*]], $methods:tt) => (
103+
#[repr(u8)]
104+
enum EnabledPasses {
105+
$($pass,)*
106+
}
107+
99108
#[allow(non_snake_case)]
100109
$v struct $name {
110+
enabled_passes: rustc_index::bit_set::BitSet<u8>,
101111
$($pass: $pass,)*
102112
}
103113

104114
impl $name {
105-
$v fn new() -> Self {
115+
#[allow(non_snake_case)]
116+
$v fn new<'tcx>(tcx: TyCtxt<'tcx>) -> Self {
117+
let mut enabled_passes = rustc_index::bit_set::BitSet::new_filled(${count($pass)});
118+
let lints_that_dont_need_to_run = tcx.lints_that_dont_need_to_run(());
119+
$(
120+
let $pass = $constructor;
121+
{
122+
let lints = $pass.get_lints();
123+
// If the pass doesn't have a single needed lint, omit it.
124+
if !lints.is_empty()
125+
&& lints.iter().all(|lint| lints_that_dont_need_to_run.contains(&LintId::of(lint)))
126+
{
127+
enabled_passes.remove(EnabledPasses::$pass as u8);
128+
}
129+
}
130+
)*
106131
Self {
107-
$($pass: $constructor,)*
132+
enabled_passes,
133+
$($pass,)*
108134
}
109135
}
110136

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)