Closed
Description
Old documentation and blogposts will never be updated to not talk about the try
macro. The current output of the following code
fn foo() -> Result<(), ()> {
Ok(try!(Ok(())))
}
is
error: expected expression, found reserved keyword `try`
--> src/main.rs:2:8
|
2 | Ok(try!(Ok(())))
| ^^^ expected expression
It should provide structured suggestions to either use r#try
or ?
:
error: use of deprecated `try` macro
--> src/main.rs:2:8
|
2 | Ok(try!(Ok(())))
| ^^^^^ ^
| |
| deprecated `try` macro
= note: in the 2018 edition `try` is a reserved keyword, and the `try!()` macro is deprecated
help: you can use the `?` operator instead
|
2 | Ok(Ok(())?))
| -- ^
help: alternatively, you can still access the deprecated `try!()` macro using the "raw identifier" syntax
|
2 | Ok(r#try!(Ok(())))
| ^^
This request is similar in spirit to #67204 and feels like a subset of #65148.
This issue has been assigned to @Duddino via this comment.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: The 2018 editionArea: Lints (warnings about flaws in source code) such as unused_mut.Area: The lexing & parsing of Rust source code to an ASTCategory: An issue proposing an enhancement or a PR with one.Diagnostics: An error or lint that should account for edition differences.Diagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: An error or lint that needs small tweaks.`#![feature(try_blocks)]`Relevant to the compiler team, which will review and decide on the PR/issue.
Activity
Duddino commentedon Apr 16, 2020
@rustbot claim
Duddino commentedon Apr 16, 2020
Would it be fine if I modified
rust/src/librustc_parse/parser/diagnostics.rs
Lines 1457 to 1476 in 534a41a
try
keyword is used, or is there another way to tackle this issuetry!()
in 2018 edition and guide users in the right direction #71243Rollup merge of rust-lang#71243 - Duddino:Fix2, r=estebank