Skip to content

Commit 4310edb

Browse files
committed
handle tuple struct ctors
1 parent 584d823 commit 4310edb

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/librustc_mir/transform/add_validation.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn fn_contains_unsafe<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource) ->
128128
match tcx.hir.find(cur) {
129129
Some(Node::NodeExpr(&hir::Expr { node: hir::ExprBlock(ref block), ..})) => {
130130
if block_is_unsafe(&*block) {
131-
// We can bail out here.
131+
// Found an unsafe block, we can bail out here.
132132
return true;
133133
}
134134
}
@@ -138,6 +138,10 @@ fn fn_contains_unsafe<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource) ->
138138
// Finally, visit the closure itself.
139139
finder.visit_expr(item);
140140
}
141+
Some(Node::NodeStructCtor(_)) => {
142+
// Auto-generated tuple struct ctor. Cannot contain unsafe code.
143+
return false;
144+
},
141145
Some(_) | None =>
142146
bug!("Expected function, method or closure, found {}",
143147
tcx.hir.node_to_string(fn_node_id)),

src/test/mir-opt/validate_1.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// ignore-tidy-linelength
1212
// compile-flags: -Z verbose -Z mir-emit-validate=1
1313

14-
struct Test;
14+
struct Test(i32);
1515

1616
impl Test {
1717
// Make sure we run the pass on a method, not just on bare functions.
@@ -20,7 +20,7 @@ impl Test {
2020

2121
fn main() {
2222
let mut x = 0;
23-
Test.foo(&mut x);
23+
Test(0).foo(&mut x);
2424

2525
// Also test closures
2626
let c = |x: &mut i32| { let y = &*x; *y };
@@ -31,29 +31,29 @@ fn main() {
3131
// the interesting lines of code also contain name of the source file, so we cannot test for it.
3232

3333
// END RUST SOURCE
34-
// START rustc.node10.EraseRegions.after.mir
34+
// START rustc.node12.EraseRegions.after.mir
3535
// bb0: {
3636
// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(5) => validate_1/8cd878b::{{impl}}[0]::foo[0] }, BrAnon(0)) Test, _2: &ReFree(DefId { krate: CrateNum(0), node: DefIndex(5) => validate_1/8cd878b::{{impl}}[0]::foo[0] }, BrAnon(1)) mut i32]);
3737
// return;
3838
// }
39-
// END rustc.node10.EraseRegions.after.mir
40-
// START rustc.node21.EraseRegions.after.mir
39+
// END rustc.node12.EraseRegions.after.mir
40+
// START rustc.node23.EraseRegions.after.mir
4141
// fn main() -> () {
4242
// bb0: {
43-
// Validate(Suspend(ReScope(Misc(NodeId(30)))), [_1: i32]);
43+
// Validate(Suspend(ReScope(Misc(NodeId(34)))), [_1: i32]);
4444
// _6 = &ReErased mut _1;
45-
// Validate(Acquire, [(*_6): i32/ReScope(Misc(NodeId(30)))]);
46-
// Validate(Suspend(ReScope(Misc(NodeId(30)))), [(*_6): i32/ReScope(Misc(NodeId(30)))]);
45+
// Validate(Acquire, [(*_6): i32/ReScope(Misc(NodeId(34)))]);
46+
// Validate(Suspend(ReScope(Misc(NodeId(34)))), [(*_6): i32/ReScope(Misc(NodeId(34)))]);
4747
// _5 = &ReErased mut (*_6);
48-
// Validate(Acquire, [(*_5): i32/ReScope(Misc(NodeId(30)))]);
49-
// Validate(Release, [_3: &ReScope(Misc(NodeId(30))) Test, _5: &ReScope(Misc(NodeId(30))) mut i32]);
48+
// Validate(Acquire, [(*_5): i32/ReScope(Misc(NodeId(34)))]);
49+
// Validate(Release, [_3: &ReScope(Misc(NodeId(34))) Test, _5: &ReScope(Misc(NodeId(34))) mut i32]);
5050
// _2 = const Test::foo(_3, _5) -> bb1;
5151
// }
5252
//
5353
// bb1: {
5454
// Validate(Acquire, [_2: ()]);
55-
// EndRegion(ReScope(Misc(NodeId(30))));
55+
// EndRegion(ReScope(Misc(NodeId(34))));
5656
// return;
5757
// }
5858
// }
59-
// END rustc.node21.EraseRegions.after.mir
59+
// END rustc.node23.EraseRegions.after.mir

0 commit comments

Comments
 (0)