Commit graph

52456 commits

Author SHA1 Message Date
bors
d9617c8d9a Auto merge of #150310 - JonathanBrouwer:cfg_trace2, r=jdonszelmann
Port `#[cfg]` and `#[cfg_attr]` trace attributes to the new attribute parsers

This PR converts `cfg` and `cfg_trace` attributes to the new parsed representation.

The primary challenge is that re-parsing these attributes in the HIR is a performance regression, since these attributes were only used in rustdoc and clippy parsing them in the HIR is extra work that was not done in the compiler before. To solve this, we only parse the attributes once and then store their parsed representation in the AST.
2026-01-06 22:59:32 +00:00
bors
0aced202c2 Auto merge of #150729 - matthiaskrgr:rollup-an2m4zg, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#150026 (Fix macro_metavar_expr_concat behavior with nested repetitions)
 - rust-lang/rust#150521 (resolve: Rename "name bindings" to "name declarations")
 - rust-lang/rust#150704 (MGCA: Const constructors support)
 - rust-lang/rust#150728 (Cleanup some ui tests for const-traits)

r? `@ghost`
`@rustbot` modify labels: rollup
2026-01-06 19:41:29 +00:00
Matthias Krüger
9c45483fe6
Rollup merge of #150704 - Kivooeo:const-ctor, r=BoxyUwU
MGCA: Const constructors support

part of https://github.com/rust-lang/rust/issues/132980

fixes rust-lang/rust#132985
fixes rust-lang/rust#136138
fixes rust-lang/rust#139596

r? BoxyUwU
2026-01-06 18:43:29 +01:00
Matthias Krüger
e5a2b25f4c
Rollup merge of #150521 - petrochenkov:decl, r=nnethercote
resolve: Rename "name bindings" to "name declarations"

