Skip to content

Commit 0f1e402

Browse files
committed
check if expectation can be fulfilled in check_unsafe_derive_deserialize
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`
1 parent c58b6e6 commit 0f1e402

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

clippy_lints/src/derive.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, Visitor};
77
use rustc_hir::{
88
self as hir, BlockCheckMode, BodyId, Expr, ExprKind, FnDecl, Impl, Item, ItemKind, UnsafeSource, Unsafety,
99
};
10-
use rustc_lint::{LateContext, LateLintPass};
10+
use rustc_lint::{LateContext, LateLintPass, LintContext};
1111
use rustc_middle::hir::nested_filter;
1212
use rustc_middle::traits::Reveal;
1313
use rustc_middle::ty::{
@@ -390,6 +390,12 @@ fn check_unsafe_derive_deserialize<'tcx>(
390390
.map(|imp_did| cx.tcx.hir().expect_item(imp_did.expect_local()))
391391
.any(|imp| has_unsafe(cx, imp))
392392
{
393+
let (level, _) = cx.tcx.lint_level_at_node(UNSAFE_DERIVE_DESERIALIZE, adt_hir_id);
394+
if let Some(expectation) = level.get_expectation_id() {
395+
cx.fulfill_expectation(expectation);
396+
return;
397+
}
398+
393399
span_lint_and_help(
394400
cx,
395401
UNSAFE_DERIVE_DESERIALIZE,

0 commit comments

Comments
 (0)