Commit graph

2727 commits

Author SHA1 Message Date
enthropy7
46bb414d69
Forbid generic parameters in types of #[type_const] items 2026-01-04 07:21:35 +03:00
Matthias Krüger
cd502ff78e
Rollup merge of #150589 - AprilNEA:remove-unneeded-forbid-generic-field, r=camelid,BoxyUwU
Remove unneeded `forbid_generic` field from `Res::SelfTyAlias`

Following rust-lang/rust#150519, the `forbid_generic` field in `Res::SelfTyAlias` is no longer needed and can be removed.

- Remove the `forbid_generic: bool` field from `Res::SelfTyAlias`
- Simplify the ConstantItem rib handling in `rustc_resolve` - no longer need to mutate res to set `forbid_generic: true`
- Update all pattern matches and constructors of `SelfTyAlias`

Closes rust-lang/rust#150579

r? ``@camelid``
2026-01-03 10:09:30 +01:00
AprilNEA
cc563d5315
Remove unneeded forbid_generic field from Res::SelfTyAlias
The `forbid_generic` field in `Res::SelfTyAlias` is no longer needed.
The check for generic `Self` types in anonymous constants is now handled
by `check_param_uses_if_mcg` in HIR type lowering, making this field
redundant.

This removes:
- The `forbid_generic` field from `Res::SelfTyAlias`
- The hack in `rustc_resolve` that set `forbid_generic: true` when
encountering `Self` in constant items
- Related pattern matching and field propagation code
2026-01-03 09:02:46 +08:00
Vadim Petrochenkov
3f3db93651 metadata: Stop keeping AmbiguityKind in name bindings
It can only be `GlobVsGlob` now.
2026-01-02 16:00:12 +03:00
Vadim Petrochenkov
2e123aef70 resolve: Avoid additional ambiguities from splitting modules into two scopes 2026-01-02 15:31:09 +03:00
Vadim Petrochenkov
78c61beb48 resolve: Patch up an inconsistent resolution ICE revealed by the previous commit 2026-01-02 15:26:06 +03:00
Vadim Petrochenkov
0016a71747 resolve: Migrate one more special ambiguity for glob vs non-glob bindings
in the same module to the usual ambiguity infra in `resolve_ident_in_scope_set`
2026-01-02 15:25:56 +03:00
Vadim Petrochenkov
d7d49244ef resolve: Introduce ScopeSet::Module
for looking up a name in two scopes inside a module - non-glob and glob bindings.
2026-01-02 15:20:32 +03:00
Vadim Petrochenkov
bcfbb5619c resolve: Migrate a special ambiguity for glob vs non-glob bindings
in the same module to the usual ambiguity infra in `resolve_ident_in_scope_set`
2026-01-02 15:11:14 +03:00
Vadim Petrochenkov
75d90094e7 resolve: Split Scope::Module into two scopes for non-glob and glob bindings 2026-01-02 15:02:03 +03:00
Vadim Petrochenkov
bcdcabee75 resolve: Do not break from the scope visiting loop if we already found the innermost binding.
Previously we could lose the already found binding and break with an error, if some blocking error was found in the shadowed scopes.

Also, avoid some impossible state in the return type of `fn resolve_ident_in_scope`.
2026-01-02 14:00:27 +03:00
Vadim Petrochenkov
b018f42b7b resolve: Keep all encountered bindings in resolve_ident_in_scope_set 2025-12-28 00:01:28 +03:00
Vadim Petrochenkov
1c7d3f0ff6 resolve: Preserve binding scopes in ambiguity errors
It allows to get rid of `AmbiguityErrorMisc` and `Flags`.
2025-12-27 22:50:02 +03:00
aerooneqq
3f477dd710 Recursive delegation improvements 2025-12-25 14:49:01 +03:00
Boxy Uwu
c65551e835 Introduce hir::ConstArgKind::Struct 2025-12-23 13:54:59 +00:00
Boxy Uwu
8f3a76bd38 mgca always resolve params 2025-12-23 13:54:59 +00:00
Jonathan Brouwer
520a3c41cd
Rollup merge of #150155 - Aditya-PS-05:fix/ice-150103-root-in-suggestions, r=estebank
fix ICE when {{root}} appears in import suggestions

Fixes rust-lang/rust#150103

