Commit graph

2780 commits

Author SHA1 Message Date
bors
7ad4e69ad5 Auto merge of #152517 - jhpratt:rollup-fGRcId6, r=jhpratt
Rollup of 17 pull requests

Successful merges:

 - rust-lang/rust#142415 (Add note when inherent impl for a alias type defined outside of the crate)
 - rust-lang/rust#142680 (Fix passing/returning structs with the 64-bit SPARC ABI)
 - rust-lang/rust#150768 (Don't compute FnAbi for LLVM intrinsics in backends)
 - rust-lang/rust#151152 (Add FCW for derive helper attributes that will conflict with built-in attributes)
 - rust-lang/rust#151814 (layout: handle rigid aliases without params)
 - rust-lang/rust#151863 (Borrowck: simplify diagnostics for placeholders)
 - rust-lang/rust#152159 (Add note for `?Sized` params in int-ptr casts diag)
 - rust-lang/rust#152434 (Clarify names of `QueryVTable` functions for "executing" a query)
 - rust-lang/rust#152478 (Remove tm_factory field from CodegenContext)
 - rust-lang/rust#152498 (Partially revert "resolve: Update `NameBindingData::vis` in place")
 - rust-lang/rust#152316 (fix: add continue)
 - rust-lang/rust#152394 (Correctly check if a macro call is actually a macro call in rustdoc highlighter)
 - rust-lang/rust#152425 (Port #![test_runner] to the attribute parser)
 - rust-lang/rust#152481 (Use cg_ssa's produce_final_output_artifacts in cg_clif)
 - rust-lang/rust#152485 (fix issue#152482)
 - rust-lang/rust#152495 (Clean up some subdiagnostics)
 - rust-lang/rust#152502 (Implement `BinaryHeap::from_raw_vec`)
2026-02-12 06:57:59 +00:00
Jonathan Brouwer
635dcd819a
Remove some empty subdiagnostics 2026-02-11 19:23:46 +01:00
Lukas Bergdoll
2f3b952349 Stabilize assert_matches 2026-02-11 14:13:44 +01:00
bors
f21b4c0888 Auto merge of #152412 - JonathanBrouwer:rollup-hShycIY, r=JonathanBrouwer
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#151960 (rustc_parse: improve the error diagnostic for "missing let")
 - rust-lang/rust#152157 (Fix error spans for `asm!()` args that are macros)
 - rust-lang/rust#152317 (fix: sup_trace to sub_trace)
 - rust-lang/rust#150897 (rustc_parse_format: improve diagnostics for unsupported debug = syntax)
 - rust-lang/rust#151154 (Add `s390x-unknown-none-softfloat` with `RustcAbi::Softfloat`)
 - rust-lang/rust#152013 (Update to Xcode 26.2)
 - rust-lang/rust#152326 (Remove the compiler adhoc group)
2026-02-10 02:25:24 +00:00
Jonathan Brouwer
9709215995
Rollup merge of #151960 - Unique-Usman:ua/missingletleft, r=estebank
rustc_parse: improve the error diagnostic for "missing let"
2026-02-09 23:37:45 +01:00
bors
381e9ef09e Auto merge of #152324 - Keith-Cancel:mgca4, r=BoxyUwU
Update mgca to use `type const` syntax instead of the `#[type_const]` attribute. 

This PR changes the `#[type_const]` attribute to the `type const` syntax for  https://github.com/rust-lang/rust/issues/132980.

This will fixes https://github.com/rust-lang/rust/issues/151273 and similar issues, since we need to check `type const` of items before expansion. The move to add a syntax was mentioned here: https://github.com/rust-lang/rust/pull/151289#issuecomment-3765241397

The first part of this PR adds support by allowing `type const <IDENT>: <TYPE> { = <EXPR> };` syntax in `rustc_parse/src/parser/item.rs`.

