Skip to content

Commit 1afeb71

Browse files
committed
Track msrv attribute for manual_bits and borrow_as_prt
1 parent 9e78585 commit 1afeb71

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

clippy_lints/src/borrow_as_ptr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::{meets_msrv, msrvs};
55
use if_chain::if_chain;
66
use rustc_errors::Applicability;
77
use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability, TyKind};
8-
use rustc_lint::{LateContext, LateLintPass};
8+
use rustc_lint::{LateContext, LateLintPass, LintContext};
99
use rustc_semver::RustcVersion;
1010
use rustc_session::{declare_tool_lint, impl_lint_pass};
1111

@@ -94,4 +94,6 @@ impl<'tcx> LateLintPass<'tcx> for BorrowAsPtr {
9494
}
9595
}
9696
}
97+
98+
extract_msrv_attr!(LateContext);
9799
}

clippy_lints/src/manual_bits.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use clippy_utils::{match_def_path, meets_msrv, msrvs, paths};
44
use rustc_ast::ast::LitKind;
55
use rustc_errors::Applicability;
66
use rustc_hir::{BinOpKind, Expr, ExprKind, GenericArg, QPath};
7-
use rustc_lint::{LateContext, LateLintPass};
7+
use rustc_lint::{LateContext, LateLintPass, LintContext};
88
use rustc_middle::ty::{self, Ty};
99
use rustc_semver::RustcVersion;
1010
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -72,6 +72,8 @@ impl<'tcx> LateLintPass<'tcx> for ManualBits {
7272
}
7373
}
7474
}
75+
76+
extract_msrv_attr!(LateContext);
7577
}
7678

7779
fn get_one_size_of_ty<'tcx>(

clippy_lints/src/utils/conf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ define_Conf! {
156156
///
157157
/// Suppress lints whenever the suggested change would cause breakage for other crates.
158158
(avoid_breaking_exported_api: bool = true),
159-
/// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE.
159+
/// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS.
160160
///
161161
/// The minimum rust version that the project supports
162162
(msrv: Option<String> = None),

tests/ui-toml/min_rust_version/min_rust_version.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#![allow(clippy::redundant_clone)]
2-
#![warn(clippy::manual_non_exhaustive)]
1+
#![allow(clippy::redundant_clone, clippy::unnecessary_operation)]
2+
#![warn(clippy::manual_non_exhaustive, clippy::borrow_as_ptr, clippy::manual_bits)]
33

4+
use std::mem::{size_of, size_of_val};
45
use std::ops::Deref;
56

67
mod enums {
@@ -73,11 +74,25 @@ fn map_clone_suggest_copied() {
7374
let _: Option<u64> = Some(&16).map(|b| *b);
7475
}
7576

77+
fn borrow_as_ptr() {
78+
let val = 1;
79+
let _p = &val as *const i32;
80+
81+
let mut val_mut = 1;
82+
let _p_mut = &mut val_mut as *mut i32;
83+
}
84+
85+
fn manual_bits() {
86+
size_of::<i8>() * 8;
87+
size_of_val(&0u32) * 8;
88+
}
89+
7690
fn main() {
7791
option_as_ref_deref();
7892
match_like_matches();
7993
match_same_arms();
8094
match_same_arms2();
8195
manual_strip_msrv();
8296
check_index_refutable_slice();
97+
borrow_as_ptr();
8398
}

tests/ui-toml/min_rust_version/min_rust_version.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: you are using an explicit closure for copying elements
2-
--> $DIR/min_rust_version.rs:73:26
2+
--> $DIR/min_rust_version.rs:74:26
33
|
44
LL | let _: Option<u64> = Some(&16).map(|b| *b);
55
| ^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `Some(&16).cloned()`

0 commit comments

Comments
 (0)