Commit Graph

3184 Commits

Author SHA1 Message Date
Jonathan Brouwer
bca8bb11d6 Rollup merge of #160900 - CoCo-Japan-pan:fix-160873, r=jhpratt,Urgau
Ensure that restriction paths are ancestors

fix: rust-lang/rust#160873

This PR moves the check that `impl` and `mut` restriction paths resolve to ancestor modules from `rustc_resolve` to `rustc_ast_lowering`. This ensures that `RestrictionKind::Restricted` in HIR always refers to an ancestor module.
If a restriction path resolves to a non-ancestor, we emit an error and recover by lowering the restriction as `RestrictionKind::Unrestricted`.

Tracking Issue: rust-lang/rust#105077

r? @Urgau
cc @jhpratt
2026-08-12 12:06:14 +02:00
Jonathan Brouwer
03c3d00ee3 Make inputs to ParenthesizedArgs a ThinVec<Param> in the compiler 2026-08-11 20:47:40 +02:00
CoCo-Japan-pan
de4e2e2a23 Ensure restriction paths are ancestors of items when lowering to HIR 2026-08-11 17:51:52 +09:00
Jonathan Brouwer
db53f9c5a4 Rollup merge of #160500 - bb1yd:same-message-for-crate-and-pathroot, r=mejrs
Fix inaccurate description for crate and pathroot

Same as 8ab9fdff5a/compiler/rustc_resolve/src/diagnostics/impls.rs (L3027-L3035)
2026-08-10 19:02:04 +02:00
Jonathan Brouwer
34df6a0ab8 Rollup merge of #160216 - khyperia:gca-path-cleanup, r=BoxyUwU,bit-aloo
clean up handling of paths in mgca

related tracking issue: https://github.com/rust-lang/rust/issues/132980

Handling of ambiguous type-or-constant argument paths was really wonky and distinct from the regular `can_lower_expr_to_const_arg_direct` lowering paths. Clean that up and unify it, as discussed here https://github.com/rust-lang/rust/pull/158479#discussion_r3544664708

Also, do a bunch of other little cleanups at the same time while I'm here:

- add support for parens to the inside of direct_const_arg! and macroless_generic_const_args (idk why this wasn't a thing before)
- add constant and lifetime ribs when resolving TyKind::DirectConstArg - note the TyKind, not ExprKind (~~I am unsure if/how this changes behavior~~ added a test, `direct-const-arg-correct-rib.rs`) - this was discussed here https://github.com/rust-lang/rust/pull/158617#issuecomment-4932249112
- minor debug logging change
- various minor code shuffles/cleanups
- add test for `direct_const_arg!(_)` inferring to a type - this test should have been added in https://github.com/rust-lang/rust/pull/159058 which added this behavior (well, changed the behavior from an ICE to inferring to a type)
- add a test asserting the current behavior of parens/braces/underscores on stable - one or two of these cases already have tests elsewhere, but it's nice to assert the whole set, and also assert the whole set in the same place so it's easily visible to be able to give me confidence the whole set actually is tested (both positives and negatives are important here)
- add a test similar to the previous one, but with mgca enabled, asserting all combinations now compile successfully

r? @BoxyUwU
2026-08-10 13:45:40 +02:00
Jonathan Brouwer
6738083180 Rollup merge of #160499 - mejrs:move_diagnostic_attr_not_found_lint, r=JonathanBrouwer
rustc_resolve: move diagnostic attribute linting to attr parsing

It was in rustc_resolve because there was no general attribute parsing infra back then, but now there is, so it should be there.

Also improves some spans.

This change also makes it so that unknown diagnostic attributes are removed, rather than stay as unparsed attributes.
2026-08-08 00:38:29 +02:00
mejrs
cd19505b4a rustc_resolve: move diagnostic attribute linting to attr parsing
It had to be in rustc_resolve because there was no general attribute parsing infra back then, but now there is, so it should be there
2026-08-05 18:44:54 +02:00
Jonathan Brouwer
82c5ef1ca3 Rollup merge of #160510 - LorrensP-2158466:res-unsafe-speculative-flag, r=petrochenkov
Resolver: (un)tracked borrows for `CmRefCell` made safe by unsafe speculative flag

Implements the tracked/untracked borrowing of `CmRefCell` such that we do not mutate *any* state during speculative resolution. Made safe by an unsafe field that requires any borrows to be dropped before the flag can change.

r? @petrochenkov
2026-08-05 13:36:08 +02:00
Jonathan Brouwer
1966d4f80d Rollup merge of #160444 - mu001999-contrib:fix-160195, r=petrochenkov
Avoid resolving path keywords outside `TypeNS`

Fixes https://github.com/rust-lang/rust/issues/160195

After allowing trailing `self`, `self` imports were resolved in all namespaces wrongly. Resolving path keywords should return `Determined` immediately outside `TypeNS`.

r? petrochenkov
2026-08-05 13:36:07 +02:00
b1yd
26fba41cdb Fix inaccurate description for crate and pathroot 2026-08-05 16:31:12 +08:00
LorrensP-2158466
e0830fa2be implement unsafe speculative flag to be used by CmRefCell::borrow, which does tracked and untracked borrowing 2026-08-04 17:43:45 +02:00
Roland Xu
e3464abaed Avoid resolving path keywords outside TypeNS 2026-08-04 20:06:42 +08:00
Jakub Beránek
2e3a5cd5c6 Rollup merge of #160320 - Albab-Hasan:derive-trait-not-a-derive-macro, r=petrochenkov
point at trait definition when it is used as a derive macro

fixes https://github.com/rust-lang/rust/issues/159483

r? @petrochenkov
2026-08-04 11:10:14 +02:00
bjorn3
1a3d919258 Deny multiple EII impls on a single item
This allows implementing EIIs that don't have a default impl without the
involvement of symbol aliases by simply changing the mangled symbol name
of the implementation, which would make them trivially compatible with
all backends and targets. This change will be left to a followup PR.
2026-08-03 11:04:23 +02:00
Jonathan Brouwer
4f8f88e1c6 Rollup merge of #160271 - LorrensP-2158466:res-cm-refcell, r=petrochenkov
Resolver: Introduce `CmRef` which has a speclative borrow variant for `CmRefCell`

part of rust-lang/rust#158845

We now introduce `CmRef` that is returned by `CmRefCell::borrow`, which does a normal borrow of the underlying `T` if we are in speculative resolution. We do not alter state during speculative resolution and because it will be run in parallel in the future, updating the `RefCell` borrow counters is not possible. Thus we just return `&T` that is "untracked".

Also allows us to remove the `CmRefCell` wrapper around the external module resolution table.

r? @petrochenkov
2026-08-01 19:16:29 +02:00
LorrensP-2158466
9890f666db implement CmRef for CmRefCell, having 2 different borrow types of the underlying RefCell 2026-08-01 15:22:18 +02:00
khyperia
2f54b38220 clean up handling of paths in mgca 2026-08-01 12:37:11 +02:00
albab-hasan
6e2de73e9c point at trait definition when it is used as a derive macro
fixes https://github.com/rust-lang/rust/issues/159483
2026-08-01 14:23:28 +06:00
Jonathan Brouwer
57f2f41d80 Rollup merge of #159520 - bb1yd:fix-159491, r=folkertdev
Suggest `Vec<T>` instead of `[T]`

Fixes rust-lang/rust#159491

Looks like a regression introduced by:rust-lang/rust#151530
2026-07-31 16:02:28 +02:00
byd1
2ee8bbbecf suggest Vec<T> instead of [T] 2026-07-31 17:14:08 +08:00
Jacob Pratt
03de0965d0 Rollup merge of #160099 - LorrensP-2158466:split-module-resolutions, r=petrochenkov
Resolver: split module resolutions into local and external resolutions

Part of rust-lang/rust#158845.

This pr splits the resolution table for local and external modules, with the external table being wrapped in a `OnceLock`, because only 1 thread may create that table in parallel resolution.

r? @petrochenkov
2026-07-29 20:48:17 -04:00
Vadim Petrochenkov
c9f7b9697e rustc_resolve: Turn RefOrMut into an enum 2026-07-29 16:50:16 +03:00
Vadim Petrochenkov
6b2608e0d6 rustc_resolve: Further reduce mutability in resolver 2026-07-29 16:50:16 +03:00
LorrensP-2158466
580253e6a2 split module resolutions into local and external types, with external having a OnceLock around it for parallel import resolution 2026-07-29 14:39:38 +02:00
Jacob Pratt
37c1398c2f Rollup merge of #159413 - mejrs:on_unknown_late, r=nnethercote
Enable `#[diagnostic::on_unknown]` during late res

The pr prior to this is rust-lang/rust#157926. That PR enabled it for early res, this PR does so for late res.

r? @estebank
2026-07-28 20:09:37 -04:00
Jonathan Brouwer
bca856424e Rollup merge of #158038 - nbdd0121:register_tool, r=mejrs
Split register_tool into register_attribute_tool and register_lint_tool

Tracking issue: rust-lang/rust#66079

This implements the attribute parsing part of RFC 3808. The resolution part is yet to be implemented.

cc @jyn514
2026-07-28 21:07:45 +02:00
mejrs
bf4f8c1713 remove duplicate local 2026-07-28 14:55:38 +02:00
mejrs
80b6fdba2c Plug diagnostic::on_unknown into late resolution 2026-07-28 14:54:46 +02:00
mejrs
023d55ef2b Factor out async rust 2018+ suggestion 2026-07-28 14:50:55 +02:00
Gary Guo
75999c498f Split register_tool into register_attribute_tool and register_lint_tool
This splits the functionality to two parts per RFC. The `#![register_tool]`
attribute registers the tool in both ways.

Semantics remain unchanged and will be adjusted in later commit.
2026-07-27 19:06:33 +01:00
Gary Guo
178bddc6c9 Make RegisterToolParser implement AttributeParser directly 2026-07-27 19:00:53 +01:00
Jonathan Brouwer
447eef1523 Rollup merge of #159974 - panstromek:update-thin-vec, r=mejrs
Update thinvec to 0.2.19

It contains `may_dangle` Drop impl under a feature flag. This allows us to use it in a lot more places, notable in types that hold `&'tcx` references. This would previously fail in borrowck in arena code.

We have to enable  its "unstable" feature for this. That also enables `TrustedLen` impl, which is behind unstable flag, too. I left the flag disabled, because it regressed next-solver benchmarks, but that will be fixed in PR that needs this flag (see the comment: https://github.com/rust-lang/rust/pull/159974#issuecomment-5091132427)
2026-07-27 19:24:50 +02:00
Gary Guo
747ce1a484 Make AttributeParser::parse_limited accept filters instead of symbol
The existing API is preserved as `parse_limited_sym` as a simple helper.

Similarly, `parse_limited_should_emit` is preserved as
`parse_limited_sym_should_emit`. I've noted that all users targets crate,
so the `target_node_id` and `target` parameters are removed from it.
2026-07-27 17:42:20 +01:00
panstromek
02a54aa3ed update thinvec to latest version 2026-07-27 10:33:18 +02:00
Jacob Pratt
7a2710b9d4 Rollup merge of #159722 - GuillaumeGomez:cfg_attr-doc_cfg, r=petrochenkov,mejrs,Urgau
[rustdoc] Retrieve `cfg_attr` information for derived impls for `doc_cfg` feature

Fixes https://github.com/rust-lang/rust/issues/103300.

After long last, this PR finally allows the derive proc-macro `cfg_attr` cfg predicates information to be kept so rustdoc can use it for its `doc_cfg` feature (cc https://github.com/rust-lang/rust/issues/43781).

It works as follows: for `impl` generated by macro expansion, we then look for the attributes on the type for which the `impl` block is implemented. Then, to know which `cfg_attr` attribute we want to look at, we use `expn_that_defined` on the impl's `DefId` which returns the `Span` where the macro was expanded. If it's part of a `cfg_attr`, then the `cfg_attr`'s `Span` will contain the derive's, so from then, we just need to add the `cfg` information.

This PR also adds the cfg predicates into the `AttributeKind::CfgAttrTrace` variant so it can be reused by rustdoc (hence the `compiler/*` changes).

Thanks a lot @petrochenkov for the pointers here!

r? @petrochenkov
2026-07-24 01:59:21 -04:00
panstromek
283ec3aa54 Make FieldDef smaller 2026-07-23 14:43:52 +02:00
Guillaume Gomez
0eb2348e8b Keep cfg predicate in CfgAttrTrace so it can be used by rustdoc 2026-07-22 23:50:54 +02:00
khyperia
e895ed8c90 unify the AST repr of type const and const RHS 2026-07-22 09:22:45 +02:00
bors
f65b272fc9 Auto merge of #159440 - LorrensP-2158466:inplace-import-res, r=petrochenkov
Resolve: more preperation work for parallelizing the import resolution loop




This is basically rust-lang/rust#158845 but we do not:
- actually use `par_slice` because:
- we do not migrate `CmRefCell` to use `RwLocks` (yet) because of perf reasons.

The resolution loop is now in place instead of recollecting indeterminate imports.


r? @petrochenkov
2026-07-21 10:04:40 +00:00
Jacob Pratt
e1d8ba6e3b Rollup merge of #159307 - TorinAsakura:fix/builtin-attribute-value-diagnostics, r=petrochenkov
Improve cross-namespace name diagnostics

Close rust-lang/rust#86290

Cross-namespace name matches now use the ordinary missing-name diagnostic while preserving its error code and suggestions. The diagnostic adds a note identifying the item found in another namespace, while same-namespace wrong-kind diagnostics remain unchanged.

The UI expectations cover cross-namespace combinations across the resolver suite, including preservation of existing suggestions.
2026-07-20 23:38:00 -04:00
Andrew Ghostuhin
30bc6d2f06 fix: improve missing value diagnostics for built-in attributes 2026-07-21 01:03:16 +03:00
Jonathan Brouwer
581f102a5f Rollup merge of #159599 - LorrensP-2158466:fix-ambig-trait-glob-lint, r=petrochenkov
Resolver: Record at least 1 ambiguous trait if main decl is not a trait.

Addresses rust-lang/rust#159476.

When recording traits of a particular module, it is possible that a trait hidden in the ambiguity declaration of a main declaration (struct, enum, ...), thus causing us to never record that trait. This caused us to report an error that methods of those traits are not in scope and that we do not report the `AMBIGUOUSLY_GLOB_IMPORTED_TRAIT` lint, which was the case in rust-lang/rust#159476.

We now record at least 1 trait in the collection of ambiguous declarations, such that we don't report that error and can report the relevant lint.

Also updated the linked issue of the lint in question.

r? @petrochenkov
2026-07-20 18:06:09 +02:00
LorrensP-2158466
73ed27196b When recording traits, if a decl is ambiguous we make sure to record at least 1 trait of the ambiguous decls (is possible) such that we can record the ambiguously_glob_imported_trait lint.
Also updated the issue linked by the lint.

+ added extra test
+ bless original test because of updated link
2026-07-20 12:47:25 +02:00
LorrensP-2158466
2f3022a932 Preperation work for parallelizing the import resolution loop using par_slice.
Currently it is all still single threaded, but almost everything needed to make the loop use multithreaded code is done in this commit.

For performance reasons we do the resolution now in place instead of recollecting the indeterminate imports ([see benchmark pr](https://github.com/rust-lang/rust/pull/159387) and pr of this commit).

Populating external resolution tables now use `Once` to ensure only 1 thread builds the table and all others wait if they need it, this has no impact on single threaded behaviour.

`Cache(Ref)Cells` are not tackled yet because they are not needed here (and require extra work).
2026-07-18 10:57:47 +02:00
bors
656ccbe796 Auto merge of #159266 - nnethercote:rm-AttrItemKind, r=petrochenkov,JonathanBrouwer
Overhaul `CfgTrace`/`CfgAttrTrace` handling



I noticed that `AttrItemKind` was a bit clunky and by the time I was finished I had a PR that:
- removes `AttrItemKind`;
- removes `sym::cfg_trace` and `sym::cfg_attr_trace`;
- overhauls how these attributes are handled;
- changes the terminology used for these attributes;
- fixes some erroneous comments;
- and a few other small improvements.

It's a sizeable change but I think it makes things a lot clearer. Details in individual commits.

r? @petrochenkov
2026-07-17 13:18:23 +00:00
Nicholas Nethercote
17d526f1be Replace "early parsed" terminology
AST attributes use "early parsed"/"parsed" terminology to refer to the
`CfgTrace` and `CfgAttrTrace` attributes. I think this terminology is
meant to echo the terminology used for HIR attributes, i.e.
`hir::Attribute::{Parsed,Unparsed}`, probably because
`hir::Attribute::Parsed` is used for attributes that aren't stored in a
token-based form.

But this naming is misleading. "Early parsed" attributes aren't parsed
at all because they are inserted by the compiler and cannot be written
in source code. There are also two comments that claim that these
attributes are kept in parsed form "so they don't have to be reparsed
every time they're used, for performance", which is simply incorrect.

This commit renames these as "synthetic" attributes, which better
reflects their nature. The commit also fixes the incorrect comments.

Note that `is_parsed_attribute` is unchanged, because it refers to the
HIR attribute meaning. (And the removal of the synthetic attributes from
it in the previous commit is now more obviously correct.)
2026-07-17 08:59:25 +10:00
Nicholas Nethercote
1a8ecb0b5b Remove sym::cfg_trace and sym::cfg_attr_trace
This commit pushes further than the previous one, relying more heavily
on looking directly at `AttrKind::Parsed` to handle various cases.

Note that the removed clippy code was actually dead.
2026-07-17 08:59:25 +10:00
Nicholas Nethercote
b357c7c0ff Remove AttrItemKind
`AttrItem` currently contains an `AttrItemKind` which is either `Parsed`
or `Unparsed`. In the `Parsed` case the surrounding `AttrItem` is
basically fake, with a meaningless `unsafety` field, a synthetic
(non-ident) symbol, and an empty `tokens`.

This commit moves `Parsed` up one level to become a new variant of
`AttrKind`. It no longer needs to pretend to be an `AttrKind::Normal`,
and makes a number of things simpler:
- No `unparsed_ref` calls needed.
- Replaces the `attr_into_trace` and `Attribute::replace_args` mess with
  the much simpler `convert_normal_to_parsed`.

The commit converts a numberof non-exhaustive `AttrKind` matches (those
that don't involve matching a single attribute) to exhaustive, for
future-proofing. It uses `unreachable!` on all the `AttrKind::Parsed`
cases that aren't hit by the full test suite.
2026-07-17 08:59:24 +10:00
Jonathan Brouwer
7d1f162f49 Rollup merge of #159226 - oli-obk:extra_lifetime_params_map, r=petrochenkov
Track extra_lifetime_params_map per-owner

Part of https://github.com/rust-lang/rust-project-goals/issues/620

An easy one now that https://github.com/rust-lang/rust/pull/156508 is merged, as there are no more cross-owner dependencies on this table

r? @petrochenkov
2026-07-16 21:01:54 +02:00
Jacob Pratt
09be986317 Rollup merge of #159339 - LorrensP-2158466:extract-use-injections, r=petrochenkov
Resolver: extract `use_injections` out of main `Resolver`

Prep work for rust-lang/rust#158845. Extract the `use_injections` field out of the resolver and into the `LateResolutionVisitor`. It can then be passed into the `report_errors` pass, so no behaviour is changed.

This allows the `Resolver` to be `DynSync`, see https://github.com/rust-lang/rust/pull/158845#discussion_r3579712892.

r? @petrochenkov
2026-07-16 04:02:33 -04:00