This was discussed previously in some name resolution specification threads on zulip.
Link: [#t-compiler/help > understanding early name resolution of imports @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/understanding.20early.20name.20resolution.20of.20imports/near/545306658)

The main change is that `NameBinding` is renamed to `Decl`.
The `Name` part is skipped because almost everything in `rustc_resolve` is about names.
So in general the naming looks more compact now (`binding: NameBinding` -> `decl: Decl`).

I didn't rename *everything* including all the local variables, but did rename most of significant interfaces.
Late resolution in particular uses "bindings" in slightly different meanings, I didn't touch that.

Also, some interface comments are added/improved.

Renaming list:
- fn `define_binding_local` -> `plant_decl_into_local_module`
- fn `add_macro_use_binding` -> `add_macro_use_decl`
- fn `binding_description` -> `decl_description`
- enum `PendingBinding` -> `PendingDecl`
- field `ImportKind::Single::bindings` -> `ImportKind::Single::decls`
- field `NameResolution::non_glob_binding` -> `NameResolution::non_glob_decl`
- field `NameResolution::glob_binding` -> `NameResolution::glob_decl`
- fn `best_binding` -> `best_decl`
- fn `import` -> `new_import_decl`
- fn `try_define_local` -> `try_plant_decl_into_local_module`
- fn `new_ambiguity_binding` -> `new_decl_with_ambiguity`
- fn `new_warn_ambiguity_binding` -> `new_decl_with_warn_ambiguity`
- field `UnnecessaryQualification::binding` -> `UnnecessaryQualification::decl`
- struct `MacroRulesBinding` -> `MacroRulesDef`
- field `MacroRulesBinding::binding` -> `MacroRulesDef::decl`
- variant `MacroRulesScope::Binding` -> `MacroRulesScope::Def`
- enum `LexicalScopeBinding` -> `LateDecl`
- variant `LexicalScopeBinding::Item` -> `LateDecl::Decl`
- variant `LexicalScopeBinding::Res` -> `LateDecl::RibDef`
- field `ModuleData::self_binding` -> `ModuleData::self_decl`
- struct `NameBindingData` -> `DeclData`
- type `NameBinding` -> `Decl`
- enum `NameBindingKind` -> `DeclKind`
- variant `NameBindingKind::Res` -> `DeclKind::Def`
- field `NameBindingKind::Import::binding` -> `DeclKind::Import::source_decl`
- field `PrivacyError::binding` -> `PrivacyError::decl`
- field `ExternPreludeEntry::item_binding` -> `ExternPreludeEntry::item_decl`
- field `ExternPreludeEntry::flag_binding` -> `ExternPreludeEntry::flag_decl`
- field `Resolver::binding_parent_modules` -> `Resolver::decl_parent_modules`
- field `Resolver::dummy_binding` -> `Resolver::dummy_decl`
- field `Resolver::builtin_types_bindings` -> `Resolver::builtin_type_decls`
- field `Resolver::builtin_attrs_bindings` -> `Resolver::builtin_attr_decls`
- field `Resolver::registered_tool_bindings` -> `Resolver::registered_tool_decls`
- fn `ResolverArenas::new_res_binding` -> `ResolverArenas::new_def_decl`
- fn `ResolverArenas::new_pub_res_binding` -> `ResolverArenas::new_pub_def_decl`
- fn `ResolverArenas::alloc_name_binding` -> `ResolverArenas::alloc_decl`
- fn `ResolverArenas::alloc_macro_rules_binding` -> `ResolverArenas::alloc_macro_rules_def`
- fn `set_binding_parent_module` -> `set_decl_parent_module`
2026-01-06 18:43:28 +01:00
Matthias Krüger
8add20b77f
Rollup merge of #150026 - Delta17920:fix/150002-macro-concat-bug, r=jdonszelmann
Fix macro_metavar_expr_concat behavior with nested repetitions

**The Bug**: The `${concat(...)}` expression was using the wrong loop index when inside nested repetitions (like optional groups), causing it to get "stuck" on the first element and generate duplicate code.

**The Fix**: Updated `metavar_expr_concat` in `transcribe.rs` to correctly search the repetition stack (`tscx.repeats`) for the target variable instead of blindly using the last index.

**Tests**:
    Added `tests/ui/macros/concat-nested-repetition.rs.`

Fixes rust-lang/rust#150002
2026-01-06 18:43:28 +01:00
Vadim Petrochenkov
db26d01211 resolve: DeclKind::Import::binding -> DeclKind::Import::source_decl 2026-01-06 18:21:37 +03:00
Vadim Petrochenkov
a0ea3b0635 Update more function names and fields from bindings to declarations 2026-01-06 18:21:37 +03:00
Vadim Petrochenkov
a67e289b4d Update some function names and fields from bindings to declarations 2026-01-06 18:21:37 +03:00
Vadim Petrochenkov
844e085de6 resolve: MacroRulesScope::Binding -> MacroRulesScope::Def
`MacroRulesBinding` -> `MacroRulesDef`
2026-01-06 18:21:37 +03:00
Vadim Petrochenkov
7a34af2f67 resolve: Rename LexicalScopeBinding::(Item,Res) to LateDecl::(Decl,RibDef) 2026-01-06 18:21:37 +03:00
Vadim Petrochenkov
460f22c388 resolve: Rename NameBinding(Data,Kind) to Decl(Data,Kind)
Also, rename `DeclKind::Res` to `DeclKind::Def`.
2026-01-06 18:21:37 +03:00
Jonathan Brouwer
58b1130a18
Rollup merge of #150707 - Delta17920:fix-transmute-valtree-ice, r=BoxyUwU
Fix ICE when transmute Assume field is invalid

This PR fixes an internal compiler error in `rustc_transmute` where initializing an `Assume` field (like `alignment`) with a non-scalar constant (like a struct) caused a panic.

The fix updates `from_const` to use `try_to_scalar()` instead of assuming the value is always a leaf. It now gracefully returns `None` for invalid types, allowing the compiler to report standard "missing field initialiser" errors instead of crashing.

Fixes rust-lang/rust#150506
2026-01-06 16:19:44 +01:00
Jonathan Brouwer
959736de75
Rollup merge of #150698 - hkBst:patch-6, r=jdonszelmann
Improve comment clarity in candidate_may_shadow

I think this should be the right correction, but I'm not sure.
2026-01-06 16:19:43 +01:00
Jonathan Brouwer
dd08360136
Rollup merge of #150695 - Kivooeo:pretty-printing, r=BoxyUwU
MGCA: pretty printing for struct expressions and tuple calls

not sure

1. if there any tests that i need to adjust
2. if i should add any test for it
3. if humanity has come up with anything better than checking if that's first iteration or not with flag when printing sequences with separator

in case there is no tests for it and i dont have to add any, there is a demonstration of this  pretty  printing (this is output from `-Z unpretty=hir`)

```
fn test_errors<const N:
    usize>() {
    // accepts_enum::<{ None::<u32> }>();
    accepts_point::<Point1 { a: N, b: N }>();
    accepts_point::<Point(N, N)>();
}
```

btw it does not print const block

for this

```
accepts_point::<{ Point1 { a: const {N + 1}, b: N } }>();
```

it will print

```
accepts_point::<Point1 { a: { N + 1 }, b: N }>();
```

not sure if we want to print const blocks or not

r? BoxyUwU
2026-01-06 16:19:42 +01:00
Jonathan Brouwer
ce42a619a2
Rollup merge of #150670 - Zalathar:let-ty, r=Nadrieril
THIR pattern building: Move all `thir::Pat` creation into `rustc_mir_build::thir::pattern`

The code in `thir::cx::block` was the only code outside of `thir::pattern` that created `thir::Pat` nodes.

Moving it makes the signature of `pat_from_hir` a bit messier, but ensures that all `thir::Pat` creation occurs in one module. That will be useful when trying to change `thir::Pat`, e.g. by adding fields to remove the need for wrapper nodes.

There should be no change to compiler output.
2026-01-06 16:19:41 +01:00
Jonathan Brouwer
0a7a92d7b1
Rollup merge of #150122 - reddevilmidzy:refactor, r=lcnr
Refactor function names of `rustc_ast_lowering`

close: rust-lang/rust#150062

I'll rebase after https://github.com/rust-lang/rust/pull/149114 is merged.

Would it be better to change `lower_const_path_to_const_arg` → `lower_const_path_to_const_arg_and_intern`,
`lower_array_length_to_const_arg` → `lower_array_length_to_const_arg_and_intern`?

r? ``@lcnr``
2026-01-06 16:19:40 +01:00
Jonathan Brouwer
dea8b8b3c0
Rollup merge of #149880 - durin42:llvm-22-ppc-aix-layout, r=nikic
rustc_codegen_llvm: update alignment for double on AIX

This was recently fixed upstream in LLVM, so we update our default layout to match.

````@rustbot```` label: +llvm-main
2026-01-06 16:19:39 +01:00
Jonathan Brouwer
8b1bf8af85
Rollup merge of #144113 - mu001999-contrib:dead-code/allow-trait, r=jdonszelmann
Impls and impl items inherit `dead_code` lint level of the corresponding traits and trait items

https://github.com/rust-lang/rust/blob/master/compiler/rustc_passes/src/dead.rs#L360-L361 won't insert assoc items into the live set, so that impl items cannot be marked live.

This PR lets impls and impl items can inherit lint levels of the corresponding traits and trait items.

Fixes rust-lang/rust#144060

r? ````@petrochenkov````
2026-01-06 16:19:39 +01:00
Kivooeo
d32f1c695f add const ctor support 2026-01-06 15:04:25 +00:00
Jonathan Brouwer
5590fc034c
Make cfg and cfg_attr trace attributes into early parsed attributes 2026-01-06 09:04:08 +01:00
Jonathan Brouwer
03fb7eeced
Create a rustc_ast representation for parsed attributes 2026-01-06 09:03:35 +01:00
delta17920
e603055d89 Fix ICE when transmute Assume field is invalid 2026-01-06 04:38:51 +00:00
bors
da476f1942 Auto merge of #150640 - AprilNEA:mgca-merge-associated-const-equality, r=BoxyUwU
Merge `associated_const_equality` feature gate into MGCA

Tracking Issues: rust-lang/rust#132980 rust-lang/rust#92827

Merge `associated_const_equality`(ACE) feature gate into `min_generic_const_args`(MGCA).

- Replaces `features().associated_const_equality()` checks with `features().min_generic_const_args()`
- Updates the parser to gate associated const equality under `min_generic_const_args`
- Moves `associated_const_equality` to the removed features list
- Removes the `associated_const_equality` method from the `Features` trait
- Updates all affected tests and tools (rust-analyzer, clippy)

Closes rust-lang/rust#150617

r? `@BoxyUwU`
2026-01-06 01:36:53 +00:00
reddevilmidzy
56cb5d598b rename the lower_anon_const_to_const_arg and
`lower_anon_const_to_const_arg_direct` to
`lower_anon_const_to_const_arg_and_alloc` and
`lower_anon_const_to_const_arg`
2026-01-06 09:24:41 +09:00
reddevilmidzy
b0a581d51d rename the lower_ty and lower_ty_direct to lower_ty_and_alloc and
`lower_ty`
2026-01-06 09:19:03 +09:00
Kivooeo
85c8e41f62 add pretty printing 2026-01-05 21:58:01 +00:00
Augie Fackler
accfc34e43 rustc_codegen_llvm: update alignment for double on AIX
This was recently fixed upstream in LLVM, so we update our default
layout to match.

@rustbot label: +llvm-main
2026-01-05 14:08:51 -05:00
Jakub Beránek
469a26439c
Rollup merge of #150697 - hkBst:relate-3, r=Kivooeo
relate.rs: tiny cleanup: eliminate temp vars 2

Continuation of rust-lang/rust#150678

r? `@Kivooeo`
2026-01-05 15:54:14 +01:00
Jakub Beránek
b198dffd98
Rollup merge of #149790 - JonathanBrouwer:attr-path-perf, r=jdonszelmann
Remove `Span` from segments of `AttrPath`

r? jdonszelmann
2026-01-05 15:54:12 +01:00
Marijn Schouten
a956b56d6d
Improve comment clarity in candidate_may_shadow 2026-01-05 14:10:50 +01:00
Marijn Schouten
3d6a2c5ae1 relate.rs: tiny cleanup: eliminate temp vars 2 2026-01-05 12:31:21 +00:00
Zalathar
304101f212 Move all thir::Pat creation into rustc_mir_build::thir::pattern 2026-01-05 23:06:08 +11:00
AprilNEA
4421270516
Merge associated_const_equality feature gate into MGCA
This removes `associated_const_equality` as a separate feature gate and makes it part of `min_generic_const_args` (mgca).

Key changes:
  - Remove `associated_const_equality` from unstable features, add to removed
  - Update all test files to use `min_generic_const_args` instead
  - Preserve the original "associated const equality is incomplete" error message by specially handling `sym::associated_const_equality` spans in `feature_gate.rs`
  - Rename FIXME(associated_const_equality) to FIXME(mgca)
2026-01-05 12:31:42 +08:00
bors
6885bdf1af Auto merge of #150603 - Kivooeo:tuple-struct, r=BoxyUwU
MGCA: Support for tuple constructors

r? BoxyUwU

part of https://github.com/rust-lang/rust/issues/132980

fixes rust-lang/rust#136379
fixes rust-lang/rust#138132

i tried to keep implementation very minimal and it's very similar to how structs was implemented with small adjustments

this does not make const constructor like None works, just something like Some(n)

todo:
* ~~tests~~
* write a better description (not sure if needed)
* add more comments and FIXMEs from structs code
2026-01-05 01:45:18 +00:00
bors
451b7b6c77 Auto merge of #150682 - matthiaskrgr:rollup-jrkhivl, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - rust-lang/rust#149681 (resolve: Split `Scope::Module` into two scopes for non-glob and glob bindings )
 - rust-lang/rust#150426 (Update offload test and verify that tgt_(un)register_lib have the right type)
 - rust-lang/rust#150678 (relate.rs: tiny cleanup: eliminate temp vars)

r? `@ghost`
`@rustbot` modify labels: rollup
2026-01-04 21:47:15 +00:00
Matthias Krüger
8b1f4495e5
Rollup merge of #150678 - hkBst:relate-1, r=Kivooeo
relate.rs: tiny cleanup: eliminate temp vars
2026-01-04 21:14:06 +01:00
Matthias Krüger
1494755275
Rollup merge of #150426 - ZuseZ4:offload-register-lib, r=davidtwco
Update offload test and verify that tgt_(un)register_lib have the right type

Apparently, we weren't running offload tests when Enzyme wasn't built. Time to fix that.
Also adds a test mode which generates the host IR, but does not expect device IR/artifacts. This way, we don't have to handle artifacts and paths in our tests.
Also removes some outdated documentation.

cc `@Kevinsala,` `@Sa4dUs`

closes: https://github.com/rust-lang/rust/issues/150415

~~blocked on `needs-offload` infrastructure landing in https://github.com/rust-lang/rust/pull/150427~~
2026-01-04 21:14:05 +01:00
Matthias Krüger
df246c107a
Rollup merge of #149681 - petrochenkov:openapi1, r=davidtwco
resolve: Split `Scope::Module` into two scopes for non-glob and glob bindings

This is a re-implementation of https://github.com/rust-lang/rust/pull/144131 with all the issues mentioned there fixed.

As it turned out, the non-trivial part of the split was already done in https://github.com/rust-lang/rust/pull/149454/commits/c91b6ca58d4d870d3099db1defbd8c1f26a7d851, so the remaining part implemented in this PR is *mostly* mechanical.

After addressing the issue of already found bindings being lost due to indeterminacies in outer scopes (7e890bfa87) and adding one missing `Stage::Late` in `Finalize` the scope splitting refactoring just worked.
(One more ICE was revealed by the refactoring, but not caused by it, fixed up in the last commit.)

This is a part of implementation for the [Open API](https://rust-lang.github.io/rust-project-goals/2025h1/open-namespaces.html) proposal.
2026-01-04 21:14:04 +01:00
Marijn Schouten
359f060175 relate.rs: tiny cleanup: eliminate temp vars 2026-01-04 17:06:39 +00:00
bors
e29fcf45e4 Auto merge of #150674 - matthiaskrgr:rollup-tnkgbcx, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#150554 (test: add regression cases for valtree hashing ICE)
 - rust-lang/rust#150597 (make specialization of `Vec::extend` and `VecDeque::extend_front` work for vec::IntoIter with any `Allocator`, not just `Global`)
 - rust-lang/rust#150619 (alloc: Move Cow impl to existing ones)
 - rust-lang/rust#150660 (THIR pattern building: Pass HIR nodes instead of loose types/spans)
 - rust-lang/rust#150671 (miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
2026-01-04 16:58:33 +00:00
Matthias Krüger
cdddb85585
Rollup merge of #150660 - Zalathar:pass-nodes, r=davidtwco
THIR pattern building: Pass HIR nodes instead of loose types/spans

This should make it easier to keep track of where the types/spans came from.

There should be no change to compiler output.

---

In the future I would also like to make more of these lowering methods return `Box<thir::Pat>` instead of `thir::PatKind`, so that it becomes feasible to add more fields to `thir::Pat` (e.g. for https://github.com/rust-lang/rust/pull/150498#discussion_r2652138926). That will be easier if those methods have easy access to the corresponding HIR pattern node, from which they can obtain a type and span.
2026-01-04 16:16:11 +01:00
Kivooeo
05afcb6d26 init impl 2026-01-04 15:12:39 +00:00
Manuel Drehwald
fa584faca5 Update test and verify that tgt_(un)register_lib have the right type 2026-01-04 06:58:31 -08:00
Stuart Cook
85dc7c2361
Rollup merge of #150666 - reddevilmidzy:fix-link, r=BoxyUwU
Fix ambig-unambig-ty-and-consts link

cc: https://github.com/rust-lang/rustc-dev-guide/pull/2677
2026-01-04 21:37:06 +11:00
Stuart Cook
db41a1556e
Rollup merge of #150659 - mu001999-contrib:fix/150654, r=Urgau
Add missing translator resources for interface parse_cfg and parse_check_cfg

Missing resources leads to the failure of `translate_message`.

Fixes rust-lang/rust#150654
2026-01-04 21:37:05 +11:00
Stuart Cook
05dce482d3
Rollup merge of #150650 - enthropy7:main, r=BoxyUwU
Forbid generic parameters in types of #[type_const] items

fixes rust-lang/rust#150614

we enforce the same restriction on `#[type_const]` const items that already exists for const generic parameters - when `generic_const_parameter_types` feature gate is not enabled, the type of a `#[type_const]` item cannot reference generic parameters.  implementation follows the same pattern used for const generic parameters. we check if the item has the `#[type_const]` attribute and if the feature gate is disabled, then we apply `RibKind::ConstParamTy` restrictions when visiting the type, which prevents the use of generic parameters.

check is added in three places:
- Free const items (`ItemKind::Const`)
- Trait associated consts (`AssocItemKind::Const` in traits)
- Impl associated consts (`AssocItemKind::Const` in impls)

added tests for new feature, hope i get this task right :>

r? `@BoxyUwU`
2026-01-04 21:37:04 +11:00
reddevilmidzy
7c02e3c6eb Fix ambig-unambig-ty-and-consts link 2026-01-04 17:44:15 +09:00
Zalathar
de377241fb Prefer to pass HIR nodes instead of loose types/spans
This should make it easier to keep track of where the types/spans came from.
2026-01-04 15:54:04 +11:00
enthropy7
46bb414d69
Forbid generic parameters in types of #[type_const] items 2026-01-04 07:21:35 +03:00
mu001999
759857cce3 Add missing translator resources for interface parse_cfg and parse_check_cfg 2026-01-04 11:53:31 +08:00