Skip to content

Commit 871c879

Browse files
committed
lint: fix condition in diagnostic lints
Unfortunately, the diagnostic lints are very broken and trigger much more often than they should. Correct the conditional which checks if the function call being made is to a diagnostic function so that it returns in every intended case. Signed-off-by: David Wood <[email protected]>
1 parent 7702ae1 commit 871c879

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

compiler/rustc_lint/src/internal.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,12 @@ impl LateLintPass<'_> for Diagnostics {
406406
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
407407
let Some((span, def_id, substs)) = typeck_results_of_method_fn(cx, expr) else { return };
408408
debug!(?span, ?def_id, ?substs);
409-
if let Ok(Some(instance)) = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, substs) &&
410-
!cx.tcx.has_attr(instance.def_id(), sym::rustc_lint_diagnostics)
411-
{
409+
let has_attr = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, substs)
410+
.ok()
411+
.and_then(|inst| inst)
412+
.map(|inst| cx.tcx.has_attr(inst.def_id(), sym::rustc_lint_diagnostics))
413+
.unwrap_or(false);
414+
if !has_attr {
412415
return;
413416
}
414417

0 commit comments

Comments
 (0)