When wrong nested imports like `use A::{::Fish}` were used, the internal {{root}} would appear in diagnostic suggestions, causing an ICE in `join_path_idents` which asserted that **{{root}} should only appear at the start of a path**.

r? ``@matthiaskrgr``
2025-12-22 17:33:37 +01:00
Jonathan Brouwer
aa93a61eb2
Rollup merge of #150098 - Bryntet:perf-testing, r=JonathanBrouwer
remove `legacy_const_generic_args` cache

putting this here to run perf
2025-12-22 17:33:36 +01:00
Aditya-PS-05
678f58151e fix ICE when {{root}} appears in import suggestions 2025-12-19 19:28:35 +05:30
Jonathan Brouwer
1e496bc9e6
Rollup merge of #150024 - aerooneqq:recursive-delegation-2, r=petrochenkov
Support recursive delegation

This PR adds support for recursive delegations and is a part of the delegation feature rust-lang/rust#118212.

r? ``@petrochenkov``
2025-12-18 18:37:17 +01:00
aerooneqq
ae5e0d5492 Support recursive delegation 2025-12-18 10:42:47 +03:00
Edvin Bryntesson
8fcddc6393
remove legacy_const_generic_args cache 2025-12-17 17:03:41 +01:00
delta17920
6fac0fac99 Apply review suggestions 2025-12-17 14:53:14 +00:00
delta17920
3e78653ec3 Fix grammar in suggestion message 2025-12-17 14:08:53 +00:00
delta17920
cb301751b3 Suggest struct pattern when destructuring Range with .. syntax 2025-12-17 14:08:53 +00:00
Jacob Pratt
66155a7df6
Rollup merge of #150000 - Bryntet:brynte/parse_legacy_const_generic_args, r=jonathanbrouwer,jdonszelmann
Port `#[rustc_legacy_const_generics]` to use attribute parser

Small PR that ports the `#[rustc_legacy_const_generics]` to use the new attribute parser!

r? JonathanBrouwer
2025-12-16 23:10:10 -05:00
Edvin Bryntesson
4bd0e65bde
Port #[rustc_legacy_const_generics] to use attribute parser 2025-12-16 20:29:01 +01:00
Jonathan Brouwer
02c0e8f015
Rollup merge of #150063 - workingjubilee:remove-let-else-deny, r=Kivooeo
Remove deny of manual-let-else

During discussion on Zulip[^1], we found there was no strong consensus in favor of this in practice.

[^1]: https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/.60deny.28clippy.3A.3Amanual_let_else.29.60.20proliferation/with/564085588
2025-12-16 20:21:12 +01:00
Jonathan Brouwer
9308518af9
Rollup merge of #150025 - BoxyUwU:mgca_no_unused_defids, r=oli-obk
dont create unnecessary `DefId`s under mgca

Fixes rust-lang/rust#149977
Fixes rust-lang/rust#148838

Accidentally left this out of rust-lang/rust#149136 even though being able to do this was a large part of the point of the PR :3

First ICE was caused by the fact that we create a defid but never lower the nodeid associated with it to a hirid which later parts of the compiler can't handle.

See test for second ICE

r? oli-obk
2025-12-16 20:21:09 +01:00
Jubilee Young
0004d8d421 Remove deny of manual-let-else 2025-12-16 08:42:04 -08:00
Boxy Uwu
dbfc8c218e dont create unnecessary DefIds under mgca 2025-12-15 22:59:15 +00:00
Jane Losare-Lusby
72c84a6c80 assert impossible branch is impossible 2025-12-15 11:11:06 -08:00
bors
3f4dc1e02d Auto merge of #146348 - jdonszelmann:eiiv3, r=lcnr,oli-obk
Externally implementable items

Supersedes https://github.com/rust-lang/rust/pull/140010
Tracking issue: https://github.com/rust-lang/rust/issues/125418

Getting started:

```rust
#![feature(eii)]

#[eii(eii1)]
pub fn decl1(x: u64)
// body optional (it's the default)
{
    println!("default {x}");
}

// in another crate, maybe
#[eii1]
pub fn decl2(x: u64) {
    println!("explicit {x}");
}

fn main() {
    decl1(4);
}
```

- tiny perf regression, underlying issue makes multiple things in the compiler slow, not just EII, planning to solve those separately.
- No codegen_gcc support, they don't have bindings for weak symbols yet but could
- No windows support yet for weak definitions

