about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
diff options
context:
space:
mode:
authorblyxyas <blyxyas@gmail.com>2024-02-09 19:15:40 +0100
committerblyxyas <blyxyas@gmail.com>2024-02-09 19:15:40 +0100
commite59d9b171ed276ede55765c63c75381b47549e07 (patch)
tree4a9f85d385ab9181a0295d2296fac7bdcf8f613b /compiler/rustc_lint/src
parent8fb67fb37fed736cb04f307473af7c863be224fb (diff)
downloadrust-e59d9b171ed276ede55765c63c75381b47549e07.tar.gz
rust-e59d9b171ed276ede55765c63c75381b47549e07.zip
Avoid a collection and iteration on empty passes
Diffstat (limited to 'compiler/rustc_lint/src')
-rw-r--r--compiler/rustc_lint/src/late.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/compiler/rustc_lint/src/late.rs b/compiler/rustc_lint/src/late.rs
index caa01556591..773baf2eaca 100644
--- a/compiler/rustc_lint/src/late.rs
+++ b/compiler/rustc_lint/src/late.rs
@@ -364,14 +364,14 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
     // Note: `passes` is often empty. In that case, it's faster to run
     // `builtin_lints` directly rather than bundling it up into the
     // `RuntimeCombinedLateLintPass`.
-    let mut passes: Vec<_> = unerased_lint_store(tcx.sess)
-        .late_module_passes
-        .iter()
-        .map(|mk_pass| (mk_pass)(tcx))
-        .collect();
-    if passes.is_empty() {
+    let late_module_passes = &unerased_lint_store(tcx.sess).late_module_passes;
+    if late_module_passes.is_empty() {
         late_lint_mod_inner(tcx, module_def_id, context, builtin_lints);
     } else {
+        let mut passes: Vec<_> = late_module_passes
+            .iter()
+            .map(|mk_pass| (mk_pass)(tcx))
+            .collect();
         passes.push(Box::new(builtin_lints));
         let pass = RuntimeCombinedLateLintPass { passes: &mut passes[..] };
         late_lint_mod_inner(tcx, module_def_id, context, pass);