Bugfix: 'can_have_side_effects()' would return 'false' for struct/enum/array/tuple literals unless *all* sub-expressions had side effects. This would easily allow side effects to slip through, and also wrongly label empty literals as having side effects. Add some tests for the last point

This commit is contained in:
Morten Lohne 2023-08-10 01:14:19 +02:00
parent 27a43f0834
commit 75d5f107dd
5 changed files with 62 additions and 6 deletions

View file

@ -1843,7 +1843,7 @@ impl Expr<'_> {
.iter()
.map(|field| field.expr)
.chain(init.into_iter())
.all(|e| e.can_have_side_effects()),
.any(|e| e.can_have_side_effects()),
ExprKind::Array(args)
| ExprKind::Tup(args)
@ -1857,7 +1857,7 @@ impl Expr<'_> {
..
},
args,
) => args.iter().all(|arg| arg.can_have_side_effects()),
) => args.iter().any(|arg| arg.can_have_side_effects()),
ExprKind::If(..)
| ExprKind::Match(..)
| ExprKind::MethodCall(..)