1936 Commits

Author SHA1 Message Date
Guillaume Gomez e4097f672e Rollup merge of #156092 - susitsm:needs-hir-hash, r=petrochenkov
Clean up `TyCtxt::needs_crate_hash` usage and rename it to `needs_hir_hash`.

While reviewing `crate_hash` query usage for https://github.com/rust-lang/rust/pull/155871, the `needs_crate_hash` function turned out to be the cause of unnecessary calls to the query. The `needs_crate_hash` name is easy to mistake for the functionality of "needs the crate_hash query". This PR removes the usage of `needs_crate_hash` where it was not appropriate and renames the function to `needs_hir_hash` which better reflects its functionality.
2026-05-05 02:50:11 +02: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
Matyas Susits 5313fb1d0b rename needs_crate_hash to needs_hir_hash.
It's easy to confuse the functionality of `needs_crate_hash` with "is
the crate_hash query needed" right now. The function returns
whether we need to calculate the stable hash of various hir structs.
2026-05-02 17:53:51 +02: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
Nicholas Nethercote e7d28d3e9b Rename the HashStable* trait/derives as StableHash*.
Specifically:
- `HashStable` -> `StableHash` (trait)
- `HashStable` -> `StableHash` (derive)
- `HashStable_NoContext` -> `StableHash_NoContext` (derive)

Note: there are some names in `compiler/rustc_macros/src/hash_stable.rs`
that are still to be renamed, e.g. `HashStableMode`.

Part of MCP 983.
2026-05-02 10:16:40 +02:00
Nicholas Nethercote 851049cf58 Rename the hash_stable method as stable_hash.
Part of MCP 983.
2026-05-02 10:15:59 +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
Jonathan Brouwer c208e0e1aa Rollup merge of #155949 - GuillaumeGomez:steal-lints, r=JonathanBrouwer,kivooeo
Update `opt_ast_lowering_delayed_lints` query to allow "stealing" lints, allowing to use `FnOnce` instead of `Fn`

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

This is needed for https://github.com/rust-lang/rust/compare/main...GuillaumeGomez:rust:diagnostic-instead-of-closure?expand=1 which will allow to pass `Diagnostic` instead of a closure.

As asked by @JonathanBrouwer, I make this as a stand-alone PR. :)

r? @JonathanBrouwer
2026-04-29 23:51:41 +02:00
Jonathan Brouwer e1332f4893 Remove should_emit from stage 2026-04-29 07:41:09 +02:00
Guillaume Gomez fffc4b5781 Update opt_ast_lowering_delayed_lints query to allow "stealing" lints, allowing to use FnOnce instead of Fn 2026-04-29 01:21:54 +02:00
bors b20956b0f4 Auto merge of #155890 - JonathanBrouwer:rollup-XcHVBe9, r=JonathanBrouwer
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#154510 (Partially stabilize LoongArch target features)
 - rust-lang/rust#155137 (Allow trailing `self` in more contexts)
 - rust-lang/rust#155513 (rustc_public: implement `Pattern` type)
 - rust-lang/rust#155702 (Change `ItemKind::Trait` to a field variant.)
 - rust-lang/rust#154896 (Fix ICE: Scalar layout for non-primitive non-enum type unsafe binder)
 - rust-lang/rust#155675 (Disallow non_exhaustive structs and enums with non_exhaustive variants from implementing `ConstParamTy`)
 - rust-lang/rust#155874 (Avoid misleading closure return type note)
 - rust-lang/rust#155876 (CI: rfl: move job forward to Linux v7.1-rc1)
2026-04-27 21:47:07 +00:00
Jonathan Brouwer e8ad7f25e4 Rollup merge of #155702 - mejrs:itemkind_trait-fields, r=petrochenkov
Change `ItemKind::Trait` to a field variant.

This changes `ItemKind::Trait` from an octuple(!!) to an enum variant with fields. Their names were chosen to match up with existing usage and minimize renaming.

I'm leaning towards renaming `ident` to `name` as well; let me know if that's desired.
2026-04-27 19:54:46 +02:00
bors 52b6e2c208 Auto merge of #155760 - GuillaumeGomez:rm-attributelintkind, r=JonathanBrouwer,petrochenkov
Remove `AttributeLintKind`



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

The `AttributeLintKind` type is finally gone! \o/

Diff is this big because I moved a file and a lot of `Diagnostic` types. :')

