-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add range metadata to slice lengths #116542
Draft
the8472
wants to merge
4
commits into
rust-lang:master
Choose a base branch
from
the8472:slice-ref-len-validity
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+357
−75
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2c19fc6
Add range information to slice metadata for types that are known to n…
the8472 66ac3a8
llvm18 doesn't have range attributes in arguments
the8472 819ad3f
Don't rely on unspecified struct layouts in miri test
the8472 598d653
add UI tests for additional niches in fat pointers with usize metadata
the8472 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
use hir::HirId; | ||
use rustc_abi::Primitive::Pointer; | ||
use rustc_abi::Size; | ||
use rustc_errors::codes::*; | ||
use rustc_errors::struct_span_code_err; | ||
use rustc_hir as hir; | ||
|
@@ -88,8 +89,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
} | ||
} | ||
|
||
fn size_to_bits(size: Size) -> u128 { | ||
let Some(bits) = u128::from(size.bytes()).checked_mul(8) else { | ||
// `u128` should definitely be able to hold the size of different architectures | ||
// larger sizes should be reported as error `are too big for the current architecture` | ||
// otherwise we have a bug somewhere | ||
bug!("{:?} overflow for u128", size) | ||
}; | ||
|
||
bits | ||
} | ||
|
||
// Try to display a sensible error with as much information as possible. | ||
let skeleton_string = |ty: Ty<'tcx>, sk: Result<_, &_>| match sk { | ||
Ok(SizeSkeleton::Pointer { tail, known_size: Some(size), .. }) => { | ||
format!("{} bits, pointer to `{tail}`", size_to_bits(size)) | ||
} | ||
Ok(SizeSkeleton::Pointer { tail, .. }) => format!("pointer to `{tail}`"), | ||
Ok(SizeSkeleton::Known(size, _)) => { | ||
if let Some(v) = u128::from(size.bytes()).checked_mul(8) { | ||
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. ...oh, looks like down here also should be using such a thing |
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that https://doc.rust-lang.org/nightly/nightly-rustc/rustc_abi/struct.Size.html#method.bits and
bits_usize
already exist, maybe put a method over with them instead? Or if you're already relying on the 2⁴⁸ limit anyway, maybe just usesize.bits()
and deal inu64
?