Skip to content

Always make tuple elements a coercion site - #147834

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
WaffleLapkin:tuple-coerce
Mar 9, 2026
Merged

Always make tuple elements a coercion site#147834
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
WaffleLapkin:tuple-coerce

Conversation

@WaffleLapkin

@WaffleLapkinWaffleLapkin commented Oct 17, 2025

Copy link
Copy Markdown
Member

View all comments

Previously we only used check_expr_coercible_to_type if we had an expectation (using check_expr_with_expectation(NoExpectation) otherwise). Normally that'd be fine, because without an expectation we can't insert a coercion anyway. However, for the case of never-to-any coercion specifically, we do insert it eagerly, so this prevents some code from compiling, for example:

((),) = (loop{},);

With this PR we are always using check_expr_coercible_to_type (using an infer var if there is no expectation), which allows slightly more code to compile.

Fixes#112856

r? BoxyUwU

@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 Oct 17, 2025
@rustbot

Copy link
Copy Markdown
Collaborator

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

@WaffleLapkinWaffleLapkin added A-coercions Area: implicit and explicit `expr as Type` coercions F-never_type `#![feature(never_type)]` T-types Relevant to the types team, which will review and decide on the PR/issue. relnotes Marks issues that should be documented in the release notes of the next release. labels Oct 17, 2025
Comment threadcompiler/rustc_middle/src/ty/sty.rs Outdated

