Commit Graph

2965 Commits

Author SHA1 Message Date
Vadim Petrochenkov 16729bcb2d resolve: Set correct parent and expansion for self declarations 2026-05-09 11:19:29 +03:00
Matthias Krüger 62396df898 Rollup merge of #156244 - el-ev:issue156060, r=mu001999
fix incorrect suggestions in private import diagnostic

Resolves rust-lang/rust#156060.

1. In nested imports like `use two::{One, ...}`, the diagnostic suggested replacing the `One` with a multi-segment path of a different module, producing invalid code like `use crate::two::{one::One, Two}`. Skip it when `single_nested == true`.
2. Stop unconditionally skipping the first segment of `import.module_path`, which can produce incorrect paths in edition 2018 and later.
3. Mark the suggestion as "directly" instead of "through the re-export" when the import's source is the definition itself.
2026-05-08 20:39:25 +02:00
Iris Shi b7d22fd68b refactor path construction
Co-Authored-By: mu001999 <mu001999@outlook.com>
2026-05-08 16:48:29 +08:00
Iris Shi 1ad59ef182 mark the suggestion as directly when it is 2026-05-08 10:42:03 +08:00
Vadim Petrochenkov 503960c9a5 resolve: Avoid some Arc cloning with syntax extensions
Clone only on interface boundaries with `rustc_expand`
2026-05-07 20:23:40 +03:00
Vadim Petrochenkov c834e9fcbd resolve: Remove MacroData
All the necessary data can be taken from `SyntaxExtension` instead.
2026-05-07 20:23:37 +03:00
Iris Shi 05b97f76a4 address review comment 2026-05-07 23:43:25 +08:00
Jacob Pratt ac468d573b Rollup merge of #156173 - oli-obk:fewer-global-lookups, r=petrochenkov
Fewer global node_id_to_def_id lookups

Several of these are unnecessary if we track the `LocalDefId` together with the `NodeId`. We can't remove the `NodeId` entirely, as it is needed for lints, but it's a useful refactoring for splitting node_id_to_def_id into a per-owner table in the future

r? @petrochenkov
2026-05-07 02:12:07 -04:00
Jonathan Brouwer b1d22623ab Rollup merge of #156151 - mejrs:non_macro_attr, r=petrochenkov
Don't return dummy MacroData in `get_macro`

I was experimenting with tool attributes and ast manipulation, and wasted some time figuring out that this was happening. AFAIK all users of `get_macro` are expecting an actual macro (and none were reading the dummy MacroData) so there should be no change in behavior.
2026-05-06 22:39:20 +02:00
Iris Shi a2c0e02be8 skip incorrect suggestion in nested imports 2026-05-06 21:49:37 +08:00
mejrs facd03622b Don't return dummy MacroData in get_macro 2026-05-06 14:39:39 +02:00
Oli Scherer a082567e7b Follow-up cleanups reusing the now-available LocalDefIds 2026-05-06 10:58:52 +02:00
Oli Scherer 400240adb4 Avoid hitting the global node_id_to_def_id table for unused macros 2026-05-06 10:58:52 +02:00
Oli Scherer 191cda55e4 Avoid using id followed by local_def_id if we can just call def_id instead 2026-05-06 10:58:52 +02:00
Oli Scherer 0afe083fd1 Avoid some global node_id_to_def_id lookups in import resolution 2026-05-06 10:58:52 +02:00
Jonathan Brouwer e35334f6d4 Rollup merge of #156014 - petrochenkov:kvak, r=mu001999
resolve: Catch "cannot reexport" errors from macros 2.0 better

After the macro 2.0 related holes are closed we can report `span_delayed_bug`s in more situations.

Merging https://github.com/rust-lang/rust/pull/155945 would make changes in this PR simpler, but that PR will probably have to wait for quite some time.

This is a continuation of my import & privacy invariant hardening changes from https://github.com/rust-lang/rust/pull/155257, https://github.com/rust-lang/rust/pull/155213, https://github.com/rust-lang/rust/pull/154149, etc.

