Skip to content

Commit 0724b8d

Browse files
committed
Fix author lint + stop using symbols
1 parent 94064d4 commit 0724b8d

File tree

29 files changed

+57
-89
lines changed

29 files changed

+57
-89
lines changed

compiler/rustc_lint/src/late.rs

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_middle::hir::nested_filter;
2525
use rustc_middle::ty::{self, TyCtxt};
2626
use rustc_session::lint::LintPass;
2727
use rustc_session::Session;
28-
use rustc_span::{Span, Symbol};
28+
use rustc_span::Span;
2929

3030
use std::any::Any;
3131
use std::cell::Cell;
@@ -372,29 +372,33 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
372372
store.late_module_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();
373373

374374
// Filter unused lints
375-
let (lints_to_emit, lints_allowed) = &**tcx.lints_that_can_emit(());
375+
let lints_allowed = &**tcx.lints_that_can_emit(());
376376
// let lints_to_emit = &lints_that_can_emit.0;
377377
// let lints_allowed = &lints_that_can_emit.1;
378-
let passes_lints: Vec<_> = passes.iter().map(|pass| LintPass::get_lints(pass)).collect();
379378

380379
// Now, we'll filtered passes in a way that discards any lint that
381380
let mut filtered_passes: Vec<Box<dyn LateLintPass<'tcx>>> = passes
382381
.into_iter()
383-
.enumerate()
384-
.filter_map(|(i, pass)| {
385-
if passes_lints[i].iter().any(|&lint| {
386-
let symbol = Symbol::intern(lint.name);
387-
// ^^^ Expensive, but more expensive would be having to
388-
// cast every element to &str
389-
390-
lints_to_emit.contains(&symbol)
391-
|| (!lints_allowed.contains(&symbol)
392-
&& lint.default_level > crate::Level::Allow)
393-
}) {
394-
Some(pass)
395-
} else {
396-
None
397-
}
382+
.filter(|pass| {
383+
let pass = LintPass::get_lints(pass);
384+
pass.iter().any(|&lint| {
385+
let lint_name = &lint.name.to_lowercase()
386+
// Doing some calculations here to account for those separators
387+
[lint.name.find("::").unwrap_or(lint.name.len() - 2) + 2..];
388+
!lints_allowed.contains(&lint_name.to_string())
389+
&& lint.default_level != crate::Level::Allow
390+
})
391+
// if passes_lints[i].iter().any(|&lint| {
392+
// let symbol =
393+
// &lint.name.to_lowercase()
394+
// // Doing some calculations here to account for those separators
395+
// [lint.name.find("::").unwrap_or(lint.name.len() - 2) + 2..]
396+
397+
// // ^^^ Expensive, but more expensive would be having to
398+
// // cast every element to &str
399+
400+
// (!lints_allowed.contains(&lint.name)
401+
// && lint.default_level != crate::Level::Allow)
398402
})
399403
.collect();
400404

@@ -449,42 +453,25 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
449453
only_module: false,
450454
};
451455

452-
let (lints_to_emit, lints_allowed) = &**tcx.lints_that_can_emit(());
456+
let lints_allowed = &**tcx.lints_that_can_emit(());
453457
// let lints_to_emit = &lints_that_can_emit.0;
454458
// let lints_allowed = &lints_that_can_emit.1;
455-
let passes_lints: Vec<_> = passes.iter().map(|pass| LintPass::get_lints(pass)).collect();
456459

457460
// Now, we'll filtered passes in a way that discards any lint that
458461
let mut filtered_passes: Vec<Box<dyn LateLintPass<'tcx>>> = passes
459462
.into_iter()
460-
.enumerate()
461-
.filter_map(|(i, pass)| {
462-
if passes_lints[i].iter().any(|&lint| {
463-
let symbol = Symbol::intern(
464-
&lint.name.to_lowercase()
463+
.filter(|pass| {
464+
let pass = LintPass::get_lints(pass);
465+
pass.iter().any(|&lint| {
466+
let lint_name = &lint.name.to_lowercase()
465467
// Doing some calculations here to account for those separators
466-
[lint.name.find("::").unwrap_or(lint.name.len() - 2) + 2..],
467-
);
468-
469-
// ^^^ Expensive, but more expensive would be having to
470-
// cast every element to &str
471-
472-
lints_to_emit.contains(&symbol)
473-
|| (!lints_allowed.contains(&symbol)
474-
&& lint.default_level > crate::Level::Allow)
475-
}) {
476-
Some(pass)
477-
} else {
478-
None
479-
}
468+
[lint.name.find("::").unwrap_or(lint.name.len() - 2) + 2..];
469+
!lints_allowed.contains(&lint_name.to_string())
470+
&& lint.default_level != crate::Level::Allow
471+
})
480472
})
481473
.collect();
482474

483-
// filtered_passes may be empty in case of `#[allow(all)]`
484-
if filtered_passes.is_empty() {
485-
return;
486-
}
487-
488475
let pass = RuntimeCombinedLateLintPass { passes: &mut filtered_passes[..] };
489476
late_lint_crate_inner(tcx, context, pass);
490477
}

compiler/rustc_lint/src/levels.rs

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_ast as ast;
1717
use rustc_ast_pretty::pprust;
1818
use rustc_data_structures::{
1919
fx::FxIndexMap,
20-
sync::{join, par_for_each_in, Lock, Lrc},
20+
sync::{par_for_each_in, Lock},
2121
};
2222
use rustc_errors::{Diag, DiagMessage, LintDiagnostic, MultiSpan};
2323
use rustc_feature::{Features, GateIssue};
@@ -159,12 +159,12 @@ fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExp
159159
/// (and not allowed in the crate) and CLI lints. The returned value is a tuple
160160
/// of 1. The lints that will emit (or at least, should run), and 2.
161161
/// The lints that are allowed at the crate level and will not emit.
162-
pub fn lints_that_can_emit(tcx: TyCtxt<'_>, (): ()) -> Lrc<(Vec<Symbol>, Vec<Symbol>)> {
162+
pub fn lints_that_can_emit(tcx: TyCtxt<'_>, (): ()) -> Vec<String> {
163163
let mut visitor = LintLevelMinimum::new(tcx);
164164
visitor.process_opts();
165165
visitor.lint_level_minimums();
166166

167-
Lrc::new((visitor.lints_to_emit.into_inner(), visitor.lints_allowed.into_inner()))
167+
visitor.lints_allowed.into_inner()
168168
}
169169

170170
#[instrument(level = "trace", skip(tcx), ret)]
@@ -474,51 +474,29 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, QueryMapExpectationsWrapper<'
474474
struct LintLevelMinimum<'tcx> {
475475
tcx: TyCtxt<'tcx>,
476476
/// The actual list of detected lints.
477-
lints_to_emit: Lock<Vec<Symbol>>,
478-
lints_allowed: Lock<Vec<Symbol>>,
477+
lints_allowed: Lock<Vec<String>>,
479478
}
480479

481480
impl<'tcx> LintLevelMinimum<'tcx> {
482481
pub fn new(tcx: TyCtxt<'tcx>) -> Self {
483-
Self {
484-
tcx,
485-
// That magic number is the current number of lints + some more for possible future lints
486-
lints_to_emit: Lock::new(Vec::with_capacity(230)),
487-
lints_allowed: Lock::new(Vec::with_capacity(100)),
488-
}
482+
Self { tcx, lints_allowed: Lock::new(Vec::with_capacity(100)) }
489483
}
490484

491485
fn process_opts(&mut self) {
492486
for (lint, level) in &self.tcx.sess.opts.lint_opts {
493487
if *level == Level::Allow {
494-
self.lints_allowed
495-
.with_lock(|lints_allowed| lints_allowed.push(Symbol::intern(&lint)));
496-
} else {
497-
self.lints_to_emit
498-
.with_lock(|lints_to_emit| lints_to_emit.push(Symbol::intern(&lint)));
488+
self.lints_allowed.with_lock(|lints_allowed| lints_allowed.push(lint.to_string()));
499489
}
500490
}
501491
}
502492

503493
fn lint_level_minimums(&mut self) {
504-
join(
505-
|| {
506-
self.tcx.sess.psess.lints_that_can_emit.with_lock(|vec| {
507-
par_for_each_in(vec, |lint_symbol| {
508-
self.lints_to_emit
509-
.with_lock(|lints_to_emit| lints_to_emit.push(*lint_symbol));
510-
});
511-
});
512-
},
513-
|| {
514-
self.tcx.sess.psess.lints_allowed.with_lock(|vec| {
515-
par_for_each_in(vec, |lint_symbol| {
516-
self.lints_allowed
517-
.with_lock(|lints_allowed| lints_allowed.push(*lint_symbol));
518-
});
519-
});
520-
},
521-
);
494+
self.tcx.sess.psess.lints_allowed.with_lock(|vec| {
495+
par_for_each_in(vec, |lint_symbol| {
496+
self.lints_allowed
497+
.with_lock(|lints_allowed| lints_allowed.push(lint_symbol.to_string()));
498+
});
499+
});
522500
}
523501
}
524502

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ rustc_queries! {
431431
desc { "computing `#[expect]`ed lints in this crate" }
432432
}
433433

434-
query lints_that_can_emit(_: ()) -> &'tcx Lrc<(Vec<Symbol>, Vec<Symbol>)> {
434+
query lints_that_can_emit(_: ()) -> &'tcx Vec<String> {
435435
arena_cache
436436
desc { "Computing all lints that are explicitly enabled or with a default level great than Allow" }
437437
}

compiler/rustc_session/src/parse.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,10 @@ pub struct ParseSess {
232232
proc_macro_quoted_spans: AppendOnlyVec<Span>,
233233
/// Used to generate new `AttrId`s. Every `AttrId` is unique.
234234
pub attr_id_generator: AttrIdGenerator,
235-
/// All lints that can emit, even if not emitted (i.e. lints that are mentioned
236-
/// in e.g. #![warn] attributes)
237-
pub lints_that_can_emit: Lock<Vec<Symbol>>,
238235
/// The list of lints that cannot emit, maybe because they are allowed
239236
/// globally, or the default level is Allow and they are not activated
240237
/// manually
241-
pub lints_allowed: Lock<Vec<Symbol>>,
238+
pub lints_allowed: Lock<Vec<String>>,
242239
}
243240

244241
impl ParseSess {
@@ -273,7 +270,6 @@ impl ParseSess {
273270
assume_incomplete_release: false,
274271
proc_macro_quoted_spans: Default::default(),
275272
attr_id_generator: AttrIdGenerator::new(),
276-
lints_that_can_emit: Lock::new(Vec::with_capacity(230)),
277273
lints_allowed: Lock::new(Vec::with_capacity(100)),
278274
}
279275
}

src/tools/clippy/clippy_lints/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,8 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
640640
store.register_late_pass(|_| {
641641
Box::new(utils::internal_lints::almost_standard_lint_formulation::AlmostStandardFormulation::new())
642642
});
643+
store.register_late_pass(|_| Box::new(utils::author::Author));
644+
643645
}
644646

