From b0bb8622eea7cb447ebadb8b5fba43850305e913 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 7 Feb 2020 16:39:48 +0100 Subject: Don't print implicit type args from impl Trait --- crates/ra_hir_ty/src/lib.rs | 13 ++++++++++--- crates/ra_hir_ty/src/tests/traits.rs | 22 +++++++++++----------- 2 files changed, 21 insertions(+), 14 deletions(-) (limited to 'crates/ra_hir_ty') diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index 60c7fd0e5..68c2f0b06 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs @@ -909,9 +909,16 @@ impl HirDisplay for ApplicationTy { } } if self.parameters.len() > 0 { - write!(f, "<")?; - f.write_joined(&*self.parameters.0, ", ")?; - write!(f, ">")?; + let generics = generics(f.db, def.into()); + let (parent_params, self_param, type_params, _impl_trait_params) = + generics.provenance_split(); + let total_len = parent_params + self_param + type_params; + // We print all params except implicit impl Trait params. Still a bit weird; should we leave out parent and self? + if total_len > 0 { + write!(f, "<")?; + f.write_joined(&self.parameters.0[..total_len], ", ")?; + write!(f, ">")?; + } } write!(f, "(")?; f.write_joined(sig.params(), ", ")?; diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index f90dadc08..c6851fb69 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -886,7 +886,7 @@ fn test(x: impl Trait, y: &impl Trait) { [224; 225) 'S': S(u16) -> S [224; 228) 'S(1)': S [226; 227) '1': u16 - [234; 237) 'bar': fn bar>(S) -> () + [234; 237) 'bar': fn bar(S) -> () [234; 240) 'bar(z)': () [238; 239) 'z': S [246; 247) 'x': impl Trait @@ -943,28 +943,28 @@ fn test() { [222; 229) 'loop {}': ! [227; 229) '{}': () [301; 510) '{ ... i32 }': () - [307; 315) 'Foo::bar': fn bar<{unknown}, {unknown}, S>(S) -> {unknown} + [307; 315) 'Foo::bar': fn bar<{unknown}, {unknown}>(S) -> {unknown} [307; 318) 'Foo::bar(S)': {unknown} [316; 317) 'S': S - [324; 339) '::bar': fn bar(S) -> {unknown} + [324; 339) '::bar': fn bar(S) -> {unknown} [324; 342) '(S) -> {unknown} + [348; 354) 'F::bar': fn bar(S) -> {unknown} [348; 357) 'F::bar(S)': {unknown} [355; 356) 'S': S - [363; 378) 'Foo::bar::': fn bar<{unknown}, u32, S>(S) -> u32 + [363; 378) 'Foo::bar::': fn bar<{unknown}, u32>(S) -> u32 [363; 381) 'Foo::b...32>(S)': u32 [379; 380) 'S': S - [387; 409) '': fn bar(S) -> u32 + [387; 409) '': fn bar(S) -> u32 [387; 412) '(S)': u32 [410; 411) 'S': S - [419; 422) 'foo': fn foo<{unknown}, S>(S) -> {unknown} + [419; 422) 'foo': fn foo<{unknown}>(S) -> {unknown} [419; 425) 'foo(S)': {unknown} [423; 424) 'S': S - [431; 441) 'foo::': fn foo(S) -> u32 + [431; 441) 'foo::': fn foo(S) -> u32 [431; 444) 'foo::(S)': u32 [442; 443) 'S': S - [450; 465) 'foo::': fn foo(S) -> u32 + [450; 465) 'foo::': fn foo(S) -> u32 [450; 468) 'foo::<...32>(S)': u32 [466; 467) 'S': S "### @@ -1794,11 +1794,11 @@ fn test() -> impl Trait { [229; 241) 'S(default())': S [231; 238) 'default': fn default() -> u32 [231; 240) 'default()': u32 - [247; 250) 'foo': fn foo>(S) -> () + [247; 250) 'foo': fn foo(S) -> () [247; 254) 'foo(s1)': () [251; 253) 's1': S [264; 265) 'x': i32 - [273; 276) 'bar': fn bar>(S) -> i32 + [273; 276) 'bar': fn bar(S) -> i32 [273; 290) 'bar(S(...lt()))': i32 [277; 278) 'S': S(i32) -> S [277; 289) 'S(default())': S -- cgit v1.2.3