Avoid accidental copy of static var before creating mut ref

This commit is contained in:
David Flemström 2024-06-29 01:34:07 +02:00
parent 2f750a82bf
commit 114dda2fd1

View File

@ -142,7 +142,7 @@ impl RccInfo {
// Use .get_mut instead of []-operator so that we control how bounds checks happen. // Use .get_mut instead of []-operator so that we control how bounds checks happen.
// Otherwise, core::fmt will be pulled in here in order to format the integer in the // Otherwise, core::fmt will be pulled in here in order to format the integer in the
// out-of-bounds error. // out-of-bounds error.
if let Some(refcount) = unsafe { crate::_generated::REFCOUNTS }.get_mut(refcount_idx) { if let Some(refcount) = unsafe { crate::_generated::REFCOUNTS.get_mut(refcount_idx) } {
*refcount += 1; *refcount += 1;
if *refcount > 1 { if *refcount > 1 {
return; return;
@ -206,7 +206,7 @@ impl RccInfo {
// Use .get_mut instead of []-operator so that we control how bounds checks happen. // Use .get_mut instead of []-operator so that we control how bounds checks happen.
// Otherwise, core::fmt will be pulled in here in order to format the integer in the // Otherwise, core::fmt will be pulled in here in order to format the integer in the
// out-of-bounds error. // out-of-bounds error.
if let Some(refcount) = unsafe { crate::_generated::REFCOUNTS }.get_mut(refcount_idx) { if let Some(refcount) = unsafe { crate::_generated::REFCOUNTS.get_mut(refcount_idx) } {
*refcount -= 1; *refcount -= 1;
if *refcount > 0 { if *refcount > 0 {
return; return;