r? @JonathanBrouwer
2026-04-27 17:49:21 +00:00
Guillaume Gomez faecc47eab Update triagebot.toml file to take into account the moved file
Create a new `SharedContext::emit_dyn_lint_with_sess` method to simplify code when `Session` is not needed
Remove crate name from `UnexpectedCfgCargoMacroHelp`
2026-04-27 17:57:55 +02:00
Oli Scherer 8e1c34f5cc Check closure's constness validity in the constness query
instead of during ast lowering, where it's not easily possible to obtain all the right information in time
2026-04-27 07:44:19 +02:00
Guillaume Gomez e7b9d94435 Remove unused diagnostic types 2026-04-25 04:20:04 +02:00
Guillaume Gomez 36459d9914 Make it possible to have access to Session and crates name in attr_parsing lints 2026-04-25 04:12:23 +02:00
Camille Gillot 4433512e90 Lighten and document partial_res_overrides. 2026-04-24 23:58:52 +00:00
Camille Gillot 9044aba8e1 Use imported NodeId. 2026-04-24 23:58:52 +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 9515f52d61 Change ItemKind::Trait to have named fields. 2026-04-24 19:03:16 +02:00
aerooneqq 7f2a98d1fc Rename Self generic param to This in recursive delegations 2026-04-24 09:59:20 +03:00
Guillaume Gomez abce9f98d7 Rollup merge of #155442 - CoCo-Japan-pan:impl-restriction-reorder, r=Urgau,fmease,jhpratt
Change keyword order for `impl` restrictions

Based on rust-lang/rust#155222, this PR reorders keywords in trait definitions to group restrictions with visibility. It changes the order from `pub(...) const unsafe auto impl(...) trait Foo {...}`  to `pub(...) impl(...) const unsafe auto trait Foo {...}`.

Tracking issue for restrictions: rust-lang/rust#105077

r? @Urgau
cc @jhpratt
2026-04-23 14:42:47 +02:00
Guillaume Gomez aebbe6bb5f Rollup merge of #155644 - aerooneqq:delegation-self-ty-propagation-2, r=petrochenkov
delegation: support self ty propagation for functions in free to trait reuse

This PR adds support for self types specified in free to trait reuse. Up to this point we always generated `Self` despite the fact whether self type was specified or not. Now we use it in signature inheritance. Moreover we no more generate `Self` for static methods. Part of rust-lang/rust#118212.

```rust
trait Trait<T> {
  fn foo<const B: bool>(&self) {}
  fn bar() {}
}

impl<T> Trait<T> for usize {}

reuse <usize as Trait>::foo;

// Desugaring (no `Self` as usize is specified)
fn foo<T, const B: bool>(self: &usize) {
  <usize as Trait::<T>>::foo::<B>(self)
}

reuse Trait::bar;

// Desugaring (no `Self` as static method)
fn bar<T>() {
  Trait::<T>::bar(); //~ERROR: type annotations needed
}
```

r? @petrochenkov
2026-04-23 14:42:46 +02:00
aerooneqq abd8c38a28 Support self ty propagation for functions in free to trait reuse 2026-04-22 15:24:30 +03:00
aerooneqq 2e6a082513 Use per-parent disambiguators 2026-04-21 18:23:40 +03:00
CoCo-Japan-pan 614994fb8b Update HIR pretty printing 2026-04-19 15:58:02 +09:00
CoCo-Japan-pan a0b8e89456 Update AST pretty printing 2026-04-19 15:58:02 +09:00
bors 6f109d8a2d Auto merge of #155223 - teor2345:fndef-refactor, r=mati865
Refactor FnDecl and FnSig non-type fields into a new wrapper type





#### Why this Refactor?

