File: bad-interconversion.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 893,176 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (46 lines) | stat: -rw-r--r-- 1,553 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::ops::ControlFlow;

fn result_to_result() -> Result<u64, u8> {
    Ok(Err(123_i32)?)
    //~^ ERROR `?` couldn't convert the error to `u8`
}

fn option_to_result() -> Result<u64, String> {
    Some(3)?;
    //~^ ERROR the `?` operator can only be used on `Result`s, not `Option`s, in a function that returns `Result`
    Ok(10)
}

fn control_flow_to_result() -> Result<u64, String> {
    Ok(ControlFlow::Break(123)?)
    //~^ ERROR the `?` operator can only be used on `Result`s in a function that returns `Result`
}

fn result_to_option() -> Option<u16> {
    Some(Err("hello")?)
    //~^ ERROR the `?` operator can only be used on `Option`s, not `Result`s, in a function that returns `Option`
}

fn control_flow_to_option() -> Option<u64> {
    Some(ControlFlow::Break(123)?)
    //~^ ERROR the `?` operator can only be used on `Option`s in a function that returns `Option`
}

fn result_to_control_flow() -> ControlFlow<String> {
    ControlFlow::Continue(Err("hello")?)
    //~^ ERROR the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow`
}

fn option_to_control_flow() -> ControlFlow<u64> {
    Some(3)?;
    //~^ ERROR the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow`
    ControlFlow::Break(10)
}

fn control_flow_to_control_flow() -> ControlFlow<i64> {
    ControlFlow::Break(4_u8)?;
    //~^ ERROR the `?` operator in a function that returns `ControlFlow<B, _>` can only be used on other `ControlFlow<B, _>`s
    ControlFlow::Continue(())
}

fn main() {}