-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I have the following code:
#![feature(try_blocks)]
fn main() {
println!(
"{:?}",
try {
if true {
Ok(0usize)
} else {
Err(true)
}
}
);
}I get the following error:
error[[E0282]](https://doc.rust-lang.org/nightly/error-index.html#E0282): type annotations needed
--> src/main.rs:6:9
|
6 | / try {
7 | | if true {
8 | | Ok(0usize)
9 | | } else {
10 | | Err(true)
11 | | }
12 | | }
| |_________^ cannot infer type of the type parameter `T` declared on the associated function `new_debug`
|
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider specifying the generic argument
|
12 | }::<T>
| +++++
If I try to follow the compiler's advice by adding a trailing ::<Result<usize, bool>> on line 12, it results in code that can't be parsed:
error: expected one of `,`, `.`, `?`, `catch`, or an operator, found `::`
--> src/main.rs:12:10
|
12 | }::<Result<usize, bool>>
| ^^ expected one of `,`, `.`, `?`, `catch`, or an operator
Version
Current nightly (2022-10-01 57f097e)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.