Skip to content

Skip running all lints if --cap-lints allow is used #114026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/rustc_hir_analysis/src/check_unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ pub fn provide(providers: &mut Providers) {
}

fn check_unused_traits(tcx: TyCtxt<'_>, (): ()) {
if tcx.sess.opts.lint_cap.is_some_and(|cap| cap == rustc_session::lint::Allow) {
return;
}

let mut used_trait_imports = UnordSet::<LocalDefId>::default();

// FIXME: Use `tcx.hir().par_body_owners()` when we implement creating `DefId`s
Expand Down
20 changes: 18 additions & 2 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ fn pre_expansion_lint<'a>(
check_node: impl EarlyCheckNode<'a>,
node_name: Symbol,
) {
if sess.opts.lint_cap.is_some_and(|cap| cap == rustc_session::lint::Allow) {
return;
}

sess.prof.generic_activity_with_arg("pre_AST_expansion_lint_checks", node_name.as_str()).run(
|| {
rustc_lint::check_ast_node(
Expand Down Expand Up @@ -330,6 +334,10 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) {
rustc_ast_passes::feature_gate::check_crate(&krate, sess);
});

if sess.opts.lint_cap.is_some_and(|cap| cap == rustc_session::lint::Allow) {
return;
}

// Add all buffered lints from the `ParseSess` to the `Session`.
sess.parse_sess.buffered_lints.with_lock(|buffered_lints| {
info!("{} parse sess buffered_lints", buffered_lints.len());
Expand Down Expand Up @@ -841,8 +849,16 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
tcx.ensure().check_private_in_public(());
},
{
tcx.hir()
.par_for_each_module(|module| tcx.ensure().check_mod_deathness(module));
if !tcx
.sess
.opts
.lint_cap
.is_some_and(|cap| cap == rustc_session::lint::Allow)
{
tcx.hir().par_for_each_module(|module| {
tcx.ensure().check_mod_deathness(module)
});
}
},
{
sess.time("lint_checking", || {
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_lint/src/expect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {
return;
}

if tcx.sess.opts.lint_cap.is_some_and(|cap| cap == rustc_session::lint::Allow) {
return;
}

let lint_expectations = tcx.lint_expectations(());
let fulfilled_expectations = tcx.sess.diagnostic().steal_fulfilled_expectation_ids();

Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_lint/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ pub fn check_crate<'tcx, T: LateLintPass<'tcx> + 'tcx>(
tcx: TyCtxt<'tcx>,
builtin_lints: impl FnOnce() -> T + Send + DynSend,
) {
if tcx.sess.opts.lint_cap.is_some_and(|cap| cap == rustc_session::lint::Allow) {
return;
}

join(
|| {
tcx.sess.time("crate_lints", || {
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ impl Default for Options {
optimize: OptLevel::No,
debuginfo: DebugInfo::None,
lint_opts: Vec::new(),
lint_cap: None,
lint_cap: Some(lint::Allow),
describe_lints: false,
output_types: OutputTypes(BTreeMap::new()),
search_paths: vec![],
Expand Down Expand Up @@ -1787,7 +1787,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
}

pub fn get_cmd_lint_options(
handler: &EarlyErrorHandler,
_handler: &EarlyErrorHandler,
matches: &getopts::Matches,
) -> (Vec<(String, lint::Level)>, bool, Option<lint::Level>) {
let mut lint_opts_with_position = vec![];
Expand All @@ -1810,10 +1810,7 @@ pub fn get_cmd_lint_options(
.map(|(_, lint_name, level)| (lint_name, level))
.collect();

let lint_cap = matches.opt_str("cap-lints").map(|cap| {
lint::Level::from_str(&cap)
.unwrap_or_else(|| handler.early_error(format!("unknown lint level: `{cap}`")))
});
let lint_cap = Some(lint::Allow);

(lint_opts, describe_lints, lint_cap)
}
Expand Down