From 69b78edb5e2a40d8665db713d363bd16c835d6cf Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sat, 12 Dec 2020 18:18:19 +0100 Subject: Don't HirDisplay unknown types when displaying for source --- .../src/handlers/add_missing_impl_members.rs | 25 ++++++++++++++++++++++ crates/hir_ty/src/display.rs | 10 ++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/assists/src/handlers/add_missing_impl_members.rs b/crates/assists/src/handlers/add_missing_impl_members.rs index bbb71e261..e413505d3 100644 --- a/crates/assists/src/handlers/add_missing_impl_members.rs +++ b/crates/assists/src/handlers/add_missing_impl_members.rs @@ -781,6 +781,31 @@ impl Test for () { ${0:todo!()} } } +"#, + ) + } + + #[test] + fn missing_generic_type() { + check_assist( + add_missing_impl_members, + r#" +trait Foo { + fn foo(&self, bar: BAR); +} +impl Foo for () { + <|> +} +"#, + r#" +trait Foo { + fn foo(&self, bar: BAR); +} +impl Foo for () { + fn foo(&self, bar: BAR) { + ${0:todo!()} + } +} "#, ) } diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index e77481906..aa286c8c2 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -178,6 +178,7 @@ impl DisplayTarget { #[derive(Debug)] pub enum DisplaySourceCodeError { PathNotFound, + UnknownType, } pub enum HirDisplayError { @@ -558,7 +559,14 @@ impl HirDisplay for Ty { } }; } - Ty::Unknown => write!(f, "{{unknown}}")?, + Ty::Unknown => { + if f.display_target.is_source_code() { + return Err(HirDisplayError::DisplaySourceCodeError( + DisplaySourceCodeError::UnknownType, + )); + } + write!(f, "{{unknown}}")?; + } Ty::Infer(..) => write!(f, "_")?, } Ok(()) -- cgit v1.2.3