Skip to content

fix: Panic while rendering function type hint with impl trait arg #17832

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 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/hir-ty/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,16 +1022,16 @@ impl HirDisplay for Ty {
// We print all params except implicit impl Trait params. Still a bit weird; should we leave out parent and self?
if parameters.len() - impl_ > 0 {
// `parameters` are in the order of fn's params (including impl traits), fn's lifetimes
let without_impl = self_param as usize + type_ + const_ + lifetime;
// parent's params (those from enclosing impl or trait, if any).
let (fn_params, other) =
parameters.split_at(self_param as usize + type_ + const_ + lifetime);
let (_impl, parent_params) = other.split_at(impl_);
let (fn_params, parent_params) = parameters.split_at(without_impl + impl_);
Copy link
Member Author

Choose a reason for hiding this comment

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

as generic_args is self + type params + const params + lifetimes + hidden generic with impl trait args, we should include impl to generate generic_args_sans_defaults

debug_assert_eq!(parent_params.len(), parent_len);

let parent_params =
generic_args_sans_defaults(f, Some(generic_def_id), parent_params);
let fn_params =
generic_args_sans_defaults(f, Some(generic_def_id), fn_params);
&generic_args_sans_defaults(f, Some(generic_def_id), fn_params)
[0..without_impl];
Copy link
Member Author

Choose a reason for hiding this comment

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

And we exclude impl trait things here


write!(f, "<")?;
hir_fmt_generic_arguments(f, parent_params, None)?;
Expand Down
23 changes: 23 additions & 0 deletions crates/ide/src/hover/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8579,3 +8579,26 @@ fn main(a$0: T) {}
"#]],
);
}

#[test]
fn hover_fn_with_impl_trait_arg() {
check(
r#"
trait Foo {}
impl Foo for bool {}
fn bar<const WIDTH: u8>(_: impl Foo) {}
fn test() {
let f = bar::<3>;
f$0(true);
}
"#,
expect![[r#"
*f*

```rust
// size = 0, align = 1
let f: fn bar<3>(bool)
```
"#]],
);
}