@@ -37,6 +37,7 @@ declare_lint_pass! {
3737 DEPRECATED ,
3838 DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME ,
3939 DEPRECATED_IN_FUTURE ,
40+ DEPRECATED_SAFE ,
4041 DEPRECATED_WHERE_CLAUSE_LOCATION ,
4142 DUPLICATE_MACRO_ATTRIBUTES ,
4243 ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT ,
@@ -4844,3 +4845,51 @@ declare_lint! {
48444845 reference: "issue #124559 <https://github.com/rust-lang/rust/issues/124559>" ,
48454846 } ;
48464847}
4848+
4849+ declare_lint ! {
4850+ /// The `deprecated_safe` lint detects unsafe functions being used as safe
4851+ /// functions.
4852+ ///
4853+ /// ### Example
4854+ ///
4855+ /// ```rust,edition2021,compile_fail
4856+ /// #![deny(deprecated_safe)]
4857+ /// // edition 2021
4858+ /// use std::env;
4859+ /// fn enable_backtrace() {
4860+ /// env::set_var("RUST_BACKTRACE", "1");
4861+ /// }
4862+ /// ```
4863+ ///
4864+ /// {{produces}}
4865+ ///
4866+ /// ### Explanation
4867+ ///
4868+ /// Rust [editions] allow the language to evolve without breaking backward
4869+ /// compatibility. This lint catches code that uses `unsafe` functions that
4870+ /// were declared as safe (non-`unsafe`) in earlier editions. If you switch
4871+ /// the compiler to a new edition without updating the code, then it
4872+ /// will fail to compile if you are using a function previously marked as
4873+ /// safe.
4874+ ///
4875+ /// You can audit the code to see if it suffices the preconditions of the
4876+ /// `unsafe` code, and if it does, you can wrap it in an `unsafe` block. If
4877+ /// you can't fulfill the preconditions, you probably need to switch to a
4878+ /// different way of doing what you want to achieve.
4879+ ///
4880+ /// This lint can automatically wrap the calls in `unsafe` blocks, but this
4881+ /// obviously cannot verify that the preconditions of the `unsafe`
4882+ /// functions are fulfilled, so that is still up to the user.
4883+ ///
4884+ /// The lint is currently "allow" by default, but that might change in the
4885+ /// future.
4886+ ///
4887+ /// [editions]: https://doc.rust-lang.org/edition-guide/
4888+ pub DEPRECATED_SAFE ,
4889+ Allow ,
4890+ "detects unsafe functions being used as safe functions" ,
4891+ @future_incompatible = FutureIncompatibleInfo {
4892+ reason: FutureIncompatibilityReason :: EditionError ( Edition :: Edition2024 ) ,
4893+ reference: "issue #27970 <https://github.com/rust-lang/rust/issues/27970>" ,
4894+ } ;
4895+ }
0 commit comments