mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 05:53:45 +00:00
Auto merge of #17832 - ShoyuVanilla:issue-17811, r=Veykril
fix: Panic while rendering function type hint with impl trait arg Fixes #17811
This commit is contained in:
commit
dab022fb31
2 changed files with 27 additions and 4 deletions
|
@ -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?
|
// 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 {
|
if parameters.len() - impl_ > 0 {
|
||||||
// `parameters` are in the order of fn's params (including impl traits), fn's lifetimes
|
// `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).
|
// parent's params (those from enclosing impl or trait, if any).
|
||||||
let (fn_params, other) =
|
let (fn_params, parent_params) = parameters.split_at(without_impl + impl_);
|
||||||
parameters.split_at(self_param as usize + type_ + const_ + lifetime);
|
|
||||||
let (_impl, parent_params) = other.split_at(impl_);
|
|
||||||
debug_assert_eq!(parent_params.len(), parent_len);
|
debug_assert_eq!(parent_params.len(), parent_len);
|
||||||
|
|
||||||
let parent_params =
|
let parent_params =
|
||||||
generic_args_sans_defaults(f, Some(generic_def_id), parent_params);
|
generic_args_sans_defaults(f, Some(generic_def_id), parent_params);
|
||||||
let fn_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];
|
||||||
|
|
||||||
write!(f, "<")?;
|
write!(f, "<")?;
|
||||||
hir_fmt_generic_arguments(f, parent_params, None)?;
|
hir_fmt_generic_arguments(f, parent_params, None)?;
|
||||||
|
|
|
@ -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)
|
||||||
|
```
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue