about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2018-07-25 17:26:58 -0700
committerAlex Crichton <alex@alexcrichton.com>2018-07-26 14:14:10 -0700
commit336cf9db5f1c6efb0e2a6fe6e45a0716fd702188 (patch)
treee159aa6c1cc03ec1d45e06c878b3919310714a2f
parente842dea7a3d9babc7a19bd201711f4243840fab0 (diff)
downloadrust-336cf9db5f1c6efb0e2a6fe6e45a0716fd702188.tar.gz
rust-336cf9db5f1c6efb0e2a6fe6e45a0716fd702188.zip
Tweak the raw_identifiers lints in 2018
* Enable the `raw_identifiers` feature automatically in the 2018 preview
* Only emit lint warnings if the `raw_identifiers` feature is activated

cc rust-lang/cargo#5783
-rw-r--r--src/librustc_lint/builtin.rs16
-rw-r--r--src/libsyntax/feature_gate.rs2
-rw-r--r--src/test/ui/rust-2018/async-ident-allowed.rs21
-rw-r--r--src/test/ui/rust-2018/async-ident-allowed.stderr17
4 files changed, 49 insertions, 7 deletions
diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs
index 3ffbdc7b7dc..ca5268dc61b 100644
--- a/src/librustc_lint/builtin.rs
+++ b/src/librustc_lint/builtin.rs
@@ -1830,12 +1830,16 @@ impl Async2018 {
             span,
             "`async` is a keyword in the 2018 edition",
         );
-        lint.span_suggestion_with_applicability(
-            span,
-            "you can use a raw identifier to stay compatible",
-            "r#async".to_string(),
-            Applicability::MachineApplicable,
-        );
+
+        // Don't suggest about raw identifiers if the feature isn't active
+        if cx.sess.features_untracked().raw_identifiers {
+            lint.span_suggestion_with_applicability(
+                span,
+                "you can use a raw identifier to stay compatible",
+                "r#async".to_string(),
+                Applicability::MachineApplicable,
+            );
+        }
         lint.emit()
     }
 }
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index 30137439e77..27af8fc4175 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -409,7 +409,7 @@ declare_features! (
     (active, underscore_imports, "1.26.0", Some(48216), None),
 
     // Allows keywords to be escaped for use as identifiers
-    (active, raw_identifiers, "1.26.0", Some(48589), None),
+    (active, raw_identifiers, "1.26.0", Some(48589), Some(Edition::Edition2018)),
 
     // Allows macro invocations in `extern {}` blocks
     (active, macros_in_extern, "1.27.0", Some(49476), None),
diff --git a/src/test/ui/rust-2018/async-ident-allowed.rs b/src/test/ui/rust-2018/async-ident-allowed.rs
new file mode 100644
index 00000000000..fd4eae1f9b5
--- /dev/null
+++ b/src/test/ui/rust-2018/async-ident-allowed.rs
@@ -0,0 +1,21 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags: --edition 2015
+
+#![deny(rust_2018_compatibility)]
+
+// Don't make a suggestion for a raw identifer replacement unless raw
+// identifiers are enabled.
+
+fn main() {
+    let async = 3; //~ ERROR: is a keyword
+    //~^ WARN previously accepted
+}
diff --git a/src/test/ui/rust-2018/async-ident-allowed.stderr b/src/test/ui/rust-2018/async-ident-allowed.stderr
new file mode 100644
index 00000000000..1644102cdca
--- /dev/null
+++ b/src/test/ui/rust-2018/async-ident-allowed.stderr
@@ -0,0 +1,17 @@
+error: `async` is a keyword in the 2018 edition
+  --> $DIR/async-ident-allowed.rs:19:9
+   |
+LL |     let async = 3; //~ ERROR: is a keyword
+   |         ^^^^^
+   |
+note: lint level defined here
+  --> $DIR/async-ident-allowed.rs:13:9
+   |
+LL | #![deny(rust_2018_compatibility)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^
+   = note: #[deny(async_idents)] implied by #[deny(rust_2018_compatibility)]
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
+   = note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
+
+error: aborting due to previous error
+