/// Returns a list of tuple type arguments, or `None` if `self` isn't a tuple.
#[inline]
pub fn tuple(self) -> Option<&'tcx List<Ty<'tcx>>> {

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.

Suggested change
pubfntuple(self) -> Option<&'tcxList<Ty<'tcx>>>{
pubfnopt_tuple_fields(self) -> Option<&'tcxList<Ty<'tcx>>>{

seems like it does the same thing as tuple_fields it just doesnt panic

@WaffleLapkinWaffleLapkinOct 26, 2025

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

That is indeed the case, is there a problem with that? In the code I wrote I found this a lot more convenient than checking the type first.

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.

no it's fine I just found the differences in the names doesn't really reflect the differences in behaviour

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

If you have a better idea for the names I can rename them

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.

i suggested a different name already :P

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

🤦🏻

I swear I sleep at night sometimes

Comment threadtests/ui/tuple/coercion.rs Outdated
@BoxyUwUBoxyUwU added needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 25, 2025
@BoxyUwU

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

should crater this as it is theoretically breaking, though I don't actually expect any breakage here 🤔

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-borsBot added a commit that referenced this pull request Oct 25, 2025
Always make tuple elements a coercion site
@rustbotrustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 25, 2025
@BoxyUwUBoxyUwU 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 Oct 25, 2025
@BoxyUwU

Copy link
Copy Markdown
Member

When we stabilize the never type do we intend to change how NeverToAny coercions work? Will we continue unconditionally coercing ! to an inference variable, or will we stop doing that? Or in other words, is the stable behaviour here the behaviour we'd expect to have once never type is stabilized?

@rust-bors

rust-borsBot commented Oct 25, 2025

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: f77b5bc (f77b5bc6c7c84df104f86b0dd01d9490e3923fa8, parent: 04ff05c9c0cfbca33115c5f1b8bb20a66a54b799)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (f77b5bc): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

meanrangecount
Regressions ❌
(primary)
0.1%[0.1%, 0.2%]3
Regressions ❌
(secondary)
0.1%[0.0%, 0.1%]3
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
-0.0%[-0.0%, -0.0%]1
All ❌✅ (primary)0.1%[0.1%, 0.2%]3

Max RSS (memory usage)

Results (primary 1.4%, secondary -1.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

meanrangecount
Regressions ❌
(primary)
1.4%[0.8%, 2.1%]2
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
-1.2%[-1.2%, -1.2%]1
All ❌✅ (primary)1.4%[0.8%, 2.1%]2

Cycles

Results (primary -2.1%, secondary -3.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
-2.1%[-2.1%, -2.1%]1
Improvements ✅
(secondary)
-3.8%[-5.3%, -2.1%]4
All ❌✅ (primary)-2.1%[-2.1%, -2.1%]1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 473.373s -> 475.58s (0.47%)
Artifact size: 390.48 MiB -> 390.48 MiB (-0.00%)

@rustbotrustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Oct 25, 2025
@BoxyUwU

Copy link
Copy Markdown
Member

@craterbot check

@craterbot

Copy link
Copy Markdown
Collaborator

👌 Experiment pr-147834 created and queued.
🤖 Automatically detected try build f77b5bc
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbotcraterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 25, 2025
@WaffleLapkin

Copy link
Copy Markdown
MemberAuthor

When we stabilize the never type do we intend to change how NeverToAny coercions work? Will we continue unconditionally coercing ! to an inference variable, or will we stop doing that? Or in other words, is the stable behaviour here the behaviour we'd expect to have once never type is stabilized?

I don't expect / haven't heard of any desire to make any changes with how we insert NeverToAny coercions.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 9, 2026
Always make tuple elements a coercion site
Previously we only used `check_expr_coercible_to_type` if we had an expectation (using `check_expr_with_expectation(NoExpectation)` otherwise). Normally that'd be fine, because without an expectation we can't insert a coercion anyway. However, for the case of never-to-any coercion specifically, we _do_ insert it eagerly, so this prevents some code from compiling, for example:
```rust
((),) = (loop {},);
```
With this PR we are always using `check_expr_coercible_to_type` (using an infer var if there is no expectation), which allows slightly more code to compile.
Fixesrust-lang#112856
r? BoxyUwU
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 9, 2026
Always make tuple elements a coercion site
Previously we only used `check_expr_coercible_to_type` if we had an expectation (using `check_expr_with_expectation(NoExpectation)` otherwise). Normally that'd be fine, because without an expectation we can't insert a coercion anyway. However, for the case of never-to-any coercion specifically, we _do_ insert it eagerly, so this prevents some code from compiling, for example:
```rust
((),) = (loop {},);
```
With this PR we are always using `check_expr_coercible_to_type` (using an infer var if there is no expectation), which allows slightly more code to compile.
Fixesrust-lang#112856
r? BoxyUwU
@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors yield
Yielding to enclosing rollup

@rust-bors

rust-borsBot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #153617.

rust-borsBot pushed a commit that referenced this pull request Mar 9, 2026
…uwer
Rollup of 4 pull requests
Successful merges:
- #147834 (Always make tuple elements a coercion site)
- #150446 (miri/const eval: support `MaybeDangling`)
- #153053 (stop marking `deref_patterns` as an incomplete feature)
- #153398 (fix ICE in `const_c_variadic` when passing ZSTs)
@rust-bors

rust-borsBot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

⌛ Testing commit 3398ea2 with merge 82e4d00...

Workflow: https://github.com/rust-lang/rust/actions/runs/22865035946

rust-borsBot pushed a commit that referenced this pull request Mar 9, 2026
Always make tuple elements a coercion site
Previously we only used `check_expr_coercible_to_type` if we had an expectation (using `check_expr_with_expectation(NoExpectation)` otherwise). Normally that'd be fine, because without an expectation we can't insert a coercion anyway. However, for the case of never-to-any coercion specifically, we _do_ insert it eagerly, so this prevents some code from compiling, for example:
```rust
((),) = (loop {},);
```
With this PR we are always using `check_expr_coercible_to_type` (using an infer var if there is no expectation), which allows slightly more code to compile.
Fixes#112856
r? BoxyUwU
@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors yield
Yielding to enclosing rollup

@rust-bors

rust-borsBot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #153617.

rust-borsBot pushed a commit that referenced this pull request Mar 9, 2026
…uwer
Rollup of 4 pull requests
Successful merges:
- #147834 (Always make tuple elements a coercion site)
- #150446 (miri/const eval: support `MaybeDangling`)
- #153053 (stop marking `deref_patterns` as an incomplete feature)
- #153398 (fix ICE in `const_c_variadic` when passing ZSTs)
@rust-bors
rust-borsBot merged commit 3f1ddd5 into rust-lang:mainMar 9, 2026
11 of 12 checks passed
@rustbotrustbot added this to the 1.96.0 milestone Mar 9, 2026
rust-timer added a commit that referenced this pull request Mar 9, 2026
Rollup merge of #147834 - WaffleLapkin:tuple-coerce, r=BoxyUwU
Always make tuple elements a coercion site
Previously we only used `check_expr_coercible_to_type` if we had an expectation (using `check_expr_with_expectation(NoExpectation)` otherwise). Normally that'd be fine, because without an expectation we can't insert a coercion anyway. However, for the case of never-to-any coercion specifically, we _do_ insert it eagerly, so this prevents some code from compiling, for example:
```rust
((),) = (loop {},);
```
With this PR we are always using `check_expr_coercible_to_type` (using an infer var if there is no expectation), which allows slightly more code to compile.
Fixes#112856
r? BoxyUwU
github-actionsBot pushed a commit to rust-lang/miri that referenced this pull request Mar 10, 2026
…uwer
Rollup of 4 pull requests
Successful merges:
- rust-lang/rust#147834 (Always make tuple elements a coercion site)
- rust-lang/rust#150446 (miri/const eval: support `MaybeDangling`)
- rust-lang/rust#153053 (stop marking `deref_patterns` as an incomplete feature)
- rust-lang/rust#153398 (fix ICE in `const_c_variadic` when passing ZSTs)
@rust-rfcbotrust-rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting labels Mar 10, 2026
@apirainoapiraino removed the to-announce Announce this issue on triage meeting label Apr 2, 2026
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 25, 2026
…-never-coercion, r=jieyouxu
Add tuple never coercion collection regression test
Fixesrust-lang#100727
It's fixed by PR rust-lang#147834
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 25, 2026
…-never-coercion, r=jieyouxu
Add tuple never coercion collection regression test
Fixesrust-lang#100727
It's fixed by PR rust-lang#147834
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 25, 2026
…-never-coercion, r=jieyouxu
Add tuple never coercion collection regression test
Fixesrust-lang#100727
It's fixed by PR rust-lang#147834
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 25, 2026
…-never-coercion, r=jieyouxu
Add tuple never coercion collection regression test
Fixesrust-lang#100727
It's fixed by PR rust-lang#147834
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 26, 2026
…-never-coercion, r=jieyouxu
Add tuple never coercion collection regression test
Fixesrust-lang#100727
It's fixed by PR rust-lang#147834
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 26, 2026
…-never-coercion, r=jieyouxu
Add tuple never coercion collection regression test
Fixesrust-lang#100727
It's fixed by PR rust-lang#147834
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 26, 2026
…-never-coercion, r=jieyouxu
Add tuple never coercion collection regression test
Fixesrust-lang#100727
It's fixed by PR rust-lang#147834
rust-timer added a commit that referenced this pull request Jul 27, 2026
Rollup merge of #159810 - chenyukang:yukang-fix-100727-tuple-never-coercion, r=jieyouxu
Add tuple never coercion collection regression test
Fixes#100727
It's fixed by PR #147834
pullBot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Jul 27, 2026
…ercion, r=jieyouxu
Add tuple never coercion collection regression test
Fixesrust-lang/rust#100727
It's fixed by PR rust-lang/rust#147834
github-actionsBot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Aug 3, 2026
…ercion, r=jieyouxu
Add tuple never coercion collection regression test
Fixesrust-lang/rust#100727
It's fixed by PR rust-lang/rust#147834
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-coercionsArea: implicit and explicit `expr as Type` coercionsdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.F-never_type`#![feature(never_type)]`finished-final-comment-periodThe final comment period is finished for this PR / Issue.needs-fcpThis change is insta-stable, or significant enough to need a team FCP to proceed.perf-regressionPerformance regression.relnotesMarks issues that should be documented in the release notes of the next release.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.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.

tuple elements are not considered a coercion site

8 participants

@WaffleLapkin@rustbot@BoxyUwU@rust-timer@craterbot@rust-rfcbot@JonathanBrouwer@apiraino