Skip to content

Commit

Permalink
Properly find owner of closure in THIR unsafeck
Browse files Browse the repository at this point in the history
Co-authored-by: FabianWolff <fabian.wolff@alumni.ethz.ch>
  • Loading branch information
LeSeulArtichaut and FabianWolff committed Jul 30, 2021
1 parent 71a6c7c commit 1280423
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
11 changes: 4 additions & 7 deletions compiler/rustc_mir_build/src/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,13 +599,10 @@ pub fn check_unsafety<'tcx>(tcx: TyCtxt<'tcx>, def: ty::WithOptConstParam<LocalD

// Closures are handled by their owner, if it has a body
if tcx.is_closure(def.did.to_def_id()) {
let owner = tcx.hir().local_def_id_to_hir_id(def.did).owner;
let owner_hir_id = tcx.hir().local_def_id_to_hir_id(owner);

if tcx.hir().maybe_body_owned_by(owner_hir_id).is_some() {
tcx.ensure().thir_check_unsafety(owner);
return;
}
let hir = tcx.hir();
let owner = hir.enclosing_body_owner(hir.local_def_id_to_hir_id(def.did));
tcx.ensure().thir_check_unsafety(hir.local_def_id(owner));
return;
}

let (thir, expr) = tcx.thir_body(def);
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/unsafe/issue-87414-query-cycle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Regression test for #87414.

// check-pass
// compile-flags: -Zthir-unsafeck

fn bad<T>() -> Box<dyn Iterator<Item = [(); { |x: u32| { x }; 4 }]>> { todo!() }

fn foo() -> [(); { |x: u32| { x }; 4 }] { todo!() }
fn bar() { let _: [(); { |x: u32| { x }; 4 }]; }

// This one should not cause any errors either:
unsafe fn unsf() {}
fn bad2<T>() -> Box<dyn Iterator<Item = [(); { unsafe { || { unsf() } }; 4 }]>> { todo!() }

fn main() {}

0 comments on commit 1280423

Please sign in to comment.