Skip to content

Check for intrinsic to fn ptr casts in unified coercions - #149160

Merged
bors merged 1 commit into
rust-lang:mainfrom
maxdexh:fix-instrinsic-unifying-coercion-ice
Nov 21, 2025
Merged

Check for intrinsic to fn ptr casts in unified coercions#149160
bors merged 1 commit into
rust-lang:mainfrom
maxdexh:fix-instrinsic-unifying-coercion-ice

Conversation

@maxdexh

@maxdexhmaxdexh commented Nov 20, 2025

Copy link
Copy Markdown
Contributor

Fixes#149143 by ensuring that when coercing multiple expressions to a unified type, the same "intrinsic to fn ptr" check is applied as for other coercions.

@rustbotrustbot 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 Nov 20, 2025
@rustbot

Copy link
Copy Markdown
Collaborator

r? @chenyukang

rustbot has assigned @chenyukang.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot

This comment has been minimized.

@Kivooeo

Kivooeo commented Nov 20, 2025

Copy link
Copy Markdown
Member

Can you please add regression test and fix commit description (remove #149143 from it)

The fix itself seems reasonable to me

@maxdexh

maxdexh commented Nov 20, 2025

Copy link
Copy Markdown
ContributorAuthor

Can you please add regression test

Sure, under which crate should I put the test? nvm I think I got it

@Kivooeo

Kivooeo commented Nov 20, 2025

Copy link
Copy Markdown
Member

We don't store tests under crates but rather under tests/ui/ directory (there are some other directories under tests/ but for this case focus on ui/), so in your case I guess the most fit directory would be something tests/ui/coercion, just create a file there with name that shorts explain what it tests and put a issue number at the end of the file name like *-1234.rs, and put a link to issue in test, thanks

@maxdexh

maxdexh commented Nov 20, 2025

Copy link
Copy Markdown
ContributorAuthor

We don't store tests under crates

Yeah my bad I searched for regression in my file picker and every test that showed up was under some crate

@Kivooeo

Copy link
Copy Markdown
Member

I searched for regression in my file picker and every test that showed up was under some crate

Very likely it were not a tests, but maybe a comments or something that explains that this part of code addresses an issue

@maxdexh

Copy link
Copy Markdown
ContributorAuthor

For some reason my file picker really likes src/tools/clippy

@Kivooeo

Kivooeo commented Nov 20, 2025

Copy link
Copy Markdown
Member

Is there something particular you searching for that I can help you with?

@maxdexh
maxdexhforce-pushed the fix-instrinsic-unifying-coercion-ice branch from 20a2f5a to afb35baCompareNovember 20, 2025 22:07
@maxdexh

maxdexh commented Nov 20, 2025

Copy link
Copy Markdown
ContributorAuthor

Alright I got it, I was just fighting with how the error messages need to be specified. I'm not sure I did it correctly but the test tool doesn't complain anymore.

@Kivooeo

Copy link
Copy Markdown
Member

it looks like flake.nix got leaked in this pr :)

@maxdexh

Copy link
Copy Markdown
ContributorAuthor

Hehe oops

@maxdexh
maxdexhforce-pushed the fix-instrinsic-unifying-coercion-ice branch from afb35ba to 9dfb004CompareNovember 20, 2025 22:10

@KivooeoKivooeo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's wait on CI green (I know it will be green but just to make 1000% sure)

View changes since this review

@maxdexh

maxdexh commented Nov 20, 2025

Copy link
Copy Markdown
ContributorAuthor

It was kinda annoying getting nix to work with it, since I either had to use nix develop path:., which takes ages to copy the entire repo to a store, or use git add -f to force mynot my flake to be picked up.

Is there any better way to do this?

@Kivooeo

Copy link
Copy Markdown
Member

Hmm, I don't actually use Nix, so I can't help here, but, you might want to join the Rust Zulip, think of it as a Discord for Rust developers

You can create a topic there about Rust development on Nix, and you'll very likely get some answers from people who actually work with it

@maxdexh

Copy link
Copy Markdown
ContributorAuthor

Alright will do, thanks for the help btw!

@maxdexh

Copy link
Copy Markdown
ContributorAuthor

Oh I just realized the ICE still happens if I switch the branches 😄

@Kivooeo

Copy link
Copy Markdown
Member

Hm, can you show the example

@maxdexh

Copy link
Copy Markdown
ContributorAuthor
fnmain(){unsafe{let f = iftrue{
safe_transmute
}else{
std::mem::transmute
};let _:i64 = f(3i64);}}unsafefnsafe_transmute<A,B>(x:A) -> B{panic!()}

@Kivooeo

Kivooeo commented Nov 20, 2025

Copy link
Copy Markdown
Member

I don't get ICE with your fix, it just panics, but... it should panic

