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

Commit ae29230

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 ebcf860 + 21c2cf4 commit ae29230

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
@@ -302,12 +302,12 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
302302
// `check_foo` method in `$methods` within this pass simply calls `check_foo`
303303
// once per `$pass`. Compare with `declare_combined_late_lint_pass`, which is
304304
// similar, but combines lint passes at compile time.
305-
struct RuntimeCombinedLateLintPass<'a, 'tcx> {
306-
passes: &'a mut [LateLintPassObject<'tcx>],
305+
struct RuntimeCombinedLateLintPass<'tcx> {
306+
passes: Vec<LateLintPassObject<'tcx>>,
307307
}
308308

309309
#[allow(rustc::lint_pass_impl_without_macro)]
310-
impl LintPass for RuntimeCombinedLateLintPass<'_, '_> {
310+
impl LintPass for RuntimeCombinedLateLintPass<'_> {
311311
fn name(&self) -> &'static str {
312312
panic!()
313313
}
@@ -318,7 +318,7 @@ impl LintPass for RuntimeCombinedLateLintPass<'_, '_> {
318318

319319
macro_rules! impl_late_lint_pass {
320320
([], [$($(#[$attr:meta])* fn $f:ident($($param:ident: $arg:ty),*);)*]) => {
321-
impl<'tcx> LateLintPass<'tcx> for RuntimeCombinedLateLintPass<'_, 'tcx> {
321+
impl<'tcx> LateLintPass<'tcx> for RuntimeCombinedLateLintPass<'tcx> {
322322
$(fn $f(&mut self, context: &LateContext<'tcx>, $($param: $arg),*) {
323323
for pass in self.passes.iter_mut() {
324324
pass.$f(context, $($param),*);
@@ -355,14 +355,14 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
355355
late_lint_mod_inner(tcx, module_def_id, context, builtin_lints);
356356
} else {
357357
let builtin_lints = Box::new(builtin_lints) as Box<dyn LateLintPass<'tcx>>;
358-
let mut binding = store
358+
let passes = store
359359
.late_module_passes
360360
.iter()
361361
.map(|mk_pass| (mk_pass)(tcx))
362362
.chain(std::iter::once(builtin_lints))
363363
.collect::<Vec<_>>();
364364

365-
let pass = RuntimeCombinedLateLintPass { passes: binding.as_mut_slice() };
365+
let pass = RuntimeCombinedLateLintPass { passes };
366366
late_lint_mod_inner(tcx, module_def_id, context, pass);
367367
}
368368
}
@@ -393,10 +393,10 @@ fn late_lint_mod_inner<'tcx, T: LateLintPass<'tcx>>(
393393

394394
fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
395395
// Note: `passes` is often empty.
396-
let passes: Vec<_> =
396+
let unfiltered_passes: Vec<_> =
397397
unerased_lint_store(tcx.sess).late_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();
398398

399-
if passes.is_empty() {
399+
if unfiltered_passes.is_empty() {
400400
return;
401401
}
402402

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

414414
let lints_that_dont_need_to_run = tcx.lints_that_dont_need_to_run(());
415415

416-
let mut filtered_passes: Vec<Box<dyn LateLintPass<'tcx>>> = passes
416+
let mut passes: Vec<Box<dyn LateLintPass<'tcx>>> = unfiltered_passes
417417
.into_iter()
418418
.filter(|pass| {
419419
let lints = (**pass).get_lints();
@@ -424,8 +424,8 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
424424
})
425425
.collect();
426426

427-
filtered_passes.push(Box::new(HardwiredLints));
428-
let pass = RuntimeCombinedLateLintPass { passes: &mut filtered_passes[..] };
427+
passes.push(Box::new(HardwiredLints));
428+
let pass = RuntimeCombinedLateLintPass { passes };
429429
late_lint_crate_inner(tcx, context, pass);
430430
}
431431

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)