]> git.lizzy.rs Git - rust.git/commitdiff
partially port invalid_value lint to diagnostic items
authorRalf Jung <post@ralfj.de>
Sat, 9 Nov 2019 09:34:16 +0000 (10:34 +0100)
committerRalf Jung <post@ralfj.de>
Sat, 9 Nov 2019 09:34:16 +0000 (10:34 +0100)
src/libcore/mem/maybe_uninit.rs
src/libcore/mem/mod.rs
src/librustc_lint/builtin.rs
src/libsyntax_pos/symbol.rs

index 03093139bc2f956a1577bb0bbf972afdbab344e9..1da368d40a964b4eb57a02b7fbc02119a3a605b2 100644 (file)
@@ -254,6 +254,7 @@ pub const fn new(val: T) -> MaybeUninit<T> {
     /// [type]: union.MaybeUninit.html
     #[stable(feature = "maybe_uninit", since = "1.36.0")]
     #[inline(always)]
+    #[cfg_attr(all(not(bootstrap)), rustc_diagnostic_item = "maybe_uninit_uninit")]
     pub const fn uninit() -> MaybeUninit<T> {
         MaybeUninit { uninit: () }
     }
@@ -300,6 +301,7 @@ pub const fn uninit() -> MaybeUninit<T> {
     /// ```
     #[stable(feature = "maybe_uninit", since = "1.36.0")]
     #[inline]
+    #[cfg_attr(all(not(bootstrap)), rustc_diagnostic_item = "maybe_uninit_zeroed")]
     pub fn zeroed() -> MaybeUninit<T> {
         let mut u = MaybeUninit::<T>::uninit();
         unsafe {
index c7da56aad309a976f9291effb656acda9364a1dc..27cbff144ba9131d8905648d6f4ff814c4125f4c 100644 (file)
@@ -457,6 +457,7 @@ pub const fn needs_drop<T>() -> bool {
 #[stable(feature = "rust1", since = "1.0.0")]
 #[allow(deprecated_in_future)]
 #[allow(deprecated)]
+#[cfg_attr(all(not(bootstrap)), rustc_diagnostic_item = "mem_zeroed")]
 pub unsafe fn zeroed<T>() -> T {
     intrinsics::panic_if_uninhabited::<T>();
     intrinsics::init()
@@ -485,6 +486,7 @@ pub unsafe fn zeroed<T>() -> T {
 #[stable(feature = "rust1", since = "1.0.0")]
 #[allow(deprecated_in_future)]
 #[allow(deprecated)]
+#[cfg_attr(all(not(bootstrap)), rustc_diagnostic_item = "mem_uninitialized")]
 pub unsafe fn uninitialized<T>() -> T {
     intrinsics::panic_if_uninhabited::<T>();
     intrinsics::uninit()
index 867f5f76b59bcd34e4a8a5551bdbc07b5e3fb135..09cb784b1541a63586f530b4f7a7bbfd8837edea 100644 (file)
@@ -1903,29 +1903,23 @@ fn is_zero(expr: &hir::Expr) -> bool {
 
         /// Determine if this expression is a "dangerous initialization".
         fn is_dangerous_init(cx: &LateContext<'_, '_>, expr: &hir::Expr) -> Option<InitKind> {
-            const ZEROED_PATH: &[Symbol] = &[sym::core, sym::mem, sym::zeroed];
-            const UININIT_PATH: &[Symbol] = &[sym::core, sym::mem, sym::uninitialized];
             // `transmute` is inside an anonymous module (the `extern` block?);
             // `Invalid` represents the empty string and matches that.
+            // FIXME(#66075): use diagnostic items.  Somehow, that does not seem to work
+            // on intrinsics right now.
             const TRANSMUTE_PATH: &[Symbol] =
                 &[sym::core, sym::intrinsics, kw::Invalid, sym::transmute];
-            const MU_ZEROED_PATH: &[Symbol] =
-                &[sym::core, sym::mem, sym::maybe_uninit, sym::MaybeUninit, sym::zeroed];
-            const MU_UNINIT_PATH: &[Symbol] =
-                &[sym::core, sym::mem, sym::maybe_uninit, sym::MaybeUninit, sym::uninit];
 
             if let hir::ExprKind::Call(ref path_expr, ref args) = expr.kind {
                 // Find calls to `mem::{uninitialized,zeroed}` methods.
                 if let hir::ExprKind::Path(ref qpath) = path_expr.kind {
                     let def_id = cx.tables.qpath_res(qpath, path_expr.hir_id).opt_def_id()?;
 
-                    if cx.match_def_path(def_id, ZEROED_PATH) {
+                    if cx.tcx.is_diagnostic_item(sym::mem_zeroed, def_id) {
                         return Some(InitKind::Zeroed);
-                    }
-                    if cx.match_def_path(def_id, UININIT_PATH) {
+                    } else if cx.tcx.is_diagnostic_item(sym::mem_uninitialized, def_id) {
                         return Some(InitKind::Uninit);
-                    }
-                    if cx.match_def_path(def_id, TRANSMUTE_PATH) {
+                    } else if cx.match_def_path(def_id, TRANSMUTE_PATH) {
                         if is_zero(&args[0]) {
                             return Some(InitKind::Zeroed);
                         }
@@ -1940,9 +1934,10 @@ fn is_dangerous_init(cx: &LateContext<'_, '_>, expr: &hir::Expr) -> Option<InitK
                     if let hir::ExprKind::Call(ref path_expr, _) = args[0].kind {
                         if let hir::ExprKind::Path(ref qpath) = path_expr.kind {
                             let def_id = cx.tables.qpath_res(qpath, path_expr.hir_id).opt_def_id()?;
-                            if cx.match_def_path(def_id, MU_ZEROED_PATH) {
+
+                            if cx.tcx.is_diagnostic_item(sym::maybe_uninit_zeroed, def_id) {
                                 return Some(InitKind::Zeroed);
-                            } else if cx.match_def_path(def_id, MU_UNINIT_PATH) {
+                            } else if cx.tcx.is_diagnostic_item(sym::maybe_uninit_uninit, def_id) {
                                 return Some(InitKind::Uninit);
                             }
                         }
index 64ea82e1bdc53cb592cf1f6b50916b895fef9534..594fd5621fdb334c9d5d3e79cd5f41bbe41f6981 100644 (file)
         match_beginning_vert,
         match_default_bindings,
         may_dangle,
-        maybe_uninit,
-        MaybeUninit,
-        mem,
+        maybe_uninit_uninit,
+        maybe_uninit_zeroed,
+        mem_uninitialized,
+        mem_zeroed,
         member_constraints,
         message,
         meta,
         underscore_imports,
         underscore_lifetimes,
         uniform_paths,
-        uninit,
-        uninitialized,
         universal_impl_trait,
         unmarked_api,
         unreachable_code,
         windows,
         windows_subsystem,
         Yield,
-        zeroed,
     }
 }