Skip to content

[macros] Support shrinking value transmutes #2581

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

Merged
merged 2 commits into from
Jun 10, 2025

Conversation

joshlf
Copy link
Member

@joshlf joshlf commented Jun 9, 2025

In transmute!, support an #![allow(shrink)] attribute which is
invoked as follows:

transmute!(#![allow(shrink)] src);

When this attribute is provided, transmute! will permit shrinking
transmutes, in which the destination value may be smaller than the
source value.

Co-authored-by: Jack Wrenn [email protected]


This PR is on branch transmute-ref-dst.

@joshlf joshlf force-pushed the I46b18b4b1d10507b7e1d2e01b09dc4960cfcdce1 branch from 0dc4ac5 to 5f19ed9 Compare June 9, 2025 19:20
@joshlf joshlf requested a review from jswrenn June 9, 2025 19:20
@joshlf joshlf enabled auto-merge June 9, 2025 19:20
@joshlf joshlf force-pushed the I46b18b4b1d10507b7e1d2e01b09dc4960cfcdce1 branch 2 times, most recently from df3a207 to 15f9941 Compare June 9, 2025 20:13
@@ -51,39 +51,109 @@
/// This macro can be invoked in `const` contexts.
#[macro_export]
macro_rules! transmute {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need to document allow(shrink).

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@joshlf joshlf force-pushed the I46b18b4b1d10507b7e1d2e01b09dc4960cfcdce1 branch 3 times, most recently from c18affd to 50bb997 Compare June 9, 2025 23:11
In `transmute!`, support an `#![allow(shrink)]` attribute which is
invoked as follows:

  transmute!(#![allow(shrink)] src);

When this attribute is provided, `transmute!` will permit shrinking
transmutes, in which the destination value may be smaller than the
source value.

Co-authored-by: Jack Wrenn <[email protected]>
gherrit-pr-id: I46b18b4b1d10507b7e1d2e01b09dc4960cfcdce1
@joshlf joshlf force-pushed the I46b18b4b1d10507b7e1d2e01b09dc4960cfcdce1 branch from 50bb997 to 8e4a6e5 Compare June 10, 2025 13:12
@codecov-commenter
Copy link

codecov-commenter commented Jun 10, 2025

Codecov Report

Attention: Patch coverage is 40.00000% with 12 lines in your changes missing coverage. Please review.

Project coverage is 88.72%. Comparing base (8fbfac9) to head (076527d).

Files with missing lines Patch % Lines
src/macros.rs 40.00% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2581      +/-   ##
==========================================
- Coverage   88.91%   88.72%   -0.19%     
==========================================
  Files          20       20              
  Lines        5312     5332      +20     
==========================================
+ Hits         4723     4731       +8     
- Misses        589      601      +12     

☔ 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.

Co-authored-by: Jack Wrenn <[email protected]>
@joshlf joshlf requested a review from jswrenn June 10, 2025 15:08
@joshlf joshlf added this pull request to the merge queue Jun 10, 2025
Merged via the queue into main with commit b134526 Jun 10, 2025
89 checks passed
@joshlf joshlf deleted the I46b18b4b1d10507b7e1d2e01b09dc4960cfcdce1 branch June 10, 2025 15:56
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