Skip to content

Commit 69b78ed

Browse files
committed
Don't HirDisplay unknown types when displaying for source
1 parent 91bf15a commit 69b78ed

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

crates/assists/src/handlers/add_missing_impl_members.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,31 @@ impl Test for () {
781781
${0:todo!()}
782782
}
783783
}
784+
"#,
785+
)
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+
}
784809
"#,
785810
)
786811
}

crates/hir_ty/src/display.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ impl DisplayTarget {
178178
#[derive(Debug)]
179179
pub enum DisplaySourceCodeError {
180180
PathNotFound,
181+
UnknownType,
181182
}
182183

183184
pub enum HirDisplayError {
@@ -558,7 +559,14 @@ impl HirDisplay for Ty {
558559
}
559560
};
560561
}
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+
}
562570
Ty::Infer(..) => write!(f, "_")?,
563571
}
564572
Ok(())

0 commit comments

Comments
 (0)