]> git.lizzy.rs Git - rust.git/blob - tests/ui/suggestions/issue-59819.fixed
Rollup merge of #106919 - compiler-errors:underscore-typo-in-field-pat, r=jackh726
[rust.git] / tests / ui / suggestions / issue-59819.fixed
1 // run-rustfix
2
3 #![allow(warnings)]
4
5 // Test that suggestion to add `*` characters applies to implementations of `Deref` as well as
6 // references.
7
8 struct Foo(i32);
9
10 struct Bar(String);
11
12 impl std::ops::Deref for Foo {
13     type Target = i32;
14     fn deref(&self) -> &Self::Target {
15         &self.0
16     }
17 }
18
19 impl std::ops::Deref for Bar {
20     type Target = String;
21     fn deref(&self) -> &Self::Target {
22         &self.0
23     }
24 }
25
26 fn main() {
27     let x = Foo(42);
28     let y: i32 = *x; //~ ERROR mismatched types
29     let a = &42;
30     let b: i32 = *a; //~ ERROR mismatched types
31
32     // Do not make a suggestion when adding a `*` wouldn't actually fix the issue:
33     let f = Bar("bar".to_string());
34     let g: String = f.to_string(); //~ ERROR mismatched types
35 }