diff options
| author | Philipp Krones <hello@philkrones.com> | 2023-08-24 21:32:12 +0200 |
|---|---|---|
| committer | Philipp Krones <hello@philkrones.com> | 2023-08-24 21:32:12 +0200 |
| commit | cc61aeea54138d3d037452754456539cf4ae6192 (patch) | |
| tree | 81856c22858c5d42f7d7e8edfda44340f708cb9a /clippy_lints/src/casts | |
| parent | 32eecd4b884dd2901aad05d66d78ea643a896e25 (diff) | |
| download | rust-cc61aeea54138d3d037452754456539cf4ae6192.tar.gz rust-cc61aeea54138d3d037452754456539cf4ae6192.zip | |
Merge commit '080b587854a73f2a8cbaecff1884860a78e2ff37' into clippyup
Diffstat (limited to 'clippy_lints/src/casts')
| -rw-r--r-- | clippy_lints/src/casts/cast_ptr_alignment.rs | 6 | ||||
| -rw-r--r-- | clippy_lints/src/casts/mod.rs | 2 |
2 files changed, 5 insertions, 3 deletions
diff --git a/clippy_lints/src/casts/cast_ptr_alignment.rs b/clippy_lints/src/casts/cast_ptr_alignment.rs index 5bf467efa0f..1de69122101 100644 --- a/clippy_lints/src/casts/cast_ptr_alignment.rs +++ b/clippy_lints/src/casts/cast_ptr_alignment.rs @@ -5,6 +5,7 @@ use rustc_hir::{Expr, ExprKind, GenericArg}; use rustc_lint::LateContext; use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, Ty}; +use rustc_span::sym; use super::CAST_PTR_ALIGNMENT; @@ -76,13 +77,14 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { ExprKind::Call(func, [arg, ..]) if arg.hir_id == e.hir_id => { static PATHS: &[&[&str]] = &[ paths::PTR_READ_UNALIGNED.as_slice(), - paths::PTR_WRITE_UNALIGNED.as_slice(), paths::PTR_UNALIGNED_VOLATILE_LOAD.as_slice(), paths::PTR_UNALIGNED_VOLATILE_STORE.as_slice(), ]; + if let ExprKind::Path(path) = &func.kind && let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id() - && match_any_def_paths(cx, def_id, PATHS).is_some() + && (match_any_def_paths(cx, def_id, PATHS).is_some() + || cx.tcx.is_diagnostic_item(sym::ptr_write_unaligned, def_id)) { true } else { diff --git a/clippy_lints/src/casts/mod.rs b/clippy_lints/src/casts/mod.rs index d34de305f5d..88ffbb55486 100644 --- a/clippy_lints/src/casts/mod.rs +++ b/clippy_lints/src/casts/mod.rs @@ -418,7 +418,7 @@ declare_clippy_lint! { /// let mut_ptr = ptr.cast_mut(); /// let ptr = mut_ptr.cast_const(); /// ``` - #[clippy::version = "1.71.0"] + #[clippy::version = "1.72.0"] pub PTR_CAST_CONSTNESS, pedantic, "casting using `as` from and to raw pointers to change constness when specialized methods apply" |
