]> git.proxmox.com Git - rustc.git/blobdiff - src/tools/clippy/clippy_lints/src/large_const_arrays.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / tools / clippy / clippy_lints / src / large_const_arrays.rs
index 27db6388136139e1789e570826078a7ddaeba901..289755bfec66ff74a599c3dd5264f2e9282b4e29 100644 (file)
@@ -3,7 +3,6 @@ use if_chain::if_chain;
 use rustc_errors::Applicability;
 use rustc_hir::{Item, ItemKind};
 use rustc_lint::{LateContext, LateLintPass};
-use rustc_middle::mir::interpret::ConstValue;
 use rustc_middle::ty::layout::LayoutOf;
 use rustc_middle::ty::{self, ConstKind};
 use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -21,10 +20,11 @@ declare_clippy_lint! {
     ///
     /// ### Example
     /// ```rust,ignore
-    /// // Bad
     /// pub const a = [0u32; 1_000_000];
+    /// ```
     ///
-    /// // Good
+    /// Use instead:
+    /// ```rust.ignore
     /// pub static a = [0u32; 1_000_000];
     /// ```
     #[clippy::version = "1.44.0"]
@@ -53,8 +53,8 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays {
             if let ItemKind::Const(hir_ty, _) = &item.kind;
             let ty = hir_ty_to_ty(cx.tcx, hir_ty);
             if let ty::Array(element_type, cst) = ty.kind();
-            if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val();
-            if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx);
+            if let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind();
+            if let Ok(element_count) = element_count.try_to_machine_usize(cx.tcx);
             if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes());
             if self.maximum_allowed_size < element_count * element_size;
 
@@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays {
                         diag.span_suggestion(
                             sugg_span,
                             "make this a static item",
-                            "static".to_string(),
+                            "static",
                             Applicability::MachineApplicable,
                         );
                     }