Skip to content

Commit c9a2616

Browse files
committed
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.
1 parent 06a271a commit c9a2616

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![allow(warnings)]
2+
3+
// Test that suggestion to add `*` characters applies to implementations of `Deref` as well as
4+
// references.
5+
6+
struct Foo(i32);
7+
8+
impl std::ops::Deref for Foo {
9+
type Target = i32;
10+
fn deref(&self) -> &i32 {
11+
&self.0
12+
}
13+
}
14+
15+
fn main() {
16+
let x = Foo(42);
17+
let y: i32 = x; //~ ERROR mismatched types
18+
let a = &42;
19+
let b: i32 = a; //~ ERROR mismatched types
20+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-59819.rs:17:18
3+
|
4+
LL | let y: i32 = x;
5+
| ^ expected i32, found struct `Foo`
6+
|
7+
= note: expected type `i32`
8+
found type `Foo`
9+
10+
error[E0308]: mismatched types
11+
--> $DIR/issue-59819.rs:19:18
12+
|
13+
LL | let b: i32 = a;
14+
| ^
15+
| |
16+
| expected i32, found &{integer}
17+
| help: consider dereferencing the borrow: `*a`
18+
|
19+
= note: expected type `i32`
20+
found type `&{integer}`
21+
22+
error: aborting due to 2 previous errors
23+
24+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)