Add existing behaviour test for deref suggestions.
This commit adds a test that demonstrates the current behaviour where suggestions to add a dereference aren't given for non-references.
This commit is contained in:
parent
06a271a6eb
commit
c9a2616e44
2 changed files with 44 additions and 0 deletions
20
src/test/ui/suggestions/issue-59819.rs
Normal file
20
src/test/ui/suggestions/issue-59819.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
#![allow(warnings)]
|
||||
|
||||
// Test that suggestion to add `*` characters applies to implementations of `Deref` as well as
|
||||
// references.
|
||||
|
||||
struct Foo(i32);
|
||||
|
||||
impl std::ops::Deref for Foo {
|
||||
type Target = i32;
|
||||
fn deref(&self) -> &i32 {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = Foo(42);
|
||||
let y: i32 = x; //~ ERROR mismatched types
|
||||
let a = &42;
|
||||
let b: i32 = a; //~ ERROR mismatched types
|
||||
}
|
24
src/test/ui/suggestions/issue-59819.stderr
Normal file
24
src/test/ui/suggestions/issue-59819.stderr
Normal file
|
@ -0,0 +1,24 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-59819.rs:17:18
|
||||
|
|
||||
LL | let y: i32 = x;
|
||||
| ^ expected i32, found struct `Foo`
|
||||
|
|
||||
= note: expected type `i32`
|
||||
found type `Foo`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-59819.rs:19:18
|
||||
|
|
||||
LL | let b: i32 = a;
|
||||
| ^
|
||||
| |
|
||||
| expected i32, found &{integer}
|
||||
| help: consider dereferencing the borrow: `*a`
|
||||
|
|
||||
= note: expected type `i32`
|
||||
found type `&{integer}`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Add table
Reference in a new issue