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

Pretty print pattern type values with transmute if they don't satisfy their pattern #136235

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Jan 29, 2025

Instead of printing 0_u32 is 1.., we now print the default fallback rendering that we also use for invalid bools, chars, ...: {transmute(0x00000000): (u32) is 1..=}.

These cases can occur in mir dumps when const prop propagates a constant across a safety check that would prevent the actually UB value from existing. That's fine though, as it's dead code and we always need to allow UB in dead code.

follow-up to #136176

cc @compiler-errors @scottmcm

r? @RalfJung because of the interpreter changes

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 29, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jan 29, 2025

Some changes occurred to the CTFE machinery

cc @rust-lang/wg-const-eval

cx.validate_operand(
&allocated.into(),
/*recursive*/ false,
/*reset_provenance_and_padding*/ false,
Copy link
Contributor

Choose a reason for hiding this comment

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

existing, but maybe use enums instead of bool + comments :3

let typing_env = ty::TypingEnv::fully_monomorphized();
let mut cx = InterpCx::new(tcx.tcx, tcx.span, typing_env, machine);

let Ok(layout) = cx.layout_of(ty) else { return false };
Copy link
Member

Choose a reason for hiding this comment

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

Reporting false in case of a layout computation error seems odd? This is almost certainly a bug, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could just unwrap it and we'll do it properly when we can write a test for it

Copy link
Member

Choose a reason for hiding this comment

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

That works for me.
@matthiaskrgr heads-up if you see this ICE, please ping us and thanks in advance for generating a test case. :)

@RalfJung
Copy link
Member

RalfJung commented Feb 2, 2025

r=me with the unwrap.
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 2, 2025
@oli-obk
Copy link
Contributor Author

oli-obk commented Feb 2, 2025

@bors r=RalfJung

@bors
Copy link
Contributor

bors commented Feb 2, 2025

📌 Commit 5465770 has been approved by RalfJung

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants