1
- use std:: { cmp, iter} ;
2
-
3
1
use clippy_config:: Conf ;
4
2
use clippy_utils:: diagnostics:: span_lint_and_sugg;
5
3
use clippy_utils:: source:: snippet;
@@ -15,11 +13,12 @@ use rustc_hir::{BindingMode, Body, FnDecl, Impl, ItemKind, MutTy, Mutability, No
15
13
use rustc_lint:: { LateContext , LateLintPass } ;
16
14
use rustc_middle:: ty:: adjustment:: { Adjust , PointerCoercion } ;
17
15
use rustc_middle:: ty:: layout:: LayoutOf ;
18
- use rustc_middle:: ty:: { self , RegionKind , TyCtxt } ;
16
+ use rustc_middle:: ty:: { self , RegionKind } ;
19
17
use rustc_session:: impl_lint_pass;
20
18
use rustc_span:: def_id:: LocalDefId ;
21
19
use rustc_span:: { sym, Span } ;
22
20
use rustc_target:: spec:: abi:: Abi ;
21
+ use std:: iter;
23
22
24
23
declare_clippy_lint ! {
25
24
/// ### What it does
@@ -33,13 +32,12 @@ declare_clippy_lint! {
33
32
/// registers.
34
33
///
35
34
/// ### Known problems
36
- /// This lint is target register size dependent, it is
37
- /// limited to 32-bit to try and reduce portability problems between 32 and
38
- /// 64-bit, but if you are compiling for 8 or 16-bit targets then the limit
39
- /// will be different.
35
+ /// Certain types can be different sizes depending on the target platform,
36
+ /// e.g. `&(usize, usize)` may lint on a 32-bit target but not a 64-bit target.
40
37
///
41
38
/// The configuration option `trivial_copy_size_limit` can be set to override
42
- /// this limit for a project.
39
+ /// this limit for a project. The default limit is target independent to try
40
+ /// and reduce portability problems between 32-bit and 64-bit targets.
43
41
///
44
42
/// This lint attempts to allow passing arguments by reference if a reference
45
43
/// to that argument is returned. This is implemented by comparing the lifetime
@@ -111,20 +109,9 @@ pub struct PassByRefOrValue {
111
109
}
112
110
113
111
impl < ' tcx > PassByRefOrValue {
114
- pub fn new ( tcx : TyCtxt < ' _ > , conf : & ' static Conf ) -> Self {
115
- let ref_min_size = conf. trivial_copy_size_limit . unwrap_or_else ( || {
116
- let bit_width = u64:: from ( tcx. sess . target . pointer_width ) ;
117
- // Cap the calculated bit width at 32-bits to reduce
118
- // portability problems between 32 and 64-bit targets
119
- let bit_width = cmp:: min ( bit_width, 32 ) ;
120
- #[ expect( clippy:: integer_division) ]
121
- let byte_width = bit_width / 8 ;
122
- // Use a limit of 2 times the register byte width
123
- byte_width * 2
124
- } ) ;
125
-
112
+ pub fn new ( conf : & ' static Conf ) -> Self {
126
113
Self {
127
- ref_min_size,
114
+ ref_min_size : conf . trivial_copy_size_limit ,
128
115
value_max_size : conf. pass_by_value_size_limit ,
129
116
avoid_breaking_exported_api : conf. avoid_breaking_exported_api ,
130
117
}
0 commit comments