diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:59:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:59:35 +0000 |
commit | d1b2d29528b7794b41e66fc2136e395a02f8529b (patch) | |
tree | a4a17504b260206dec3cf55b2dca82929a348ac2 /tests/ui/parser/ternary_operator.rs | |
parent | Releasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip |
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/parser/ternary_operator.rs')
-rw-r--r-- | tests/ui/parser/ternary_operator.rs | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/ui/parser/ternary_operator.rs b/tests/ui/parser/ternary_operator.rs new file mode 100644 index 000000000..23d537e77 --- /dev/null +++ b/tests/ui/parser/ternary_operator.rs @@ -0,0 +1,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 `?` +} |