Skip to content

Conversation

@Shourya742
Copy link
Contributor

@Shourya742 Shourya742 commented Feb 25, 2025

closes #17310

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 25, 2025
@Shourya742 Shourya742 marked this pull request as draft February 25, 2025 18:54
@ChayimFriedman2
Copy link
Contributor

Please add a test.

@Shourya742 Shourya742 force-pushed the 2025-02-25-fix-completion-ref-matching branch 2 times, most recently from ce38f1d to 51709c5 Compare February 26, 2025 15:59
@Shourya742 Shourya742 marked this pull request as ready for review February 26, 2025 16:50
@Shourya742
Copy link
Contributor Author

Hello @ChayimFriedman2, this only addresses part of the issue and does not cover the aspect related to unsized types. The approach I took was as follows: In the case of a redundant borrowing suggestion, the issue was that the completion type was (&'{error} AdtId(StructId(StructId(1191))), whereas the expected type was (&'static AdtId(StructId(StructId(1191)))<[]>). I believe the lifetime error indicates undetermined lifetimes in this context. My approach was to strip the reference from the expected_type, append the undetermined lifetime annotation, and check if it matches the completion_type. If they match, the suggestion should not be made. However, I might be wrong—please let me know if you see any issues with this approach.

@ChayimFriedman2
Copy link
Contributor

ChayimFriedman2 commented Feb 27, 2025

A better approach will be to fold both types and convert all lifetimes to error lifetimes. You can see examples of type folders in this file: https://github.com/rust-lang/rust-analyzer/blob/master/crates/hir-ty/src/lib.rs.

@Shourya742 Shourya742 force-pushed the 2025-02-25-fix-completion-ref-matching branch from b7cb7f5 to dcb25b1 Compare February 28, 2025 04:33
@Shourya742
Copy link
Contributor Author

Shourya742 commented Feb 28, 2025

A better approach will be to fold both types and convert all lifetimes to error lifetimes. You can see examples of type folders in this file: https://github.com/rust-lang/rust-analyzer/blob/master/crates/hir-ty/src/lib.rs.

@ChayimFriedman2 , Ah! I updated the check to use the could_unify_with method, which, in turn, folds both types to verify compatibility.

@ChayimFriedman2
Copy link
Contributor

Thanks!

@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue Mar 3, 2025
Merged via the queue into rust-lang:master with commit 9e014a0 Mar 3, 2025
9 checks passed
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.

more refined suggestions for functions that return a reference

3 participants