|
| 1 | +error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) |
| 2 | + --> $DIR/return-from-residual-sugg-issue-125997.rs:10:44 |
| 3 | + | |
| 4 | +LL | fn test1() { |
| 5 | + | ---------- this function should return `Result` or `Option` to accept `?` |
| 6 | +LL | let mut _file = File::create("foo.txt")?; |
| 7 | + | ^ cannot use the `?` operator in a function that returns `()` |
| 8 | + | |
| 9 | + = help: the trait `FromResidual<Result<Infallible, std::io::Error>>` is not implemented for `()` |
| 10 | +help: consider adding return type |
| 11 | + | |
| 12 | +LL ~ fn test1() -> Result<(), Box<dyn std::error::Error>> { |
| 13 | +LL | let mut _file = File::create("foo.txt")?; |
| 14 | +LL | |
| 15 | +LL + |
| 16 | +LL + Ok(()) |
| 17 | +LL + } |
| 18 | + | |
| 19 | + |
| 20 | +error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) |
| 21 | + --> $DIR/return-from-residual-sugg-issue-125997.rs:15:44 |
| 22 | + | |
| 23 | +LL | fn test2() { |
| 24 | + | ---------- this function should return `Result` or `Option` to accept `?` |
| 25 | +LL | let mut _file = File::create("foo.txt")?; |
| 26 | + | ^ cannot use the `?` operator in a function that returns `()` |
| 27 | + | |
| 28 | + = help: the trait `FromResidual<Result<Infallible, std::io::Error>>` is not implemented for `()` |
| 29 | +help: consider adding return type |
| 30 | + | |
| 31 | +LL ~ fn test2() -> Result<(), Box<dyn std::error::Error>> { |
| 32 | +LL | let mut _file = File::create("foo.txt")?; |
| 33 | +LL | |
| 34 | +LL | println!(); |
| 35 | +LL + |
| 36 | +LL + Ok(()) |
| 37 | +LL + } |
| 38 | + | |
| 39 | + |
| 40 | +error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) |
| 41 | + --> $DIR/return-from-residual-sugg-issue-125997.rs:31:44 |
| 42 | + | |
| 43 | +LL | fn main() { |
| 44 | + | --------- this function should return `Result` or `Option` to accept `?` |
| 45 | +LL | let mut _file = File::create("foo.txt")?; |
| 46 | + | ^ cannot use the `?` operator in a function that returns `()` |
| 47 | + | |
| 48 | + = help: the trait `FromResidual<Result<Infallible, std::io::Error>>` is not implemented for `()` |
| 49 | +help: consider adding return type |
| 50 | + | |
| 51 | +LL ~ fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 52 | +LL | let mut _file = File::create("foo.txt")?; |
| 53 | +LL | |
| 54 | +LL | mac!(); |
| 55 | +LL + |
| 56 | +LL + Ok(()) |
| 57 | +LL + } |
| 58 | + | |
| 59 | + |
| 60 | +error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) |
| 61 | + --> $DIR/return-from-residual-sugg-issue-125997.rs:23:52 |
| 62 | + | |
| 63 | +LL | fn test3() { |
| 64 | + | ---------- this function should return `Result` or `Option` to accept `?` |
| 65 | +LL | let mut _file = File::create("foo.txt")?; |
| 66 | + | ^ cannot use the `?` operator in a function that returns `()` |
| 67 | +... |
| 68 | +LL | mac!(); |
| 69 | + | ------ in this macro invocation |
| 70 | + | |
| 71 | + = help: the trait `FromResidual<Result<Infallible, std::io::Error>>` is not implemented for `()` |
| 72 | + = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) |
| 73 | +help: consider adding return type |
| 74 | + | |
| 75 | +LL ~ fn test3() -> Result<(), Box<dyn std::error::Error>> { |
| 76 | +LL | let mut _file = File::create("foo.txt")?; |
| 77 | +LL | |
| 78 | +LL | println!(); |
| 79 | +LL ~ |
| 80 | +LL + Ok(()) |
| 81 | +LL + } |
| 82 | + | |
| 83 | + |
| 84 | +error: aborting due to 4 previous errors |
| 85 | + |
| 86 | +For more information about this error, try `rustc --explain E0277`. |
0 commit comments