Skip to content

fix unsoundness when compiling [diverging_const; _] - #165497

Merged
rust-bors[bot] merged 4 commits into
rust-lang:mainfrom
WaffleLapkin:_
Nov 5, 2026
Merged

rust-bors[bot] merged 4 commits into
rust-lang:mainfrom
WaffleLapkin:_

Conversation

@WaffleLapkin

Copy link
Copy Markdown
Member

Follow up to #165416, because I missed a case. r? @BoxyUwU

@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 Nov 5, 2026
@rustbot

rustbot commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

BoxyUwU is currently at their maximum review capacity.
They may take a while to respond.

@WaffleLapkin WaffleLapkin added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Nov 5, 2026
@WaffleLapkin

Copy link
Copy Markdown
Member Author

Beta nominating for the same reason as #165416 -- this (hopefully now actually) fixes an unsoundness with the never type that's about to be stable.

Comment thread compiler/rustc_hir_typeck/src/expr.rs Resolved

@BoxyUwU BoxyUwU 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.

So the problem here is that in [CONST; 0] we dont actually evaluate CONST so even though the expr CONST diverges, the function as a whole does not?

And you fix this by making it so that if we aren't guaranteed that the repeat count is greater than zero, then we treat the array repeat expression as being non-diverging?

And the thing talked about in the original issue that another fix might be to instead actually evaluate CONST unconditionally? But we're not doing that rn because its more involved than papering over the issue?

does that all sounds like a correct understanding? if so lgtm r=me

View changes since this review

@BoxyUwU

BoxyUwU commented Nov 5, 2026

Copy link
Copy Markdown
Member

I guess this also assumes that conservatively not considering things to be diverging is ok, is that the case xd

@theemathas

Copy link
Copy Markdown
Contributor

Just to be sure again: Does this require a crater run?

@WaffleLapkin

Copy link
Copy Markdown
Member Author

@BoxyUwU yes, I think everything you said is correct.

I guess this also assumes that conservatively not considering things to be diverging is ok, is that the case xd

To the best of my knowledge, yes. Assumption of divergence allows the compiler to do a lot of things (such as removing code presumed unreachable). The opposite isn't true, if the compiler doesn't know if something diverges, that does not give any information to it.

Note how you can always wrap a diverging expression in a function to hide (from the type system) the fact that it diverges.

@WaffleLapkin

Copy link
Copy Markdown
Member Author

@theemathas I think this is still fine. To have a problem with this you need:

  • an array repeat expression with length 0 (potentially inferred through _
  • ... with an element value that is a constant
  • ... that is not evaluated through other means
  • ... and has type !
  • ... which is explicitly specified (which is only possible through hacks / once never gets stabilized) (due to how divergence checking and never-to-any coercions work)

I think this is very improbable, and I don't feel like there is a need for crater.

@rustbot

rustbot commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

beta backport approved as per compiler team on Zulip. A backport PR will be authored by the release team at the end of the current development cycle. Backport labels are handled by them.

@rustbot rustbot added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Nov 5, 2026
// Issue: <https://github.com/rust-lang/rust/issues/165323>
//
//@ build-fail
#![feature(generic_const_exprs)]

@WaffleLapkin WaffleLapkin Nov 5, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@BoxyUwU the only way I found to make a test with T::ASSOC work is to use GCE, is this what you wanted?

View changes since the review

@WaffleLapkin

Copy link
Copy Markdown
Member Author

@bors r=BoxyUwU

@rust-bors

rust-bors Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 8dfb82d has been approved by BoxyUwU

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 5, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 5, 2026
fix unsoundness when compiling `[diverging_const; _]`

Follow up to rust-lang#165416, because I [missed a case](rust-lang#165416 (comment)). r? @BoxyUwU
rust-bors Bot pushed a commit that referenced this pull request Nov 5, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #165496 (c-variadic: remove stale `cfg(bootstrap)` comment)
 - #164716 (Lower UEFI targets through LLVM's *uefi triple)
 - #165497 (fix unsoundness when compiling `[diverging_const; _]`)
 - #165275 (Build TPDE with local Clang when available)
 - #165467 (Use `emit_ptr_va_arg` for `va_arg` on MSP430)
 - #165483 (compiletest: Fix the edition of minicore to the latest stable one)
 - #165498 (LoongArch: Fix direct-access-external-data test)
 - #165501 (rustdoc: Don't add a border on an empty `:target` element)
@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors p=10

@JonathanBrouwer JonathanBrouwer removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Nov 5, 2026
@JonathanBrouwer JonathanBrouwer added this to the 1.100.0 milestone Nov 5, 2026
@rust-bors
rust-bors Bot merged commit f3f187e into rust-lang:main Nov 5, 2026
14 checks passed
rust-bors Bot pushed a commit that referenced this pull request Nov 5, 2026
Rollup merge of #165497 - WaffleLapkin:_, r=BoxyUwU

fix unsoundness when compiling `[diverging_const; _]`

Follow up to #165416, because I [missed a case](#165416 (comment)). r? @BoxyUwU
@rustbot rustbot modified the milestones: 1.100.0, 1.101.0 Nov 5, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 5, 2026
[beta] backports

Cherry picked:
* #165497
* #165499
  - rust-lang/rust-clippy#17752 (was already last beta, but we didn't manage to get the proper fixed merged in time like we planned)
  - rust-lang/rust-clippy#17828
  - rust-lang/rust-clippy#17941

r? @ghost
@cuviper cuviper modified the milestones: 1.101.0, 1.100.0 Nov 5, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 5, 2026
[beta] backports

Cherry picked:
* #165497
* #165499
  - rust-lang/rust-clippy#17752 (was already last beta, but we didn't manage to get the proper fixed merged in time like we planned)
  - rust-lang/rust-clippy#17828
  - rust-lang/rust-clippy#17941

r? @ghost
@WaffleLapkin
WaffleLapkin deleted the _ branch November 6, 2026 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beta-accepted Accepted for backporting to the compiler in the beta channel. 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.

6 participants