r? @mu001999
2026-05-05 14:25:22 +02:00
Oli Scherer fd701b79a7 Remove most uses of def_id_to_node_id
Especially those happening during normal resolving, where we are actually looking at current parent scopes
2026-05-04 17:40:26 +02:00
Oli Scherer 71177d1b66 Add NodeId to ModuleKind 2026-05-04 17:40:26 +02:00
Vadim Petrochenkov 21c58d8ad9 resolve: Harden some invariant checks for visibilities 2026-05-04 15:51:36 +03:00
Vadim Petrochenkov 65e5bd6610 resolve: Catch "cannot reexport" errors from macros 2.0 better 2026-05-04 15:51:36 +03:00
Vadim Petrochenkov cf636ec649 resolve: Factor out reporting of "cannot reexport" errors into a separate function 2026-05-04 15:51:33 +03:00
Jacob Pratt bd8d0260ca Rollup merge of #156091 - Bryntet:move-tools, r=JonathanBrouwer
change field `tools` on `AttributeParser` to hold `&'tcx RegisteredTools`

Makes tools actually stored, and not just tool names

this was originally part of rust-lang/rust#155691 but was split out to make that PR smaller.

r? @petrochenkov
cc @JonathanBrouwer
2026-05-03 00:25:34 -04:00
mejrs 4a13f36265 Remove more spans from AttributeKind 2026-05-02 17:41:30 +02:00
Edvin Bryntesson 76fd1b3df3 make tools on AttributeParser hold reference to RegisteredTools 2026-05-02 16:02:34 +02:00
Jonathan Brouwer 7be04ef0a6 Rollup merge of #155948 - SynapLink:fix/pub-visibility-order, r=petrochenkov,mu001999
Fix order-dependent visibility diagnostics

Fixes rust-lang/rust#40066.
Fixes https://github.com/rust-lang/rust/issues/109657.
Delay visibility path diagnostics until module collection has finished, so paths to later non-ancestor modules report E0742 instead of an unresolved path error.
2026-05-01 13:10:34 +02:00
Jacob Pratt 894bdf298e Rollup merge of #155980 - nnethercote:mv-feature-methods, r=TaKO8Ki
Move `feature*` methods from `parse` mod to `errors` mod.

As the FIXME comment says, these no longer use `ParseSess` and so the `parse` mod is not a good place for them. The `errors` mod is a better home.

r? @TaKO8Ki
2026-04-30 22:28:33 -04:00
Jacob Pratt 654c350837 Rollup merge of #154610 - jakubadamw:issue-13065, r=TaKO8Ki
Suggest public re-exports when a private module makes an import path inaccessible

This is an attempt at solving rust-lang/rust#13065.

When a `use` path fails because it passes through a private module (E0603), and a public re-export of the target item exists elsewhere, the compiler will now suggest importing through that re-export instead.

For example, given:

```rust
mod outer {
    pub use self::inner::MyStruct;
    mod inner {
        pub struct MyStruct;
    }
}

use outer::inner::MyStruct; // error: module `inner` is private
```

the compiler will now suggest use `outer::MyStruct`; - the publicly accessible path - rather than just pointing at the private module definition and leaving the user to figure out the alternative.

When possible, relative paths are suggested, including those using `super` (currently capped at a maximum of one `super` path item).

The newly added test is parametrised by editions because of the change in behaviour around `crate::`-prefixed imports in edition 2018. Perhaps that’s an overkill – I’ll be happy to remove the variations for editions 2021 and 2024.

Closes rust-lang/rust#13065.
2026-04-30 22:28:31 -04:00
Jacob Pratt 248756dc40 Rollup merge of #153566 - JohnTitor:sugg-generic-params-from-outer-item-err, r=wesleywiser
Add suggestion for E0401 on inner const items