gh-Kivooeo@dev-desktop-eu-1 ~/rust (pr-branch) [101]> ./build/aarch64-unknown-linux-gnu/stage1/bin/rustc ~/test_/src/main.rs
warning: unused variable: `x`
--> /home/gh-Kivooeo/test_/src/main.rs:13:32
|
13 | unsafe fn safe_transmute<A, B>(x: A) -> B {
| ^ help: if this is intentional, prefix it with an underscore: `_x`|
= note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
warning: 1 warning emitted
gh-Kivooeo@dev-desktop-eu-1 ~/rust (pr-branch)> ./main
thread 'main' (3589235) panicked at /home/gh-Kivooeo/test_/src/main.rs:14:5:
explicit panic
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Hm, it don't give error for some reason

@maxdexh

maxdexh commented Nov 20, 2025

Copy link
Copy Markdown
ContributorAuthor

Now it works for me too, I am just confused at this point. I guess I should use cargo clean more often

@Kivooeo

Copy link
Copy Markdown
Member

I don't know, should this give error in both cases or just in the one from issue?

@maxdexh

Copy link
Copy Markdown
ContributorAuthor

Both cases should error

@Kivooeo

Copy link
Copy Markdown
Member

At very first glance, it seems that you also should add this to next_adjustment

@maxdexh

Copy link
Copy Markdown
ContributorAuthor

I'm not sure what you mean, it errors in both cases

@maxdexh

Copy link
Copy Markdown
ContributorAuthor

Should I add a second test or just expand the other one?

@Kivooeo

Kivooeo commented Nov 20, 2025

Copy link
Copy Markdown
Member

Just expand the current test, something like

let f2 = iftrue{ safe_transmute }else{ transmute };//~^ ERROR `if` and `else` have incompatible typeslet _:i64 = f2(5i64);

@maxdexh

Copy link
Copy Markdown
ContributorAuthor

Oh yeah I also had to add it in next_adjustment, stale compiler output confused the hell out of me

Ensures that when coercing multiple expressions to a
unified type, the same "intrinsic to fn ptr" check is applied as for
other coercions.
@maxdexh
maxdexhforce-pushed the fix-instrinsic-unifying-coercion-ice branch from 9dfb004 to ebf1c38CompareNovember 20, 2025 23:01
@maxdexh

maxdexh commented Nov 20, 2025

Copy link
Copy Markdown
ContributorAuthor

It's a bit weird that the note "cannot coerce intrinsics to function pointers" always points at the second expression, but that has apparently been the case before 1.84 too

@Kivooeo

Copy link
Copy Markdown
Member

stale compiler output confused the hell out of me

well, I always use directly the compiled compiler to test something locally and not cargo, like this ./build/your-target/stage1/bin/rustc path/to/your/rs-file-you-want-test (have no idea if this even correct or not but works good)

@maxdexh

Copy link
Copy Markdown
ContributorAuthor

well, I always use directly the compiled compiler to test something locally and not cargo

Does rustc not use incremental compilation?

@Kivooeo

Copy link
Copy Markdown
Member

it does

@maxdexh

maxdexh commented Nov 20, 2025

Copy link
Copy Markdown
ContributorAuthor

Then I don't see how it would be immune to this, cargo clean is just a helper to delete target/, right?

@maxdexh

Copy link
Copy Markdown
ContributorAuthor

I guess I had no reason to be using it on my 'experiment' folder anyway, since I could've just used a test :)

@Kivooeo

Kivooeo commented Nov 20, 2025

Copy link
Copy Markdown
Member

cargo clean is just a helper to delete target/, right?

afaik yes

the point is you directly call latest builded locally compiler with your fix, and not having trouble with cache and other stuff

@maxdexh

Copy link
Copy Markdown
ContributorAuthor

the point is you directly call latest builded locally compiler with your fix, and not having trouble with cache and other stuff

hmm good to know, more ergonomic than going through rustup toolchain link every time anyway

@Kivooeo

Copy link
Copy Markdown
Member

(fyi, im not going to wait on CI one more hour to merge this right away because it's 4 in a morning to me, and I would not be able to merge this later today as well, because I will lost access to internet in 3 hours for few days (in perfect scenario), so you would have to wait for another reviwer, it's very likely will be Yukang that is already assigned by a rustbot)

@maxdexh

maxdexh commented Nov 20, 2025

Copy link
Copy Markdown
ContributorAuthor

it's 4 in a morning to me

You don't have to, I can wait. It's late for me too, have a good night :)

And thanks again!

@BoxyUwU

Copy link
Copy Markdown
Member

Oh I didn't notice this in #148602 but I imagine my PR fixes this too.

@bors =Kivooeo,BoxyUwU rollup

@BoxyUwU

Copy link
Copy Markdown
Member

@bors r=Kivooeo,BoxyUwU rollup

@bors

bors commented Nov 21, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit ebf1c38 has been approved by Kivooeo,BoxyUwU

It is now in the queue for this repository.

@borsbors 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-review Status: Awaiting review from the assignee but also interested parties. labels Nov 21, 2025
@BoxyUwUBoxyUwU assigned BoxyUwU and Kivooeo and unassigned chenyukangNov 21, 2025
@BoxyUwUBoxyUwU added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Nov 21, 2025
@ZalatharZalathar mentioned this pull request Nov 21, 2025
bors added a commit that referenced this pull request Nov 21, 2025
Rollup of 5 pull requests
Successful merges:
- #148990 (Exhaustively specify names and stability of `--print` values)
- #149127 (unwrap ret ty of `iter::ArrayChunks::into_remainder` )
- #149134 (std: sys: net: uefi: Implement read_vectored)
- #149135 (Constify `residual_into_try_type`)
- #149160 (Check for intrinsic to fn ptr casts in unified coercions)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit db50517 into rust-lang:mainNov 21, 2025
11 checks passed
rust-timer added a commit that referenced this pull request Nov 21, 2025
Rollup merge of #149160 - maxdexh:fix-instrinsic-unifying-coercion-ice, r=Kivooeo,BoxyUwU
Check for intrinsic to fn ptr casts in unified coercions
Fixes#149143 by ensuring that when coercing multiple expressions to a unified type, the same "intrinsic to fn ptr" check is applied as for other coercions.
@rustbotrustbot added this to the 1.93.0 milestone Nov 21, 2025
@maxdexh
maxdexh deleted the fix-instrinsic-unifying-coercion-ice branch November 21, 2025 08:33
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Conditional assignment of transmute to a function pointer leads to ICE during monomorphization

6 participants

@maxdexh@rustbot@Kivooeo@BoxyUwU@bors@chenyukang