Skip to content

Commit c198719

Browse files
authored
Rollup merge of rust-lang#58555 - scottmcm:try-2015, r=Centril
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.
2 parents a8722c2 + 9312ca1 commit c198719

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/librustc_resolve/error_reporting.rs

+4
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ impl<'a> Resolver<'a> {
259259
format!("{}!", path_str),
260260
Applicability::MaybeIncorrect,
261261
);
262+
if path_str == "try" && span.rust_2015() {
263+
err.note("if you want the `try` keyword, \
264+
you need to be in the 2018 edition");
265+
}
262266
}
263267
(Def::TyAlias(..), PathSource::Trait(_)) => {
264268
err.span_label(span, "type aliases cannot be used as traits");

src/test/ui/try-block/try-block-in-edition2015.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ error[E0574]: expected struct, variant or union type, found macro `try`
1616
|
1717
LL | let try_result: Option<_> = try {
1818
| ^^^ help: use `!` to invoke the macro: `try!`
19+
|
20+
= note: if you want the `try` keyword, you need to be in the 2018 edition
1921

2022
error: aborting due to 2 previous errors
2123

0 commit comments

Comments
 (0)