]> git.lizzy.rs Git - rust.git/blob - tests/ui/suggestions/issue-86100-tuple-paren-comma.rs
Rollup merge of #106670 - albertlarsan68:check-docs-in-pr-ci, r=Mark-Simulacrum
[rust.git] / tests / ui / suggestions / issue-86100-tuple-paren-comma.rs
1 // Tests that a suggestion is issued for type mismatch errors when a
2 // 1-tuple is expected and a parenthesized expression of non-tuple
3 // type is supplied.
4
5 fn foo<T>(_t: (T,)) {}
6 struct S { _s: (String,) }
7
8 fn main() {
9     let _x: (i32,) = (5);
10     //~^ ERROR: mismatched types [E0308]
11     //~| HELP: use a trailing comma to create a tuple with one element
12
13     foo((Some(3)));
14     //~^ ERROR: mismatched types [E0308]
15     //~| HELP: use a trailing comma to create a tuple with one element
16
17     let _s = S { _s: ("abc".to_string()) };
18     //~^ ERROR: mismatched types [E0308]
19     //~| HELP: use a trailing comma to create a tuple with one element
20
21     // Do not issue the suggestion if the found type is already a tuple.
22     let t = (1, 2);
23     let _x: (i32,) = (t);
24     //~^ ERROR: mismatched types [E0308]
25 }