645647
store.register_late_pass(move |_| {
@@ -658,7 +660,6 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
658660
});
659661
store.register_early_pass(|| Box::<utils::format_args_collector::FormatArgsCollector>::default());
660662
store.register_late_pass(|_| Box::new(utils::dump_hir::DumpHir));
661-
store.register_late_pass(|_| Box::new(utils::author::Author));
662663
store.register_late_pass(move |_| {
663664
Box::new(await_holding_invalid::AwaitHolding::new(
664665
await_holding_invalid_types.clone(),

src/tools/clippy/clippy_lints/src/utils/author.rs renamed to src/tools/clippy/clippy_lints/src/utils/internal_lints/author.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_span::symbol::{Ident, Symbol};
1616
use std::cell::Cell;
1717
use std::fmt::{Display, Formatter, Write as _};
1818

19-
declare_lint_pass!(
19+
declare_clippy_lint!{
2020
/// ### What it does
2121
/// Generates clippy code that detects the offending pattern
2222
///
@@ -48,8 +48,13 @@ declare_lint_pass!(
4848
/// // report your lint here
4949
/// }
5050
/// ```
51-
Author => []
52-
);
51+
#[clippy::version = "1.0.0"]
52+
pub AUTHOR,
53+
internal,
54+
"The author lint, see documentation at <https://doc.rust-lang.org/nightly/clippy/development/adding_lints.html#author-lint>"
55+
};
56+
57+
declare_lint_pass! { Author => [AUTHOR] }
5358

5459
/// Writes a line of output with indentation added
5560
macro_rules! out {

src/tools/clippy/clippy_lints/src/utils/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
pub mod author;
21
pub mod dump_hir;
32
pub mod format_args_collector;
43
#[cfg(feature = "internal")]

src/tools/clippy/tests/ui/author.rs renamed to src/tools/clippy/tests/ui-internal/author.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![warn(clippy::author)]
2+
13
fn main() {
24
#[clippy::author]
35
let x: char = 0x45 as char;

0 commit comments

Comments
 (0)