-
Notifications
You must be signed in to change notification settings - Fork 13.5k
UnsafeCell
blocks niches inside its nested type from being available outside
#99011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
2a899dc
8d9f609
4bfba76
69b1b3c
4239155
984db78
3f4cf59
af8536e
fef596f
9a20450
fcd7207
8440208
d935c70
cdd6bba
0318b70
3338593
24e8796
7269196
519c07b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -542,14 +542,12 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { | |
debug!("univariant offset: {:?} field: {:#?}", offset, field); | ||
offsets[i as usize] = offset; | ||
|
||
if !repr.hide_niche() { | ||
if let Some(mut niche) = field.largest_niche { | ||
let available = niche.available(dl); | ||
if available > largest_niche_available { | ||
largest_niche_available = available; | ||
niche.offset += offset; | ||
largest_niche = Some(niche); | ||
} | ||
if let Some(mut niche) = field.largest_niche { | ||
let available = niche.available(dl); | ||
if available > largest_niche_available { | ||
largest_niche_available = available; | ||
niche.offset += offset; | ||
largest_niche = Some(niche); | ||
} | ||
} | ||
|
||
|
@@ -1104,23 +1102,29 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { | |
assert!(valid_range.end >= end); | ||
valid_range.end = end; | ||
} | ||
|
||
// Update `largest_niche` if we have introduced a larger niche. | ||
let niche = if def.repr().hide_niche() { | ||
None | ||
if def.is_unsafe_cell() { | ||
match scalar { | ||
Scalar::Initialized { value, valid_range } => { | ||
*valid_range = WrappingRange::full(value.size(dl)) | ||
} | ||
// Already doesn't have any niches | ||
Scalar::Union { .. } => {} | ||
} | ||
st.largest_niche = None; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like the original code got misplaced into the More specifically, So when testing, make sure to also check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I tried, we have checks preventing such datastructures from existing at all. So this can't happen. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The checks are not perfect: https://godbolt.org/z/W8o3Gxhdo. |
||
} else { | ||
Niche::from_scalar(dl, Size::ZERO, *scalar) | ||
}; | ||
if let Some(niche) = niche { | ||
match st.largest_niche { | ||
Some(largest_niche) => { | ||
// Replace the existing niche even if they're equal, | ||
// because this one is at a lower offset. | ||
if largest_niche.available(dl) <= niche.available(dl) { | ||
st.largest_niche = Some(niche); | ||
// Update `largest_niche` if we have introduced a larger niche. | ||
let niche = Niche::from_scalar(dl, Size::ZERO, *scalar); | ||
if let Some(niche) = niche { | ||
match st.largest_niche { | ||
Some(largest_niche) => { | ||
// Replace the existing niche even if they're equal, | ||
// because this one is at a lower offset. | ||
if largest_niche.available(dl) <= niche.available(dl) { | ||
st.largest_niche = Some(niche); | ||
} | ||
} | ||
None => st.largest_niche = Some(niche), | ||
} | ||
None => st.largest_niche = Some(niche), | ||
} | ||
} | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.