-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rustdoc: Cleanup clean
part 2
#88895
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,7 +168,7 @@ impl Clean<Type> for (ty::TraitRef<'_>, &[TypeBinding]) { | |
|
||
debug!("ty::TraitRef\n subst: {:?}\n", trait_ref.substs); | ||
|
||
ResolvedPath { path, did: trait_ref.def_id, is_generic: false } | ||
ResolvedPath { path, did: trait_ref.def_id } | ||
} | ||
} | ||
|
||
|
@@ -1442,12 +1442,12 @@ impl<'tcx> Clean<Type> for Ty<'tcx> { | |
}; | ||
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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This path is for a |
||
ResolvedPath { path, did } | ||
} | ||
ty::Foreign(did) => { | ||
inline::record_extern_fqn(cx, did, ItemType::ForeignType); | ||
let path = external_path(cx, did, false, vec![], InternalSubsts::empty()); | ||
ResolvedPath { path, did, is_generic: false } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This path is for an |
||
ResolvedPath { path, did } | ||
} | ||
ty::Dynamic(ref obj, ref reg) => { | ||
// HACK: pick the first `did` as the `did` of the trait object. Someone | ||
|
@@ -1473,7 +1473,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> { | |
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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This path is for one of the trait bounds after the first (i.e., one of the auto trait bounds) in a |
||
trait_: ResolvedPath { path, did }, | ||
generic_params: Vec::new(), | ||
}; | ||
bounds.push(bound); | ||
|
@@ -1490,10 +1490,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> { | |
let path = external_path(cx, did, false, bindings, substs); | ||
bounds.insert( | ||
0, | ||
PolyTrait { | ||
trait_: ResolvedPath { path, did, is_generic: false }, | ||
generic_params: Vec::new(), | ||
}, | ||
Comment on lines
-1493
to
-1496
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This path is for the first trait bound in a |
||
PolyTrait { trait_: ResolvedPath { path, did }, generic_params: Vec::new() }, | ||
); | ||
|
||
DynTrait(bounds, lifetime) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1114,10 +1114,7 @@ impl GenericBound { | |
let path = external_path(cx, did, false, vec![], empty); | ||
inline::record_extern_fqn(cx, did, ItemType::Trait); | ||
GenericBound::TraitBound( | ||
PolyTrait { | ||
trait_: ResolvedPath { path, did, is_generic: false }, | ||
generic_params: Vec::new(), | ||
}, | ||
Comment on lines
-1117
to
-1120
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This path belongs to the |
||
PolyTrait { trait_: ResolvedPath { path, did }, generic_params: Vec::new() }, | ||
hir::TraitBoundModifier::Maybe, | ||
) | ||
} | ||
|
@@ -1384,8 +1381,6 @@ crate enum Type { | |
ResolvedPath { | ||
path: Path, | ||
did: DefId, | ||
/// `true` if is a `T::Name` path for associated types. | ||
camelid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
is_generic: bool, | ||
}, | ||
/// `dyn for<'a> Trait<'a> + Send + 'static` | ||
DynTrait(Vec<PolyTrait>, Option<Lifetime>), | ||
|
@@ -1504,8 +1499,8 @@ impl Type { | |
} | ||
|
||
crate fn is_generic(&self) -> bool { | ||
match *self { | ||
ResolvedPath { is_generic, .. } => is_generic, | ||
match self { | ||
ResolvedPath { path, .. } => path.is_generic(), | ||
_ => false, | ||
} | ||
} | ||
|
@@ -1994,6 +1989,15 @@ impl Path { | |
String::from(if self.global { "::" } else { "" }) | ||
+ &self.segments.iter().map(|s| s.name.to_string()).collect::<Vec<_>>().join("::") | ||
} | ||
|
||
crate fn is_generic(&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, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, PartialEq, Eq, Debug, Hash)] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,9 +159,7 @@ pub(super) fn external_path( | |
|
||
crate fn strip_type(ty: Type) -> Type { | ||
match ty { | ||
Type::ResolvedPath { path, did, is_generic } => { | ||
Type::ResolvedPath { path: strip_path(&path), did, is_generic } | ||
} | ||
Type::ResolvedPath { path, did } => Type::ResolvedPath { path: strip_path(&path), did }, | ||
Type::DynTrait(mut bounds, lt) => { | ||
let first = bounds.remove(0); | ||
let stripped_trait = strip_type(first.trait_); | ||
|
@@ -404,19 +402,15 @@ crate fn print_const_expr(tcx: TyCtxt<'_>, body: hir::BodyId) -> String { | |
crate fn resolve_type(cx: &mut DocContext<'_>, path: Path) -> Type { | ||
debug!("resolve_type({:?})", path); | ||
|
||
let is_generic = match path.res { | ||
Res::PrimTy(p) => return Primitive(PrimitiveType::from(p)), | ||
Res::SelfTy(..) if path.segments.len() == 1 => { | ||
return Generic(kw::SelfUpper); | ||
} | ||
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => { | ||
return Generic(path.segments[0].name); | ||
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 } | ||
} | ||
} | ||
Comment on lines
+405
to
414
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The part of this code that computed |
||
|
||
crate fn get_auto_trait_and_blanket_impls( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -752,9 +752,9 @@ fn fmt_type<'cx>( | |
|
||
match *t { | ||
clean::Generic(name) => write!(f, "{}", name), | ||
clean::ResolvedPath { did, ref path, is_generic } => { | ||
clean::ResolvedPath { did, ref path } => { | ||
// Paths like `T::Output` and `Self::Output` should be rendered with all segments. | ||
resolved_path(f, did, path, is_generic, use_absolute, cx) | ||
resolved_path(f, did, path, path.is_generic(), use_absolute, cx) | ||
} | ||
clean::DynTrait(ref bounds, ref lt) => { | ||
f.write_str("dyn ")?; | ||
|
@@ -825,28 +825,17 @@ fn fmt_type<'cx>( | |
hir::Mutability::Mut => "mut", | ||
hir::Mutability::Not => "const", | ||
}; | ||
match **t { | ||
clean::Generic(_) | clean::ResolvedPath { is_generic: true, .. } => { | ||
if f.alternate() { | ||
primitive_link( | ||
f, | ||
clean::PrimitiveType::RawPointer, | ||
&format!("*{} {:#}", m, t.print(cx)), | ||
cx, | ||
) | ||
} else { | ||
primitive_link( | ||
f, | ||
clean::PrimitiveType::RawPointer, | ||
&format!("*{} {}", m, t.print(cx)), | ||
cx, | ||
) | ||
} | ||
} | ||
_ => { | ||
primitive_link(f, clean::PrimitiveType::RawPointer, &format!("*{} ", m), cx)?; | ||
fmt::Display::fmt(&t.print(cx), f) | ||
} | ||
|
||
if matches!(**t, clean::Generic(_)) || t.is_generic() { | ||
jyn514 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let text = if f.alternate() { | ||
format!("*{} {:#}", m, t.print(cx)) | ||
} else { | ||
format!("*{} {}", m, t.print(cx)) | ||
}; | ||
primitive_link(f, clean::PrimitiveType::RawPointer, &text, cx) | ||
} else { | ||
primitive_link(f, clean::PrimitiveType::RawPointer, &format!("*{} ", m), cx)?; | ||
fmt::Display::fmt(&t.print(cx), f) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made a couple of cleanup changes here to reduce rightward drift and make the code easier to understand:
The only other change is replacing the pattern |
||
} | ||
clean::BorrowedRef { lifetime: ref l, mutability, type_: ref ty } => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This path is for a trait in a
ty::TraitRef
(e.g., awhere
clause trait bound), so itsRes
should be correct and preserve theis_generic: false
behavior.