summaryrefslogtreecommitdiffstats
path: root/tests/ui/parser/ternary_operator.rs
blob: 23d537e77f79e99ae9e6e618ed8c7a929ad720d7 (plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// A good chunk of these errors aren't shown to the user, but are still
// required in the test for it to pass.

fn a() { //~ NOTE this function should return `Result` or `Option` to accept `?`
    let x = 5 > 2 ? true : false;
    //~^ ERROR Rust has no ternary operator
    //~| HELP use an `if-else` expression instead
    //~| ERROR the `?` operator can only be applied to values that implement `Try` [E0277]
    //~| HELP the trait `Try` is not implemented for `{integer}`
    //~| ERROR the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) [E0277]
    //~| HELP the trait `FromResidual<_>` is not implemented for `()`
    //~| NOTE in this expansion of desugaring of operator `?`
    //~| NOTE the `?` operator cannot be applied to type `{integer}`
    //~| NOTE in this expansion of desugaring of operator `?`
    //~| NOTE in this expansion of desugaring of operator `?`
    //~| NOTE cannot use the `?` operator in a function that returns `()`
    //~| NOTE in this expansion of desugaring of operator `?`
}

fn b() { //~ NOTE this function should return `Result` or `Option` to accept `?`
    let x = 5 > 2 ? { true } : { false };
    //~^ ERROR Rust has no ternary operator
    //~| HELP use an `if-else` expression instead
    //~| ERROR the `?` operator can only be applied to values that implement `Try` [E0277]
    //~| HELP the trait `Try` is not implemented for `{integer}`
    //~| ERROR the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) [E0277]
    //~| HELP the trait `FromResidual<_>` is not implemented for `()`
    //~| NOTE in this expansion of desugaring of operator `?`
    //~| NOTE the `?` operator cannot be applied to type `{integer}`
    //~| NOTE in this expansion of desugaring of operator `?`
    //~| NOTE in this expansion of desugaring of operator `?`
    //~| NOTE cannot use the `?` operator in a function that returns `()`
    //~| NOTE in this expansion of desugaring of operator `?`
}

fn c() { //~ NOTE this function should return `Result` or `Option` to accept `?`
    let x = 5 > 2 ? f32::MAX : f32::MIN;
    //~^ ERROR Rust has no ternary operator
    //~| HELP use an `if-else` expression instead
    //~| ERROR the `?` operator can only be applied to values that implement `Try` [E0277]
    //~| HELP the trait `Try` is not implemented for `{integer}`
    //~| ERROR the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) [E0277]
    //~| HELP the trait `FromResidual<_>` is not implemented for `()`
    //~| NOTE in this expansion of desugaring of operator `?`
    //~| NOTE the `?` operator cannot be applied to type `{integer}`
    //~| NOTE in this expansion of desugaring of operator `?`
    //~| NOTE in this expansion of desugaring of operator `?`
    //~| NOTE cannot use the `?` operator in a function that returns `()`
    //~| NOTE in this expansion of desugaring of operator `?`
}

fn main() { //~ NOTE this function should return `Result` or `Option` to accept `?`
    let x = 5 > 2 ? { let x = vec![]: Vec<u16>; x } : { false };
    //~^ ERROR Rust has no ternary operator
    //~| HELP use an `if-else` expression instead
    //~| ERROR expected one of `.`, `;`, `?`, `else`, or an operator, found `:`
    //~| NOTE expected one of `.`, `;`, `?`, `else`, or an operator
    //~| ERROR the `?` operator can only be applied to values that implement `Try` [E0277]
    //~| HELP the trait `Try` is not implemented for `{integer}`
    //~| ERROR the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) [E0277]
    //~| HELP the trait `FromResidual<_>` is not implemented for `()`
    //~| NOTE type ascription syntax has been removed, see issue #101728 <https://github.com/rust-lang/rust/issues/101728>
    //~| NOTE in this expansion of desugaring of operator `?`
    //~| NOTE the `?` operator cannot be applied to type `{integer}`
    //~| NOTE in this expansion of desugaring of operator `?`
    //~| NOTE in this expansion of desugaring of operator `?`
    //~| NOTE cannot use the `?` operator in a function that returns `()`
    //~| NOTE in this expansion of desugaring of operator `?`
}