-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #136032 - estebank:issue-136028, r=SparrowLii
Account for mutable borrow in argument suggestion ``` error: value assigned to `object` is never read --> $DIR/mut-arg-of-borrowed-type-meant-to-be-arg-of-mut-borrow.rs:21:5 | LL | object = &mut object2; | ^^^^^^ | help: you might have meant to mutate the pointed at value being passed in, instead of changing the reference in the local binding | LL ~ fn change_object3(object: &mut Object) { LL | LL | let object2 = Object; LL ~ *object = object2; | ``` instead of ``` error: value assigned to `object` is never read --> $DIR/mut-arg-of-borrowed-type-meant-to-be-arg-of-mut-borrow.rs:21:5 | LL | object = &mut object2; | ^^^^^^ | help: you might have meant to mutate the pointed at value being passed in, instead of changing the reference in the local binding | LL ~ fn change_object3(object: &mut mut Object) { LL | LL | let object2 = Object; LL ~ *object = object2; | ``` Fix #136028.
- Loading branch information
Showing
6 changed files
with
114 additions
and
57 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
18 changes: 14 additions & 4 deletions
18
tests/ui/fn/mut-arg-of-borrowed-type-meant-to-be-arg-of-mut-borrow.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 |
---|---|---|
@@ -1,22 +1,32 @@ | ||
//@ run-rustfix | ||
#![deny(unused_assignments, unused_variables)] | ||
#![allow(unused_mut)] | ||
struct Object; | ||
|
||
fn change_object(object: &mut Object) { //~ HELP you might have meant to mutate | ||
let object2 = Object; | ||
*object = object2; //~ ERROR mismatched types | ||
let object2 = Object; | ||
*object = object2; //~ ERROR mismatched types | ||
} | ||
|
||
fn change_object2(object: &mut Object) { //~ ERROR variable `object` is assigned to, but never used | ||
//~^ HELP you might have meant to mutate | ||
let object2 = Object; | ||
*object = object2; | ||
//~^ ERROR `object2` does not live long enough | ||
//~| ERROR value assigned to `object` is never read | ||
} | ||
|
||
fn change_object3(object: &mut Object) { //~ ERROR variable `object` is assigned to, but never used | ||
//~^ HELP you might have meant to mutate | ||
let object2 = Object; | ||
let mut object2 = Object; //~ HELP consider changing this to be mutable | ||
*object = object2; | ||
//~^ ERROR `object2` does not live long enough | ||
//~^ ERROR cannot borrow `object2` as mutable | ||
//~| ERROR value assigned to `object` is never read | ||
} | ||
|
||
fn main() { | ||
let mut object = Object; | ||
change_object(&mut object); | ||
change_object2(&mut object); | ||
change_object3(&mut object); | ||
} |
20 changes: 15 additions & 5 deletions
20
tests/ui/fn/mut-arg-of-borrowed-type-meant-to-be-arg-of-mut-borrow.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 |
---|---|---|
@@ -1,22 +1,32 @@ | ||
//@ run-rustfix | ||
#![deny(unused_assignments, unused_variables)] | ||
#![allow(unused_mut)] | ||
struct Object; | ||
|
||
fn change_object(mut object: &Object) { //~ HELP you might have meant to mutate | ||
let object2 = Object; | ||
object = object2; //~ ERROR mismatched types | ||
let object2 = Object; | ||
object = object2; //~ ERROR mismatched types | ||
} | ||
|
||
fn change_object2(mut object: &Object) { //~ ERROR variable `object` is assigned to, but never used | ||
//~^ HELP you might have meant to mutate | ||
let object2 = Object; | ||
object = &object2; | ||
//~^ ERROR `object2` does not live long enough | ||
//~| ERROR value assigned to `object` is never read | ||
} | ||
|
||
fn change_object3(mut object: &mut Object) { //~ ERROR variable `object` is assigned to, but never used | ||
//~^ HELP you might have meant to mutate | ||
let object2 = Object; | ||
object = &object2; | ||
//~^ ERROR `object2` does not live long enough | ||
let object2 = Object; //~ HELP consider changing this to be mutable | ||
object = &mut object2; | ||
//~^ ERROR cannot borrow `object2` as mutable | ||
//~| ERROR value assigned to `object` is never read | ||
} | ||
|
||
fn main() { | ||
let mut object = Object; | ||
change_object(&mut object); | ||
change_object2(&mut object); | ||
change_object3(&mut object); | ||
} |
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