forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
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#120095 - Nadrieril:lint-resetting-mut, r=<try>
Experiment: lint resetting `mut` bindings We would like to fix rust-lang#105647 in rust 2024. To evaluate the breakage, I wrote a lint that detects the cases where there would be a difference between now and rust 2024. I'd like to request a crater run with `dereferencing_mut_binding` set to `deny` to see how many crates would be affected.
- Loading branch information
Showing
15 changed files
with
199 additions
and
10 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
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
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,9 +1,11 @@ | ||
#![warn(dereferencing_mut_binding)] | ||
struct Foo {} | ||
|
||
pub fn main() { | ||
let mut tups = vec![(Foo {}, Foo {})]; | ||
// The below desugars to &(ref n, mut m). | ||
for (n, mut m) in &tups { | ||
//~^ ERROR cannot move out of a shared reference | ||
//~| WARN dereferencing `mut` | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
tests/ui/rfcs/rfc-2005-default-binding-mode/resetting-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,30 @@ | ||
// `mut` resets the binding mode. | ||
#![deny(dereferencing_mut_binding)] | ||
|
||
fn main() { | ||
let (x, mut y) = &(0, 0); | ||
//~^ ERROR dereferencing `mut` | ||
let _: &u32 = x; | ||
let _: u32 = y; | ||
|
||
match &Some(5i32) { | ||
Some(mut n) => { | ||
//~^ ERROR dereferencing `mut` | ||
n += 1; | ||
let _ = n; | ||
} | ||
None => {} | ||
}; | ||
if let Some(mut n) = &Some(5i32) { | ||
//~^ ERROR dereferencing `mut` | ||
n += 1; | ||
let _ = n; | ||
}; | ||
match &Some(5i32) { | ||
&Some(mut n) => { | ||
n += 1; | ||
let _ = n; | ||
} | ||
None => {} | ||
}; | ||
} |
43 changes: 43 additions & 0 deletions
43
tests/ui/rfcs/rfc-2005-default-binding-mode/resetting-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,43 @@ | ||
error: dereferencing `mut` binding | ||
--> $DIR/resetting-mut.rs:5:13 | ||
| | ||
LL | let (x, mut y) = &(0, 0); | ||
| ^^^^^ `mut` dereferences the type of this binding | ||
| | ||
help: this will change in edition 2024 | ||
--> $DIR/resetting-mut.rs:5:13 | ||
| | ||
LL | let (x, mut y) = &(0, 0); | ||
| ^^^^^ | ||
note: the lint level is defined here | ||
--> $DIR/resetting-mut.rs:2:9 | ||
| | ||
LL | #![deny(dereferencing_mut_binding)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: dereferencing `mut` binding | ||
--> $DIR/resetting-mut.rs:11:14 | ||
| | ||
LL | Some(mut n) => { | ||
| ^^^^^ `mut` dereferences the type of this binding | ||
| | ||
help: this will change in edition 2024 | ||
--> $DIR/resetting-mut.rs:11:14 | ||
| | ||
LL | Some(mut n) => { | ||
| ^^^^^ | ||
|
||
error: dereferencing `mut` binding | ||
--> $DIR/resetting-mut.rs:18:17 | ||
| | ||
LL | if let Some(mut n) = &Some(5i32) { | ||
| ^^^^^ `mut` dereferences the type of this binding | ||
| | ||
help: this will change in edition 2024 | ||
--> $DIR/resetting-mut.rs:18:17 | ||
| | ||
LL | if let Some(mut n) = &Some(5i32) { | ||
| ^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|