Skip to content

Commit a15d196

Browse files
bors[bot]Veykril
andauthored
Merge #6845
6845: Don't HirDisplay unknown types when displaying for source r=Veykril a=Veykril Was wondering why the add missing impl assist didn't do anything here: ![Code_JCA1Qo0V9P](https://user-images.githubusercontent.com/3757771/101990300-7af44a80-3ca6-11eb-8431-e5eb4de4e78c.png) Turns out me forgetting to set the Index::Idx type in the trait causes RA to panic due to it trying to to create an unparsable type in the `make` module. Now we get this instead which imo is definitely better to have. ![Code_MUFPJUCULY](https://user-images.githubusercontent.com/3757771/101990347-c9094e00-3ca6-11eb-9c6a-146bddf64b7c.png) Co-authored-by: Lukas Wirth <[email protected]>
2 parents 10f6332 + 69b78ed commit a15d196

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)