about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2022-06-15 17:44:53 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2022-06-16 09:51:48 +1000
commit969a2cc8c1e83ce93a13ab126c4519a72405bb69 (patch)
tree8cc8f0db26f6b0ba0dfd6819b720a2fc8ca0eff1 /compiler
parentca983054e19afd74d63c3ed37997f3bf30fe85d0 (diff)
downloadrust-969a2cc8c1e83ce93a13ab126c4519a72405bb69.tar.gz
rust-969a2cc8c1e83ce93a13ab126c4519a72405bb69.zip
Fix quadratic behaviour in the `MissingDoc` lint.
The `MissingDoc` lint has quadratic behaviour when processing doc comments.
This is a problem for large doc comments (e.g. 1000+ lines) when
`deny(missing_code)` is enabled.

A 1000-line doc comment using `//!` comments is represented as 1000 attributes
on an item. The lint machinery iterates over each attribute with
`visit_attribute`. `MissingDoc`'s impl of that function calls
`with_lint_attrs`, which calls `enter_attrs`, which iterates over all 1000
attributes looking for a `doc(hidden)` attribute. I.e. for every attribute we
iterate over all the other attributes.

The fix is simple: don't call `with_lint_attrs` on attributes. This makes
sense: `with_lint_attrs` is intended to iterate over the attributes on a
language fragment like a statement or expression, but it doesn't need to
be called on attributes themselves.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_lint/src/late.rs6
1 files changed, 2 insertions, 4 deletions
diff --git a/compiler/rustc_lint/src/late.rs b/compiler/rustc_lint/src/late.rs
index 772ab7fe226..9ca80334e05 100644
--- a/compiler/rustc_lint/src/late.rs
+++ b/compiler/rustc_lint/src/late.rs
@@ -337,10 +337,8 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
         hir_visit::walk_path(self, p);
     }
 
-    fn visit_attribute(&mut self, hir_id: hir::HirId, attr: &'tcx ast::Attribute) {
-        self.with_lint_attrs(hir_id, |cx| {
-            lint_callback!(cx, check_attribute, attr);
-        })
+    fn visit_attribute(&mut self, _hir_id: hir::HirId, attr: &'tcx ast::Attribute) {
+        lint_callback!(self, check_attribute, attr);
     }
 }