This PR is part of an initial cleanup for the [arg splat experiment](https://github.com/rust-lang/rust/issues/153629), but it's a useful refactor by itself.

It refactors the non-type fields of `FnDecl`, `FnSig`, and `FnHeader` into a new packed wrapper types, based on this comment in the `splat` experiment PR:
https://github.com/rust-lang/rust/pull/153697#discussion_r3004637413

It also refactors some common `FnSig` creation settings into their own methods. I did this instead of creating a struct with defaults.

#### Relationship to `splat` Experiment

I don't think we can use functional struct updates (`..default()`) to create `FnDecl` and `FnSig`, because we need the bit-packing for the `splat` experiment.

Bit-packing will avoid breaking "type is small" assertions for commonly used types when `splat` is added.
This PR packs these types:
- ExternAbi: enum + `unwind` variants (38) -> 6 bits
- ImplicitSelfKind: enum variants (5) -> 3 bits
- lifetime_elision_allowed, safety, c_variadic: bool -> 1 bit

#### Minor Changes

Fixes some typos, and applies rustfmt to clippy files that got skipped somehow.
2026-04-18 23:46:37 +00:00
Guillaume Gomez c5b9918540 Set up API to make it possible to pass closures instead of AttributeLint.
The end goal being to completely remove `AttributeLint`.
2026-04-17 23:43:06 +02:00
bors f29256dd14 Auto merge of #155248 - JonathanBrouwer:no_hash_delayed_lints, r=GuillaumeGomez
Don't hash `DelayedLints`

This PR unblocks https://github.com/rust-lang/rust/pull/154432, and was also a minor perf win locally
2026-04-17 16:05:32 +00:00
Jonathan Brouwer d14311c4a1 Don't hash DelayedLints 2026-04-17 16:08:45 +02:00
aerooneqq 699eb29443 Fix delegation def path hash collision, add per-parent disambiguators 2026-04-17 09:46:54 +03:00
teor dafb6bb801 Refactor FnDecl and FnSig flags into packed structs 2026-04-16 07:08:08 +10:00
mu001999 77419b45dc Add FIXME for the fatal errors 2026-04-15 21:52:11 +08:00
mu001999 1fca34d15d Emit fatal on defaults for generic params in binders if with nested defs 2026-04-15 21:41:19 +08:00
mu001999 58af51e243 Emit fatal on invalid const args with nested defs 2026-04-14 09:43:02 +08:00
bors 17584a1819 Auto merge of #155253 - JonathanBrouwer:rollup-lERdTAB, r=JonathanBrouwer
Rollup of 19 pull requests

Successful merges:

 - rust-lang/rust#155162 (relnotes for 1.95)
 - rust-lang/rust#140763 (Change codegen of LLVM intrinsics to be name-based, and add llvm linkage support for `bf16(xN)` and `i1xN`)
 - rust-lang/rust#153604 (Fix thread::available_parallelism on WASI targets with threads)
 - rust-lang/rust#154193 (Implement EII for statics)
 - rust-lang/rust#154389 (Add more robust handling of nested query cycles)
 - rust-lang/rust#154435 (resolve: Some import resolution cleanups)
 - rust-lang/rust#155236 (Normalize individual predicate of `InstantiatedPredicates` inside `predicates_for_generics`)
 - rust-lang/rust#155243 (cg_ssa: transmute between scalable vectors)
 - rust-lang/rust#153941 (tests/debuginfo/basic-stepping.rs: Explain why all lines are not steppable)
 - rust-lang/rust#154587 (Add --verbose-run-make-subprocess-output flag to suppress verbose run-make output for passing tests)
 - rust-lang/rust#154624 (Make `DerefPure` dyn-incompatible)
 - rust-lang/rust#154929 (Add `const Default` impls for `LazyCell` and `LazyLock`)
 - rust-lang/rust#154944 (Small refactor of `arena_cache` query values)
 - rust-lang/rust#155055 (UI automation)
 - rust-lang/rust#155062 (Move tests from `tests/ui/issues/` to appropriate directories)
 - rust-lang/rust#155131 (Stabilize feature `uint_bit_width`)
 - rust-lang/rust#155147 (Stabilize feature `int_lowest_highest_one`)
 - rust-lang/rust#155174 (Improve emission of `UnknownDiagnosticAttribute` lint)
 - rust-lang/rust#155194 (Fix manpage version replacement and use verbose version)
2026-04-13 18:32:47 +00:00
Jonathan Brouwer d2fa85cd4d Rollup merge of #154193 - JonathanBrouwer:external-static, r=jdonszelmann
Implement EII for statics

This PR implements EII for statics. I've tried to mirror the implementation for functions in a few places, this causes some duplicate code but I'm also not really sure whether there's a clean way to merge the implementations.

This does not implement defaults for static EIIs yet, I will do that in a followup PR
2026-04-13 20:19:56 +02:00
Jonathan Brouwer f8a8c9e244 Rollup merge of #155003 - malezjaa:update-thinvec, r=davidtwco
update thin-vec

With thin-vec v0.2.15 released, copy-pasted implementation of ExtractIf can be removed.
2026-04-13 14:02:35 +02:00
Jonathan Brouwer 14b5df4749 Rollup merge of #155226 - aerooneqq:delegation-hir-crate-items-revert, r=petrochenkov
delegation: revert execution of hir_crate_items before delayed lowering

This PR reverts rust-lang/rust#154368, as after weekend consideration I don't think that it is a correct way of fixing cycles during delayed lowering:

- The number of ICEs were reported, fixing them would require to develop solution from rust-lang/rust#154368 but I am afraid that it would lead to cancer code growing,
- The [memory regression](https://github.com/rust-lang/rust/pull/154368#issuecomment-4229353764) for rustdoc was reported, it can be fixed with moving `tcx.force_delayed_owners_lowering` call earlier, but it is already bad that this is call is now required everywhere, before rust-lang/rust#154368 AST was dropped before `hir_crate_items` automatically and users of `rustc` API did not have to think about it.

I will try to come up with a more robust solution leaving rust-lang/rust#154368 as a last resort if nothing else will work.

Re-opens rust-lang/rust#154169.
Fixes rust-lang/rust#155125. Fixes rust-lang/rust#155127. Fixes rust-lang/rust#155128. Fixes rust-lang/rust#155164. Fixes rust-lang/rust#155202.
Part of rust-lang/rust#118212.

r? @petrochenkov
2026-04-13 14:02:34 +02:00
Jonathan Brouwer ab551b1550 Rollup merge of #155096 - aerooneqq:delegation-user-specified-args-impl-traits, r=petrochenkov
delegation: support proper interaction of user-specified args and impl Traits

This PR supports usages of user-specified args with impl Traits. When there are user-specified args in child we still need to generate synthetic generic params and use them during signature inheritance:
```rust
fn foo<T, const N: usize>(f: impl FnOnce()) {}

reuse foo::<String, 123> as bar;

//desugaring
fn bar<TSynth: impl FnOnce()>(f: _) {
    foo::<String, 123>(f)
}
```
When inheriting predicates we process impl Trait ones, so we need generic params to instantiate them. Other approach may involve not generating synthetic generic params and try to filter out those predicates, but fairly generating synthetic params seems more consistent?.

Fixes rust-lang/rust#154780, part of rust-lang/rust#118212.

r? @petrochenkov
2026-04-13 14:02:31 +02:00
aerooneqq 51888a15fb Support proper interaction of user-specified args and impl Traits 2026-04-13 10:55:03 +03:00
aerooneqq 791a3dcef0 Revert "Fix cycles during delayed lowering" 2026-04-13 10:19:33 +03:00
Jonathan Brouwer e756d1607d Add eii_impls argument to StaticItem 2026-04-11 10:17:07 +02:00
Jacob Pratt 44bad026ce Rollup merge of #154661 - CoCo-Japan-pan:impl-restriction-check, r=jhpratt,Urgau
Semantic checks of `impl` restrictions

This PR implements semantic checks for `impl` restrictions proposed in the [Restrictions RFC](https://rust-lang.github.io/rfcs/3323-restrictions.html) (Tracking Issue rust-lang/rust#105077), and linked to a [GSOC idea/proposal](https://github.com/rust-lang/google-summer-of-code/tree/142433eb3b104b2f32bae0b9dfafb78a0a2ac579?tab=readme-ov-file#implementing-impl-and-mut-restrictions).

It lowers the resolved paths of `impl` restrictions from the AST to HIR and into `TraitDef`, and integrates the checks into the coherence phase by extending `check_impl`. As parsing (rust-lang/rust#152943) and path resolution (rust-lang/rust#153556) have already been implemented, this PR provides a working implementation of `impl` restrictions.

r? @Urgau
cc @jhpratt
2026-04-11 01:49:12 -04:00
Jonathan Brouwer ad68deab08 Rollup merge of #154369 - ver-nyan:fix-bit_or-pat_macro-msg, r=JohnTitor
Fix `pattern_from_macro_note` for bit-or expr

This is a continuation of issue https://github.com/rust-lang/rust/issues/99380 (and pr https://github.com/rust-lang/rust/pull/124488) but covers bit-or pattern.

Essentially a `pat1 | pat2`, or any bit-or pattern used in a `$e:expr` was not firing the `.pattern_from_macro_note` diagnostic bc `ast::Expr::is_approximately_pattern()` did not cover bit-or.

The cover for bit-or is only added in `lower_expr_within_pat()`, otherwise doing it in `is_approximately_pattern()` would result in the suggestion `if (i + 2) = 2 => if let (i + 2) = 2` from `suggest_pattern_match_with_let()` (which is the only other place `ast::Expr::is_approximately_pattern()` is used from what i see).

resolves https://github.com/rust-lang/rust/issues/99380
refs https://github.com/rust-lang/rust/pull/124488
2026-04-10 15:33:13 +02:00
bors dd82fd2034 Auto merge of #155056 - JonathanBrouwer:revert-lint-port, r=lqd,mati865
Revert "Port lint attributes to attribute parser"

This PR reverts the following two PRs:
- https://github.com/rust-lang/rust/pull/154808
- https://github.com/rust-lang/rust/pull/152369

This was not a clean revert, I manually solved several merge conflicts.

Closes https://github.com/rust-lang/rust/issues/154878
Closes https://github.com/rust-lang/rust/issues/154800
Closes https://github.com/rust-lang/rust/issues/155008
Re-opens https://github.com/rust-lang/rust/issues/132218 (this was never closed, oops)

r? @ghost
2026-04-09 23:54:22 +00:00
Jonathan Brouwer 65745a1b95 Revert #152369 because of multiple regressions
The regressions are documented in the PR comments.
This reverts commit 2972b5e, reversing changes made to f908263.
2026-04-09 18:53:59 +02:00