mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
Use break api config for pass by value or ref
This commit is contained in:
parent
d7f47f280e
commit
ee79077d80
3 changed files with 13 additions and 9 deletions
|
@ -1947,6 +1947,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||
let pass_by_ref_or_value = pass_by_ref_or_value::PassByRefOrValue::new(
|
||||
conf.trivial_copy_size_limit,
|
||||
conf.pass_by_value_size_limit,
|
||||
conf.avoid_breaking_exported_api,
|
||||
&sess.target,
|
||||
);
|
||||
store.register_late_pass(move || box pass_by_ref_or_value);
|
||||
|
|
|
@ -102,10 +102,16 @@ declare_clippy_lint! {
|
|||
pub struct PassByRefOrValue {
|
||||
ref_min_size: u64,
|
||||
value_max_size: u64,
|
||||
avoid_breaking_exported_api: bool,
|
||||
}
|
||||
|
||||
impl<'tcx> PassByRefOrValue {
|
||||
pub fn new(ref_min_size: Option<u64>, value_max_size: u64, target: &Target) -> Self {
|
||||
pub fn new(
|
||||
ref_min_size: Option<u64>,
|
||||
value_max_size: u64,
|
||||
avoid_breaking_exported_api: bool,
|
||||
target: &Target,
|
||||
) -> Self {
|
||||
let ref_min_size = ref_min_size.unwrap_or_else(|| {
|
||||
let bit_width = u64::from(target.pointer_width);
|
||||
// Cap the calculated bit width at 32-bits to reduce
|
||||
|
@ -120,10 +126,14 @@ impl<'tcx> PassByRefOrValue {
|
|||
Self {
|
||||
ref_min_size,
|
||||
value_max_size,
|
||||
avoid_breaking_exported_api,
|
||||
}
|
||||
}
|
||||
|
||||
fn check_poly_fn(&mut self, cx: &LateContext<'tcx>, hir_id: HirId, decl: &FnDecl<'_>, span: Option<Span>) {
|
||||
if self.avoid_breaking_exported_api && cx.access_levels.is_exported(hir_id) {
|
||||
return;
|
||||
}
|
||||
let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
|
||||
|
||||
let fn_sig = cx.tcx.fn_sig(fn_def_id);
|
||||
|
@ -184,7 +194,6 @@ impl<'tcx> PassByRefOrValue {
|
|||
}
|
||||
|
||||
if_chain! {
|
||||
if !cx.access_levels.is_exported(hir_id);
|
||||
if is_copy(cx, ty);
|
||||
if !is_self_ty(input);
|
||||
if let Some(size) = cx.layout_of(ty).ok().map(|l| l.size.bytes());
|
||||
|
|
|
@ -88,12 +88,6 @@ error: this argument (N byte) is passed by reference, but would be more efficien
|
|||
LL | fn trait_method(&self, _foo: &Foo);
|
||||
| ^^^^ help: consider passing by value instead: `Foo`
|
||||
|
||||
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:80:37
|
||||
|
|
||||
LL | fn trait_method2(&self, _color: &Color);
|
||||
| ^^^^^^ help: consider passing by value instead: `Color`
|
||||
|
||||
error: this argument (N byte) is passed by reference, but would be more efficient if passed by value (limit: N byte)
|
||||
--> $DIR/trivially_copy_pass_by_ref.rs:108:21
|
||||
|
|
||||
|
@ -106,5 +100,5 @@ error: this argument (N byte) is passed by reference, but would be more efficien
|
|||
LL | fn foo(x: &i32) {
|
||||
| ^^^^ help: consider passing by value instead: `i32`
|
||||
|
||||
error: aborting due to 17 previous errors
|
||||
error: aborting due to 16 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue