1
Fork 0

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 <david.wood@huawei.com>
This commit is contained in:
David Wood 2022-06-22 11:25:10 +01:00
parent 7702ae16a2
commit 871c879bff

View file

@ -406,9 +406,12 @@ impl LateLintPass<'_> for Diagnostics {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
let Some((span, def_id, substs)) = typeck_results_of_method_fn(cx, expr) else { return }; let Some((span, def_id, substs)) = typeck_results_of_method_fn(cx, expr) else { return };
debug!(?span, ?def_id, ?substs); debug!(?span, ?def_id, ?substs);
if let Ok(Some(instance)) = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, substs) && let has_attr = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, substs)
!cx.tcx.has_attr(instance.def_id(), sym::rustc_lint_diagnostics) .ok()
{ .and_then(|inst| inst)
.map(|inst| cx.tcx.has_attr(inst.def_id(), sym::rustc_lint_diagnostics))
.unwrap_or(false);
if !has_attr {
return; return;
} }