about summary refs log tree commit diff
path: root/compiler/rustc_lint_defs/src/builtin.rs
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2021-06-14 12:56:49 +0000
committerlrh2000 <lrh2000@pku.edu.cn>2021-06-26 23:11:04 +0800
commitd837c00d1008c2ab13bf80117b81f5e482fc9edb (patch)
treef17ee6f36f349b76ad8b54e360812a392604b01d /compiler/rustc_lint_defs/src/builtin.rs
parent40fb2e97053e2655016688264ff19160741c1dbb (diff)
downloadrust-d837c00d1008c2ab13bf80117b81f5e482fc9edb.tar.gz
rust-d837c00d1008c2ab13bf80117b81f5e482fc9edb.zip
Add migration lint for reserved prefixes.
Diffstat (limited to 'compiler/rustc_lint_defs/src/builtin.rs')
-rw-r--r--compiler/rustc_lint_defs/src/builtin.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs
index 53970b485ee..ba8a8c3d8c9 100644
--- a/compiler/rustc_lint_defs/src/builtin.rs
+++ b/compiler/rustc_lint_defs/src/builtin.rs
@@ -2973,6 +2973,7 @@ declare_lint_pass! {
         OR_PATTERNS_BACK_COMPAT,
         LARGE_ASSIGNMENTS,
         FUTURE_PRELUDE_COLLISION,
+        RESERVED_PREFIX,
     ]
 }
 
@@ -3263,3 +3264,39 @@ declare_lint! {
         reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
     };
 }
+
+declare_lint! {
+    /// The `reserved_prefix` lint detects identifiers that will be parsed as a
+    /// prefix instead in Rust 2021.
+    ///
+    /// ### Example
+    ///
+    /// ```rust,compile_fail
+    /// #![deny(reserved_prefix)]
+    ///
+    /// macro_rules! m {
+    ///     (z $x:expr) => ();
+    /// }
+    ///
+    /// m!(z"hey");
+    /// ```
+    ///
+    /// {{produces}}
+    ///
+    /// ### Explanation
+    ///
+    /// In Rust 2015 and 2018, `z"hey"` is two tokens: the identifier `z`
+    /// followed by the string literal `"hey"`. In Rust 2021, the `z` is
+    /// considered a prefix for `"hey"`.
+    ///
+    /// This lint suggests to add whitespace between the `z` and `"hey"` tokens
+    /// to keep them separated in Rust 2021.
+    pub RESERVED_PREFIX,
+    Allow,
+    "identifiers that will be parsed as a prefix in Rust 2021",
+    @future_incompatible = FutureIncompatibleInfo {
+        reference: "issue #84978 <https://github.com/rust-lang/rust/issues/84978>",
+        edition: Some(Edition::Edition2021),
+    };
+    crate_level_only
+}