forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
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 rust-lang#102951 - SparrowLii:type_annotation, r=este…
…bank suggest type annotation for local statement initialed by ref expression In a local statement with a type declaration, if a ref expression is used on the right side and not used on the left side, in addition to removing the `&` and `&mut` on the right side, we can add them on the left side alternatively Fixes rust-lang#102892
- Loading branch information
Showing
5 changed files
with
160 additions
and
4 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,25 @@ | ||
#![allow(dead_code, unused_variables)] | ||
|
||
use std::sync::Arc; | ||
|
||
#[derive(Debug)] | ||
struct A; | ||
#[derive(Debug)] | ||
struct B; | ||
|
||
fn process_without_annot(arc: &Arc<(A, B)>) { | ||
let (a, b) = **arc; // suggests putting `&**arc` here; with that, fixed! | ||
} | ||
|
||
fn process_with_annot(arc: &Arc<(A, B)>) { | ||
let (a, b): (A, B) = &**arc; // suggests putting `&**arc` here too | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
fn process_with_tuple_annot(mutation: &mut (A, B), arc: &Arc<(A, B)>) { | ||
let (a, b): ((A, B), A) = (&mut *mutation, &(**arc).0); // suggests putting `&**arc` here too | ||
//~^ ERROR mismatched types | ||
//~| 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,57 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-102892.rs:15:26 | ||
| | ||
LL | let (a, b): (A, B) = &**arc; // suggests putting `&**arc` here too | ||
| ------ ^^^^^^ expected tuple, found `&(A, B)` | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected tuple `(A, B)` | ||
found reference `&(A, B)` | ||
help: consider removing the borrow | ||
| | ||
LL - let (a, b): (A, B) = &**arc; // suggests putting `&**arc` here too | ||
LL + let (a, b): (A, B) = **arc; // suggests putting `&**arc` here too | ||
| | ||
help: alternatively, consider changing the type annotation | ||
| | ||
LL | let (a, b): &(A, B) = &**arc; // suggests putting `&**arc` here too | ||
| + | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-102892.rs:20:32 | ||
| | ||
LL | let (a, b): ((A, B), A) = (&mut *mutation, &(**arc).0); // suggests putting `&**arc` here too | ||
| ^^^^^^^^^^^^^^ expected tuple, found `&mut (A, B)` | ||
| | ||
= note: expected tuple `(A, B)` | ||
found mutable reference `&mut (A, B)` | ||
help: consider removing the borrow | ||
| | ||
LL - let (a, b): ((A, B), A) = (&mut *mutation, &(**arc).0); // suggests putting `&**arc` here too | ||
LL + let (a, b): ((A, B), A) = (*mutation, &(**arc).0); // suggests putting `&**arc` here too | ||
| | ||
help: alternatively, consider changing the type annotation | ||
| | ||
LL | let (a, b): (&mut (A, B), A) = (&mut *mutation, &(**arc).0); // suggests putting `&**arc` here too | ||
| ++++ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-102892.rs:20:48 | ||
| | ||
LL | let (a, b): ((A, B), A) = (&mut *mutation, &(**arc).0); // suggests putting `&**arc` here too | ||
| ^^^^^^^^^^ expected struct `A`, found `&A` | ||
| | ||
help: consider removing the borrow | ||
| | ||
LL - let (a, b): ((A, B), A) = (&mut *mutation, &(**arc).0); // suggests putting `&**arc` here too | ||
LL + let (a, b): ((A, B), A) = (&mut *mutation, (**arc).0); // suggests putting `&**arc` here too | ||
| | ||
help: alternatively, consider changing the type annotation | ||
| | ||
LL | let (a, b): ((A, B), &A) = (&mut *mutation, &(**arc).0); // suggests putting `&**arc` here too | ||
| + | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |