Commit Graph

320176 Commits

Author SHA1 Message Date
Travis Cross fe71b660c5 Fix comment on is_horizontal_whitespace
The comment on `is_horizontal_whitespace` says "This is
Pattern_White_Space", but the function matches only tab (U+0009) and
space (U+0020) -- two of the eleven `Pattern_White_Space` code points.
This has been the case since Rust PR 146106, which narrowed the set
from full `Pattern_White_Space` to the horizontal subset.

The correct characterization is that this is the horizontal space
subset of `Pattern_White_Space`, as categorized by UAX 31,
Section 4.1, which partitions `Pattern_White_Space` into line endings,
ignorable format controls, and horizontal space.
2026-03-04 06:10:42 +00:00
bors d933cf483e Auto merge of #153377 - Zalathar:rollup-cWj10b1, r=Zalathar
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#153280 (Add regression test for `doc(fake_variadic)` on reexports)
 - rust-lang/rust#153302 (x86: reserve `bl` and `bh` registers to match `rbx`)
 - rust-lang/rust#153358 (Boundary tests for various Duration-float operations)
 - rust-lang/rust#153048 (Improve irrefutable let-else lint wording)
 - rust-lang/rust#153258 (diag: Suppress `.clone()` suggestion inside derive macro expansions)
 - rust-lang/rust#153272 (Add `Path::absolute` method as alias for `std::path::absolute`)
 - rust-lang/rust#153295 (update panicking() docs for panic=abort)
 - rust-lang/rust#153352 (Migration of `LintDiagnostic` - part 6)
2026-03-04 00:55:21 +00:00
Stuart Cook c4f239ec6a Rollup merge of #153352 - GuillaumeGomez:migrate-diag, r=JonathanBrouwer
Migration of `LintDiagnostic` - part 6

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

r? @JonathanBrouwer
2026-03-04 11:54:11 +11:00
Stuart Cook 49966fedd6 Rollup merge of #153295 - biscuitrescue:fix-panicking-docs, r=tgross35
update panicking() docs for panic=abort

fixes rust-lang/rust#151458

The documentation for `std::thread::panicking()` has not been changed since v1.0, even though panic hooks were added in v1.10.
Current documentation is misleading for `panic=abort`

`panicking()` can return `true` in 2 different cases:
1. Thread unwinds due to panic
2. Panic hook is executing with `panic=abort`

r? @SpriteOvO
2026-03-04 11:54:11 +11:00
Stuart Cook b5f3ca196a Rollup merge of #153272 - wmmc88:add-path-absolute-method, r=tgross35
Add `Path::absolute` method as alias for `std::path::absolute`

`Path::canonicalize()` is an alias for `fs::canonicalize()`, but there's no equivalent `Path::absolute()` for `path::absolute()`. This adds one.

Discussed in https://github.com/rust-lang/rust/issues/92750#issuecomment-2867636150, Chris [said](https://github.com/rust-lang/rust/issues/92750#issuecomment-2904002333) a PR would be welcome.

Tracking issue: rust-lang/rust#153328
2026-03-04 11:54:10 +11:00
Stuart Cook 010bca6fc7 Rollup merge of #153258 - lapla-cogito:issue_153126, r=Kivooeo
diag: Suppress `.clone()` suggestion inside derive macro expansions

Derives on a packed struct with non-Copy fields generate moves whose spans point back at the original field type definitions. `suggest_cloning_inner()` then proposes inserting `.clone()` at those locations, producing nonsensical output like `String.clone()` in the struct definition.

close rust-lang/rust#153126
2026-03-04 11:54:10 +11:00
Stuart Cook 70287b9bc2 Rollup merge of #153048 - ozankenangungor:fix-irrefutable-let-else-wording, r=Kivooeo
Improve irrefutable let-else lint wording

Update the `irrefutable_let_patterns` wording for let-else to better reflect that the `else` clause is unreachable when the LHS pattern always matches.

