Commit Graph

2995 Commits

Author SHA1 Message Date
Jacob Pratt 81eb844071 Rollup merge of #156824 - CoCo-Japan-pan:mut-restriction-parse, r=Urgau,jhpratt
Parse `mut` restrictions

This PR is part of the progress implementing `mut` restrictions proposed in [RFC 3323](https://rust-lang.github.io/rfcs/3323-restrictions.html), and linked to a [GSoC proposal](https://rust-lang.zulipchat.com/#narrow/channel/421156-gsoc/topic/Project.3A.20Implementing.20impl.20and.20mut.20restrictions/with/592352432).
This PR focuses solely on the parsing of `mut` restrictions.
The keyword order is `pub(...) mut(...) unsafe field`.
The new syntax is guared by `#[feature(mut_restriction)]` feature gate.
Tracking Issue: rust-lang/rust#105077

r? @Urgau
cc @jhpratt
2026-05-24 16:39:41 +02:00
bors a06c1ca53a Auto merge of #156839 - qaijuang:fix-single-use-lifetimes-impl-bounds, r=mu001999
[single_use_lifetimes]: Account for lifetime bounds

This PR makes `single_use_lifetimes` account for bounds on lifetime parameters, so a lifetime such as `'b` in `<'a, 'b: 'a>` is not treated as single-use just because its bound is stored separately from ordinary lifetime uses.

Fixes rust-lang/rust#153836
2026-05-24 09:47:31 +00:00
CoCo-Japan-pan c43fa7a8bb Parse mut restrictions 2026-05-24 17:33:46 +09:00
Qai Juang ccb9e9e84a account for lifetime bounds in single_use_lifetimes 2026-05-24 04:15:17 -04:00
bors dd8b2d6162 Auto merge of #155598 - makai410:partial-ord, r=nnethercote
Implement fast path for `derive(PartialOrd)` when deriving `Ord`



Closes: https://github.com/rust-lang/rust/issues/155537

Unfortunately, this PR shares the same issue with https://github.com/rust-lang/rust/issues/124794, which doesn't work when `derive(PartialOrd)` is before `derive(Ord)`.
2026-05-24 00:06:21 +00:00
aerooneqq a83eba4086 Visit delegation body under elided-infer lifetime rib 2026-05-22 12:50:49 +03:00
Makai c9a560b30d Implement fast path for derive(PartialOrd) 2026-05-21 17:59:41 +08:00
aerooneqq b75c53288e Visit delegation's qself under elided-infer lifetime rib too 2026-05-20 08:35:27 +03:00
Jacob Pratt 41ab1f8af7 Rollup merge of #156705 - aerooneqq:delegation-error-gen-no-node-id, r=petrochenkov
delegation: visit path under elided-infer lifetime rib

Up to this moment we processed delegation path under `LifetimeRibKind::Generics` which is not correct as we are processing generic args of a future call, not generic params. In this PR we visit path under
`LifetimeRibKind::Elided(LifetimeRes::Infer)`.

Fixes rust-lang/rust#156342. Part of rust-lang/rust#118212.

r? @petrochenkov
2026-05-18 13:52:55 +02:00
aerooneqq 34c536c594 Visit delegation path under elided-infer lifetime rib 2026-05-18 13:43:30 +03:00
Jonathan Brouwer 9e8d48c551 Rollup merge of #156598 - cijiugechu:decl-macro-diag, r=mu001999
Avoid rustfix suggestions for macro-expanded unused imports

Avoid emitting rustfix suggestions for unused imports when the removal span is not directly editable.

Closes rust-lang/rust#147855
2026-05-17 15:52:40 +02:00
bors 281c97c324 Auto merge of #156518 - estebank:match-rustfmt, r=mejrs
[style] rustfmt `match`es with comments in or-patterns

Using https://github.com/rust-lang/rustfmt/pull/6893, I reformatted the whole codebase. The result is that `match`es that *should have* been formatted under normal circumstances but are getting skipped now got their expected format. These match expressions were being entirely skipped because they contain or-patterns with comments in between patterns, causing rustfmt to bail out entirely. The or-patterns with comments themselves remain untouched, but now the match arm bodies and other patterns without comments do get formatted under that PR.

Because the fix in rustfmt isn't landed yet, I reworked some of the or-patterns with comments so that formatting doesn't regress. Tried doing this only in larger blocks that are more likely to regress in the meantime.

(Introduced and) removed a bunch of stray backticks \` likely left after an editor autoclosed the intended closing \`, resulting in <code>\`name\`\`</code> in comments.
2026-05-17 01:27:37 +00:00
Jonathan Brouwer a29e5e14c9 Rollup merge of #156452 - P8L1:implement-pin-drop-sugar-upstream, r=petrochenkov
Implement pinned drop sugar

Implements `fn drop(&pin mut self)` as sugar for `Drop::pin_drop`.

The resolver recognizes `fn drop(&pin mut self)` syntactically in trait impls and performs lookup using the effective `pin_drop` name. AST lowering independently rechecks the syntactic sugar, validates that the resolved item belongs to the actual `Drop` lang trait, and emits HIR with ident `pin_drop` for accepted sugar. Existing type checking, Drop validation, drop glue, and direct-call checks remain unchanged.

Drop identity is checked during AST lowering through `tcx.lang_items().drop_trait()`, after resolver has performed the effective `pin_drop` lookup. The resolver does not need to know whether the trait is the actual `Drop` lang item, and it no longer passes marked impl item IDs to lowering.

This intentionally preserves the base pinned-drop behavior where `#[pin_v2]` types must use `pin_drop`, while non-`#[pin_v2]` types may still implement `pin_drop`.

r? @petrochenkov

## Related

https://github.com/rust-lang/rust/pull/144537
https://github.com/rust-lang/rust/issues/130494
2026-05-15 20:11:42 +02:00
cijiugechu ecf01910d5 Avoid rustfix suggestions for macro-expanded unused imports 2026-05-15 17:43:09 +08:00
Pieter-Louis Schoeman 282ec28bf8 Implement pinned drop sugar 2026-05-14 16:54:53 +02:00
Jonathan Brouwer 604d124199 Rollup merge of #156500 - Bryanskiy:macros_vis, r=petrochenkov
Privacy: move macros handling to early stage

The patch moves effective visibility computation for macros from `rustc_privacy` to `rustc_resolve`. It will enable this optimization: https://github.com/rust-lang/rust/pull/156228.

However, I found some problems with macro handling while I was doing this. The current implementation was written ~6 years ago and checks the reachability of a definition from a macro by nominal visibility. In general this is incorrect.

For example, in the current implementation modules are not traversed if their nominal visibility is less then the nominal visibility of a module defining macro: https://github.com/rust-lang/rust/blob/29b7590130c83542a095cdf1323ed0f78eec2bb8/compiler/rustc_privacy/src/lib.rs#L618-L626

As a result, in order to compile code like  `tests/ui/definition-reachable/auxiliary/field-method-macro.rs`. we have to additionally traverse types of adt fields: https://github.com/rust-lang/rust/blob/29b7590130c83542a095cdf1323ed0f78eec2bb8/compiler/rustc_privacy/src/lib.rs#L628-L638

This is a hack and the proper solution would be to check definitions with `EffectiveVisibilities::is_reachable`. I haven’t done this yet, as it would start to trigger many lints as more items become reachable. I think it’s better to leave the change to another commit.

r? @petrochenkov
2026-05-14 00:35:36 +02:00
Bryanskiy 3d0ee528cb Privacy: move macros handling to early stage 2026-05-13 20:04:42 +03:00
Oli Scherer 3a2ae6a204 Stop putting owner's DefId into their own node_id_to_def_id map
Now they unfortunately land in their parent, which is not necessary
2026-05-13 09:29:22 +02:00
Oli Scherer adb2b0fd57 Split the resolver tables into per-owner tables, starting with node_id_to_def_id 2026-05-13 09:22:55 +02:00
Oli Scherer 66a2b8565f Make UnordItems::flat_map take UnordItems as args, too 2026-05-13 08:47:29 +02:00
Oli Scherer 1887b9cd74 Split trait item resolving into its own method 2026-05-13 08:47:29 +02:00
Esteban Küber 31e0383ea6 rustfmt matches with comments in or-patterns
Using https://github.com/rust-lang/rustfmt/pull/6893, reformat the codebase. The result is that matches that *would have* been formatted under normal circumstances get their expected format. These match expressions were being entirely skipped because they contain or-patterns with comments in between patterns, causing rustfmt to bail out entirely. The or-patterns with comments themselves remain untouched, but now the match arm bodies and other patterns without comments do get formatted under that PR.

Because the fix in rustfmt isn't landed yet, I reworked some of the or-patterns with comments so that formatting doesn't regress. Tried doing this only in larger blocks that are more likely to regress in the meantime.
2026-05-13 02:35:29 +00:00
Jonathan Brouwer 63322d00e9 Rollup merge of #156284 - petrochenkov:kvak2, r=mu001999
resolve: Fix a false positive "cannot reexport" error for ambiguous glob sets

Fixes https://github.com/rust-lang/rust/issues/156264.
2026-05-12 18:53:39 +02:00
Jonathan Brouwer 4ce7ac120c Rollup merge of #156287 - cyrgani:unbox-2, r=petrochenkov
move more compiler crates away from `box_patterns`

Part of https://github.com/rust-lang/rust/issues/156110.
2026-05-12 18:53:35 +02:00
Jonathan Brouwer e383845f33 Rollup merge of #154918 - fmease:fix-enum-var-lt, r=jackh726
Fix elided lifetime resolution & trait object lifetime defaulting for enum variant paths

Context: https://github.com/rust-lang/rust/pull/129543#discussion_r3035614838.
Fixes rust-lang/rust#108224.

I consider this to be a minor bug fix that doesn't demand a (T-types) FCP.

r? @lcnr or reassign
2026-05-12 07:03:56 +02:00
cyrgani 985fe34821 use deref_patterns in rustc_resolve 2026-05-10 21:05:36 +00:00
Vadim Petrochenkov a07cc548e4 resolve: Module-related refactorings 2026-05-10 20:11:34 +03:00
Vadim Petrochenkov cc630bc470 resolve: Evaluate private visibilities eagerly in eff vis computation 2026-05-10 08:06:03 +03:00
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
Vadim Petrochenkov 235fa6b34c resolve: Fix a false positive "cannot reexport" error for ambiguous glob sets 2026-05-07 19:29:09 +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