Skip to content

Emit a pre-expansion feature gate warning for box'ed struct field patterns#154475

Merged
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
fmease:soft-gate-box-struct-field-pat
Mar 28, 2026
Merged

Emit a pre-expansion feature gate warning for box'ed struct field patterns#154475
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
fmease:soft-gate-box-struct-field-pat

Conversation

@fmease
Copy link
Copy Markdown
Member

@fmease fmease commented Mar 27, 2026

While the following code triggers a feature gate warning:

fn f() {
    #[cfg(false)]
    let box x; //~ WARN box pattern syntax is experimental
}

the code below does not (on stable & main):

fn f() {
    #[cfg(false)]
    let Struct { box x };
}

This is an oversight as both are part of the unstable feature box_patterns (that isn't properly gated pre expansion for historical reasons). Of course, both forms lead to a feature gate error post expansion.

This is a bug fix and doesn't need any input from T-compiler or T-lang. For context, emitting warnings in these cases is legitimized by MCP 5351.

Part of #154045.

Footnotes

  1. In case you're wondering why the MCP talks about a lint even though the feature gate warnings as seen today don't reference any lint by name, read https://github.com/rust-lang/rust/issues/154045#issuecomment-4144034419.

@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 Mar 27, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 27, 2026

r? @TaKO8Ki

rustbot has assigned @TaKO8Ki.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 11 candidates

@fmease fmease changed the title Emit a pre-expansion feature gate warning for box'ed struct field patterns Emit a pre-expansion feature gate warning for box'ed struct field patterns Mar 27, 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.

Replaced by tests/ui/feature-gates/soft-feature-gate-auto_traits.rs.

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.

Replaced by tests/ui/feature-gates/soft-feature-gate-try_blocks.rs.

@rust-log-analyzer

This comment has been minimized.

@fmease fmease force-pushed the soft-gate-box-struct-field-pat branch 2 times, most recently from 334925d to 3a5aa21 Compare March 27, 2026 17:37
@rust-log-analyzer

This comment has been minimized.

@fmease fmease force-pushed the soft-gate-box-struct-field-pat branch from 3a5aa21 to a7ad9ac Compare March 27, 2026 19:50
@Kivooeo
Copy link
Copy Markdown
Member

Kivooeo commented Mar 28, 2026

r? me @bors r+ rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Mar 28, 2026

📌 Commit a7ad9ac has been approved by Kivooeo

It is now in the queue for this repository.

@rust-bors rust-bors bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Mar 28, 2026
@rust-bors rust-bors bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 28, 2026
rust-bors bot pushed a commit that referenced this pull request Mar 28, 2026
Rollup of 11 pull requests

Successful merges:

 - #152880 (Tweak incorrect assoc item note)
 - #153526 (Fix LegacyKeyValueFormat report from docker build: i686)
 - #153613 (interpreter error reporting: remove arguments that are always the same)
 - #154029 (Replace `truncate(0)` with `clear()`)
 - #154125 (Inline and remove `DepGraphData::try_mark_parent_green`.)
 - #154185 (Prevent no_threads RwLock's write() impl from setting mode to -1 when it is locked for reading)
 - #154394 (Normalize rustc path prefix when testing `-Z track-diagnostics`)
 - #154450 (Use the normal arg-parsing machinery for `-Zassert-incr-state`)
 - #154475 (Emit a pre-expansion feature gate warning for `box`'ed struct field patterns)
 - #154500 (EnumSizeOpt: use Allocation::write_scalar instead of manual endianess logic)
 - #154502 (interpret: ensure that untupled arguments are actually tuples)
@rust-bors rust-bors bot merged commit 7ee19eb into rust-lang:main Mar 28, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 28, 2026
rust-timer added a commit that referenced this pull request Mar 28, 2026
Rollup merge of #154475 - fmease:soft-gate-box-struct-field-pat, r=Kivooeo

Emit a pre-expansion feature gate warning for `box`'ed struct field patterns

While the following code triggers a feature gate *warning*:

```rs
fn f() {
    #[cfg(false)]
    let box x; //~ WARN box pattern syntax is experimental
}
```

the code below does not (on stable & main):

```rs
fn f() {
    #[cfg(false)]
    let Struct { box x };
}
```

This is an oversight as both are part of the unstable feature `box_patterns` (that isn't properly gated pre expansion for historical reasons). Of course, both forms lead to a feature gate error *post expansion*.

This is a bug fix and doesn't need any input from T-compiler or T-lang. For context, emitting warnings in these cases is legitimized by [MCP 535](https://github.com/rust-lang/compiler-team/issues/535)[^1].

Part of #154045.

[^1]: In case you're wondering why the MCP talks about a *lint* even though the feature gate warnings as seen today don't reference any lint by name, read #154045 (comment).
@fmease fmease deleted the soft-gate-box-struct-field-pat branch March 28, 2026 17:14
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