Skip to content

Commit d3167c6

Browse files
committed
Handle constant arrays with single value
1 parent 1bab67c commit d3167c6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

clippy_lints/src/consts.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,17 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
356356
Constant::F64(x) => Some(Constant::F64(x)),
357357
_ => None,
358358
},
359+
(Some(Constant::Vec(vec)), _) => {
360+
if !vec.is_empty() && vec.iter().all(|x| *x == vec[0]) {
361+
match vec[0] {
362+
Constant::F32(x) => Some(Constant::F32(x)),
363+
Constant::F64(x) => Some(Constant::F64(x)),
364+
_ => None,
365+
}
366+
} else {
367+
None
368+
}
369+
},
359370
_ => None,
360371
}
361372
}

0 commit comments

Comments
 (0)