Skip to content

Commit 06cf9ca

Browse files
committed
minor: simplify and enhance notable traits rendering
1 parent 723121e commit 06cf9ca

File tree

2 files changed

+16
-36
lines changed

2 files changed

+16
-36
lines changed

crates/ide/src/hover/render.rs

+14-34
Original file line numberDiff line numberDiff line change
@@ -909,9 +909,9 @@ fn render_notable_trait(
909909
let mut needs_impl_header = true;
910910
for (trait_, assoc_types) in notable_traits {
911911
desc.push_str(if mem::take(&mut needs_impl_header) {
912-
"Implements notable traits: "
912+
"Implements notable traits: `"
913913
} else {
914-
", "
914+
"`, `"
915915
});
916916
format_to!(desc, "{}", trait_.name(db).display(db, edition));
917917
if !assoc_types.is_empty() {
@@ -931,7 +931,12 @@ fn render_notable_trait(
931931
desc.push('>');
932932
}
933933
}
934-
desc.is_empty().not().then_some(desc)
934+
if desc.is_empty() {
935+
None
936+
} else {
937+
desc.push('`');
938+
Some(desc)
939+
}
935940
}
936941

937942
fn type_info(
@@ -958,37 +963,12 @@ fn type_info(
958963
res.markup = if let Some(adjusted_ty) = adjusted {
959964
walk_and_push_ty(db, &adjusted_ty, &mut push_new_def);
960965

961-
let notable = {
962-
let mut desc = String::new();
963-
let mut needs_impl_header = true;
964-
for (trait_, assoc_types) in notable_traits(db, &original) {
965-
desc.push_str(if mem::take(&mut needs_impl_header) {
966-
"Implements Notable Traits: "
967-
} else {
968-
", "
969-
});
970-
format_to!(desc, "{}", trait_.name(db).display(db, edition));
971-
if !assoc_types.is_empty() {
972-
desc.push('<');
973-
format_to!(
974-
desc,
975-
"{}",
976-
assoc_types.into_iter().format_with(", ", |(ty, name), f| {
977-
f(&name.display(db, edition))?;
978-
f(&" = ")?;
979-
match ty {
980-
Some(ty) => f(&ty.display(db, display_target)),
981-
None => f(&"?"),
982-
}
983-
})
984-
);
985-
desc.push('>');
986-
}
987-
}
988-
if !desc.is_empty() {
989-
desc.push('\n');
990-
}
991-
desc
966+
let notable = if let Some(notable) =
967+
render_notable_trait(db, &notable_traits(db, &original), edition, display_target)
968+
{
969+
format!("{notable}\n")
970+
} else {
971+
String::new()
992972
};
993973

994974
let original = original.display(db, display_target).to_string();

crates/ide/src/hover/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8929,7 +8929,7 @@ fn main(notable$0: u32) {}
89298929
89308930
---
89318931
8932-
Implements notable traits: Notable\<Assoc = &str, Assoc2 = char>
8932+
Implements notable traits: `Notable<Assoc = &str, Assoc2 = char>`
89338933
89348934
---
89358935
@@ -9054,7 +9054,7 @@ fn main() {
90549054
S
90559055
```
90569056
___
9057-
Implements notable traits: Future<Output = u32>, Iterator<Item = S>, Notable"#]],
9057+
Implements notable traits: `Future<Output = u32>`, `Iterator<Item = S>`, `Notable`"#]],
90589058
);
90599059
}
90609060

0 commit comments

Comments
 (0)