Skip to content

Commit

Permalink
check if expectation can be fulfilled in `check_unsafe_derive_deseria…
Browse files Browse the repository at this point in the history
…lize`

This commit adds fulfilling expectations to `check_unsafe_derive_deserialize`.

The utility function `clippy_utils::fulfill_or_allowed` is not used because
using it would require to move the check for allowed after the check
iterating over all inherent impls of the type, doing possibly
unnecessary work.
Instead, `is_lint_allowed` is called as before, but additionally, once
certain that the lint should be emitted, expectations are checked and
fulfilled if found. In that case actually emitting the lint is skipped.

fixes: rust-lang#12802

changelog: fulfill expectations in `check_unsafe_derive_deserialize`
  • Loading branch information
B14CK313 committed May 15, 2024
1 parent c58b6e6 commit 0f1e402
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion clippy_lints/src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, Visitor};
use rustc_hir::{
self as hir, BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, Impl, Item, ItemKind, UnsafeSource, Unsafety,
};
use rustc_lint::{LateContext, LateLintPass};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::hir::nested_filter;
use rustc_middle::traits::Reveal;
use rustc_middle::ty::{
Expand Down Expand Up @@ -390,6 +390,12 @@ fn check_unsafe_derive_deserialize<'tcx>(
.map(|imp_did| cx.tcx.hir().expect_item(imp_did.expect_local()))
.any(|imp| has_unsafe(cx, imp))
{
let (level, _) = cx.tcx.lint_level_at_node(UNSAFE_DERIVE_DESERIALIZE, adt_hir_id);
if let Some(expectation) = level.get_expectation_id() {
cx.fulfill_expectation(expectation);
return;
}

span_lint_and_help(
cx,
UNSAFE_DERIVE_DESERIALIZE,
Expand Down

0 comments on commit 0f1e402

Please sign in to comment.