Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for use of try!() in 2018 edition and guide users in the right direction #71155

Closed
estebank opened this issue Apr 14, 2020 · 2 comments · Fixed by #71243
Closed

Account for use of try!() in 2018 edition and guide users in the right direction #71155

estebank opened this issue Apr 14, 2020 · 2 comments · Fixed by #71243
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-edition-2018 Area: The 2018 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-parser Area: The parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one. D-edition Diagnostics: An error or lint that should account for edition differences. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. F-try_blocks `#![feature(try_blocks)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Apr 14, 2020

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.

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-edition-2018-lints F-try_blocks `#![feature(try_blocks)]` D-papercut Diagnostics: An error or lint that needs small tweaks. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-edition Diagnostics: An error or lint that should account for edition differences. labels Apr 14, 2020
@JohnTitor JohnTitor added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Apr 15, 2020
@Duddino
Copy link

Duddino commented Apr 16, 2020

@rustbot claim

@rustbot rustbot self-assigned this Apr 16, 2020
@Duddino
Copy link

Duddino commented Apr 16, 2020

Would it be fine if I modified

pub(super) fn expected_expression_found(&self) -> DiagnosticBuilder<'a> {
let (span, msg) = match (&self.token.kind, self.subparser_name) {
(&token::Eof, Some(origin)) => {
let sp = self.sess.source_map().next_point(self.token.span);
(sp, format!("expected expression, found end of {}", origin))
}
_ => (
self.token.span,
format!("expected expression, found {}", super::token_descr(&self.token),),
),
};
let mut err = self.struct_span_err(span, &msg);
let sp = self.sess.source_map().start_point(self.token.span);
if let Some(sp) = self.sess.ambiguous_block_expr_parse.borrow().get(&sp) {
self.sess.expr_parentheses_needed(&mut err, *sp, None);
}
err.span_label(span, "expected expression");
err
}
and check if the try keyword is used, or is there another way to tackle this issue

@bors bors closed this as completed in 4b9eeca Apr 18, 2020
@fmease fmease added A-edition-2018 Area: The 2018 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. and removed A-edition-2018-lints labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-edition-2018 Area: The 2018 edition A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-parser Area: The parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one. D-edition Diagnostics: An error or lint that should account for edition differences. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. F-try_blocks `#![feature(try_blocks)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants