suggest type annotation for local statement initialed by ref expression
This commit is contained in:
parent
56f132565e
commit
0fca075ce8
5 changed files with 160 additions and 4 deletions
|
|
@ -11,6 +11,10 @@ help: consider removing the borrow
|
|||
LL - let a: String = &String::from("a");
|
||||
LL + let a: String = String::from("a");
|
||||
|
|
||||
help: alternatively, consider changing the type annotation
|
||||
|
|
||||
LL | let a: &String = &String::from("a");
|
||||
| +
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/format-borrow.rs:4:21
|
||||
|
|
@ -25,6 +29,10 @@ help: consider removing the borrow
|
|||
LL - let b: String = &format!("b");
|
||||
LL + let b: String = format!("b");
|
||||
|
|
||||
help: alternatively, consider changing the type annotation
|
||||
|
|
||||
LL | let b: &String = &format!("b");
|
||||
| +
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/format-borrow.rs:6:21
|
||||
|
|
@ -39,6 +47,10 @@ help: consider removing the borrow
|
|||
LL - let c: String = &mut format!("c");
|
||||
LL + let c: String = format!("c");
|
||||
|
|
||||
help: alternatively, consider changing the type annotation
|
||||
|
|
||||
LL | let c: &mut String = &mut format!("c");
|
||||
| ++++
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/format-borrow.rs:8:21
|
||||
|
|
@ -53,6 +65,10 @@ help: consider removing the borrow
|
|||
LL - let d: String = &mut (format!("d"));
|
||||
LL + let d: String = format!("d"));
|
||||
|
|
||||
help: alternatively, consider changing the type annotation
|
||||
|
|
||||
LL | let d: &mut String = &mut (format!("d"));
|
||||
| ++++
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
|||
25
src/test/ui/suggestions/issue-102892.rs
Normal file
25
src/test/ui/suggestions/issue-102892.rs
Normal file
|
|
@ -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() {}
|
||||
57
src/test/ui/suggestions/issue-102892.stderr
Normal file
57
src/test/ui/suggestions/issue-102892.stderr
Normal file
|
|
@ -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`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue