X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=clippy_lints%2Fsrc%2Flarge_stack_arrays.rs;h=bbb6c1f902ce077e7fcfc6f168021f71fb356cde;hb=e6455ea72ca3a4602f6a6b097cb80647a1f69388;hp=9fd3780e14e04023423491d9c94cac1994de5b3a;hpb=28f9b84042b7d0ffd1f913e8ba82348ebe23dd1b;p=rust.git diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index 9fd3780e14e..bbb6c1f902c 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -1,22 +1,21 @@ +use clippy_utils::diagnostics::span_lint_and_help; +use clippy_utils::source::snippet; +use if_chain::if_chain; use rustc_hir::{Expr, ExprKind}; 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}; -use if_chain::if_chain; - -use crate::rustc_target::abi::LayoutOf; -use crate::utils::{snippet, span_lint_and_help}; - declare_clippy_lint! { - /// **What it does:** Checks for local arrays that may be too large. - /// - /// **Why is this bad?** Large local arrays may cause stack overflow. + /// ### What it does + /// Checks for local arrays that may be too large. /// - /// **Known problems:** None. + /// ### Why is this bad? + /// Large local arrays may cause stack overflow. /// - /// **Example:** + /// ### Example /// ```rust,ignore /// let a = [0u32; 1_000_000]; /// ``` @@ -43,8 +42,7 @@ fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { if let ExprKind::Repeat(_, _) = expr.kind; if let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind(); - if let ConstKind::Value(val) = cst.val; - if let ConstValue::Scalar(element_count) = val; + if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val; if let Ok(element_count) = element_count.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;