X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_lint_defs%2Fsrc%2Fbuiltin.rs;h=ba8a8c3d8c993cc036270771d061417c0045d0de;hb=d837c00d1008c2ab13bf80117b81f5e482fc9edb;hp=53970b485eecd6a8d7616d149c931e8e066afe0d;hpb=481971978fda83aa7cf1f1f3c80cfad822377cf2;p=rust.git 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 @@ OR_PATTERNS_BACK_COMPAT, LARGE_ASSIGNMENTS, FUTURE_PRELUDE_COLLISION, + RESERVED_PREFIX, ] } @@ -3263,3 +3264,39 @@ 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 ", + edition: Some(Edition::Edition2021), + }; + crate_level_only +}