The next part since the AST item does not contain enough information to determine if we have a `type const` was rework `ConstItemRhs` into `ConstItemRhsKind` to store the information since we no longer have the attribute acting as a source of extra data/metadata. 

The hir node `ConstItemRhsKind` current shape mostly works, except in the case of `TraitItemKind` where it is an option. I initially went about giving `hir::ConstItemRhsKind` a similar form the AST, but it touches a lot more lines of code and files so because of that, the less invasive option was to add a simple boolean flag to `TraitItemKind`. 

The forth part of this PR includes adding a query I called `is_rhs_type_const` so that we can handle both local and foreign def_ids. 

The fifth aspect of the PR is adding a `mgca_type_const_syntax` feature gate that is checked before expansion. The standard mgca feature gate is ran after expansion. This feature gate allows for conditional compilation (e.g #[cfg(..)]) of the `type const` syntax  in nightly without `min_generic_const_args` being enabled. 

The last bit is updating all the the tests that used the `#[type_const]` attribute to use the new syntax that failed because of the changes. This is the bulk of touched/edited files in the PR. 

r? @BoxyUwU 
@rustbot label +F-associated_const_equality +F-min_generic_const_args
2026-02-09 22:37:29 +00:00
Keith-Cancel
73a991fb9d Allow provisional mgca syntax of type const <IDENT> = <EXPR> to be reconized.
Revert, but without type const.

Update symbol for feature err, then update suggestion output, and lastly update tests that change because of those.

Update these new tests with the correct syntax, and few existing tests with the new outputs the merge with main added.

Fix for tidyfmt and some errors when manually resolving a merge conflicts.

Update these tests to use update error messages and type const syntax.

Update comments and error message to use new syntax instead of old type_const attribute.

Remove the type_const attribute

update some more tests to use the new syntax.

Update these test cases.

update feature gate test

Change gate logic for `mgca_type_const_syntax` to work also if `min_generic_const_args` is enabled.

Create a new feature gate that checks for the feature before expansion.

Make rustfmt handle the `type const` syntax correctly.

Add a convience method to check if a RhsKind is type const.

Rename `Const` discriminant to `Body` for `ConstItemRhsKind`

Give the `TraitItemKind` flag an enum instead of a simple bool to better describe what the flag is for.

Update formatting for these match statements.

Update clippy test to use type const syntax.

Update test to use type const syntax.

update rustfmt to match ast items.

Update clippy to match ast and hir items.

Few more test cases that used old attribute, instead of 'type const'

Update to match the output from the feature gate checks.

tidyfmt adjustments.

Update the is_type_const, so I can constrain record!(..) in encoder.rs

Update conditional compilation test.

Move the feature gate to after expansion to allow for cfg(...) to work.

Update some more tests to use the new syntax.

Update type const tests in associated-const-bindings to use new syntax.

Don't check based off the attribute, but the item here.

Update some tests outside of the const_generics folder that were using #[type_const]

update the tests in associated consts that use #[type_const] to use type const

Update these mgca tests with the type const syntax.

Add a flag to TraitItemKind for detecting type const for now. Maybe later change ItemConstRhs to have optional consts but that touches a lot more lines of code.

Don't need into for these now that it's a query.

Add is_type_const query to handle foreign def ids.

update this test to use type const syntax.

Fix logic here, we only want to lower if there is expression in this case.

Update built-in macros to use ConstItemRhsKind

Update more instance of the old ConstItemRhs.

Rename ConstItemKind to ConstItemRhsKind, I noticed there is a typed called ConstantItemKind, so add the Rhs to the name to avoid confusion.

Update lower to use ConstItemKind

Add an other helper method to check if the rhs kinda has an expr.

Update item parse to use ConstItemKind enum.

Felt the field name could a be little clear when editing a few other things.

Change the ConstItem struct see know if we have a type const or regular const.

Make sure this syntax is properly feature gated.
2026-02-09 07:59:24 -08:00
Jacob Pratt
9d31498271
Rollup merge of #152276 - JonathanBrouwer:fmt-check, r=jdonszelmann
Add message format checking

Checks the indentation of diagnostic messages, it checks that everything is at least as indented as the attribute that contains it

r? @jdonszelmann (Anyone else, also feel free to review, just assigning to Jana because she's been reviewing the other PRs)
2026-02-09 05:20:29 -05:00
Stuart Cook
7ae47be6aa
Rollup merge of #150823 - camelid:ogca, r=BoxyUwU
Implement MVP for opaque generic const arguments

This is meant to be the interim successor to generic const expressions.
Essentially, const item RHS's will be allowed to do arbitrary const
operations using generics. The limitation is that these const items will
be treated opaquely, like ADTs in nominal typing, such that uses of them
will only be equal if the same const item is referenced. In other words,
two const items with the exact same RHS will not be considered equal.

I also added some logic to check feature gates that depend on others
being enabled (like oGCA depending on mGCA).

### Coherence

During coherence, OGCA consts should be normalized ambiguously because
they are opaque but eventually resolved to a real value. We don't want
two OGCAs that have the same value to be treated as distinct for
coherence purposes. (Just like opaque types.)

This actually doesn't work yet because there are pre-existing
fundamental issues with equate relations involving consts that need to
be normalized. The problem is that we normalize only one layer of the
const item and don't actually process the resulting anon const. Normally
the created inference variable should be handled, which in this case
would cause us to hit the anon const, but that's not happening.
Specifically, `visit_const` on `Generalizer` should be updated to be
similar to `visit_ty`.

r? @BoxyUwU
2026-02-09 14:31:59 +11:00
Jonathan Brouwer
99c6009c45
Reformat existing messages 2026-02-08 23:07:58 +01:00
Jonathan Brouwer
78bd6abbe6
Rollup merge of #152341 - folkertdev:cfg-select-optional-comma, r=JonathanBrouwer
`cfg_select!`: allow optional comma after `{ /* ... */ }`
2026-02-08 19:15:28 +01:00
Jonathan Brouwer
0d9b0ab620
Rollup merge of #152328 - JonathanBrouwer:fix_diags, r=JonathanBrouwer
Fix a few diagnostics

When working on the inline diagnostics conversion (https://github.com/rust-lang/rust/issues/151366), I noticed that my script sometimes took the wrong message.
Because it didn't happen very often, I just fixed it manually when a uitest fails.

However I got paranoid that the script changed messages that were not covered by uitests, so I checked for all messages in the previous `messages.ftl` files, whether they occured at least once in the codebase. I found 3 messages that indeed were wrongly replaced by my script, fixed them, and added uitests to make sure this doesn't happen again :)

r? @jdonszelmann (Anyone else, also feel free to review, just assigning to Jana because she's been reviewing the other PRs)
2026-02-08 19:15:26 +01:00
Jonathan Brouwer
7fbde8b9c8
Rollup merge of #152250 - JonathanBrouwer:convert_finish, r=jdonszelmann
Remove support for slugs in diagnostic messages

This PR contains 5 commits, and is best reviewed commit-by-commit:
- https://github.com/rust-lang/rust/pull/152250/changes/ea8733133cacf4496a2766b3d002492cc29ea7bf Removes support from slugs from `rustc_errors`
- https://github.com/rust-lang/rust/pull/152250/changes/62dd37131f6f43d0dab3e26cf125cd841a08e003 Removes support from slugs from `rustc_macros` (which declares `derive(Diagnostic)`)
- https://github.com/rust-lang/rust/pull/152250/changes/2289e6cfb7e379eba777a10df0a6f474f9450b02 Adjuist the `ui-fulldeps` testsuite to match the changes in `rustc_macros`
- https://github.com/rust-lang/rust/pull/152250/changes/0db0acd6993cbdf84384b00773d7509df6bc20fb Removes support for the fallback bundle (which previously contained all messages, but is now empty) from `rustc_driver_impl` and `rustc_session`
- https://github.com/rust-lang/rust/pull/152250/changes/81d42146040c4a6b3d252e3dc3ac32e563694796 Removes an integration test that tested the translation system using fluent
2026-02-08 19:15:25 +01:00
Noah Lev
9a30ec8149 Implement MVP for opaque generic const arguments
This is meant to be the interim successor to generic const expressions.
Essentially, const item RHS's will be allowed to do arbitrary const
operations using generics. The limitation is that these const items will
be treated opaquely, like ADTs in nominal typing, such that uses of them
will only be equal if the same const item is referenced. In other words,
two const items with the exact same RHS will not be considered equal.

I also added some logic to check feature gates that depend on others
being enabled (like oGCA depending on mGCA).

= Coherence =

During coherence, OGCA consts should be normalized ambiguously because
they are opaque but eventually resolved to a real value. We don't want
two OGCAs that have the same value to be treated as distinct for
coherence purposes. (Just like opaque types.)

This actually doesn't work yet because there are pre-existing
fundamental issues with equate relations involving consts that need to
be normalized. The problem is that we normalize only one layer of the
const item and don't actually process the resulting anon const. Normally
the created inference variable should be handled, which in this case
would cause us to hit the anon const, but that's not happening.
Specifically, `visit_const` on `Generalizer` should be updated to be
similar to `visit_ty`.
2026-02-08 18:15:11 +00:00
Jonathan Brouwer
d14c26f45a
Fix help on AmbiguousMissingKwForItemSub diagnostic 2026-02-08 17:02:40 +01:00
Folkert de Vries
053f76e9f0
cfg_select!: allow optional comma after { /* ... */ } 2026-02-08 13:46:29 +01:00
Jonathan Brouwer
0db0acd699
Remove the fallback bundle 2026-02-08 11:06:42 +01:00
Stuart Cook
55277add61
Rollup merge of #150443 - estebank:long-diff-markers, r=jackh726
Support long diff conflict markers

git can be configured to use more than 7 characters for conflict markers, and jj automatically uses longer conflict markers when the text contains any char sequence that could be confused with conflict markers. Ensure that we only point at markers that are consistent with the start marker's length.

Ensure that we only consider char sequences at the beginning of a line as a diff marker.

Fix https://github.com/rust-lang/rust/issues/150352.
2026-02-08 16:58:23 +11:00
Usman Akinyemi
85ca098f55 rustc_parse: improve the error diagnostic for "missing let"
Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
2026-02-07 22:12:04 +05:30
Jonathan Brouwer
c5587ca919
Split parse_inner_attr errors by case 2026-02-07 10:30:42 +01:00
Jonathan Brouwer
cda9b8c157
Split ComparisonOrShiftInterpretedAsGenericSugg 2026-02-07 10:30:42 +01:00
Jonathan Brouwer
9a114c686f
Convert to inline diagnostics in rustc_parse 2026-02-07 10:30:40 +01:00
Boxy
a86cfbbaab keep const blocks around 2026-02-06 19:36:39 +00:00
Jonathan Brouwer
3fb526578e
Rollup merge of #151474 - nnethercote:circ-deps, r=davidtwco
Minor structural improvements

Some small cleanups.

r? @davidtwco
2026-02-06 10:06:42 +01:00
Jonathan Brouwer
70f1120363
Rollup merge of #151102 - zachs18:mut-ref-in-struct-pattern-shorthand-gate, r=JonathanBrouwer
Feature-gate `mut ref` patterns in struct pattern field shorthand

Tracking issue for `mut_ref` (and other parts of Match Ergonomics 2024): https://github.com/rust-lang/rust/issues/123076

https://github.com/rust-lang/rust/pull/123080 introduced `mut ref`[^1] patterns (for by-reference bindings where the binding itself is mutable), feature-gated behind the `mut_ref` feature, except for in struct pattern shorthand, where the feature gating was missing. Thus, `mut ref` patterns in struct pattern shorthand has been unintentionally stable for ~18 months (since 1.79.0 ([compiler explorer](https://rust.godbolt.org/z/4WTrvhboT))).

This PR adds feature-gating for `mut ref` patterns in struct pattern shorthand. Since this is reverting an accidental stabilization, this probably needs a crater run and a T-lang FCP?

Some alternative possibilities:

* Do nothing (let the inconsistency exist until `feature(mut_ref)` is stabilized)
* Document the existing behavior
* Do a FCW instead of fully feature-gating
* Stabilize `feature(mut_ref)`

CC https://github.com/rust-lang/rust/pull/123080#issuecomment-3746793632

CC @Nadrieril

[^1]: everything in this description also applies analogously to `mut ref mut` patterns.
2026-01-31 21:42:46 +01:00
yukang
dc48704f98 Fix ICE when parsing frontmatter without newline 2026-01-31 08:51:40 +00:00
Stuart Cook
b6ce0c0028
Rollup merge of #149823 - epage:f, r=Kivooeo
fix(parser): Disallow CR in frontmatter

T-lang came back on the stabilization PR (rust-lang/rust#148051) asking for CR to be disallowed
to leave room for all stray CRs to be rejected in the future.
At that point, the test can remain but the implementation can be
removed.

If that plan does not go through, we'll need to re-evaluate
- whether this is more lint-like and should defer to the calling tool
  that is managing the frontmatter
- how much Rust should treat the frontmatter as Rust and apply the same
  grammar restrictions of "no stray CR" (like raw string literals)

Part of rust-lang/rust#136889
2026-01-29 22:34:09 +11:00
Ed Page
52d4ef12a8 fix(parser): Disallow CR in frontmatter
T-lang came back on the stabilization PR asking for CR to be disallowed
to leave room for all stray CRs to be rejected in the future.
At that point, the test can remain but the implementation can be
removed.

If that plan does not go through, we'll need to re-evaluate
- whether this is more lint-like and should defer to the calling tool
  that is managing the frontmatter
- how much Rust should treat the frontmatter as Rust and apply the same
  grammar restrictions of "no stray CR" (like raw string literals)
2026-01-28 13:01:02 -06:00
Ed Page
dd5539251c refactor(parse): Use a common frame of reference 2026-01-28 13:01:02 -06:00
Ed Page
053b947aa9 refactor(parse): Consistently use real_s 2026-01-28 13:01:02 -06:00
Ed Page
e9122481a4 refactor(parse): Be consistent in naming 2026-01-28 13:01:02 -06:00
Usman Akinyemi
9ca8ed38eb rustc_parse: improve the error diagnostic for "missing let in let chain"
Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
2026-01-28 16:47:41 +05:30
Nicholas Nethercote
b33fdb2c70 Move TokenDescription.
From the `parser` module to the `errors` module, which is where most of
its uses are.

This means the `errors` module no longer depends on the `parser` module,
removing a cyclic dependency between the two modules.
2026-01-27 12:07:37 +11:00
Nicholas Nethercote
506ea790ca Move two rustc_parse error diagnostics.
Every diagnostic struct in `rustc_parse` is in the `errors` module,
except for `ForbiddenLetReason` and `MisspelledKw`. There's no good
reason for this, and presumably it is just an accidental inconsistency.
This commit moves them into `errors`.
2026-01-27 12:07:33 +11:00
Jonathan Brouwer
6ff5bb3968
Rollup merge of #151290 - Unique-Usman:ua/nostruct, r=estebank
Recover from struct literals with placeholder or empty path

Based on earlier work by León Orell Valerian Liehr.
2026-01-26 18:19:12 +01:00
Usman Akinyemi
54fc546f20 Recover from struct literals with placeholder or empty path
Based on earlier work by León Orell Valerian Liehr.

Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
Signed-off-by: Usman Akinyemi <uniqueusman@archlinux>
2026-01-26 04:09:28 +05:30
Matthias Krüger
0bb15457de
Rollup merge of #149174 - GrigorenkoPV:const_block_item, r=me,ytmimi
`const` blocks as a `mod` item

Tracking issue: rust-lang/rust#149226

This adds support for writing `const { ... }` as an item in a module. In the current implementation, this is a unique AST item that gets lowered to `const _: () = const { ... };` in HIR.

rustfmt support included.

TODO:
- `pub const { ... }` does not make sense (see rust-lang/rust#147136). Reject it. Should this be rejected by the parser or smth?
- Improve diagnostics (preferably they should not mention the fake `_` ident).
2026-01-24 15:35:08 +01:00
Pavel Grigorenko
a315d230d5 const_block_items: do not create an AnonConst 2026-01-21 19:36:27 +03:00
Pavel Grigorenko
e77b11924f const_block_items: tests 2026-01-21 19:36:27 +03:00
Pavel Grigorenko
5eb01938c9 Audit AllowConstBlockItems 2026-01-21 19:36:14 +03:00
Pavel Grigorenko
61ac56209d separate ast item for const block items 2026-01-21 18:26:57 +03:00
Pavel Grigorenko
8439fda014 Sugar for const _: () = 2026-01-21 18:12:21 +03:00
bjorn3
3ccabc6a8d Remove old error emitter
This completes the transition to annotate-snippets
2026-01-21 12:14:51 +00:00
Jonathan Brouwer
8c5e10bb11
Rollup merge of #151249 - fix/151238, r=petrochenkov
Parse ident with allowing recovery when trying to diagnose

Fixes rust-lang/rust#151238

rust-lang/rust#146978 made parsing ident not always allowed-recovery ([change](https://github.com/rust-lang/rust/pull/146978/changes#diff-ef8d6186dc7fb1d03a71446d0c9e6cc9e72158ec6896703dcf05686ee7dc83fcL469-R469)), so when matching macro with `NoopTracker`, which has `Recovery::Forbidden`, ICE happens when trying to parse kw as ident and then unwraping it.

This PR introduces a new method for parsing ident with allowing recovery when trying to diagnose. Then errors will behave like previous.

r? @petrochenkov
2026-01-19 20:53:24 +01:00
Jonathan Brouwer
1968df85fb
Rollup merge of #151171 - issue-141436, r=davidtwco
Do not recover from `Trait()` if generic list is unterminated

If we encounter `fn foo<T: Trait()`, the recovery logic would it as if `Trait` was intended to use the Fn-like trait syntax, but if we don't know for certain that we've parsed a full trait bound (`fn foo<T: Trait()>`), we bail from the recovery as more likely there could have been a missing closing `>` and the `(` corresponds to the start of the fn parameter list.

Fix rust-lang/rust#141436.
2026-01-19 20:53:23 +01:00
Jonathan Brouwer
0ee7d96253
Remove all allows for diagnostic_outside_of_impl and untranslatable_diagnostic throughout the codebase
This PR was mostly made by search&replacing
2026-01-19 17:39:49 +01:00
Zalathar
7ec34defe9 Temporarily re-export assert_matches! to reduce stabilization churn 2026-01-19 18:26:53 +11:00
mu001999
3713512217 Parse ident with allowing recovery when trying to recover in diagnosing 2026-01-19 10:08:45 +08:00
Esteban Küber
c6c4372f82 Use default field values in Parser 2026-01-15 19:46:54 +00:00
Esteban Küber
d194795f14 Do not recover from Trait() if generic list is unterminated
If we encounter `fn foo<T: Trait()`, the recovery logic would it as if `Trait` was intended to use the Fn-like trait syntax, but if we don't know for certain that we've parsed a full trait bound (`fn foo<T: Trait()>`), we bail from the recovery as more likely there could have been a missing closing `>` and the `(` corresponds to the start of the fn parameter list.
2026-01-15 19:32:39 +00:00