Skip to content

Commit fc2f703

Browse files
committed
fulfill expectations in 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, `span_lint_hir_and_then` is called instead of `span_lint_and_help` to also fulfill expectations. fixes: #12802 changelog: fulfill expectations in `check_unsafe_derive_deserialize`
1 parent e669d97 commit fc2f703

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

clippy_lints/src/derive.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then};
1+
use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_sugg, span_lint_and_then, span_lint_hir_and_then};
22
use clippy_utils::ty::{implements_trait, implements_trait_with_env, is_copy};
33
use clippy_utils::{has_non_exhaustive_attr, is_lint_allowed, match_def_path, paths};
44
use rustc_errors::Applicability;
@@ -390,13 +390,17 @@ 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-
span_lint_and_help(
393+
span_lint_hir_and_then(
394394
cx,
395395
UNSAFE_DERIVE_DESERIALIZE,
396+
adt_hir_id,
396397
item.span,
397398
"you are deriving `serde::Deserialize` on a type that has methods using `unsafe`",
398-
None,
399-
"consider implementing `serde::Deserialize` manually. See https://serde.rs/impl-deserialize.html",
399+
|diag| {
400+
diag.help(
401+
"consider implementing `serde::Deserialize` manually. See https://serde.rs/impl-deserialize.html",
402+
);
403+
},
400404
);
401405
}
402406
}

0 commit comments

Comments
 (0)