forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
22 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,30 @@ | ||
// 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 `?` | ||
fn a() { | ||
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 `?` | ||
fn b() { | ||
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 `?` | ||
fn c() { | ||
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 bad() { | ||
// regression test for #117208 | ||
v ? return; | ||
//~^ ERROR expected one of | ||
//~| NOTE expected one of | ||
} | ||
|
||
fn main() { //~ NOTE this function should return `Result` or `Option` to accept `?` | ||
fn main() { | ||
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 `?` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,121 +1,48 @@ | ||
error: Rust has no ternary operator | ||
--> $DIR/ternary_operator.rs:5:19 | ||
--> $DIR/ternary_operator.rs:2:19 | ||
| | ||
LL | let x = 5 > 2 ? true : false; | ||
| ^^^^^^^^^^^^^^^ | ||
| | ||
= help: use an `if-else` expression instead | ||
|
||
error: Rust has no ternary operator | ||
--> $DIR/ternary_operator.rs:21:19 | ||
--> $DIR/ternary_operator.rs:8:19 | ||
| | ||
LL | let x = 5 > 2 ? { true } : { false }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: use an `if-else` expression instead | ||
|
||
error: Rust has no ternary operator | ||
--> $DIR/ternary_operator.rs:37:19 | ||
--> $DIR/ternary_operator.rs:14:19 | ||
| | ||
LL | let x = 5 > 2 ? f32::MAX : f32::MIN; | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: use an `if-else` expression instead | ||
|
||
error: expected one of `.`, `;`, `?`, `}`, or an operator, found keyword `return` | ||
--> $DIR/ternary_operator.rs:54:9 | ||
--> $DIR/ternary_operator.rs:21:9 | ||
| | ||
LL | v ? return; | ||
| ^^^^^^ expected one of `.`, `;`, `?`, `}`, or an operator | ||
|
||
error: expected one of `.`, `;`, `?`, `else`, or an operator, found `:` | ||
--> $DIR/ternary_operator.rs:60:37 | ||
--> $DIR/ternary_operator.rs:26:37 | ||
| | ||
LL | let x = 5 > 2 ? { let x = vec![]: Vec<u16>; x } : { false }; | ||
| ^ expected one of `.`, `;`, `?`, `else`, or an operator | ||
| | ||
= note: type ascription syntax has been removed, see issue #101728 <https://github.com/rust-lang/rust/issues/101728> | ||
|
||
error: Rust has no ternary operator | ||
--> $DIR/ternary_operator.rs:60:19 | ||
--> $DIR/ternary_operator.rs:26:19 | ||
| | ||
LL | let x = 5 > 2 ? { let x = vec![]: Vec<u16>; x } : { false }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: use an `if-else` expression instead | ||
|
||
error[E0277]: the `?` operator can only be applied to values that implement `Try` | ||
--> $DIR/ternary_operator.rs:5:17 | ||
| | ||
LL | let x = 5 > 2 ? true : false; | ||
| ^^^ the `?` operator cannot be applied to type `{integer}` | ||
| | ||
= help: the trait `Try` is not implemented for `{integer}` | ||
|
||
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) | ||
--> $DIR/ternary_operator.rs:5:19 | ||
| | ||
LL | fn a() { | ||
| ------ this function should return `Result` or `Option` to accept `?` | ||
LL | let x = 5 > 2 ? true : false; | ||
| ^ cannot use the `?` operator in a function that returns `()` | ||
| | ||
= help: the trait `FromResidual<_>` is not implemented for `()` | ||
|
||
error[E0277]: the `?` operator can only be applied to values that implement `Try` | ||
--> $DIR/ternary_operator.rs:21:17 | ||
| | ||
LL | let x = 5 > 2 ? { true } : { false }; | ||
| ^^^ the `?` operator cannot be applied to type `{integer}` | ||
| | ||
= help: the trait `Try` is not implemented for `{integer}` | ||
|
||
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) | ||
--> $DIR/ternary_operator.rs:21:19 | ||
| | ||
LL | fn b() { | ||
| ------ this function should return `Result` or `Option` to accept `?` | ||
LL | let x = 5 > 2 ? { true } : { false }; | ||
| ^ cannot use the `?` operator in a function that returns `()` | ||
| | ||
= help: the trait `FromResidual<_>` is not implemented for `()` | ||
|
||
error[E0277]: the `?` operator can only be applied to values that implement `Try` | ||
--> $DIR/ternary_operator.rs:37:17 | ||
| | ||
LL | let x = 5 > 2 ? f32::MAX : f32::MIN; | ||
| ^^^ the `?` operator cannot be applied to type `{integer}` | ||
| | ||
= help: the trait `Try` is not implemented for `{integer}` | ||
|
||
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) | ||
--> $DIR/ternary_operator.rs:37:19 | ||
| | ||
LL | fn c() { | ||
| ------ this function should return `Result` or `Option` to accept `?` | ||
LL | let x = 5 > 2 ? f32::MAX : f32::MIN; | ||
| ^ cannot use the `?` operator in a function that returns `()` | ||
| | ||
= help: the trait `FromResidual<_>` is not implemented for `()` | ||
|
||
error[E0277]: the `?` operator can only be applied to values that implement `Try` | ||
--> $DIR/ternary_operator.rs:60:17 | ||
| | ||
LL | let x = 5 > 2 ? { let x = vec![]: Vec<u16>; x } : { false }; | ||
| ^^^ the `?` operator cannot be applied to type `{integer}` | ||
| | ||
= help: the trait `Try` is not implemented for `{integer}` | ||
|
||
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) | ||
--> $DIR/ternary_operator.rs:60:19 | ||
| | ||
LL | fn main() { | ||
| --------- this function should return `Result` or `Option` to accept `?` | ||
LL | let x = 5 > 2 ? { let x = vec![]: Vec<u16>; x } : { false }; | ||
| ^ cannot use the `?` operator in a function that returns `()` | ||
| | ||
= help: the trait `FromResidual<_>` is not implemented for `()` | ||
|
||
error: aborting due to 14 previous errors | ||
error: aborting due to 6 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |