Skip to content

fix: don't offer unwrap result/option return type assist in trait impls#21831

Closed
Albab-Hasan wants to merge 1 commit intorust-lang:masterfrom
Albab-Hasan:fix/unwrap-result-return-type-in-trait-impl
Closed

fix: don't offer unwrap result/option return type assist in trait impls#21831
Albab-Hasan wants to merge 1 commit intorust-lang:masterfrom
Albab-Hasan:fix/unwrap-result-return-type-in-trait-impl

Conversation

@Albab-Hasan
Copy link
Contributor

@Albab-Hasan Albab-Hasan commented Mar 17, 2026

fixes #13560

the unwrap_result_return_type and unwrap_option_return_type assists were incorrectly offered inside trait impl methods. applying the assist removes the return type breaking the trait contract and producing a compile error.

this fix disables both assists when the function is a trait impl method, checked via implemented_trait. this approach was chosen over showing the assist with a warning, since silently producing uncompilable code is wrong behavior.

added a test to cover this case.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 17, 2026
@ChayimFriedman2
Copy link
Contributor

Assists aren't required to produce compilable code, and this can be useful even in trait methods (for example, if you want to change the trait signature as well).

@Albab-Hasan
Copy link
Contributor Author

@ChayimFriedman2 youre right. my mistake. shouldve done more research before making the pr. ill close it

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Unwrap Result return type" shouldn't trigger in trait impls

3 participants