Skip to content

fix refining_impl_trait suggestion with return_type_notation#151744

Open
enthropy7 wants to merge 1 commit intorust-lang:mainfrom
enthropy7:fix-refining-impl-trait-rtn
Open

fix refining_impl_trait suggestion with return_type_notation#151744
enthropy7 wants to merge 1 commit intorust-lang:mainfrom
enthropy7:fix-refining-impl-trait-rtn

Conversation

@enthropy7
Copy link
Contributor

@enthropy7 enthropy7 commented Jan 27, 2026

using #![feature(return_type_notation)] on top of refining_impl_trait made the lint suggest a pretty wild “wrap the body in <Self as Trait>::f(..)” fix instead of the simple “just copy the return type from the trait”. this patch makes the lint always suggest the plain return-type replacement based on the trait signature (by grabbing the original snippet when possible), so you don’t get RTN-style desugarings in the help

new test here

fixes #151663

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 27, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 27, 2026

r? @davidtwco

rustbot has assigned @davidtwco.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rust-log-analyzer

This comment has been minimized.

@enthropy7 enthropy7 force-pushed the fix-refining-impl-trait-rtn branch from fb2bd79 to 34c9ebf Compare January 27, 2026 15:42
@@ -332,6 +332,16 @@ fn report_mismatched_rpitit_signature<'tcx>(
hir::FnRetTy::Return(ty) => ty.span,
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm interested in the reason why the type gets printed that way under RTN. I would look in the HIR pretty printer to look for the culprit. Once identified, there might be a more robust solution because using span_to_snippet is more like hot patching the bug (e.g., if the source is not available (so None) I'm pretty sure we will continue to print the type that way under RTN).

Copy link
Contributor Author

@enthropy7 enthropy7 Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty_print_rpitit used RtnMode::ForDiagnostic by default. it gives impl Trait { T::method(..) } while RTN.

@enthropy7 enthropy7 force-pushed the fix-refining-impl-trait-rtn branch from 34c9ebf to a7458f5 Compare January 27, 2026 19:09
@rust-log-analyzer

This comment has been minimized.

@enthropy7 enthropy7 force-pushed the fix-refining-impl-trait-rtn branch 2 times, most recently from c81c4d4 to 8c9c35e Compare January 27, 2026 19:51
@rust-log-analyzer

This comment has been minimized.

@enthropy7 enthropy7 force-pushed the fix-refining-impl-trait-rtn branch 2 times, most recently from e9229ca to 849725e Compare January 27, 2026 21:55
@davidtwco
Copy link
Member

@bors r+ rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 5, 2026

📌 Commit 849725e has been approved by davidtwco

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 5, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 5, 2026
…rtn, r=davidtwco

fix refining_impl_trait suggestion with return_type_notation

using `#![feature(return_type_notation)] `on top of `refining_impl_trait` made the lint suggest a pretty wild “wrap the body in `<Self as Trait>::f(..)”` fix instead of the simple “just copy the return type from the trait”. this patch makes the lint always suggest the plain return-type replacement based on the trait signature (by grabbing the original snippet when possible), so you don’t get RTN-style desugarings in the help

new test here

fixes rust-lang#151663
rust-bors bot pushed a commit that referenced this pull request Feb 5, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - #151278 (Provide more context on trait bounds being unmet due to imperfect derive)
 - #151955 (escape symbol names in global asm)
 - #149329 (Mark match arms in try and for as being from desugarings.)
 - #151474 (Minor structural improvements)
 - #151744 (fix refining_impl_trait suggestion with return_type_notation)
 - #152107 (Convert to inline diagnostics in `rustc_borrowck`)
 - #152117 (Convert to inline diagnostics in `rustc_trait_selection`)
 - #152136 (Consolidate type const checks on `tcx.is_type_const`)
 - #152170 (Port `rustc_effective_visibility` to the new attribute parser)
rust-bors bot pushed a commit that referenced this pull request Feb 5, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - #151278 (Provide more context on trait bounds being unmet due to imperfect derive)
 - #151955 (escape symbol names in global asm)
 - #149329 (Mark match arms in try and for as being from desugarings.)
 - #151474 (Minor structural improvements)
 - #151744 (fix refining_impl_trait suggestion with return_type_notation)
 - #152107 (Convert to inline diagnostics in `rustc_borrowck`)
 - #152117 (Convert to inline diagnostics in `rustc_trait_selection`)
 - #152136 (Consolidate type const checks on `tcx.is_type_const`)
 - #152170 (Port `rustc_effective_visibility` to the new attribute parser)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 5, 2026
…rtn, r=davidtwco

fix refining_impl_trait suggestion with return_type_notation

using `#![feature(return_type_notation)] `on top of `refining_impl_trait` made the lint suggest a pretty wild “wrap the body in `<Self as Trait>::f(..)”` fix instead of the simple “just copy the return type from the trait”. this patch makes the lint always suggest the plain return-type replacement based on the trait signature (by grabbing the original snippet when possible), so you don’t get RTN-style desugarings in the help

new test here

fixes rust-lang#151663
rust-bors bot pushed a commit that referenced this pull request Feb 5, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #152174 (stdarch subtree update)
 - #151278 (Provide more context on trait bounds being unmet due to imperfect derive)
 - #151955 (escape symbol names in global asm)
 - #149329 (Mark match arms in try and for as being from desugarings.)
 - #151474 (Minor structural improvements)
 - #151744 (fix refining_impl_trait suggestion with return_type_notation)
 - #152107 (Convert to inline diagnostics in `rustc_borrowck`)
 - #152117 (Convert to inline diagnostics in `rustc_trait_selection`)
 - #152136 (Consolidate type const checks on `tcx.is_type_const`)
 - #152170 (Port `rustc_effective_visibility` to the new attribute parser)
 - #152184 (Port rustc_abi to the attribute parser)
rust-bors bot pushed a commit that referenced this pull request Feb 5, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #152174 (stdarch subtree update)
 - #151278 (Provide more context on trait bounds being unmet due to imperfect derive)
 - #151955 (escape symbol names in global asm)
 - #149329 (Mark match arms in try and for as being from desugarings.)
 - #151474 (Minor structural improvements)
 - #151744 (fix refining_impl_trait suggestion with return_type_notation)
 - #152107 (Convert to inline diagnostics in `rustc_borrowck`)
 - #152117 (Convert to inline diagnostics in `rustc_trait_selection`)
 - #152136 (Consolidate type const checks on `tcx.is_type_const`)
 - #152170 (Port `rustc_effective_visibility` to the new attribute parser)
 - #152184 (Port rustc_abi to the attribute parser)
rust-bors bot pushed a commit that referenced this pull request Feb 5, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #152174 (stdarch subtree update)
 - #151278 (Provide more context on trait bounds being unmet due to imperfect derive)
 - #151955 (escape symbol names in global asm)
 - #149329 (Mark match arms in try and for as being from desugarings.)
 - #151474 (Minor structural improvements)
 - #151744 (fix refining_impl_trait suggestion with return_type_notation)
 - #152107 (Convert to inline diagnostics in `rustc_borrowck`)
 - #152117 (Convert to inline diagnostics in `rustc_trait_selection`)
 - #152136 (Consolidate type const checks on `tcx.is_type_const`)
 - #152170 (Port `rustc_effective_visibility` to the new attribute parser)
 - #152184 (Port rustc_abi to the attribute parser)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 6, 2026
…rtn, r=davidtwco

fix refining_impl_trait suggestion with return_type_notation

using `#![feature(return_type_notation)] `on top of `refining_impl_trait` made the lint suggest a pretty wild “wrap the body in `<Self as Trait>::f(..)”` fix instead of the simple “just copy the return type from the trait”. this patch makes the lint always suggest the plain return-type replacement based on the trait signature (by grabbing the original snippet when possible), so you don’t get RTN-style desugarings in the help

new test here

fixes rust-lang#151663
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 6, 2026
…rtn, r=davidtwco

fix refining_impl_trait suggestion with return_type_notation

using `#![feature(return_type_notation)] `on top of `refining_impl_trait` made the lint suggest a pretty wild “wrap the body in `<Self as Trait>::f(..)”` fix instead of the simple “just copy the return type from the trait”. this patch makes the lint always suggest the plain return-type replacement based on the trait signature (by grabbing the original snippet when possible), so you don’t get RTN-style desugarings in the help

new test here

fixes rust-lang#151663
rust-bors bot pushed a commit that referenced this pull request Feb 6, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - #152191 (Convert to inline diagnostics in `rustc_hir_analysis`)
 - #149329 (Mark match arms in try and for as being from desugarings.)
 - #151474 (Minor structural improvements)
 - #152107 (Convert to inline diagnostics in `rustc_borrowck`)
 - #152117 (Convert to inline diagnostics in `rustc_trait_selection`)
 - #152136 (Consolidate type const checks on `tcx.is_type_const`)
 - #152140 (Hard code the error code registry for custom drivers)
 - #152155 (Fix typos in riscv64a23-unknown-linux-gnu.md)
 - #152170 (Port `rustc_effective_visibility` to the new attribute parser)
 - #152182 (update compiler stable backport zulip msg)
 - #152184 (Port rustc_abi to the attribute parser)
 - #152195 (update openmp/offload builds to LLVM 22, Part 1)
 - #152202 (chore: clearify tidy's error message)

Failed merges:

 - #151744 (fix refining_impl_trait suggestion with return_type_notation)
 - #152212 (Port some attributes to the attr parser)
@rust-bors rust-bors bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 6, 2026
@rust-bors

This comment has been minimized.

@enthropy7 enthropy7 force-pushed the fix-refining-impl-trait-rtn branch from 849725e to bcde3fc Compare February 6, 2026 13:22
@rustbot
Copy link
Collaborator

rustbot commented Feb 6, 2026

This PR was rebased onto a different main 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-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lint group refining_impl_trait: Enabling return_type_notation negatively affects the suggested fix

5 participants