]> git.lizzy.rs Git - rust.git/blob - src/test/ui/try-trait/bad-interconversion.rs
Auto merge of #79608 - alessandrod:bpf, r=nagisa
[rust.git] / src / test / ui / try-trait / bad-interconversion.rs
1 #![feature(control_flow_enum)]
2
3 use std::ops::ControlFlow;
4
5 fn result_to_result() -> Result<u64, u8> {
6     Ok(Err(123_i32)?)
7     //~^ ERROR `?` couldn't convert the error to `u8`
8 }
9
10 fn option_to_result() -> Result<u64, String> {
11     Some(3)?;
12     //~^ ERROR the `?` operator can only be used on `Result`s, not `Option`s, in a function that returns `Result`
13     Ok(10)
14 }
15
16 fn control_flow_to_result() -> Result<u64, String> {
17     Ok(ControlFlow::Break(123)?)
18     //~^ ERROR the `?` operator can only be used on `Result`s in a function that returns `Result`
19 }
20
21 fn result_to_option() -> Option<u16> {
22     Some(Err("hello")?)
23     //~^ ERROR the `?` operator can only be used on `Option`s, not `Result`s, in a function that returns `Option`
24 }
25
26 fn control_flow_to_option() -> Option<u64> {
27     Some(ControlFlow::Break(123)?)
28     //~^ ERROR the `?` operator can only be used on `Option`s in a function that returns `Option`
29 }
30
31 fn result_to_control_flow() -> ControlFlow<String> {
32     ControlFlow::Continue(Err("hello")?)
33     //~^ ERROR the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow`
34 }
35
36 fn option_to_control_flow() -> ControlFlow<u64> {
37     Some(3)?;
38     //~^ ERROR the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow`
39     ControlFlow::Break(10)
40 }
41
42 fn control_flow_to_control_flow() -> ControlFlow<i64> {
43     ControlFlow::Break(4_u8)?;
44     //~^ ERROR the `?` operator in a function that returns `ControlFlow<B, _>` can only be used on other `ControlFlow<B, _>`s
45     ControlFlow::Continue(())
46 }
47
48 fn main() {}