X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_lint_defs%2Fsrc%2Fbuiltin.rs;h=ba8a8c3d8c993cc036270771d061417c0045d0de;hb=d837c00d1008c2ab13bf80117b81f5e482fc9edb;hp=f95d4a6ca54812b2efb33dce2d2ad6a46ae9dd72;hpb=c38111c4fb9c22a36f9a9195d1884052bb670af2;p=rust.git diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index f95d4a6ca54..ba8a8c3d8c9 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -6,7 +6,7 @@ //! compiler code, rather than using their own custom pass. Those //! lints are all available in `rustc_lint::builtin`. -use crate::{declare_lint, declare_lint_pass, FutureBreakage}; +use crate::{declare_lint, declare_lint_pass, FutureBreakage, FutureIncompatibilityReason}; use rustc_span::edition::Edition; declare_lint! { @@ -41,7 +41,6 @@ "applying forbid to lint-groups", @future_incompatible = FutureIncompatibleInfo { reference: "issue #81670 ", - edition: None, }; } @@ -77,7 +76,6 @@ "ill-formed attribute inputs that were previously accepted and used in practice", @future_incompatible = FutureIncompatibleInfo { reference: "issue #57571 ", - edition: None, }; crate_level_only } @@ -114,7 +112,6 @@ "conflicts between `#[repr(..)]` hints that were previously accepted and used in practice", @future_incompatible = FutureIncompatibleInfo { reference: "issue #68585 ", - edition: None, }; } @@ -293,7 +290,6 @@ "constant evaluation encountered erroneous expression", @future_incompatible = FutureIncompatibleInfo { reference: "issue #71800 ", - edition: None, }; report_in_external_macro } @@ -900,7 +896,6 @@ "detect private items in public interfaces not caught by the old implementation", @future_incompatible = FutureIncompatibleInfo { reference: "issue #34537 ", - edition: None, }; } @@ -980,7 +975,6 @@ "detect public re-exports of private extern crates", @future_incompatible = FutureIncompatibleInfo { reference: "issue #34537 ", - edition: None, }; } @@ -1010,7 +1004,6 @@ "type parameter default erroneously allowed in invalid location", @future_incompatible = FutureIncompatibleInfo { reference: "issue #36887 ", - edition: None, }; } @@ -1078,7 +1071,6 @@ "detects unaligned references to fields of packed structs", @future_incompatible = FutureIncompatibleInfo { reference: "issue #82523 ", - edition: None, }; report_in_external_macro } @@ -1200,7 +1192,6 @@ "patterns in functions without body were erroneously allowed", @future_incompatible = FutureIncompatibleInfo { reference: "issue #35203 ", - edition: None, }; } @@ -1244,7 +1235,6 @@ "detects missing fragment specifiers in unused `macro_rules!` patterns", @future_incompatible = FutureIncompatibleInfo { reference: "issue #40107 ", - edition: None, }; } @@ -1286,7 +1276,6 @@ "detects generic lifetime arguments in path segments with late bound lifetime parameters", @future_incompatible = FutureIncompatibleInfo { reference: "issue #42868 ", - edition: None, }; } @@ -1322,7 +1311,6 @@ "trait-object types were treated as different depending on marker-trait order", @future_incompatible = FutureIncompatibleInfo { reference: "issue #56484 ", - edition: None, }; } @@ -1362,7 +1350,6 @@ "distinct impls distinguished only by the leak-check code", @future_incompatible = FutureIncompatibleInfo { reference: "issue #56105 ", - edition: None, }; } @@ -1554,7 +1541,7 @@ "raw pointer to an inference variable", @future_incompatible = FutureIncompatibleInfo { reference: "issue #46906 ", - edition: Some(Edition::Edition2018), + reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018), }; } @@ -1621,7 +1608,7 @@ "suggest using `dyn Trait` for trait objects", @future_incompatible = FutureIncompatibleInfo { reference: "issue #80165 ", - edition: Some(Edition::Edition2021), + reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021), }; } @@ -1676,7 +1663,7 @@ instead of `crate`, `self`, or an extern crate name", @future_incompatible = FutureIncompatibleInfo { reference: "issue #53130 ", - edition: Some(Edition::Edition2018), + reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018), }; } @@ -1725,7 +1712,6 @@ "floating-point literals cannot be used in patterns", @future_incompatible = FutureIncompatibleInfo { reference: "issue #41620 ", - edition: None, }; } @@ -1769,7 +1755,6 @@ "detects name collision with an existing but unstable method", @future_incompatible = FutureIncompatibleInfo { reference: "issue #48919 ", - edition: None, // Note: this item represents future incompatibility of all unstable functions in the // standard library, and thus should never be removed or changed to an error. }; @@ -1873,7 +1858,6 @@ "checks the object safety of where clauses", @future_incompatible = FutureIncompatibleInfo { reference: "issue #51443 ", - edition: None, }; } @@ -1940,7 +1924,6 @@ "detects proc macro derives using inaccessible names from parent modules", @future_incompatible = FutureIncompatibleInfo { reference: "issue #83583 ", - edition: None, }; } @@ -2043,7 +2026,6 @@ cannot be referred to by absolute paths", @future_incompatible = FutureIncompatibleInfo { reference: "issue #52234 ", - edition: None, }; crate_level_only } @@ -2134,7 +2116,6 @@ "constant used in pattern contains value of non-structural-match type in a field or a variant", @future_incompatible = FutureIncompatibleInfo { reference: "issue #62411 ", - edition: None, }; } @@ -2190,7 +2171,6 @@ "pointers are not structural-match", @future_incompatible = FutureIncompatibleInfo { reference: "issue #62411 ", - edition: None, }; } @@ -2229,7 +2209,6 @@ expression contains values of non-structural-match types", @future_incompatible = FutureIncompatibleInfo { reference: "issue #73448 ", - edition: None, }; } @@ -2287,7 +2266,6 @@ "ambiguous associated items", @future_incompatible = FutureIncompatibleInfo { reference: "issue #57644 ", - edition: None, }; } @@ -2318,7 +2296,6 @@ "reservation of a two-phased borrow conflicts with other shared borrows", @future_incompatible = FutureIncompatibleInfo { reference: "issue #59159 ", - edition: None, }; } @@ -2360,7 +2337,6 @@ "a feature gate that doesn't break dependent crates", @future_incompatible = FutureIncompatibleInfo { reference: "issue #64266 ", - edition: None, }; } @@ -2589,7 +2565,6 @@ "a C-like enum implementing Drop is cast", @future_incompatible = FutureIncompatibleInfo { reference: "issue #73333 ", - edition: None, }; } @@ -2629,7 +2604,6 @@ "detects a generic constant is used in a type without a emitting a warning", @future_incompatible = FutureIncompatibleInfo { reference: "issue #76200 ", - edition: None, }; } @@ -2688,7 +2662,6 @@ "uninhabited static", @future_incompatible = FutureIncompatibleInfo { reference: "issue #74840 ", - edition: None, }; } @@ -2758,7 +2731,6 @@ "unsupported naked function definitions", @future_incompatible = FutureIncompatibleInfo { reference: "issue #32408 ", - edition: None, }; } @@ -2831,7 +2803,6 @@ "trailing semicolon in macro body used as expression", @future_incompatible = FutureIncompatibleInfo { reference: "issue #79813 ", - edition: None, }; } @@ -3001,6 +2972,8 @@ PROC_MACRO_BACK_COMPAT, OR_PATTERNS_BACK_COMPAT, LARGE_ASSIGNMENTS, + FUTURE_PRELUDE_COLLISION, + RESERVED_PREFIX, ] } @@ -3153,7 +3126,6 @@ "detects invalid `#[doc(...)]` attributes", @future_incompatible = FutureIncompatibleInfo { reference: "issue #82730 ", - edition: None, }; } @@ -3200,7 +3172,6 @@ "detects usage of old versions of certain proc-macro crates", @future_incompatible = FutureIncompatibleInfo { reference: "issue #83125 ", - edition: None, future_breakage: Some(FutureBreakage { date: None }) @@ -3241,6 +3212,91 @@ "detects usage of old versions of or-patterns", @future_incompatible = FutureIncompatibleInfo { reference: "issue #84869 ", + reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021), + }; +} + +declare_lint! { + /// The `future_prelude_collision` lint detects the usage of trait methods which are ambiguous + /// with traits added to the prelude in future editions. + /// + /// ### Example + /// + /// ```rust,compile_fail + /// #![deny(future_prelude_collision)] + /// + /// trait Foo { + /// fn try_into(self) -> Result; + /// } + /// + /// impl Foo for &str { + /// fn try_into(self) -> Result { + /// Ok(String::from(self)) + /// } + /// } + /// + /// fn main() { + /// let x: String = "3".try_into().unwrap(); + /// // ^^^^^^^^ + /// // This call to try_into matches both Foo:try_into and TryInto::try_into as + /// // `TryInto` has been added to the Rust prelude in 2021 edition. + /// println!("{}", x); + /// } + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// In Rust 2021, one of the important introductions is the [prelude changes], which add + /// `TryFrom`, `TryInto`, and `FromIterator` into the standard library's prelude. Since this + /// results in an ambiguity as to which method/function to call when an existing `try_into` + /// method is called via dot-call syntax or a `try_from`/`from_iter` associated function + /// is called directly on a type. + /// + /// [prelude changes]: https://blog.rust-lang.org/inside-rust/2021/03/04/planning-rust-2021.html#prelude-changes + pub FUTURE_PRELUDE_COLLISION, + Allow, + "detects the usage of trait methods which are ambiguous with traits added to the \ + prelude in future editions", + @future_incompatible = FutureIncompatibleInfo { + reference: "issue #85684 ", + 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 }