-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 #91545 - compiler-errors:deref-suggestion-improvement…
…s, r=estebank Generalize "remove `&`" and "add `*`" suggestions to more than one deref Suggest removing more than one `&` and `&mut`, along with suggesting adding more than one `*` (or a combination of the two). r? `@estebank` (since you're experienced with these types of suggestions, feel free to reassign)
- Loading branch information
Showing
7 changed files
with
214 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
fn a(x: &&i32) -> i32 { | ||
x | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
fn a2(x: &&&&&i32) -> i32 { | ||
x | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
fn b(x: &i32) -> i32 { | ||
&x | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
fn c(x: Box<i32>) -> i32 { | ||
&x | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
fn d(x: std::sync::Mutex<&i32>) -> i32 { | ||
x.lock().unwrap() | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
fn main() {} |
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,72 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/deref-multi.rs:2:5 | ||
| | ||
LL | fn a(x: &&i32) -> i32 { | ||
| --- expected `i32` because of return type | ||
LL | x | ||
| ^ expected `i32`, found `&&i32` | ||
| | ||
help: consider dereferencing the borrow | ||
| | ||
LL | **x | ||
| ++ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/deref-multi.rs:7:5 | ||
| | ||
LL | fn a2(x: &&&&&i32) -> i32 { | ||
| --- expected `i32` because of return type | ||
LL | x | ||
| ^ expected `i32`, found `&&&&&i32` | ||
| | ||
help: consider dereferencing the borrow | ||
| | ||
LL | *****x | ||
| +++++ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/deref-multi.rs:12:5 | ||
| | ||
LL | fn b(x: &i32) -> i32 { | ||
| --- expected `i32` because of return type | ||
LL | &x | ||
| ^^ expected `i32`, found `&&i32` | ||
| | ||
help: consider removing the `&` and dereferencing the borrow instead | ||
| | ||
LL | *x | ||
| ~ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/deref-multi.rs:17:5 | ||
| | ||
LL | fn c(x: Box<i32>) -> i32 { | ||
| --- expected `i32` because of return type | ||
LL | &x | ||
| ^^ expected `i32`, found `&Box<i32>` | ||
| | ||
= note: expected type `i32` | ||
found reference `&Box<i32>` | ||
help: consider removing the `&` and dereferencing the borrow instead | ||
| | ||
LL | *x | ||
| ~ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/deref-multi.rs:22:5 | ||
| | ||
LL | fn d(x: std::sync::Mutex<&i32>) -> i32 { | ||
| --- expected `i32` because of return type | ||
LL | x.lock().unwrap() | ||
| ^^^^^^^^^^^^^^^^^ expected `i32`, found struct `MutexGuard` | ||
| | ||
= note: expected type `i32` | ||
found struct `MutexGuard<'_, &i32>` | ||
help: consider dereferencing the type | ||
| | ||
LL | **x.lock().unwrap() | ||
| ++ | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |