Skip to content

Commit 969a2cc

Browse files
committed
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.
1 parent ca98305 commit 969a2cc

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

compiler/rustc_lint/src/late.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,8 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
337337
hir_visit::walk_path(self, p);
338338
}
339339

340-
fn visit_attribute(&mut self, hir_id: hir::HirId, attr: &'tcx ast::Attribute) {
341-
self.with_lint_attrs(hir_id, |cx| {
342-
lint_callback!(cx, check_attribute, attr);
343-
})
340+
fn visit_attribute(&mut self, _hir_id: hir::HirId, attr: &'tcx ast::Attribute) {
341+
lint_callback!(self, check_attribute, attr);
344342
}
345343
}
346344

0 commit comments

Comments
 (0)