Merge pull request #19651 from roife/enhance-notable-trait-render

minor: simplify and enhance notable traits rendering
This commit is contained in:
Lukas Wirth 2025-04-21 11:48:43 +00:00 committed by GitHub
commit 5004778384
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 36 deletions

View File

@ -909,9 +909,9 @@ fn render_notable_trait(
let mut needs_impl_header = true;
for (trait_, assoc_types) in notable_traits {
desc.push_str(if mem::take(&mut needs_impl_header) {
"Implements notable traits: "
"Implements notable traits: `"
} else {
", "
"`, `"
});
format_to!(desc, "{}", trait_.name(db).display(db, edition));
if !assoc_types.is_empty() {
@ -931,7 +931,12 @@ fn render_notable_trait(
desc.push('>');
}
}
desc.is_empty().not().then_some(desc)
if desc.is_empty() {
None
} else {
desc.push('`');
Some(desc)
}
}
fn type_info(
@ -958,37 +963,12 @@ fn type_info(
res.markup = if let Some(adjusted_ty) = adjusted {
walk_and_push_ty(db, &adjusted_ty, &mut push_new_def);
let notable = {
let mut desc = String::new();
let mut needs_impl_header = true;
for (trait_, assoc_types) in notable_traits(db, &original) {
desc.push_str(if mem::take(&mut needs_impl_header) {
"Implements Notable Traits: "
} else {
", "
});
format_to!(desc, "{}", trait_.name(db).display(db, edition));
if !assoc_types.is_empty() {
desc.push('<');
format_to!(
desc,
"{}",
assoc_types.into_iter().format_with(", ", |(ty, name), f| {
f(&name.display(db, edition))?;
f(&" = ")?;
match ty {
Some(ty) => f(&ty.display(db, display_target)),
None => f(&"?"),
}
})
);
desc.push('>');
}
}
if !desc.is_empty() {
desc.push('\n');
}
desc
let notable = if let Some(notable) =
render_notable_trait(db, &notable_traits(db, &original), edition, display_target)
{
format!("{notable}\n")
} else {
String::new()
};
let original = original.display(db, display_target).to_string();

View File

@ -8929,7 +8929,7 @@ fn main(notable$0: u32) {}
---
Implements notable traits: Notable\<Assoc = &str, Assoc2 = char>
Implements notable traits: `Notable<Assoc = &str, Assoc2 = char>`
---
@ -9054,7 +9054,7 @@ fn main() {
S
```
___
Implements notable traits: Future<Output = u32>, Iterator<Item = S>, Notable"#]],
Implements notable traits: `Future<Output = u32>`, `Iterator<Item = S>`, `Notable`"#]],
);
}