Auto merge of #18349 - dqkqd:issue-18344, r=Veykril

feat: render docs from aliased type when type has no docs

Trying to close #18344

- [x] ~Find the docs by traversing upwards if the type itself has none but aliasing for another type that might have.~
- [x] Show docs from aliased type.
- [x] Showing description that we are displaying documentation for different definition in hover box.

![image](https://github.com/user-attachments/assets/820d6f97-aa2c-4dc4-8a25-75746e32d950)
This commit is contained in:
bors 2024-10-22 11:56:16 +00:00
commit eddab6e98c
2 changed files with 166 additions and 1 deletions

View file

@ -178,7 +178,19 @@ impl Definition {
Definition::Static(it) => it.docs(db),
Definition::Trait(it) => it.docs(db),
Definition::TraitAlias(it) => it.docs(db),
Definition::TypeAlias(it) => it.docs(db),
Definition::TypeAlias(it) => {
it.docs(db).or_else(|| {
// docs are missing, try to fall back to the docs of the aliased item.
let adt = it.ty(db).as_adt()?;
let docs = adt.docs(db)?;
let docs = format!(
"*This is the documentation for* `{}`\n\n{}",
adt.display(db, edition),
docs.as_str()
);
Some(Documentation::new(docs))
})
}
Definition::BuiltinType(it) => {
famous_defs.and_then(|fd| {
// std exposes prim_{} modules with docstrings on the root to document the builtins