forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#11647 - flip1995:needless-pass-by-ref-mut-pub…
…-api, r=xFrednet Honor `avoid-breaking-exported-api` in `needless_pass_by_ref_mut` Until now, the lint only emitted a warning, when breaking public API. Now it doesn't lint at all when the config value is not set to `false`, bringing it in line with the other lints using this config value. Also ensures that this config value is documented in the lint. changelog: none (I don't think a changelog is necessary, since this lint is in `nursery`) --- Fixes rust-lang/rust-clippy#11374 cc `@GuillaumeGomez` Marking as draft: Does this lint even break public API? If I change a function signature from `fn foo(x: &mut T)` to `fn foo(x: &T)`, I can still call it with `foo(&mut x)`. The only "breaking" thing is that the `clippy::unnecessary_mut_passed` lint will complain that `&mut` at the callsite is not necessary, possibly trickling down to the crate user having to remote a `mut` from a variable. [Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=058165a7663902e84af1d23e35c10d66). Are there examples where this actually breaks public API, that I'm missing?
- Loading branch information
Showing
12 changed files
with
86 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
avoid-breaking-exported-api = false |
10 changes: 10 additions & 0 deletions
10
tests/ui-toml/needless_pass_by_ref_mut/needless_pass_by_ref_mut.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![warn(clippy::needless_pass_by_ref_mut)] | ||
#![allow(clippy::ptr_arg)] | ||
|
||
// Should warn | ||
pub fn pub_foo(s: &Vec<u32>, b: &u32, x: &mut u32) { | ||
//~^ ERROR: this argument is a mutable reference, but not used mutably | ||
*x += *b + s.len() as u32; | ||
} | ||
|
||
fn main() {} |
10 changes: 10 additions & 0 deletions
10
tests/ui-toml/needless_pass_by_ref_mut/needless_pass_by_ref_mut.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![warn(clippy::needless_pass_by_ref_mut)] | ||
#![allow(clippy::ptr_arg)] | ||
|
||
// Should warn | ||
pub fn pub_foo(s: &mut Vec<u32>, b: &u32, x: &mut u32) { | ||
//~^ ERROR: this argument is a mutable reference, but not used mutably | ||
*x += *b + s.len() as u32; | ||
} | ||
|
||
fn main() {} |
12 changes: 12 additions & 0 deletions
12
tests/ui-toml/needless_pass_by_ref_mut/needless_pass_by_ref_mut.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error: this argument is a mutable reference, but not used mutably | ||
--> tests/ui-toml/needless_pass_by_ref_mut/needless_pass_by_ref_mut.rs:5:19 | ||
| | ||
LL | pub fn pub_foo(s: &mut Vec<u32>, b: &u32, x: &mut u32) { | ||
| ^^^^^^^^^^^^^ help: consider changing to: `&Vec<u32>` | ||
| | ||
= warning: changing this function will impact semver compatibility | ||
= note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_ref_mut)]` | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
error: this argument is a mutable reference, but not used mutably | ||
--> tests/ui/needless_pass_by_ref_mut2.rs:8:30 | ||
--> tests/ui/needless_pass_by_ref_mut2.rs:8:26 | ||
| | ||
LL | pub async fn inner_async3(x: &mut i32, y: &mut u32) { | ||
| ^^^^^^^^ help: consider changing to: `&i32` | ||
LL | async fn inner_async3(x: &mut i32, y: &mut u32) { | ||
| ^^^^^^^^ help: consider changing to: `&i32` | ||
| | ||
= warning: changing this function will impact semver compatibility | ||
= note: `-D clippy::needless-pass-by-ref-mut` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::needless_pass_by_ref_mut)]` | ||
|
||
error: this argument is a mutable reference, but not used mutably | ||
--> tests/ui/needless_pass_by_ref_mut2.rs:16:43 | ||
--> tests/ui/needless_pass_by_ref_mut2.rs:16:39 | ||
| | ||
LL | pub async fn inner_async4(u: &mut i32, v: &mut u32) { | ||
| ^^^^^^^^ help: consider changing to: `&u32` | ||
| | ||
= warning: changing this function will impact semver compatibility | ||
LL | async fn inner_async4(u: &mut i32, v: &mut u32) { | ||
| ^^^^^^^^ help: consider changing to: `&u32` | ||
|
||
error: aborting due to 2 previous errors | ||
|