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 <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2020-12-12 18:06:36 +00:00 committed by GitHub
commit a15d19619e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View file

@ -781,6 +781,31 @@ impl Test for () {
${0:todo!()} ${0:todo!()}
} }
} }
"#,
)
}
#[test]
fn missing_generic_type() {
check_assist(
add_missing_impl_members,
r#"
trait Foo<BAR> {
fn foo(&self, bar: BAR);
}
impl Foo for () {
<|>
}
"#,
r#"
trait Foo<BAR> {
fn foo(&self, bar: BAR);
}
impl Foo for () {
fn foo(&self, bar: BAR) {
${0:todo!()}
}
}
"#, "#,
) )
} }

View file

@ -178,6 +178,7 @@ impl DisplayTarget {
#[derive(Debug)] #[derive(Debug)]
pub enum DisplaySourceCodeError { pub enum DisplaySourceCodeError {
PathNotFound, PathNotFound,
UnknownType,
} }
pub enum HirDisplayError { 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, "_")?, Ty::Infer(..) => write!(f, "_")?,
} }
Ok(()) Ok(())