Skip to content

Commit a5d5edc

Browse files
committed
Do not trigger trailing_empty_array in tests
1 parent c2d23ad commit a5d5edc

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
@@ -192,3 +192,17 @@ type C = ConstParamNoDefault<0>;
192192
type D = ConstParamNonZeroDefault<0>;
193193

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

0 commit comments

Comments
 (0)