rustdoc: Cleanup clean part 2#88895
Conversation
It can be computed on-demand.
The new name is more accurate than the previous one.
camelid
left a comment
There was a problem hiding this comment.
I left explanatory comments on each nontrivial part of the diff to hopefully make this change easier to review :)
| match path.res { | ||
| Res::PrimTy(p) => Primitive(PrimitiveType::from(p)), | ||
| Res::SelfTy(..) if path.segments.len() == 1 => Generic(kw::SelfUpper), | ||
| Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => Generic(path.segments[0].name), | ||
| _ => { | ||
| let did = register_res(cx, path.res); | ||
| ResolvedPath { path, did } | ||
| } | ||
| Res::SelfTy(..) | Res::Def(DefKind::TyParam | DefKind::AssocTy, _) => true, | ||
| _ => false, | ||
| }; | ||
| let did = register_res(cx, path.res); | ||
| ResolvedPath { path, did, is_generic } | ||
| } | ||
| } |
There was a problem hiding this comment.
The part of this code that computed is_generic is now covered by Path::is_assoc_ty(), so I removed it.
| crate fn is_assoc_ty(&self) -> bool { | ||
| match self.res { | ||
| Res::SelfTy(..) if self.segments.len() != 1 => true, | ||
| Res::Def(DefKind::TyParam, _) if self.segments.len() != 1 => true, | ||
| Res::Def(DefKind::AssocTy, _) => true, | ||
| _ => false, | ||
| } | ||
| } |
There was a problem hiding this comment.
This code is adapted directly from resolve_type().
| PolyTrait { | ||
| trait_: ResolvedPath { path, did, is_generic: false }, | ||
| generic_params: Vec::new(), | ||
| }, |
There was a problem hiding this comment.
This path belongs to the Sized trait, so it's not an associated type, and Path::is_assoc_ty should preserve that because the Res should be "correct by construction".
| PolyTrait { | ||
| trait_: ResolvedPath { path, did, is_generic: false }, | ||
| generic_params: Vec::new(), | ||
| }, |
There was a problem hiding this comment.
This path is for the first trait bound in a dyn Trait1 + Trait2 + ... object, so its Res should be correct and preserve the is_generic: false behavior.
| let path = external_path(cx, did, false, vec![], empty); | ||
| inline::record_extern_fqn(cx, did, ItemType::Trait); | ||
| let bound = PolyTrait { | ||
| trait_: ResolvedPath { path, did, is_generic: false }, |
There was a problem hiding this comment.
This path is for one of the trait bounds after the first (i.e., one of the auto trait bounds) in a dyn Trait1 + Trait2 + ... object, so its Res should be correct and preserve the is_generic: false behavior.
| }; | ||
| inline::record_extern_fqn(cx, did, kind); | ||
| let path = external_path(cx, did, false, vec![], substs); | ||
| ResolvedPath { path, did, is_generic: false } |
There was a problem hiding this comment.
This path is for a struct/enum/union declaration, so its Res should be correct and preserve the is_generic: false behavior.
|
|
||
| debug!("ty::TraitRef\n subst: {:?}\n", trait_ref.substs); | ||
|
|
||
| ResolvedPath { path, did: trait_ref.def_id, is_generic: false } |
There was a problem hiding this comment.
This path is for a trait in a ty::TraitRef (e.g., a where clause trait bound), so its Res should be correct and preserve the is_generic: false behavior.
| clean::ResolvedPath { ref path, .. } | ||
| | clean::BorrowedRef { type_: box clean::ResolvedPath { ref path, .. }, .. } | ||
| if !path.is_assoc_ty() => | ||
| { | ||
| implementor_dups[&path.last()].1 | ||
| } |
There was a problem hiding this comment.
is_assoc_ty() is the replacement for is_generic == true; this is the negation of that.
| clean::ResolvedPath { ref path, did, .. } | ||
| | clean::BorrowedRef { | ||
| type_: box clean::ResolvedPath { ref path, did, is_generic: false, .. }, | ||
| .. | ||
| } => { | ||
| type_: box clean::ResolvedPath { ref path, did, .. }, .. | ||
| } if !path.is_assoc_ty() => { |
There was a problem hiding this comment.
Same as the above comment.
| } else { | ||
| primitive_link(f, clean::PrimitiveType::RawPointer, &format!("*{} ", m), cx)?; | ||
| fmt::Display::fmt(&t.print(cx), f) | ||
| } |
There was a problem hiding this comment.
I made a couple of cleanup changes here to reduce rightward drift and make the code easier to understand:
- replaced
matchwithif matches! - extracted a
textlocal variable
The only other change is replacing the pattern clean::Generic(_) | clean::ResolvedPath { is_generic: true, .. } with the conditional if matches!(**t, clean::Generic(_)) || t.is_assoc_ty()), which is necessary now that the is_generic field has been removed in favor of using an is_assoc_ty() function.
jyn514
left a comment
There was a problem hiding this comment.
This is awesome ❤️ I just have a couple nits.
It's adapted from the old documentation for the `is_generic` field.
|
I re-added the documentation, but I did not remove the |
|
@bors r+ Thanks! |
|
📌 Commit dace2ee has been approved by |
|
⌛ Testing commit dace2ee with merge b05ffbcff9af79f70d6f5889c7ec7a784ee934d0... |
…arth Rollup of 7 pull requests Successful merges: - rust-lang#88895 (rustdoc: Cleanup `clean` part 2) - rust-lang#88973 (Expose the std_detect env_override feature) - rust-lang#89010 (Add some intra doc links) - rust-lang#89198 (rustdoc: Don't show hidden trait methods) - rust-lang#89216 (Consistent big O notation) - rust-lang#89224 (Change the order of imports suggestions) - rust-lang#89256 (Fix typo in release notes) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Split out from #88379. This contains the following commits from that PR:
Type::ResolvedPath.is_genericis_generic()tois_assoc_ty()r? @jyn514