mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Auto merge of #5941 - ThibsG:InlineInCopyPassByRef, r=yaahc
Don't lint if it has always inline attribute Don't trigger the lint `trivially_copy_pass_by_ref` if it has `#[inline(always)]` attribute. Note: I am not particularly familiar with `inline` impacts, so I implemented this the way that if only `#[inline]` attribute is here (without `always`), the lint will still trigger. Also, it will still trigger if it has `#[inline(never)]`. Just tell me if it sounds too much conservative. Fixes: #5876 changelog: none
This commit is contained in:
commit
dd07860b83
@ -2,6 +2,7 @@ use std::cmp;
|
|||||||
|
|
||||||
use crate::utils::{is_copy, is_self_ty, snippet, span_lint_and_sugg};
|
use crate::utils::{is_copy, is_self_ty, snippet, span_lint_and_sugg};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
|
use rustc_ast::attr;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::intravisit::FnKind;
|
use rustc_hir::intravisit::FnKind;
|
||||||
@ -155,8 +156,12 @@ impl<'tcx> LateLintPass<'tcx> for TriviallyCopyPassByRef {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for a in attrs {
|
for a in attrs {
|
||||||
if a.meta_item_list().is_some() && a.has_name(sym!(proc_macro_derive)) {
|
if let Some(meta_items) = a.meta_item_list() {
|
||||||
return;
|
if a.has_name(sym!(proc_macro_derive))
|
||||||
|
|| (a.has_name(sym!(inline)) && attr::list_contains_name(&meta_items, sym!(always)))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -97,6 +97,24 @@ mod issue3992 {
|
|||||||
pub fn c(d: &u16) {}
|
pub fn c(d: &u16) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod issue5876 {
|
||||||
|
// Don't lint here as it is always inlined
|
||||||
|
#[inline(always)]
|
||||||
|
fn foo_always(x: &i32) {
|
||||||
|
println!("{}", x);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(never)]
|
||||||
|
fn foo_never(x: &i32) {
|
||||||
|
println!("{}", x);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn foo(x: &i32) {
|
||||||
|
println!("{}", x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let (mut foo, bar) = (Foo(0), Bar([0; 24]));
|
let (mut foo, bar) = (Foo(0), Bar([0; 24]));
|
||||||
let (mut a, b, c, x, y, z) = (0, 0, Bar([0; 24]), 0, Foo(0), 0);
|
let (mut a, b, c, x, y, z) = (0, 0, Bar([0; 24]), 0, Foo(0), 0);
|
||||||
|
@ -94,5 +94,17 @@ error: this argument (N byte) is passed by reference, but would be more efficien
|
|||||||
LL | fn trait_method2(&self, _color: &Color);
|
LL | fn trait_method2(&self, _color: &Color);
|
||||||
| ^^^^^^ help: consider passing by value instead: `Color`
|
| ^^^^^^ help: consider passing by value instead: `Color`
|
||||||
|
|
||||||
error: aborting due to 15 previous errors
|
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
|
||||||
|
|
|
||||||
|
LL | fn foo_never(x: &i32) {
|
||||||
|
| ^^^^ help: consider passing by value instead: `i32`
|
||||||
|
|
||||||
|
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:113:15
|
||||||
|
|
|
||||||
|
LL | fn foo(x: &i32) {
|
||||||
|
| ^^^^ help: consider passing by value instead: `i32`
|
||||||
|
|
||||||
|
error: aborting due to 17 previous errors
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user