This PR merges the implementation of EII for just llvm + not windows, doesn't yet contain like a new panic handler implementation or alloc handler. With this implementation, it would support implementing the panic handler in terms of EII already since it requires no default implementation so no weak symbols

The PR has been open in various forms for about a year now, but I feel that having some implementation merged to build upon
2025-12-14 04:20:26 +00:00
bors
8188f6c808 Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco
Overhaul filename handling for cross-compiler consistency

This PR overhauls the way we handle filenames in the compiler and `rmeta` in order to achieve achieve cross-compiler consistency (ie. having the same path no matter if the filename was created in the current compiler session or is coming from `rmeta`).

This is required as some parts of the compiler rely on consistent paths for the soundness of generated code (see rust-lang/rust#148328).

In order to achieved consistency multiple steps are being taken by this PR:
 - by making `RealFileName` immutable
 - by only having `SourceMap::to_real_filename` create `RealFileName`
   - currently `RealFileName` can be created from any `Path` and are remapped afterwards, which creates consistency issue
 - by also making `RealFileName` holds it's working directory, embeddable name and the remapped scopes
   - this removes the need for a `Session`, to know the current(!) scopes and cwd, which is invalid as they may not be equal to the scopes used when creating the filename

In order for `SourceMap::to_real_filename` to know which scopes to apply `FilePathMapping` now takes the current remapping scopes to apply, which makes `FileNameDisplayPreference` and company useless and are removed.

This PR is split-up in multiple commits (unfortunately not atomic), but should help review the changes.

Unblocks https://github.com/rust-lang/rust/pull/147611
Fixes https://github.com/rust-lang/rust/issues/148328
2025-12-13 14:32:09 +00:00
Jacob Pratt
47f1502c73
Rollup merge of #149860 - Delta17920:fix/149821-root-cause, r=petrochenkov
Fix: Prevent macro-expanded extern crates from shadowing extern arguments

prevents an ICE by fixing a logic bug in `build_reduced_graph.rs`.
the bug caused the compiler to correctly detect and report a shadowing error for a macro-expanded `extern crate` but then continue processing the invalid item, corrupting the resolver's internal state (`extern_prelude`) and leading to a crash in later resolution passes the fix adds an early return after the shadowing error is reported to ensure the invalid item is not added to the resolution graph.

Fixes rust-lang/rust#149821
2025-12-13 00:55:56 -05:00
Jacob Pratt
e7ba4a5e6d
Rollup merge of #149843 - aerooneqq:inherit-attributes-in-delegation, r=petrochenkov
Inherit attributes in delegation

This PR adds support for inheriting attributes of the original function of the delegation and is a part of rust-lang/rust#118212, for now we inherit only #[must_use] attribute, but we can add other attributes to inherit. The list of processed attributes can be found [here](https://github.com/aerooneqq/public-docs/blob/master/rust/delegation/processed_attributes.md).

r? ``@petrochenkov``
2025-12-13 00:55:56 -05:00
Jacob Pratt
b32845c61a
Rollup merge of #148837 - estebank:let-else, r=Kivooeo
Use `let...else` instead of `match foo { ... _ => return };` and `if let ... else return`
2025-12-13 00:55:55 -05:00
Esteban Küber
a49c175380 #![deny(clippy::manual_let_else)] in some rustc modules 2025-12-12 17:53:19 +00:00
Esteban Küber
146711fc24 Use let...else instead of match foo { ... _ => return }; and if let ... else return 2025-12-12 17:52:39 +00:00
aerooneqq
0a3fd24287 Support attribute inheritance in delegation 2025-12-12 20:34:54 +03:00
delta17920
0748492e2b Fix: Prevent macro-expanded extern crates from shadowing extern arguments 2025-12-12 16:22:25 +00:00
Boxy Uwu
acc3a0e2da Syntactically distinguish anon const const args 2025-12-12 15:45:37 +00:00
Jana Dönszelmann
f7e453e2fa
visibility using std_internal_symbol 2025-12-12 11:32:31 +01:00
Jana Dönszelmann
59d50cd2ad
EII nameres changes 2025-12-12 11:17:33 +01:00
Urgau
8cbfb26383 Overhaul filename handling for cross-compiler consistency
This commit refactors `SourceMap` and most importantly `RealFileName` to
make it self-contained in order to achieve cross-compiler consistency.

This is achieved:
 - by making `RealFileName` immutable
 - by only having `SourceMap::to_real_filename` create `RealFileName`
 - by also making `RealFileName` holds it's working directory,
   it's embeddable name and the remapped scopes
 - by making most `FileName` and `RealFileName` methods take a scope as
   an argument

In order for `SourceMap::to_real_filename` to know which scopes to apply
`FilePathMapping` now takes the current remapping scopes to apply, which
makes `FileNameDisplayPreference` and company useless and are removed.

The scopes type `RemapPathScopeComponents` was moved from
`rustc_session::config` to `rustc_span`.

The previous system for scoping the local/remapped filenames
`RemapFileNameExt::for_scope` is no longer useful as it's replaced by
methods on `FileName` and `RealFileName`.
2025-12-12 07:33:09 +01:00
bors
c4dc70ee0a Auto merge of #149891 - matthiaskrgr:rollup-jh6xrhz, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#142380 (Put negative implementors first and apply same ordering logic to foreign implementors)
 - rust-lang/rust#146584 (remove duplicated columns from `rustc_error_code::error_codes!`)
 - rust-lang/rust#148717 (Point at span within local macros even when error happens in nested external macro)
 - rust-lang/rust#149565 (rustdoc: Add unstable `--merge-doctests=yes/no/auto` flag)
 - rust-lang/rust#149770 (Rename some issue-* tests)
 - rust-lang/rust#149807 (Use ubuntu:24.04 for the `x86_64-gnu-miri` job)
 - rust-lang/rust#149850 (Remove "tidy" tool for `tests/rustdoc` testsuite)
 - rust-lang/rust#149863 (Do not suggest moving expression out of for loop when hitting `break` from desugaring)
 - rust-lang/rust#149867 (only resolve main in bin crates)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-12-12 06:30:06 +00:00
bors
5b150d238f Auto merge of #149645 - GuillaumeGomez:doc-attr-based, r=jdonszelmann,jonathanbrouwer
Port `doc` attributes to new attribute API

Part of https://github.com/rust-lang/rust/issues/131229.

This PR ports the `doc` attributes to the new attribute API. However, there are things that will need to be fixed in a follow-up:

* Some part of `cfg_old.rs` are likely unused now, so they should be removed.
* Not all error/lints are emitted at the same time anymore, making them kinda less useful considering that you need to run and fix rustc/rustdoc multiple times to get through all of them.
* For coherency with the other attribute errors, I didn't modify the default output too much, meaning that we have some new messages now. I'll likely come back to that to check if the previous ones were better in a case-by-case approach.
* `doc(test(attr(...)))` is handled in a horrifying manner currently. Until we can handle it correctly with the `Attribute` system, it'll remain that thing we're all very ashamed of. 😈
* A type in rustdoc got its size increased, I'll check the impact on performance. But in any case, I plan to improve it in a follow-up so should be "ok".
* Because of error reporting, some fields of `Doc` are suboptimal, like `inline` which instead of being an `Option` is a `ThinVec` because we report the error later on. Part of the things I'm not super happy about but can be postponed to future me.
* In `src/librustdoc/clean/cfg.rs`, the `pub(crate) fn parse(cfg: &MetaItemInner) -> Result<Cfg, InvalidCfgError> {` function should be removed once `cfg_trace` has been ported to new `cfg` API.
* Size of type `DocFragment` went from 32 to 48. Would be nice to get it back to 32.
* ``malformed `doc` attribute input`` wasn't meant for so many candidates, should be improved.
* See how many of the checks in `check_attr` we can move to attribute parsing
* Port target checking to be in the attribute parser completely
* Fix target checking for `doc(alias)` on fields & patterns

And finally, once this PR is merged, I plan to finally stabilize `doc_cfg` feature. :)

cc `@jdonszelmann`
r? `@JonathanBrouwer`
2025-12-11 21:08:19 +00:00
21aslade
c27bcef6f8 don't resolve main in lib crates 2025-12-10 14:17:47 -07:00
Guillaume Gomez
348d9d98e0 Correctly iterate doc comments in intra-doc resolution in rustc_resolve 2025-12-10 12:28:07 +01:00
Guillaume Gomez
aa3bf6fde9 Update rustc_resolve unit tests 2025-12-10 12:27:34 +01:00