]> git.lizzy.rs Git - rust.git/blob - tests/ui/inference/issue-72616.rs
Auto merge of #106827 - alexcrichton:update-llvm-to-15.0.7, r=cuviper
[rust.git] / tests / ui / inference / issue-72616.rs
1 // ignore-wasm32 FIXME: ignoring wasm as it suggests slightly different impls
2
3 // Regression test for #72616, it used to emit incorrect diagnostics, like:
4 // error[E0283]: type annotations needed for `String`
5 //  --> src/main.rs:8:30
6 //   |
7 // 5 |         let _: String = "".to_owned().try_into().unwrap();
8 //   |             - consider giving this pattern a type
9 // ...
10 // 8 |         if String::from("a") == "a".try_into().unwrap() {}
11 //   |                              ^^ cannot infer type for struct `String`
12 //   |
13 //   = note: cannot satisfy `String: PartialEq<_>`
14
15 use std::convert::TryInto;
16
17 pub fn main() {
18     {
19         let _: String = "".to_owned().try_into().unwrap();
20     }
21     {
22         if String::from("a") == "a".try_into().unwrap() {}
23         //~^ ERROR type annotations needed
24         //~| ERROR type annotations needed
25     }
26     {
27         let _: String = match "_".try_into() {
28             Ok(a) => a,
29             Err(_) => "".into(),
30         };
31     }
32 }