Fix rust-lang/rust#68373
r? @estebank
2026-04-30 22:28:30 -04:00
SynapLink f7c62f533e Fix order-dependent visibility diagnostics 2026-04-30 20:51:53 +02:00
Nicholas Nethercote 6d79bc6f01 Move feature* methods from parse mod to errors mod.
As the FIXME comment says, these no longer use `ParseSess` and so the
`parse` mod is not a good place for them. The `errors` mod is a better
home.
2026-04-30 12:02:33 +10:00
Vadim Petrochenkov d28ea81a98 resolve: Extend ambiguous_import_visibilities deprecation lint to glob-vs-glob ambiguities 2026-04-29 22:34:16 +03:00
Jonathan Brouwer 67cf0dee49 Remove most usages of Stage 2026-04-29 07:41:14 +02:00
Jonathan Brouwer e1332f4893 Remove should_emit from stage 2026-04-29 07:41:09 +02:00
mu001999 d93395c3ff Remove the special case of ::self after edition 2018 2026-04-27 14:02:25 +08:00
mu001999 8b584ebcf6 Remove type_ns_only 2026-04-27 14:02:25 +08:00
mu001999 4467940555 Support trailing self in normal paths 2026-04-27 14:02:22 +08:00
mu001999 d5a26d811b Support trailing self in import paths 2026-04-27 10:58:30 +08:00
Jonathan Brouwer 139bcba8f6 Rollup merge of #155822 - mejrs:default_fmt_args, r=JonathanBrouwer
Add default field values to diagnostic FormatArgs

This type has a decent amount of unused fields (and I am planning to add more).
2026-04-26 19:06:32 +02:00
Jonathan Brouwer 37b53a9461 Rollup merge of #155789 - JonathanBrouwer:attribute-ext, r=mejrs
Cleanups to `AttributeExt`

r? @mejrs

- Makes some functions take `ast::Attribute` instead of `impl AttributeExt`
- Remove `deprecation_note` from `AttributeExt`, since the two implementations are basically seperate
2026-04-26 19:06:29 +02:00
mejrs 48fe89f994 add default field values to diagnostic FormatArgs 2026-04-26 14:23:53 +02:00
Jonathan Brouwer 3b59d9d58e Rollup merge of #155783 - qaijuang:issue-150566-cfg-trace-suggestions, r=JonathanBrouwer
Do not suggest internal cfg trace attributes

Fixes rust-lang/rust#150566.
2026-04-25 23:07:53 +02:00
Jonathan Brouwer f113540cec Remove unnecessary uses of AttributeExt 2026-04-25 21:25:43 +02:00
bors 9838411cb7 Auto merge of #155257 - petrochenkov:visatleast, r=adwinwhite
privacy: Assert that compared visibilities are (usually) ordered



And make "greater than" (`>`) the new primary operation for comparing visibilities instead of "is at least" (`>=`).
2026-04-25 16:15:55 +00:00
Qai Juang b17822575c Do not suggest internal cfg trace attributes 2026-04-25 11:47:34 -04:00
bors fb76025f2f Auto merge of #155460 - cjgillot:unmut-resolver-ast, r=oli-obk
Do not modify resolver outputs during lowering



Split from https://github.com/rust-lang/rust/pull/142830

I believe this achieves the same thing as https://github.com/rust-lang/rust/pull/153656 but in a much simpler way. 

This PR forces AST->HIR lowering to stop mutating resolver outputs. Instead, it manages a few override maps that only live during lowering and are dropped afterwards.

r? @petrochenkov 
cc @aerooneqq
2026-04-25 10:01:32 +00:00
Camille Gillot 0705bbac94 Do not modify resolver outputs during lowering
Co-authored-by: Camille Gillot <gillot.camille@gmail.com>
2026-04-24 23:58:52 +00:00
mejrs c2916be8d7 Permit {This} in diagnostic attribute format literals 2026-04-24 19:59:32 +02:00
Vadim Petrochenkov 714df2bf00 privacy: Assert that compared visibilities are (usually) ordered
Also use `greater_than` instead of `is_at_least` for comparing visibilities, which we can do because visibilities are asserted to be ordered now.
2026-04-23 18:22:48 +03:00
Jonathan Brouwer 6f6e6bb485 Rollup merge of #155632 - nnethercote:split-Metadata, r=mejrs
Some metadata cleanups

Details in individual commits.

r? @mejrs
2026-04-22 19:18:32 +02:00
Jonathan Brouwer 5e48418496 Rollup merge of #155587 - oli-obk:feed-visibility-no-hash, r=petrochenkov
Immediately feed visibility on DefId creation

This system was originally introduced in rust-lang/rust#121089

This PR was enabled by refactorings in rust-lang/rust#154945, because after that, the visibility feeding happens directly after the `DefId` creation, so we don't need to go through the intermediate hash table anymore

Should unblock rust-lang/rust#138995
2026-04-22 19:18:29 +02:00