Closes rust-lang/rust#152938
2026-03-04 11:54:09 +11:00
Stuart Cook 54bb7b8212 Rollup merge of #153358 - eggyal:duration-flop-boundary-tests, r=tgross35
Boundary tests for various Duration-float operations

As requested in https://github.com/rust-lang/rust/pull/150933#discussion_r2875490030

r? tgross35
2026-03-04 11:54:09 +11:00
Stuart Cook df44e396c0 Rollup merge of #153302 - CathalMullan:rbx, r=Amanieu
x86: reserve `bl` and `bh` registers to match `rbx`

`bl` and `bh` need to be explicitly marked as reserved, as they are sub-registers of `rbx`, which is reserved by LLVM.

Discovered this while trying to run Graviola through Cranelift, which was becoming corrupted due to the register allocator assigning `bl`: https://github.com/rust-lang/rustc_codegen_cranelift/pull/1629

cc: @bjorn3
2026-03-04 11:54:08 +11:00
Stuart Cook d16ec8534b Rollup merge of #153280 - GuillaumeGomez:add-test-reexport, r=lolbinarycat
Add regression test for `doc(fake_variadic)` on reexports

Follow-up of https://github.com/rust-lang/rust/pull/153136. Out of the four doc attributes remaining to be tested (`fake_variadic`, `keyword`, `attribute` and `notable_trait`), only `fake_variadic` could have been impacted by reexports:

