Skip to content
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

explain why Rvalue::Len still exists #129939

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_middle/src/mir/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,9 @@ pub enum Rvalue<'tcx> {
/// If the type of the place is an array, this is the array length. For slices (`[T]`, not
/// `&[T]`) this accesses the place's metadata to determine the length. This rvalue is
/// ill-formed for places of other types.
///
/// This cannot be a `UnOp(PtrMetadata, _)` because that expects a value, and we only
/// have a place, and `UnOp(PtrMetadata, RawPtr(place))` is not a thing.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other complication here, dunno whether it's worth mentioning, is that PtrMetadata needs a wide pointer, so if the place is an array you also need to unsize it to slice.

BTW, are there [ST]B issues with adding a short-lived raw-ref to use PtrMetadata if the place is something like (*_2).1? Or is it just that it's a bit annoying to make the temporary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other complication here, dunno whether it's worth mentioning, is that PtrMetadata needs a wide pointer, so if the place is an array you also need to unsize it to slice.

Not really, as you said above -- if the place is an array we can just emit a constant instead.

BTW, are there [ST]B issues with adding a short-lived raw-ref to use PtrMetadata if the place is something like (*_2).1? Or is it just that it's a bit annoying to make the temporary?

There also shouldn't be any -- creating a raw pointer you never use should be effectively a NOP.

Len(Place<'tcx>),

/// Performs essentially all of the casts that can be performed via `as`.
Expand Down
Loading