Skip to content

Commit 786f090

Browse files
authored
Do not trigger trailing_empty_array in tests (#13844)
Close #13837 changelog: [`trailing_empty_array`]: do not trigger on tests
2 parents 998c780 + a5d5edc commit 786f090

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

clippy_lints/src/trailing_empty_array.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
2-
use clippy_utils::has_repr_attr;
2+
use clippy_utils::{has_repr_attr, is_in_test};
33
use rustc_hir::{Item, ItemKind};
44
use rustc_lint::{LateContext, LateLintPass};
55
use rustc_middle::ty;
@@ -37,7 +37,10 @@ declare_lint_pass!(TrailingEmptyArray => [TRAILING_EMPTY_ARRAY]);
3737

3838
impl<'tcx> LateLintPass<'tcx> for TrailingEmptyArray {
3939
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
40-
if is_struct_with_trailing_zero_sized_array(cx, item) && !has_repr_attr(cx, item.hir_id()) {
40+
if is_struct_with_trailing_zero_sized_array(cx, item)
41+
&& !has_repr_attr(cx, item.hir_id())
42+
&& !is_in_test(cx.tcx, item.hir_id())
43+
{
4144
span_lint_and_help(
4245
cx,
4346
TRAILING_EMPTY_ARRAY,

tests/ui/trailing_empty_array.rs

+14
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,17 @@ type C = ConstParamNoDefault<0>;
193193
type D = ConstParamNonZeroDefault<0>;
194194

195195
fn main() {}
196+
197+
#[cfg(test)]
198+
mod tests {
199+
pub struct Friend {
200+
age: u8,
201+
}
202+
203+
#[test]
204+
fn oldest_empty_is_none() {
205+
struct Michael {
206+
friends: [Friend; 0],
207+
}
208+
}
209+
}

0 commit comments

Comments
 (0)