diff options
author | Lukas Wirth <[email protected]> | 2020-12-12 17:18:19 +0000 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2020-12-12 18:05:00 +0000 |
commit | 69b78edb5e2a40d8665db713d363bd16c835d6cf (patch) | |
tree | 32b0fc4b548d1a3d3057e7dfbaea10a977f7b0cc /crates | |
parent | 91bf15a2f53629209bd13d2e46121b9be8af1f94 (diff) |
Don't HirDisplay unknown types when displaying for source
Diffstat (limited to 'crates')
-rw-r--r-- | crates/assists/src/handlers/add_missing_impl_members.rs | 25 | ||||
-rw-r--r-- | crates/hir_ty/src/display.rs | 10 |
2 files changed, 34 insertions, 1 deletions
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 | |||
@@ -784,4 +784,29 @@ impl Test for () { | |||
784 | "#, | 784 | "#, |
785 | ) | 785 | ) |
786 | } | 786 | } |
787 | |||
788 | #[test] | ||
789 | fn missing_generic_type() { | ||
790 | check_assist( | ||
791 | add_missing_impl_members, | ||
792 | r#" | ||
793 | trait Foo<BAR> { | ||
794 | fn foo(&self, bar: BAR); | ||
795 | } | ||
796 | impl Foo for () { | ||
797 | <|> | ||
798 | } | ||
799 | "#, | ||
800 | r#" | ||
801 | trait Foo<BAR> { | ||
802 | fn foo(&self, bar: BAR); | ||
803 | } | ||
804 | impl Foo for () { | ||
805 | fn foo(&self, bar: BAR) { | ||
806 | ${0:todo!()} | ||
807 | } | ||
808 | } | ||
809 | "#, | ||
810 | ) | ||
811 | } | ||
787 | } | 812 | } |
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 { | |||
178 | #[derive(Debug)] | 178 | #[derive(Debug)] |
179 | pub enum DisplaySourceCodeError { | 179 | pub enum DisplaySourceCodeError { |
180 | PathNotFound, | 180 | PathNotFound, |
181 | UnknownType, | ||
181 | } | 182 | } |
182 | 183 | ||
183 | pub enum HirDisplayError { | 184 | pub enum HirDisplayError { |
@@ -558,7 +559,14 @@ impl HirDisplay for Ty { | |||
558 | } | 559 | } |
559 | }; | 560 | }; |
560 | } | 561 | } |
561 | Ty::Unknown => write!(f, "{{unknown}}")?, | 562 | Ty::Unknown => { |
563 | if f.display_target.is_source_code() { | ||
564 | return Err(HirDisplayError::DisplaySourceCodeError( | ||
565 | DisplaySourceCodeError::UnknownType, | ||
566 | )); | ||
567 | } | ||
568 | write!(f, "{{unknown}}")?; | ||
569 | } | ||
562 | Ty::Infer(..) => write!(f, "_")?, | 570 | Ty::Infer(..) => write!(f, "_")?, |
563 | } | 571 | } |
564 | Ok(()) | 572 | Ok(()) |