Skip to content

[layout] Support sized->unsized, sized->sized casts#2950

Merged
joshlf merged 1 commit intomainfrom
G374c587ce49c18d4dd1d7de970df8556ed7834e3
Jan 30, 2026
Merged

[layout] Support sized->unsized, sized->sized casts#2950
joshlf merged 1 commit intomainfrom
G374c587ce49c18d4dd1d7de970df8556ed7834e3

Conversation

@joshlf
Copy link
Member

@joshlf joshlf commented Jan 29, 2026

Makes progress on #2721


Latest Update: v9 — Compare vs v8

📚 Full Patch History

Links show the diff between the row version and the column version.

Version v8 v7 v6 v5 v4 v3 v2 v1 Base
v9 v8 v7 v6 v5 v4 v3 v2 v1 Base
v8 v7 v6 v5 v4 v3 v2 v1 Base
v7 v6 v5 v4 v3 v2 v1 Base
v6 v5 v4 v3 v2 v1 Base
v5 v4 v3 v2 v1 Base
v4 v3 v2 v1 Base
v3 v2 v1 Base
v2 v1 Base
v1 Base

Stacked PRs enabled by GHerrit.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @joshlf, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the pointer casting capabilities within the layout module by introducing support for Sized to Unsized and Sized to Sized type conversions. The core change involves a redesign of the CastParams mechanism to explicitly model and compute the necessary parameters for these diverse casting scenarios at compile time, ensuring type safety and correctness. This work directly addresses a long-standing FIXME and generalizes the internal casting infrastructure.

Highlights

  • Generalized Pointer Casting: The Cast and CastExact traits now support a broader range of pointer metadata types by removing the PointerMetadata = usize constraint from KnownLayout, allowing for more flexible type conversions.
  • Explicit Cast Type Handling: The CastParams structure has been refactored into a generic struct with an enum CastParamsInner to explicitly differentiate and handle UnsizedToUnsized, SizedToUnsized, and SizedToSized pointer casts, improving clarity and correctness.
  • Enhanced Metadata Conversion: A new to_elem_count method has been added to the PointerMetadata trait, providing a standardized way to convert pointer metadata into an element count, which is crucial for the new casting logic and its various scenarios.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a significant and well-executed refactoring that adds support for sized-to-sized and sized-to-unsized casts, complementing the existing support for unsized-to-unsized casts. The changes primarily involve src/layout.rs, where the casting logic is generalized using a new CastParamsInner enum and associated functions. A new to_elem_count method has been added to the PointerMetadata trait in src/lib.rs to support this generalization. The implementation appears correct, robust, and handles the increased complexity effectively. The code is of high quality, and I have no specific comments for improvement.

@codecov-commenter
Copy link

codecov-commenter commented Jan 29, 2026

Codecov Report

❌ Patch coverage is 18.84058% with 56 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.84%. Comparing base (7dc98fd) to head (9504690).

Files with missing lines Patch % Lines
src/layout.rs 15.87% 53 Missing ⚠️
src/lib.rs 50.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2950      +/-   ##
==========================================
- Coverage   92.29%   91.84%   -0.46%     
==========================================
  Files          19       19              
  Lines        5868     5908      +40     
==========================================
+ Hits         5416     5426      +10     
- Misses        452      482      +30     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joshlf joshlf enabled auto-merge January 29, 2026 20:51
@joshlf joshlf requested a review from jswrenn January 29, 2026 20:52
@joshlf joshlf force-pushed the G374c587ce49c18d4dd1d7de970df8556ed7834e3 branch from c3f1d21 to 8f56cbe Compare January 29, 2026 22:44
@joshlf joshlf changed the base branch from main to Gf4fc8f4ade59c568c9fef502015da09b4a508560 January 29, 2026 22:44
auto-merge was automatically disabled January 29, 2026 22:44

Merge commits are not allowed on this repository

Base automatically changed from Gf4fc8f4ade59c568c9fef502015da09b4a508560 to main January 30, 2026 14:33
Makes progress on #2721

gherrit-pr-id: G374c587ce49c18d4dd1d7de970df8556ed7834e3
@joshlf joshlf force-pushed the G374c587ce49c18d4dd1d7de970df8556ed7834e3 branch from 8f56cbe to 9504690 Compare January 30, 2026 14:34
@joshlf joshlf enabled auto-merge January 30, 2026 14:35
Copy link
Collaborator

@jswrenn jswrenn left a comment

Choose a reason for hiding this comment

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

Let's also try to eventually support unsized to sized casts where the unsized thing has a trailing element size of 0.

@joshlf joshlf added this pull request to the merge queue Jan 30, 2026
@joshlf
Copy link
Member Author

joshlf commented Jan 30, 2026

Let's also try to eventually support unsized to sized casts where the unsized thing has a trailing element size of 0.

Filed #2954

Merged via the queue into main with commit f28e016 Jan 30, 2026
104 checks passed
@joshlf joshlf deleted the G374c587ce49c18d4dd1d7de970df8556ed7834e3 branch January 30, 2026 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants