Skip to content

Commit

Permalink
Rollup merge of rust-lang#58555 - scottmcm:try-2015, r=Centril
Browse files Browse the repository at this point in the history
Add a note about 2018e if someone uses `try {` in 2015e

Inspired by rust-lang#58491, where a `try_blocks` example was accidentally run in 2015, which of course produces a bunch of errors.

What's the philosophy about gating for this?  The keyword is stably a keyword in 2018, so I haven't gated it for now but am not mentioning what the keyword _does_.  Let me know if I should do differently.
  • Loading branch information
Centril authored Feb 20, 2019
2 parents a8722c2 + 9312ca1 commit c198719
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/librustc_resolve/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ impl<'a> Resolver<'a> {
format!("{}!", path_str),
Applicability::MaybeIncorrect,
);
if path_str == "try" && span.rust_2015() {
err.note("if you want the `try` keyword, \
you need to be in the 2018 edition");
}
}
(Def::TyAlias(..), PathSource::Trait(_)) => {
err.span_label(span, "type aliases cannot be used as traits");
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/try-block/try-block-in-edition2015.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ error[E0574]: expected struct, variant or union type, found macro `try`
|
LL | let try_result: Option<_> = try {
| ^^^ help: use `!` to invoke the macro: `try!`
|
= note: if you want the `try` keyword, you need to be in the 2018 edition

error: aborting due to 2 previous errors

Expand Down

0 comments on commit c198719

Please sign in to comment.