handle tuple struct ctors

This commit is contained in:
Ralf Jung 2017-08-01 08:48:28 -07:00
parent 584d823bf2
commit 4310edb4cb
2 changed files with 17 additions and 13 deletions

View File

@ -128,7 +128,7 @@ fn fn_contains_unsafe<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource) ->
match tcx.hir.find(cur) { match tcx.hir.find(cur) {
Some(Node::NodeExpr(&hir::Expr { node: hir::ExprBlock(ref block), ..})) => { Some(Node::NodeExpr(&hir::Expr { node: hir::ExprBlock(ref block), ..})) => {
if block_is_unsafe(&*block) { if block_is_unsafe(&*block) {
// We can bail out here. // Found an unsafe block, we can bail out here.
return true; return true;
} }
} }
@ -138,6 +138,10 @@ fn fn_contains_unsafe<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource) ->
// Finally, visit the closure itself. // Finally, visit the closure itself.
finder.visit_expr(item); finder.visit_expr(item);
} }
Some(Node::NodeStructCtor(_)) => {
// Auto-generated tuple struct ctor. Cannot contain unsafe code.
return false;
},
Some(_) | None => Some(_) | None =>
bug!("Expected function, method or closure, found {}", bug!("Expected function, method or closure, found {}",
tcx.hir.node_to_string(fn_node_id)), tcx.hir.node_to_string(fn_node_id)),

View File

@ -11,7 +11,7 @@
// ignore-tidy-linelength // ignore-tidy-linelength
// compile-flags: -Z verbose -Z mir-emit-validate=1 // compile-flags: -Z verbose -Z mir-emit-validate=1
struct Test; struct Test(i32);
impl Test { impl Test {
// Make sure we run the pass on a method, not just on bare functions. // Make sure we run the pass on a method, not just on bare functions.
@ -20,7 +20,7 @@ impl Test {
fn main() { fn main() {
let mut x = 0; let mut x = 0;
Test.foo(&mut x); Test(0).foo(&mut x);
// Also test closures // Also test closures
let c = |x: &mut i32| { let y = &*x; *y }; let c = |x: &mut i32| { let y = &*x; *y };
@ -31,29 +31,29 @@ fn main() {
// the interesting lines of code also contain name of the source file, so we cannot test for it. // the interesting lines of code also contain name of the source file, so we cannot test for it.
// END RUST SOURCE // END RUST SOURCE
// START rustc.node10.EraseRegions.after.mir // START rustc.node12.EraseRegions.after.mir
// bb0: { // bb0: {
// 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]); // 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]);
// return; // return;
// } // }
// END rustc.node10.EraseRegions.after.mir // END rustc.node12.EraseRegions.after.mir
// START rustc.node21.EraseRegions.after.mir // START rustc.node23.EraseRegions.after.mir
// fn main() -> () { // fn main() -> () {
// bb0: { // bb0: {
// Validate(Suspend(ReScope(Misc(NodeId(30)))), [_1: i32]); // Validate(Suspend(ReScope(Misc(NodeId(34)))), [_1: i32]);
// _6 = &ReErased mut _1; // _6 = &ReErased mut _1;
// Validate(Acquire, [(*_6): i32/ReScope(Misc(NodeId(30)))]); // Validate(Acquire, [(*_6): i32/ReScope(Misc(NodeId(34)))]);
// Validate(Suspend(ReScope(Misc(NodeId(30)))), [(*_6): i32/ReScope(Misc(NodeId(30)))]); // Validate(Suspend(ReScope(Misc(NodeId(34)))), [(*_6): i32/ReScope(Misc(NodeId(34)))]);
// _5 = &ReErased mut (*_6); // _5 = &ReErased mut (*_6);
// Validate(Acquire, [(*_5): i32/ReScope(Misc(NodeId(30)))]); // Validate(Acquire, [(*_5): i32/ReScope(Misc(NodeId(34)))]);
// Validate(Release, [_3: &ReScope(Misc(NodeId(30))) Test, _5: &ReScope(Misc(NodeId(30))) mut i32]); // Validate(Release, [_3: &ReScope(Misc(NodeId(34))) Test, _5: &ReScope(Misc(NodeId(34))) mut i32]);
// _2 = const Test::foo(_3, _5) -> bb1; // _2 = const Test::foo(_3, _5) -> bb1;
// } // }
// //
// bb1: { // bb1: {
// Validate(Acquire, [_2: ()]); // Validate(Acquire, [_2: ()]);
// EndRegion(ReScope(Misc(NodeId(30)))); // EndRegion(ReScope(Misc(NodeId(34))));
// return; // return;
// } // }
// } // }
// END rustc.node21.EraseRegions.after.mir // END rustc.node23.EraseRegions.after.mir