Skip to content

fix: resolve inferred type params when inlining trait method calls#21864

Open
Albab-Hasan wants to merge 2 commits intorust-lang:masterfrom
Albab-Hasan:fix/inline-into-concrete-type
Open

fix: resolve inferred type params when inlining trait method calls#21864
Albab-Hasan wants to merge 2 commits intorust-lang:masterfrom
Albab-Hasan:fix/inline-into-concrete-type

Conversation

@Albab-Hasan
Copy link
Contributor

when inlining a method call like expr.into() the inline assist produced U::from(expr). this happened because PathTransform was only applied when explicit generic args (turbofish) were present and even then only handled the functions own type params not the containing trait/impl's params.

the fix resolves inferred generic substitutions from the method call site using resolve_method_call_fallback and applies them to the inlined body via a new PathTransform::with_type_substs() builder correctly replacing trait level type parameters with concrete types.

also improves PathTransform to avoid unnecessary <> wrapping when substituting a type parameter used as a path qualifier with a simple path type (e.g. T::method() becomes Foo::method() instead of <Foo>::method()).

closes #21601

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 25, 2026
When inlining a method call like `expr.into()`, the inline assist
produced `U::from(expr)` where `U` is the unresolved type parameter
name from the trait definition. This happened because PathTransform
was only applied when explicit generic args (turbofish) were present,
and even then only handled the function's own type params, not the
containing trait/impl's params.

The fix resolves inferred generic substitutions from the method call
site using `resolve_method_call_fallback` and applies them to the
inlined body via a new `PathTransform::with_type_substs()` builder,
correctly replacing trait-level type parameters with concrete types.

Also improves PathTransform to avoid unnecessary `<>` wrapping when
substituting a type parameter used as a path qualifier with a simple
path type (e.g. `T::method()` becomes `Foo::method()` instead of
`<Foo>::method()`).

Closes rust-lang#21601
@Albab-Hasan Albab-Hasan force-pushed the fix/inline-into-concrete-type branch from d7e43cb to b02752a Compare March 25, 2026 04:33
@rustbot
Copy link
Collaborator

rustbot commented Mar 25, 2026

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inline assist on .into() produces wrong code

2 participants