Skip to content

Commit b5d2ff0

Browse files
authored
Rollup merge of #78265 - JohnTitor:type-iference-diag-test, r=lcnr
Add some inference-related regression tests about incorrect diagnostics Closes #71732 Closes #72616
2 parents 6884632 + 98e1316 commit b5d2ff0

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

src/test/ui/inference/issue-71732.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Regression test for #71732, it used to emit incorrect diagnostics, like:
2+
// error[E0283]: type annotations needed
3+
// --> src/main.rs:5:10
4+
// |
5+
// 5 | .get(&"key".into())
6+
// | ^^^ cannot infer type for struct `String`
7+
// |
8+
// = note: cannot satisfy `String: Borrow<_>`
9+
// help: consider specifying the type argument in the method call
10+
// |
11+
// 5 | .get::<Q>(&"key".into())
12+
// |
13+
14+
use std::collections::hash_map::HashMap;
15+
16+
fn foo(parameters: &HashMap<String, String>) -> bool {
17+
parameters
18+
.get(&"key".into()) //~ ERROR: type annotations needed
19+
.and_then(|found: &String| Some(false))
20+
.unwrap_or(false)
21+
}
22+
23+
fn main() {}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0283]: type annotations needed
2+
--> $DIR/issue-71732.rs:18:10
3+
|
4+
LL | .get(&"key".into())
5+
| ^^^ ------------ this method call resolves to `T`
6+
| |
7+
| cannot infer type for type parameter `Q` declared on the associated function `get`
8+
|
9+
= note: cannot satisfy `String: Borrow<_>`
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0283`.

src/test/ui/inference/issue-72616.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Regression test for #72616, it used to emit incorrect diagnostics, like:
2+
// error[E0283]: type annotations needed for `String`
3+
// --> src/main.rs:8:30
4+
// |
5+
// 5 | let _: String = "".to_owned().try_into().unwrap();
6+
// | - consider giving this pattern a type
7+
// ...
8+
// 8 | if String::from("a") == "a".try_into().unwrap() {}
9+
// | ^^ cannot infer type for struct `String`
10+
// |
11+
// = note: cannot satisfy `String: PartialEq<_>`
12+
13+
use std::convert::TryInto;
14+
15+
pub fn main() {
16+
{
17+
let _: String = "".to_owned().try_into().unwrap();
18+
}
19+
{
20+
if String::from("a") == "a".try_into().unwrap() {}
21+
//~^ ERROR: type annotations needed
22+
}
23+
{
24+
let _: String = match "_".try_into() {
25+
Ok(a) => a,
26+
Err(_) => "".into(),
27+
};
28+
}
29+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0283]: type annotations needed
2+
--> $DIR/issue-72616.rs:20:30
3+
|
4+
LL | if String::from("a") == "a".try_into().unwrap() {}
5+
| ^^ -------------- this method call resolves to `std::result::Result<T, <Self as TryInto<T>>::Error>`
6+
| |
7+
| cannot infer type
8+
|
9+
= note: cannot satisfy `String: PartialEq<_>`
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0283`.

0 commit comments

Comments
 (0)