-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: Panic while hovering associated function with type annotation on generic param that not inherited from its container type #17893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this does look like the wrong way to render this doesn't it. Ideally we'd render this as
fn <S as T>::f::<i32>()or so?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think so, too. Currently we are rendering such container type into
<>when rendering associated functionrust-analyzer 1.80.0 (05147895 2024-07-21)

And we can find such things in many places of our test cases like
rust-analyzer/crates/hir-ty/src/tests/traits.rs
Line 1108 in 2b86639
I tried to fix them altogather when I was dealing with this issue, but it seems that our generic displaying has many problems that should be dealt with - especially when there are 'parent' generic parameters -, so I just turned to fix this panic with minimal touch and file the issue in proper way 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there was no need to do all of that in this PR given its separate issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing I think that strange is;
We are rendering generics in many cases with
fn hir_fmt_generic_argumentsrust-analyzer/crates/hir-ty/src/display.rs
Lines 1484 to 1518 in 2b86639
and this moves lifetimes before the type and const parameters as it assumes that the input it gets has types and const parameters before the lifetime parameters, as
generics.iter()gives them in this order;rust-analyzer/crates/hir-ty/src/generics.rs
Lines 88 to 95 in 2b86639
But this function does not do such re-ordering to parent parameters and we only do such re-ordering manually in the block I've modified in this PR.
So, in other types the parent generics can be renderered in the rear position of the generic parameters and I'm not sure whether that's correct.
And If we should do such re-ordering everywhere we have to thinkabout grand-parent generics as well, I think 🤔
Furthermore, in
fn generic_args_sans_defaults, we assume that the default parameters are comming in the consecutive last some parameters and this is correct in general in proper rust syntax(L1476)rust-analyzer/crates/hir-ty/src/display.rs
Lines 1431 to 1482 in 2b86639
But I think that this can be problematic if we have both non-empty self parameters and parent parameters, and they are have some both defaults and non defaults.
In this case, aren't we losing some non-default generic parameter of the parent? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I'm just trying to specify the exact problems we have here with some experiments 😅
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might be leftovers, we used to have lifetimes after type/const params, but we've since fixed that order. (this is also why some stuff might look a bit weird still with lifetime param handling)
I don't think Rust currently has that anywhere?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general the order ought to be
rust-analyzer/crates/hir-ty/src/generics.rs
Lines 1 to 9 in bd4785a
now. Ideally parents should come first though I think, but that doesn't work due to chalk iirc