[unnecessary_mut_passed]: don't lint in macro expansions

This commit is contained in:
y21 2023-07-31 21:09:52 +02:00
parent 29730969b1
commit dc1e8b0dd9
3 changed files with 23 additions and 5 deletions

View file

@ -37,6 +37,11 @@ declare_lint_pass!(UnnecessaryMutPassed => [UNNECESSARY_MUT_PASSED]);
impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed {
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
if e.span.from_expansion() {
// Issue #11268
return;
}
match e.kind {
ExprKind::Call(fn_expr, arguments) => {
if let ExprKind::Path(ref path) = fn_expr.kind {

View file

@ -1,8 +1,21 @@
#![allow(unused_variables)]
#![allow(unused_variables, dead_code)]
fn takes_an_immutable_reference(a: &i32) {}
fn takes_a_mutable_reference(a: &mut i32) {}
mod issue11268 {
macro_rules! x {
($f:expr) => {
$f(&mut 1);
};
}
fn f() {
x!(super::takes_an_immutable_reference);
x!(super::takes_a_mutable_reference);
}
}
struct MyStruct;
impl MyStruct {

View file

@ -1,5 +1,5 @@
error: the function `takes_an_immutable_reference` doesn't need a mutable reference
--> $DIR/mut_reference.rs:17:34
--> $DIR/mut_reference.rs:30:34
|
LL | takes_an_immutable_reference(&mut 42);
| ^^^^^^^
@ -7,19 +7,19 @@ LL | takes_an_immutable_reference(&mut 42);
= note: `-D clippy::unnecessary-mut-passed` implied by `-D warnings`
error: the function `as_ptr` doesn't need a mutable reference
--> $DIR/mut_reference.rs:19:12
--> $DIR/mut_reference.rs:32:12
|
LL | as_ptr(&mut 42);
| ^^^^^^^
error: the method `takes_an_immutable_reference` doesn't need a mutable reference
--> $DIR/mut_reference.rs:23:44
--> $DIR/mut_reference.rs:36:44
|
LL | my_struct.takes_an_immutable_reference(&mut 42);
| ^^^^^^^
error: this argument is a mutable reference, but not used mutably
--> $DIR/mut_reference.rs:11:44
--> $DIR/mut_reference.rs:24:44
|
LL | fn takes_a_mutable_reference(&self, a: &mut i32) {}
| ^^^^^^^^ help: consider changing to: `&i32`