* `attribute` and `keyword` are not supposed to be reexported (they're supposed to be used on private modules)
* `notable_trait` is applied to a trait, so whether it's reexported or not, it still works.

r? @lolbinarycat
2026-03-04 11:54:08 +11:00
Guillaume Gomez 56d636a762 Implement Diagnostic directly on Box<FnOnce...> 2026-03-03 22:14:53 +01:00
Guillaume Gomez b5ff567193 Migrate more types from LintDiagnostic to Diagnostic 2026-03-03 21:57:02 +01:00
biscuitrescue 014344b0c3 update panicking() docs for panic=abort
rephrasing and grammar
2026-03-04 01:38:06 +05:30
bors d9563937fa Auto merge of #153355 - JonathanBrouwer:rollup-Bh4zTly, r=JonathanBrouwer
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#152712 (Use shell-words to parse output from llvm-config)
 - rust-lang/rust#152911 (Stabilize `control_flow_ok`)
 - rust-lang/rust#153223 (Fix LegacyKeyValueFormat report from docker build: host-aarch64)
 - rust-lang/rust#153345 (MGCA: fix type error handling for const array and tuple lowering logic)
2026-03-03 19:26:06 +00:00
Alan Egerton d96ec37d7e Boundary tests for various Duration-float operations 2026-03-03 19:01:53 +00:00
Melvin Wang bde5b584a6 Add Path::absolute method as alias for path::absolute
Add a convenience method Path::absolute() that delegates to the
existing free function std::path::absolute(), mirroring the pattern of
Path::canonicalize() delegating to fs::canonicalize().

Tracking issue: https://github.com/rust-lang/rust/issues/153328
2026-03-03 10:40:19 -08:00
Jonathan Brouwer 0605ef5223 Rollup merge of #153345 - Human9000-bit:mgca-diagnostics-fix, r=fmease
MGCA: fix type error handling for const array and tuple lowering logic

It's a simple fix; just needed to handle Ty::Error in `lower_const_arg_array` and `lower_const_arg_tup`

Fixes rust-lang/rust#153254

r? @fmease
2026-03-03 19:11:50 +01:00
Jonathan Brouwer 340497d589 Rollup merge of #153223 - homersimpsons:chore/fix-LegacyKeyValueFormat-aarch64, r=marcoieni
Fix LegacyKeyValueFormat report from docker build: host-aarch64

Part of https://github.com/rust-lang/rust/pull/152305

Following rust-lang/rust#153109

r? @marcoieni
2026-03-03 19:11:50 +01:00
Jonathan Brouwer f4810cb4a3 Rollup merge of #152911 - nxsaken:stable_control_flow_ok, r=dtolnay
Stabilize `control_flow_ok`

Feature: `control_flow_ok`
Tracking issue: rust-lang/rust#140266

r? @dtolnay
2026-03-03 19:11:49 +01:00
Jonathan Brouwer 6a44bbd91b Rollup merge of #152712 - eggyal:quote-lib-paths, r=ChrisDenton
Use shell-words to parse output from llvm-config

llvm-config might output paths that contain spaces, in which case the naive approach of splitting on whitespace breaks; instead we ask llvm-config to quote any paths and use the [shell-words](https://crates.io/crates/shell-words) crate by @tmiasko (a new dependency) to parse the output.

r? ChrisDenton
Fixes rust-lang/rust#152707
2026-03-03 19:11:48 +01:00
Guillaume Gomez bd538f90fe Remove unused rustc_errors::LintDiagnosticBox trait 2026-03-03 17:21:41 +01:00
Guillaume Gomez 924748717b Implement Diagnostic trait for rustc_errors::DecorateDiagCompat 2026-03-03 17:21:16 +01:00
bors d2218f5f5c Auto merge of #153344 - JonathanBrouwer:rollup-uL4XlqI, r=JonathanBrouwer
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#153336 (stdarch subtree update)
 - rust-lang/rust#152943 (Parse `impl` restrictions)
 - rust-lang/rust#153184 (Replace CodegenResults with CompiledModules)
 - rust-lang/rust#153285 (Update call-llvm-intrinsics test for Rust 1.94.0 IR)
 - rust-lang/rust#153319 (Comments and docs: add missing periods to "ie.")
 - rust-lang/rust#153326 (Make `rustc_with_all_queries!` pass query modifiers as named values)
2026-03-03 12:09:37 +00:00
Jonathan Brouwer d53a01c410 Rollup merge of #153326 - Zalathar:query-modifiers, r=nnethercote
Make `rustc_with_all_queries!` pass query modifiers as named values

This PR is a bold overhaul of how the proc-macro in `rustc_macros::query` passes query modifiers to the callback macros in `rustc_middle` and `rustc_query_impl`.

The existing approach passes modifiers as a list that looks like `[(arena_cache), (no_hash)]`. That style requires a family of helper macros (`if_arena_cache!`, `if_no_hash!`) to check for modifiers when consuming the query list.

This PR changes the proc-macro to instead pass modifiers like this:

```text
{
    anon: false,
    arena_cache: true,
    cache_on_disk: false,
    ...
}
```

This style allows each of the callback macros to deconstruct the modifier list in a relatively straightforward way, by binding the true/false literals to variables like `$arena_cache:literal`.

One of the big advantages of this style is that we can write things like `#[cfg($arena_cache)]` and `#[cfg(not($arena_cache))]` to select blocks of code, eliminating the need for the `if_arena_cache!` family of helper macros.

In follow-up PRs, we can also try to take advantage of the new modifier style to pass richer information for some modifiers, such as `desc` or `cache_on_disk_if`. That could potentially make it more reasonable to get rid of the `_description_fns` and `_cache_on_disk_if_fns` modules, as proposed in https://github.com/rust-lang/rust/pull/153065.

r? nnethercote
2026-03-03 13:08:46 +01:00
Jonathan Brouwer f3f04699c1 Rollup merge of #153319 - DanielEScherzer:ie-dots, r=jhpratt
Comments and docs: add missing periods to "ie."

"i.e." is short for the Latin "id est" and thus both letters should be followed by periods.
2026-03-03 13:08:45 +01:00
Jonathan Brouwer 0ce5963923 Rollup merge of #153285 - DeepeshWR:codegen-llvm-sqrt-call-1.94, r=folkertdev
Update call-llvm-intrinsics test for Rust 1.94.0 IR

Rust 1.94 now passes constants directly to llvm.sqrt.f32 instead of
storing/loading via the stack.

- Updated the FileCheck pattern to match the new IR:
    // CHECK: call float @llvm.sqrt.f32(float 4.000000e+00)
  The test intent is unchanged: it still ensures the intrinsic is
  emitted as a 'call' (not 'invoke').

- Removed unnecessary local variables and Drop usage to work in
  `#![no_core]` mode with minicore.

- Added required crate attributes:
    #![feature(no_core, lang_items)]
    #![no_std]
    #![no_core]

- Replaced `//@ only-riscv64` (host-based execution) with explicit
  revisions for:
      riscv32gc-unknown-linux-gnu
      riscv64gc-unknown-linux-gnu
  This ensures deterministic multi-target coverage in CI without
  relying on the host architecture.

- Added `//@ needs-llvm-components: riscv` and
  `//@ min-llvm-version: 21` for CI compatibility.

Fixes rust-lang/rust#153271
2026-03-03 13:08:45 +01:00
Jonathan Brouwer ee8e2dfaea Rollup merge of #153184 - bjorn3:split_crate_info_out_of_codegen_results, r=nnethercote
Replace CodegenResults with CompiledModules

This is already CodegenResults without CrateInfo. The driver can calculate the CrateInfo and pass it by-ref to the backend. Using CompiledModules makes it a bit easier to move some other things out of the backend as will be necessary for moving LTO to the link phase.

Helps with https://github.com/rust-lang/compiler-team/issues/908
2026-03-03 13:08:44 +01:00
Jonathan Brouwer bef489b0ce Rollup merge of #152943 - CoCo-Japan-pan:impl-restriction-parse, r=Urgau,jhpratt
Parse `impl` restrictions

This PR implements the parsing logic for `impl` restrictions (e.g., `pub impl(crate) trait Foo {}`) as proposed in [RFC 3323](https://rust-lang.github.io/rfcs/3323-restrictions.html).
As the first step of the RFC implementation, this PR focuses strictly on the parsing phase. The new syntax is guarded by the `#![feature(impl_restriction)]` feature gate.
This implementation basically follows the pattern used in rust-lang/rust#141754.

r? @jhpratt
2026-03-03 13:08:43 +01:00
Jonathan Brouwer 8b1ebb3e3a Rollup merge of #153336 - folkertdev:stdarch-sync-2026-03-03, r=folkertdev
stdarch subtree update

Subtree update of `stdarch` to https://github.com/rust-lang/stdarch/commit/d4a226dc06f5f3a89607747038a994e956ae724b.

Created using https://github.com/rust-lang/josh-sync.

r? @ghost
2026-03-03 13:08:42 +01:00
human9000 ee1d0cfbe6 MGCA: fix type error handling for array and tuple lowering logic 2026-03-03 17:08:26 +05:00
bors 1b7d722f42 Auto merge of #153331 - JonathanBrouwer:rollup-hr9XbEa, r=JonathanBrouwer
Rollup of 12 pull requests

Successful merges:

 - rust-lang/rust#152941 (prefer actual ABI-controling fields over target.abi when making ABI decisions)
 - rust-lang/rust#153227 (Don’t report missing fields in struct exprs with syntax errors.)
 - rust-lang/rust#153265 (Clarified doc comments + added tests confirming current behavior for intersperse/intersperse_with)
 - rust-lang/rust#152966 (Migrate 11 tests from tests/ui/issues to specific directories)
 - rust-lang/rust#153003 (rustdoc: make `--emit` and `--out-dir` mimic rustc)
 - rust-lang/rust#153034 (Remove unhelpful hint from trivial bound errors)
 - rust-lang/rust#153152 (Migration of LintDiagnostic - part 5)
 - rust-lang/rust#153177 (disable the ptr_fragment_in_final test on s390x)
 - rust-lang/rust#153221 (Add release notes for 1.94.0)
 - rust-lang/rust#153279 (feat: Provide an '.item_kind()' method on ItemEnum)
 - rust-lang/rust#153297 (Update the name of the Hermit operating system)
 - rust-lang/rust#153309 (Cleanup of c-variadic link test)
2026-03-03 07:00:49 +00:00
Jonathan Brouwer cec85ce732 Rollup merge of #153309 - folkertdev:c-variadic-link-test-cleanup, r=jieyouxu
Cleanup of c-variadic link test

Some changes pulled out of https://github.com/rust-lang/rust/pull/152980 that are just cosmetic, but will help make the code run on embedded targets.

r? jieyouxu
2026-03-03 07:14:18 +01:00
Jonathan Brouwer 8845cc0c67 Rollup merge of #153297 - Gelbpunkt:hermitcore-hermit, r=joboet
Update the name of the Hermit operating system

The HermitCore name was dropped a while ago, the project is now simply called "Hermit". See for example [the website](https://hermit-os.org/).

cc @stlankes @mkroening
2026-03-03 07:14:17 +01:00
Jonathan Brouwer 3bb52457bb Rollup merge of #153279 - LukeMathWalker:add-kind-method, r=aDotInTheVoid
feat: Provide an '.item_kind()' method on ItemEnum

A little helper method which I found myself adding over and over again in all the projects I maintain which depend on `rustdoc-json-types`.

r? @aDotInTheVoid
2026-03-03 07:14:17 +01:00
Jonathan Brouwer 3caa6aba9e Rollup merge of #153221 - Mark-Simulacrum:relnotes, r=cuviper
Add release notes for 1.94.0

Replaces https://github.com/rust-lang/rust/issues/151650.

r? cuviper
2026-03-03 07:14:16 +01:00
Jonathan Brouwer bb2b75b82c Rollup merge of #153177 - fneddy:s390x_fix_test_ptr_fragments_final, r=fmease
disable the ptr_fragment_in_final test on s390x

on s390x 128bit types have a smaller alignment then on x86[^1]. This leads to the tests falling due to different errors emitted.

As this affects the same infrastructure as rust-lang/rust#149056 [^2] lets also for now disable the tests on s390x.

[^1]: s390x ELF ABI Table 1.1, Page 12 https://github.com/IBM/s390x-abi
[^2]: https://github.com/rust-lang/rust/pull/149056#issuecomment-3547543222
2026-03-03 07:14:16 +01:00
Jonathan Brouwer 4a56a45083 Rollup merge of #153152 - GuillaumeGomez:migrate-diag, r=JonathanBrouwer
Migration of LintDiagnostic - part 5

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

With this, `rust_lint` is finally done, although the change of API of `decorate_builtin_lint` impacted a few other crates, although minimal, still needed to be mentioned.

r? @JonathanBrouwer
2026-03-03 07:14:15 +01:00
Jonathan Brouwer 87bd517707 Rollup merge of #153034 - arferreira:fix-trivial-bound-diagnostic, r=Kivooeo
Remove unhelpful hint from trivial bound errors

The `= help: see issue #48214` hint on trivial bound errors isn't useful, most users hitting these errors aren't trying to use the `trivial_bounds` feature. The `disabled_nightly_features` call already handles suggesting the feature gate on nightly.

Closes rust-lang/rust#152872
2026-03-03 07:14:15 +01:00
Jonathan Brouwer f9d22c04a5 Rollup merge of #153003 - notriddle:emit-outdir, r=fmease
rustdoc: make `--emit` and `--out-dir` mimic rustc

The behavior in the test case matches rustc's:

    test-dingus % ls
    main.rs
    test-dingus % mkdir foobar
    test-dingus % rustc --emit=dep-info main.rs --out-dir=foobar
    test-dingus % ls
    foobar  main.rs
    test-dingus % ls foobar
    main.d
    test-dingus % rustc --emit=dep-info=testfile.d main.rs --out-dir=foobar
    test-dingus % ls
    foobar          main.rs         testfile.d
    test-dingus % ls foobar
    main.d

CC https://github.com/rust-lang/rust/pull/146220#issuecomment-3936957755
2026-03-03 07:14:14 +01:00
Jonathan Brouwer e77eff6bc2 Rollup merge of #152966 - raushan728:reorganize-ui-issues-1, r=Kivooeo
Migrate 11 tests from tests/ui/issues to specific directories

Moved 11 regression tests from `tests/ui/issues` to their relevant subdirectories (`imports`, `pattern`, `lint`, and `typeck`).

* Added standard issue tracking comments at the top of each file.
* Relocated associated `aux-build` files.
* Ran `./x.py test --bless` successfully.
2026-03-03 07:14:13 +01:00
Jonathan Brouwer c4384629c0 Rollup merge of #153265 - asder8215:intersperse_changes, r=jhpratt
Clarified doc comments + added tests confirming current behavior for intersperse/intersperse_with

This PR builds on top of rust-lang/rust#152855. I just added clarifying comments to `intersperse`/`intersperse_with` about its guarantees for fused iterators (and how behavior for non-fused iterators are subject to change). I also added in tests for non-fused iterators demonstrating its current behavior; fused iterators are already tested for in existing tests for `intersperse`/`intersperse_with`.
2026-03-03 07:14:12 +01:00
Jonathan Brouwer 7174c100f4 Rollup merge of #153227 - kpreid:struct-missing-field, r=estebank
Don’t report missing fields in struct exprs with syntax errors.

@Noratrieb [told me](https://internals.rust-lang.org/t/custom-cargo-command-to-show-only-errors-avoid-setting-rustflags-every-time/24032/7?u=kpreid) that “it is a bug if this recovery causes follow-up errors that would not be there if the user fixed the first error.” So, here’s a contribution to hide a follow-up error that annoyed me recently.

Specifically, if the user writes a struct literal with a syntax error, such as

```rust
StructName { foo: 1 bar: 2 }
```

the compiler will no longer report that the field `bar` is missing in addition to the syntax error.

This is my first time attempting any change to the parser or AST; please let me know if there is a better way to do what I’ve done here. ~~The part I’m least happy with is the blast radius of adding another field to `hir::ExprKind::Struct`, but this seems to be in line with the style of the rest of the code. (If this were my own code, I would consider changing `hir::ExprKind::Struct` to a nested struct, the same way it is in `ast::ExprKind`.)~~ The additional information is now stored as an additional variant of `ast::StructRest` / `hir::StructTailExpr`.

**Note to reviewers:** I recommend reviewing each commit separately, and in the case of the first one with indentation changes ignored.
2026-03-03 07:14:12 +01:00
Jonathan Brouwer ca1b24406d Rollup merge of #152941 - RalfJung:abi-control, r=mati865
prefer actual ABI-controling fields over target.abi when making ABI decisions

We don't actually check that `abi` is consistent with the fields that control the ABI, e.g. one could set `llvm_abiname` to "ilp32e" on a riscv target without setting a matching `abi`. So, if we need to make actual decisions, better to use the source of truth we forward to LLVM than the informational string we forward to the user.

This is a breaking change for aarch64 JSON target specs: setting `abi` to "softfloat" is no longer enough; one has to also set `rustc_abi` to "softfloat". That is consistent with riscv and arm32, but it's still surprising. Cc @Darksonn in case this affects the Linux kernel.

Also see https://github.com/rust-lang/rust/pull/153035 which does something similar for PowerPC, and [Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/De-spaghettifying.20ABI.20controls/with/575095372). Happy to delay this PR if someone has a better idea.

Cc @folkertdev @workingjubilee
2026-03-03 07:14:11 +01:00
Zalathar 083b5db476 Make rustc_with_all_queries! pass query modifiers as named values 2026-03-03 16:43:46 +11:00
Deepesh Varatharajan 1d678f6b08 Update call-llvm-intrinsics test for Rust 1.94.0 IR and multi-target CI
Rust 1.94 now passes constants directly to llvm.sqrt.f32 instead of
storing/loading via the stack.

- Updated the FileCheck pattern to match the new IR:
    // CHECK: call float @llvm.sqrt.f32(float 4.000000e+00)
  The test intent is unchanged: it still ensures the intrinsic is
  emitted as a 'call' (not 'invoke').

- Removed unnecessary local variables and Drop usage to work in
  `#![no_core]` mode with minicore.

- Added required crate attributes:
    #![feature(no_core, lang_items)]
    #![no_std]
    #![no_core]

- Replaced `//@ only-riscv64` (host-based execution) with explicit
  revisions for:
      riscv32gc-unknown-linux-gnu
      riscv64gc-unknown-linux-gnu
  This ensures deterministic multi-target coverage in CI without
  relying on the host architecture.

- Added `//@ needs-llvm-components: riscv` and
  `//@ min-llvm-version: 21` for CI compatibility.

Signed-off-by: Deepesh Varatharajan <Deepesh.Varatharajan@windriver.com>
2026-03-02 18:50:12 -08:00
bors d3877ec332 Auto merge of #151864 - aerooneqq:delegation-generics-propagation, r=petrochenkov
Implement AST -> HIR generics propagation in delegation



This PR adds support for generics propagation during AST -> HIR lowering and is a part of rust-lang/rust#118212.

# High-level design overview

## Motivation
The task is to generate generics for delegations (i.e. in this context we assume a function that is created for `reuse` statements) during AST -> HIR lowering. Then we want to propagate those generated params to generated method call (or default call) in delegation. This will help to solve issues like the following:

```rust
mod to_reuse {
    pub fn consts<const N: i32>() -> i32 {
        N
    }
}

reuse to_reuse::consts;
//~^ ERROR  type annotations needed

// DESUGARED CURRENT:
#[attr = Inline(Hint)]
fn consts() -> _ { to_reuse::consts() }

// DESUGARED DESIRED:
#[attr = Inline(Hint)]
fn consts<const N: i32>() -> _ { to_reuse::consts::<N>() }
```

Moreover, user can specify generic args in `reuse`, we need to propagate them (works now) and inherit signature with substituted generic args:

```rust
mod to_reuse {
    pub fn foo<T>(t: T) -> i32 {
        0
    }
}

reuse to_reuse::foo::<i32>;
//~^ ERROR  mismatched types

fn main() {
    foo(123);
}

error[E0308]: mismatched types
  --> src/main.rs:24:17
   |
19 |     pub fn foo<T>(t: T) -> i32 {
   |                - found this type parameter
...
24 | reuse to_reuse::foo::<i32>;
   |                 ^^^
   |                 |
   |                 expected `i32`, found type parameter `T`
   |                 arguments to this function are incorrect
   |
   = note:        expected type `i32`
           found type parameter `T`
```
In this case we want the delegation to have signature that have one `i32` parameter (not `T` parameter).
Considering all other cases, for now we want to preserve existing behavior, which was almost fully done (at this stage there are changes in behavior of delegations with placeholders and late-bound lifetimes).

## Main approach overview
The main approach is as follows:
- We determine generic params of delegee parent (now only trait can act as a parent as delegation to inherent impls is not yet supported) and delegee function,
- Based on presence of user-specified args in `reuse` statement (i.e. `reuse Trait::<'static, i32, 123>::foo::<String>`)  we either generate delegee generic params or not. If not, then we should include user-specified generic args into the signature of delegation,
- The general order of generic params generation is as following: 
   `[DELEGEE PARENT LIFETIMES, DELEGEE LIFETIMES, DELEGEE PARENT TYPES AND CONSTS, DELEGEE TYPES AND CONSTS]`,
- There are two possible generic params orderings (they differ only in a position of `Self` generic param):
  - When Self is after lifetimes, this happens only in free to trait delegation scenario, as we need to generate implicit Self param of the delegee trait,
  - When Self is in the beginning and we should not generate Self param, this is basically all other cases if there is an implicit Self generic param in delegation parent.
- Considering propagation, we do not propagate lifetimes for child, as at AST -> HIR lowering stage we can not know whether the lifetime is late-bound or early bound, so for now we do not propagate them at all. There is one more hack with child lifetimes, for the same reason we create predicates of kind `'a: 'a` in order to preserve all lifetimes in HIR, so for now we can generate more lifetimes params then needed. This will be partially fixed in one of next pull requests.

## Implementation details

- We obtain AST generics either from AST of a current crate if delegee is local or from external crate through `generics_of` of `tcx`. Next, as we want to generate new generic params we generate new node ids for them, remove default types and then invoke already existent routine for lowering AST generic params into HIR,
- If there are user-specified args in either parent or child parts of the path, we save HIR ids of those segments and pass them to `hir_analysis` part, where user-specified args are obtained, then lowered through existing API and then used during signature and predicates inheritance,
- If there are no user-specified args then we propagate generic args that correspond to generic params during generation of delegation,
- During signature inheritance we know whether parent or child generic args were specified by the user, if so, we should merge them with generic params (i.e. cases when parent args are specified and child args are not: `reuse Trait::<String>::foo`), next we use those generic args and mapping for delegee parent and child generic params into those args in order to fold delegee signature and delegee predicates.

## Tests

New tests were developed and can be found in `ast-hir-engine` folder, those tests cover all cases of delegation with different number of lifetimes, types, consts in generic params and different user-specified args cases (parent and child, parent/child only, none). 

## Edge cases
There are some edge cases worth mentioning. 

### Free to trait delegation. 
Consider this example:
```rust
trait Trait<'a, T, const N: usize> {
    fn foo<'x: 'x, A, B>(&self) {}
}

reuse Trait::foo;
```

As we are reusing from trait and delegee has `&self` param it means that delegation must have `Self` generic param:
```rust
fn foo<'a, 'x, Self, T, const N: usize, A, B>(self) {}
```

We inherit predicates from Self implicit generic param in `Trait`, thus we can pass to delegation anything that implements this trait. Now, consider the case when user explicitly specifies parent generic args.
```rust
reuse Trait::<'static, String, 1>::foo;
```

In this case we do not need to generate parent generic params, but we still need to generate `Self` in delegation (`DelegationGenerics::SelfAndUserSpecified` variant):
```rust
fn foo<'x, Self, A, B>(self) {}
```
User-specified generic arguments should be used to replace parent generic params in delegation, so if we had param of type `T` in `foo`, during signature inheritance we should replace it with user-specified `String` type.

### impl trait delegation
When we delegate from impl trait to something, we want the delegation to have signature that matches signature in trait. For this reason we already resolve delegation not to the actual delegee but to the trait method in order to inherit its signature. That is why when processing user-specified args when the caller kind is `impl trait` (`FnKind::AssocTraitImpl`), we discard parent user-specified args and replace them with those that are specified in trait header. In future we will also discard `child_args` but we need proper error handling for this case, so it will be addressed in one of future pull requests that are approximately specified in "Nearest future work" section.

## Nearest future work (approximate future pull requests):
- Late-bound lifetimes
- `impl Trait` params in functions
- Proper propagation of parent generics when generating method call
- ~Fix diagnostics duplication during lowering of user-specified types~
- Support for recursive delegations
- Self types support `reuse <u8 as Trait<_>>::foo as generic_arguments2`
- Decide what to do with infer args `reuse Trait::<_, _>::foo::<_>`
- Proper error handling when there is a mismatch between actual and expected args (impl trait case)

r? @petrochenkov
2026-03-03 02:39:40 +00:00
Daniel Scherzer 158ac1a10b Comments and docs: add missing periods to "ie."
"i.e." is short for the Latin "id est" and thus both letters should be followed
by periods.
2026-03-02 18:11:13 -08:00
lapla 3cecc8d003 Suppress .clone() suggestion inside derive macro expansions 2026-03-03 11:10:19 +09:00
Mahdi Ali-Raihan c8d343e5c8 Added guarantee and non-guarantee comments + tests for intersperse/intersperse_with regarding fused/non-fused iterators 2026-03-02 19:44:15 -05:00
Ozan Kenan Güngör a8d4eeef1b Improve irrefutable let-else lint wording 2026-03-03 03:39:56 +03:00