diff options
| author | Shoyu Vanilla <modulo641@gmail.com> | 2024-08-08 22:03:31 +0900 |
|---|---|---|
| committer | Shoyu Vanilla <modulo641@gmail.com> | 2024-08-08 22:03:31 +0900 |
| commit | ce846da6d6a13cbfc36bb5d4e93675a62e4115ec (patch) | |
| tree | ad03709b82fcae79073caa872ff92fb54759f797 | |
| parent | 8666a717db64fc99a705bd612f46f943c79d94c6 (diff) | |
| download | rust-ce846da6d6a13cbfc36bb5d4e93675a62e4115ec.tar.gz rust-ce846da6d6a13cbfc36bb5d4e93675a62e4115ec.zip | |
fix: Panic while rendering function with impl trait arg
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir-ty/src/display.rs | 8 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide/src/hover/tests.rs | 23 |
2 files changed, 27 insertions, 4 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/display.rs b/src/tools/rust-analyzer/crates/hir-ty/src/display.rs index a433ecfd778..47ea2f5347c 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/display.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/display.rs @@ -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_); 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]; write!(f, "<")?; hir_fmt_generic_arguments(f, parent_params, None)?; diff --git a/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs b/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs index ecfcf82e00c..516e32ef917 100644 --- a/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs +++ b/src/tools/rust-analyzer/crates/ide/src/hover/tests.rs @@ -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) + ``` + "#]], + ); +} |
