mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
Prevent cyclic locks of alloc_map
This commit is contained in:
@@ -453,8 +453,11 @@ pub fn get_size_and_align(
|
||||
if let Ok(alloc) = self.get(id) {
|
||||
return Ok((Size::from_bytes(alloc.bytes.len() as u64), alloc.align));
|
||||
}
|
||||
// can't do this in the match argument, we may get cycle errors since the lock would get
|
||||
// dropped after the match.
|
||||
let alloc = self.tcx.alloc_map.lock().get(id);
|
||||
// Could also be a fn ptr or extern static
|
||||
match self.tcx.alloc_map.lock().get(id) {
|
||||
match alloc {
|
||||
Some(GlobalAlloc::Function(..)) => Ok((Size::ZERO, Align::from_bytes(1).unwrap())),
|
||||
// `self.get` would also work, but can cause cycles if a static refers to itself
|
||||
Some(GlobalAlloc::Static(did)) => {
|
||||
|
||||
Reference in New Issue
Block a user