From bb4f2e05905d948d1a8c70517d284fc4c641e063 Mon Sep 17 00:00:00 2001 From: Areredify Date: Tue, 12 Nov 2019 22:22:53 +0000 Subject: [PATCH 1/8] initial implementation --- CHANGELOG.md | 1 + README.md | 2 +- clippy_lints/src/large_stack_arrays.rs | 50 +++++++++++++++++++ clippy_lints/src/lib.rs | 5 ++ clippy_lints/src/utils/conf.rs | 2 + src/lintlist/mod.rs | 9 +++- .../toml_unknown_key/conf_unknown_key.stderr | 2 +- tests/ui/large_stack_arrays.rs | 30 +++++++++++ tests/ui/large_stack_arrays.stderr | 35 +++++++++++++ 9 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 clippy_lints/src/large_stack_arrays.rs create mode 100644 tests/ui/large_stack_arrays.rs create mode 100644 tests/ui/large_stack_arrays.stderr diff --git a/CHANGELOG.md b/CHANGELOG.md index 30d3108e0be4..94858c8fa17d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1059,6 +1059,7 @@ Released 2018-09-13 [`just_underscores_and_digits`]: https://rust-lang.github.io/rust-clippy/master/index.html#just_underscores_and_digits [`large_digit_groups`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_digit_groups [`large_enum_variant`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant +[`large_stack_arrays`]: https://rust-lang.github.io/rust-clippy/master/index.html#large_stack_arrays [`len_without_is_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty [`len_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#len_zero [`let_and_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return diff --git a/README.md b/README.md index 922dbcd11380..c5106e074cbc 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. -[There are 333 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) +[There are 334 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you: diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs new file mode 100644 index 000000000000..df407d5a08ef --- /dev/null +++ b/clippy_lints/src/large_stack_arrays.rs @@ -0,0 +1,50 @@ +use rustc::hir::*; +use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; +use rustc::mir::interpret::{ConstValue, Scalar}; +use rustc::ty; +use rustc::{declare_tool_lint, impl_lint_pass}; + +use if_chain::if_chain; + +use crate::rustc_target::abi::LayoutOf; +use crate::utils::span_help_and_lint; + +declare_clippy_lint! { + pub LARGE_STACK_ARRAYS, + pedantic, + "allocating large arrays on stack may cause stack overflow" +} + +pub struct LargeStackArrays { + maximum_size_allowed: u64, +} + +impl LargeStackArrays { + #[must_use] + pub fn new(maximum_size_allowed: u64) -> Self { + Self { maximum_size_allowed } + } +} + +impl_lint_pass!(LargeStackArrays => [LARGE_STACK_ARRAYS]); + +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeStackArrays { + 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.tables.expr_ty(expr).kind; + if let ConstValue::Scalar(Scalar::Raw{data: element_count, size: _}) = cst.val; + if let Ok(element_size) = cx.layout_of(element_type).map(|l| l.size.bytes()); + if (self.maximum_size_allowed as u128) < element_count * element_size as u128; + then { + span_help_and_lint( + cx, + LARGE_STACK_ARRAYS, + expr.span, + "allocating large array on the stack", + "consider allocating on the heap with vec![...].into_boxed_slice()", + ); + } + } + } +} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 00028ec19650..e417097b3b08 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -211,6 +211,7 @@ pub mod int_plus_one; pub mod integer_division; pub mod items_after_statements; pub mod large_enum_variant; +pub mod large_stack_arrays; pub mod len_zero; pub mod let_if_seq; pub mod lifetimes; @@ -537,6 +538,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf &integer_division::INTEGER_DIVISION, &items_after_statements::ITEMS_AFTER_STATEMENTS, &large_enum_variant::LARGE_ENUM_VARIANT, + &large_stack_arrays::LARGE_STACK_ARRAYS, &len_zero::LEN_WITHOUT_IS_EMPTY, &len_zero::LEN_ZERO, &let_if_seq::USELESS_LET_IF_SEQ, @@ -949,6 +951,8 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf store.register_late_pass(|| box mutable_debug_assertion::DebugAssertWithMutCall); store.register_late_pass(|| box exit::Exit); store.register_late_pass(|| box to_digit_is_some::ToDigitIsSome); + let array_size_threshold = conf.array_size_threshold; + store.register_late_pass(move || box large_stack_arrays::LargeStackArrays::new(array_size_threshold)); store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![ LintId::of(&arithmetic::FLOAT_ARITHMETIC), @@ -1002,6 +1006,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf LintId::of(&if_not_else::IF_NOT_ELSE), LintId::of(&infinite_iter::MAYBE_INFINITE_ITER), LintId::of(&items_after_statements::ITEMS_AFTER_STATEMENTS), + LintId::of(&large_stack_arrays::LARGE_STACK_ARRAYS), LintId::of(&literal_representation::LARGE_DIGIT_GROUPS), LintId::of(&loops::EXPLICIT_INTO_ITER_LOOP), LintId::of(&loops::EXPLICIT_ITER_LOOP), diff --git a/clippy_lints/src/utils/conf.rs b/clippy_lints/src/utils/conf.rs index 734b689ab1a6..a3407d1e9902 100644 --- a/clippy_lints/src/utils/conf.rs +++ b/clippy_lints/src/utils/conf.rs @@ -151,6 +151,8 @@ define_Conf! { (trivial_copy_size_limit, "trivial_copy_size_limit", None => Option), /// Lint: TOO_MANY_LINES. The maximum number of lines a function or method can have (too_many_lines_threshold, "too_many_lines_threshold", 100 => u64), + /// Lint: LARGE_STACK_ARRAYS. The maximum allowed size for arrays on the stack + (array_size_threshold, "array_size_threshold", 512_000 => u64), } impl Default for Conf { diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 0b301b6be963..83bab9c865d4 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -6,7 +6,7 @@ pub use lint::Lint; pub use lint::LINT_LEVELS; // begin lint list, do not remove this comment, it’s used in `update_lints` -pub const ALL_LINTS: [Lint; 333] = [ +pub const ALL_LINTS: [Lint; 334] = [ Lint { name: "absurd_extreme_comparisons", group: "correctness", @@ -903,6 +903,13 @@ pub const ALL_LINTS: [Lint; 333] = [ deprecation: None, module: "large_enum_variant", }, + Lint { + name: "large_stack_arrays", + group: "pedantic", + desc: "allocating large arrays on stack may cause stack overflow", + deprecation: None, + module: "large_stack_arrays", + }, Lint { name: "len_without_is_empty", group: "style", diff --git a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr index c9446cda77cf..cbb4126a8668 100644 --- a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr +++ b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr @@ -1,4 +1,4 @@ -error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `blacklisted-names`, `cognitive-complexity-threshold`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `literal-representation-threshold`, `trivial-copy-size-limit`, `too-many-lines-threshold`, `third-party` at line 5 column 1 +error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `blacklisted-names`, `cognitive-complexity-threshold`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `literal-representation-threshold`, `trivial-copy-size-limit`, `too-many-lines-threshold`, `array-size-threshold`, `third-party` at line 5 column 1 error: aborting due to previous error diff --git a/tests/ui/large_stack_arrays.rs b/tests/ui/large_stack_arrays.rs new file mode 100644 index 000000000000..d9161bfcf154 --- /dev/null +++ b/tests/ui/large_stack_arrays.rs @@ -0,0 +1,30 @@ +#![warn(clippy::large_stack_arrays)] +#![allow(clippy::large_enum_variant)] + +#[derive(Clone, Copy)] +struct S { + pub data: [u64; 32], +} + +#[derive(Clone, Copy)] +enum E { + S(S), + T(u32), +} + +fn main() { + let bad = ( + [0u32; 20_000_000], + [S { data: [0; 32] }; 5000], + [Some(""); 20_000_000], + [E::T(0); 5000], + ); + + let good = ( + [0u32; 1000], + [S { data: [0; 32] }; 1000], + [Some(""); 1000], + [E::T(0); 1000], + [(); 20_000_000], + ); +} diff --git a/tests/ui/large_stack_arrays.stderr b/tests/ui/large_stack_arrays.stderr new file mode 100644 index 000000000000..f68f44712379 --- /dev/null +++ b/tests/ui/large_stack_arrays.stderr @@ -0,0 +1,35 @@ +error: allocating large array on the stack + --> $DIR/large_stack_arrays.rs:17:9 + | +LL | [0u32; 20_000_000], + | ^^^^^^^^^^^^^^^^^^ + | + = note: `-D clippy::large-stack-arrays` implied by `-D warnings` + = help: consider allocating on the heap with vec![...].into_boxed_slice() + +error: allocating large array on the stack + --> $DIR/large_stack_arrays.rs:18:9 + | +LL | [S { data: [0; 32] }; 5000], + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider allocating on the heap with vec![...].into_boxed_slice() + +error: allocating large array on the stack + --> $DIR/large_stack_arrays.rs:19:9 + | +LL | [Some(""); 20_000_000], + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = help: consider allocating on the heap with vec![...].into_boxed_slice() + +error: allocating large array on the stack + --> $DIR/large_stack_arrays.rs:20:9 + | +LL | [E::T(0); 5000], + | ^^^^^^^^^^^^^^^ + | + = help: consider allocating on the heap with vec![...].into_boxed_slice() + +error: aborting due to 4 previous errors + From 4ae615c35e47470a588b90bc3e946ceda33291c2 Mon Sep 17 00:00:00 2001 From: Areredify Date: Tue, 12 Nov 2019 22:40:18 +0000 Subject: [PATCH 2/8] added documentation --- clippy_lints/src/large_stack_arrays.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index df407d5a08ef..435ad3efd9ea 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -10,19 +10,29 @@ use crate::rustc_target::abi::LayoutOf; use crate::utils::span_help_and_lint; 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. + /// + /// **Known problems:** None. + /// + /// **Example:** + /// ```rust + /// let a = [0u32; 1_000_000_000]; + /// ``` pub LARGE_STACK_ARRAYS, pedantic, "allocating large arrays on stack may cause stack overflow" } pub struct LargeStackArrays { - maximum_size_allowed: u64, + maximum_allowed_size: u64, } impl LargeStackArrays { #[must_use] - pub fn new(maximum_size_allowed: u64) -> Self { - Self { maximum_size_allowed } + pub fn new(maximum_allowed_size: u64) -> Self { + Self { maximum_allowed_size } } } @@ -35,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeStackArrays { if let ty::Array(element_type, cst) = cx.tables.expr_ty(expr).kind; if let ConstValue::Scalar(Scalar::Raw{data: element_count, size: _}) = cst.val; if let Ok(element_size) = cx.layout_of(element_type).map(|l| l.size.bytes()); - if (self.maximum_size_allowed as u128) < element_count * element_size as u128; + if (self.maximum_allowed_size as u128) < element_count * element_size as u128; then { span_help_and_lint( cx, From 69b286157f60cc816d07fe93a3dec8c2e6734026 Mon Sep 17 00:00:00 2001 From: Mikhail Babenko Date: Wed, 13 Nov 2019 02:03:49 +0300 Subject: [PATCH 3/8] minor style fix --- clippy_lints/src/large_stack_arrays.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index 435ad3efd9ea..81f4801a804a 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -43,7 +43,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeStackArrays { if_chain! { if let ExprKind::Repeat(_, _) = expr.kind; if let ty::Array(element_type, cst) = cx.tables.expr_ty(expr).kind; - if let ConstValue::Scalar(Scalar::Raw{data: element_count, size: _}) = cst.val; + if let ConstValue::Scalar(Scalar::Raw{data: element_count, ..}) = cst.val; if let Ok(element_size) = cx.layout_of(element_type).map(|l| l.size.bytes()); if (self.maximum_allowed_size as u128) < element_count * element_size as u128; then { From 0ef1b08f88bd1dcb3a46c877a34e8073e5813373 Mon Sep 17 00:00:00 2001 From: Mikhail Babenko Date: Wed, 13 Nov 2019 02:36:09 +0300 Subject: [PATCH 4/8] change as to ::from --- clippy_lints/src/large_stack_arrays.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index 81f4801a804a..0a9ad1e1f69e 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -45,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeStackArrays { if let ty::Array(element_type, cst) = cx.tables.expr_ty(expr).kind; if let ConstValue::Scalar(Scalar::Raw{data: element_count, ..}) = cst.val; if let Ok(element_size) = cx.layout_of(element_type).map(|l| l.size.bytes()); - if (self.maximum_allowed_size as u128) < element_count * element_size as u128; + if u128::from(self.maximum_allowed_size) < element_count * u128::from(element_size); then { span_help_and_lint( cx, From 3d2518a9142a4de54ca6f8776d12efdd2b9f2d85 Mon Sep 17 00:00:00 2001 From: Mikhail Babenko Date: Wed, 13 Nov 2019 03:07:06 +0300 Subject: [PATCH 5/8] add ignore to doc --- clippy_lints/src/large_stack_arrays.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index 0a9ad1e1f69e..b47b300ed743 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -17,8 +17,8 @@ declare_clippy_lint! { /// **Known problems:** None. /// /// **Example:** - /// ```rust - /// let a = [0u32; 1_000_000_000]; + /// ```rust,ignore + /// let a = [0u32; 1_000_000]; /// ``` pub LARGE_STACK_ARRAYS, pedantic, From 5a2feb1bfcb4e741b17a0bce7334b2f4d498ac52 Mon Sep 17 00:00:00 2001 From: Mikhail Babenko Date: Wed, 13 Nov 2019 18:02:10 +0300 Subject: [PATCH 6/8] include threshold in lint message/make suggestion more apparent/use Scalar api instead of matching --- clippy_lints/src/large_stack_arrays.rs | 19 +++++++++++++------ tests/ui/large_stack_arrays.stderr | 16 ++++++++-------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index b47b300ed743..cccda9fe5408 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -1,13 +1,13 @@ use rustc::hir::*; use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass}; -use rustc::mir::interpret::{ConstValue, Scalar}; +use rustc::mir::interpret::ConstValue; use rustc::ty; use rustc::{declare_tool_lint, impl_lint_pass}; use if_chain::if_chain; use crate::rustc_target::abi::LayoutOf; -use crate::utils::span_help_and_lint; +use crate::utils::{snippet_opt, span_help_and_lint}; declare_clippy_lint! { /// **What it does:** Checks for local arrays that may be too large. @@ -43,16 +43,23 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeStackArrays { if_chain! { if let ExprKind::Repeat(_, _) = expr.kind; if let ty::Array(element_type, cst) = cx.tables.expr_ty(expr).kind; - if let ConstValue::Scalar(Scalar::Raw{data: element_count, ..}) = cst.val; + if let 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 u128::from(self.maximum_allowed_size) < element_count * u128::from(element_size); + if self.maximum_allowed_size < element_count * element_size; then { span_help_and_lint( cx, LARGE_STACK_ARRAYS, expr.span, - "allocating large array on the stack", - "consider allocating on the heap with vec![...].into_boxed_slice()", + &format!( + "allocating a local array larger than {} bytes", + self.maximum_allowed_size + ), + &format!( + "consider allocating on the heap with vec!{}.into_boxed_slice()", + snippet_opt(cx, expr.span).as_ref().map(String::as_str).unwrap_or("[...]") + ), ); } } diff --git a/tests/ui/large_stack_arrays.stderr b/tests/ui/large_stack_arrays.stderr index f68f44712379..98d8262372df 100644 --- a/tests/ui/large_stack_arrays.stderr +++ b/tests/ui/large_stack_arrays.stderr @@ -1,35 +1,35 @@ -error: allocating large array on the stack +error: allocating a local array larger than 512000 bytes --> $DIR/large_stack_arrays.rs:17:9 | LL | [0u32; 20_000_000], | ^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::large-stack-arrays` implied by `-D warnings` - = help: consider allocating on the heap with vec![...].into_boxed_slice() + = help: consider allocating on the heap with vec![0u32; 20_000_000].into_boxed_slice() -error: allocating large array on the stack +error: allocating a local array larger than 512000 bytes --> $DIR/large_stack_arrays.rs:18:9 | LL | [S { data: [0; 32] }; 5000], | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider allocating on the heap with vec![...].into_boxed_slice() + = help: consider allocating on the heap with vec![S { data: [0; 32] }; 5000].into_boxed_slice() -error: allocating large array on the stack +error: allocating a local array larger than 512000 bytes --> $DIR/large_stack_arrays.rs:19:9 | LL | [Some(""); 20_000_000], | ^^^^^^^^^^^^^^^^^^^^^^ | - = help: consider allocating on the heap with vec![...].into_boxed_slice() + = help: consider allocating on the heap with vec![Some(""); 20_000_000].into_boxed_slice() -error: allocating large array on the stack +error: allocating a local array larger than 512000 bytes --> $DIR/large_stack_arrays.rs:20:9 | LL | [E::T(0); 5000], | ^^^^^^^^^^^^^^^ | - = help: consider allocating on the heap with vec![...].into_boxed_slice() + = help: consider allocating on the heap with vec![E::T(0); 5000].into_boxed_slice() error: aborting due to 4 previous errors From 590854ab7a89becd423332fe81fc79a8b8251eb8 Mon Sep 17 00:00:00 2001 From: Mikhail Babenko Date: Wed, 13 Nov 2019 18:12:25 +0300 Subject: [PATCH 7/8] style fix --- clippy_lints/src/large_stack_arrays.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index cccda9fe5408..cb22ed117657 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -58,7 +58,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeStackArrays { ), &format!( "consider allocating on the heap with vec!{}.into_boxed_slice()", - snippet_opt(cx, expr.span).as_ref().map(String::as_str).unwrap_or("[...]") + snippet_opt(cx, expr.span).as_ref().map_or("[...]", String::as_str) ), ); } From 1f917525d98e08e2c34bba8ef1b50855da866331 Mon Sep 17 00:00:00 2001 From: Mikhail Babenko Date: Wed, 13 Nov 2019 18:28:05 +0300 Subject: [PATCH 8/8] shange snippet_opt to snippet --- clippy_lints/src/large_stack_arrays.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index cb22ed117657..acc90214ff86 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -7,7 +7,7 @@ use rustc::{declare_tool_lint, impl_lint_pass}; use if_chain::if_chain; use crate::rustc_target::abi::LayoutOf; -use crate::utils::{snippet_opt, span_help_and_lint}; +use crate::utils::{snippet, span_help_and_lint}; declare_clippy_lint! { /// **What it does:** Checks for local arrays that may be too large. @@ -58,7 +58,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeStackArrays { ), &format!( "consider allocating on the heap with vec!{}.into_boxed_slice()", - snippet_opt(cx, expr.span).as_ref().map_or("[...]", String::as_str) + snippet(cx, expr.span, "[...]") ), ); }