about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-02-22 14:58:02 +0100
committerGitHub <noreply@github.com>2019-02-22 14:58:02 +0100
commitbcb7dce75c7b566f091b9f2d5486d7aa162337de (patch)
tree9abc00f9070e678a6023e26310e3e3c41a5d210c
parent42b9a046d46ef00ecd3a13135f3cd5d7044218b6 (diff)
parent9312ca10b6cd672c4fa1da4b4a3cc232f7d7dde6 (diff)
downloadrust-bcb7dce75c7b566f091b9f2d5486d7aa162337de.tar.gz
rust-bcb7dce75c7b566f091b9f2d5486d7aa162337de.zip
Rollup merge of #58555 - scottmcm:try-2015, r=Centril
Add a note about 2018e if someone uses `try {` in 2015e

Inspired by https://github.com/rust-lang/rust/issues/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.

Resolves #53672
-rw-r--r--src/librustc_resolve/error_reporting.rs4
-rw-r--r--src/test/ui/try-block/try-block-in-edition2015.stderr2
2 files changed, 6 insertions, 0 deletions
diff --git a/src/librustc_resolve/error_reporting.rs b/src/librustc_resolve/error_reporting.rs
index c8b3e2f4e4c..cd771d93e00 100644
--- a/src/librustc_resolve/error_reporting.rs
+++ b/src/librustc_resolve/error_reporting.rs
@@ -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");
diff --git a/src/test/ui/try-block/try-block-in-edition2015.stderr b/src/test/ui/try-block/try-block-in-edition2015.stderr
index a7b81060d3d..7394fec6f36 100644
--- a/src/test/ui/try-block/try-block-in-edition2015.stderr
+++ b/src/test/ui/try-block/try-block-in-edition2015.stderr
@@ -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