@@ -8,7 +8,6 @@ use if_chain::if_chain;
8
8
use rustc_ast:: { FloatTy , IntTy , LitFloatType , LitIntType , LitKind , UintTy } ;
9
9
use rustc_errors:: { Applicability , DiagnosticBuilder } ;
10
10
use rustc_hir as hir;
11
- use rustc_hir:: def:: Res ;
12
11
use rustc_hir:: intravisit:: { walk_body, walk_expr, walk_ty, FnKind , NestedVisitorMap , Visitor } ;
13
12
use rustc_hir:: {
14
13
BinOpKind , Block , Body , Expr , ExprKind , FnDecl , FnRetTy , FnSig , GenericArg , GenericBounds , GenericParamKind , HirId ,
@@ -33,9 +32,9 @@ use crate::consts::{constant, Constant};
33
32
use crate :: utils:: paths;
34
33
use crate :: utils:: sugg:: Sugg ;
35
34
use crate :: utils:: {
36
- clip, comparisons, differing_macro_contexts, higher, in_constant, indent_of, int_bits, is_type_diagnostic_item ,
37
- last_path_segment, match_def_path, match_path, meets_msrv, method_chain_args, multispan_sugg ,
38
- numeric_literal:: NumericLiteral , qpath_res, reindent_multiline, sext, snippet, snippet_opt,
35
+ clip, comparisons, differing_macro_contexts, higher, in_constant, indent_of, int_bits, is_hir_ty_cfg_dependant ,
36
+ is_type_diagnostic_item , last_path_segment, match_def_path, match_path, meets_msrv, method_chain_args,
37
+ multispan_sugg , numeric_literal:: NumericLiteral , qpath_res, reindent_multiline, sext, snippet, snippet_opt,
39
38
snippet_with_applicability, snippet_with_macro_callsite, span_lint, span_lint_and_help, span_lint_and_sugg,
40
39
span_lint_and_then, unsext,
41
40
} ;
@@ -1282,8 +1281,8 @@ declare_clippy_lint! {
1282
1281
}
1283
1282
1284
1283
declare_clippy_lint ! {
1285
- /// **What it does:** Checks for casts from a less-strictly-aligned pointer to a
1286
- /// more-strictly-aligned pointer
1284
+ /// **What it does:** Checks for casts, using `as` or ` pointer::cast`,
1285
+ /// from a less-strictly-aligned pointer to a more-strictly-aligned pointer
1287
1286
///
1288
1287
/// **Why is this bad?** Dereferencing the resulting pointer may be undefined
1289
1288
/// behavior.
@@ -1296,6 +1295,9 @@ declare_clippy_lint! {
1296
1295
/// ```rust
1297
1296
/// let _ = (&1u8 as *const u8) as *const u16;
1298
1297
/// let _ = (&mut 1u8 as *mut u8) as *mut u16;
1298
+ ///
1299
+ /// (&1u8 as *const u8).cast::<u16>();
1300
+ /// (&mut 1u8 as *mut u8).cast::<u16>();
1299
1301
/// ```
1300
1302
pub CAST_PTR_ALIGNMENT ,
1301
1303
pedantic,
@@ -1725,18 +1727,6 @@ fn get_numeric_literal<'e>(expr: &'e Expr<'e>) -> Option<&'e Lit> {
1725
1727
}
1726
1728
}
1727
1729
1728
- fn is_hir_ty_cfg_dependant ( cx : & LateContext < ' _ > , ty : & hir:: Ty < ' _ > ) -> bool {
1729
- if_chain ! {
1730
- if let TyKind :: Path ( QPath :: Resolved ( _, path) ) = ty. kind;
1731
- if let Res :: Def ( _, def_id) = path. res;
1732
- then {
1733
- cx. tcx. has_attr( def_id, sym:: cfg) || cx. tcx. has_attr( def_id, sym:: cfg_attr)
1734
- } else {
1735
- false
1736
- }
1737
- }
1738
- }
1739
-
1740
1730
fn show_unnecessary_cast ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > , literal_str : & str , cast_from : Ty < ' _ > , cast_to : Ty < ' _ > ) {
1741
1731
let literal_kind_name = if cast_from. is_integral ( ) { "integer" } else { "float" } ;
1742
1732
span_lint_and_sugg (
0 commit comments