Don't lint if it has always inline attribute

This commit is contained in:
ThibsG 2020-08-22 10:35:18 +02:00
parent a8520b0636
commit 191b6c798f
3 changed files with 38 additions and 3 deletions

View file

@ -2,6 +2,7 @@ use std::cmp;
use crate::utils::{is_copy, is_self_ty, snippet, span_lint_and_sugg};
use if_chain::if_chain;
use rustc_ast::attr;
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::intravisit::FnKind;
@ -155,8 +156,12 @@ impl<'tcx> LateLintPass<'tcx> for TriviallyCopyPassByRef {
return;
}
for a in attrs {
if a.meta_item_list().is_some() && a.has_name(sym!(proc_macro_derive)) {
return;
if let Some(meta_items) = a.meta_item_list() {
if a.has_name(sym!(proc_macro_derive))
|| (a.has_name(sym!(inline)) && attr::list_contains_name(&meta_items, sym!(always)))
{
return;
}
}
}
},

View file

@ -97,6 +97,24 @@ mod issue3992 {
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() {
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);

View file

@ -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);
| ^^^^^^ 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