Fix soundness hole in struct with expressions.
Fixes #18567. Struct{x:foo, .. with_expr} did not walk with_expr, which allowed
using moved variables in some cases. The CFG for structs also built up with
with_expr happening before the fields, which is now reversed. (Fields are now
before the with_expr in the CFG)
diff --git a/src/librustc/middle/cfg/construct.rs b/src/librustc/middle/cfg/construct.rs
index 1468918..1419c48 100644
--- a/src/librustc/middle/cfg/construct.rs
+++ b/src/librustc/middle/cfg/construct.rs
@@ -448,8 +448,8 @@
}
ast::ExprStruct(_, ref fields, ref base) => {
- let base_exit = self.opt_expr(base, pred);
- self.straightline(expr, base_exit, fields.iter().map(|f| &*f.expr))
+ let field_cfg = self.straightline(expr, pred, fields.iter().map(|f| &*f.expr));
+ self.opt_expr(base, field_cfg)
}
ast::ExprRepeat(ref elem, ref count) => {