Thread pattern types through the HIR
This commit is contained in:
parent
c340e67dec
commit
c4efc25bfa
15 changed files with 48 additions and 5 deletions
|
|
@ -1782,6 +1782,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
|
|||
BorrowedRef { lifetime, mutability: m.mutbl, type_: Box::new(clean_ty(m.ty, cx)) }
|
||||
}
|
||||
TyKind::Slice(ty) => Slice(Box::new(clean_ty(ty, cx))),
|
||||
TyKind::Pat(ty, pat) => Type::Pat(Box::new(clean_ty(ty, cx)), format!("{pat:?}").into()),
|
||||
TyKind::Array(ty, ref length) => {
|
||||
let length = match length {
|
||||
hir::ArrayLen::Infer(..) => "_".to_string(),
|
||||
|
|
|
|||
|
|
@ -1483,7 +1483,9 @@ pub(crate) enum Type {
|
|||
///
|
||||
/// This is mostly Rustdoc's version of [`hir::Path`].
|
||||
/// It has to be different because Rustdoc's [`PathSegment`] can contain cleaned generics.
|
||||
Path { path: Path },
|
||||
Path {
|
||||
path: Path,
|
||||
},
|
||||
/// A `dyn Trait` object: `dyn for<'a> Trait<'a> + Send + 'static`
|
||||
DynTrait(Vec<PolyTrait>, Option<Lifetime>),
|
||||
/// A type parameter.
|
||||
|
|
@ -1500,10 +1502,15 @@ pub(crate) enum Type {
|
|||
///
|
||||
/// The `String` field is a stringified version of the array's length parameter.
|
||||
Array(Box<Type>, Box<str>),
|
||||
Pat(Box<Type>, Box<str>),
|
||||
/// A raw pointer type: `*const i32`, `*mut i32`
|
||||
RawPointer(Mutability, Box<Type>),
|
||||
/// A reference type: `&i32`, `&'a mut Foo`
|
||||
BorrowedRef { lifetime: Option<Lifetime>, mutability: Mutability, type_: Box<Type> },
|
||||
BorrowedRef {
|
||||
lifetime: Option<Lifetime>,
|
||||
mutability: Mutability,
|
||||
type_: Box<Type>,
|
||||
},
|
||||
|
||||
/// A qualified path to an associated item: `<Type as Trait>::Name`
|
||||
QPath(Box<QPathData>),
|
||||
|
|
@ -1700,6 +1707,7 @@ impl Type {
|
|||
BareFunction(..) => PrimitiveType::Fn,
|
||||
Slice(..) => PrimitiveType::Slice,
|
||||
Array(..) => PrimitiveType::Array,
|
||||
Type::Pat(..) => PrimitiveType::Pat,
|
||||
RawPointer(..) => PrimitiveType::RawPointer,
|
||||
QPath(box QPathData { ref self_type, .. }) => return self_type.inner_def_id(cache),
|
||||
Generic(_) | Infer | ImplTrait(_) => return None,
|
||||
|
|
@ -1753,6 +1761,7 @@ pub(crate) enum PrimitiveType {
|
|||
Str,
|
||||
Slice,
|
||||
Array,
|
||||
Pat,
|
||||
Tuple,
|
||||
Unit,
|
||||
RawPointer,
|
||||
|
|
@ -1907,6 +1916,7 @@ impl PrimitiveType {
|
|||
Bool => sym::bool,
|
||||
Char => sym::char,
|
||||
Array => sym::array,
|
||||
Pat => sym::pat,
|
||||
Slice => sym::slice,
|
||||
Tuple => sym::tuple,
|
||||
Unit => sym::unit,
|
||||
|
|
|
|||
|
|
@ -1071,6 +1071,10 @@ fn fmt_type<'cx>(
|
|||
write!(f, "]")
|
||||
}
|
||||
},
|
||||
clean::Type::Pat(ref t, ref pat) => {
|
||||
fmt::Display::fmt(&t.print(cx), f)?;
|
||||
write!(f, " is {pat}")
|
||||
}
|
||||
clean::Array(ref t, ref n) => match **t {
|
||||
clean::Generic(name) if !f.alternate() => primitive_link(
|
||||
f,
|
||||
|
|
|
|||
|
|
@ -668,7 +668,7 @@ fn get_index_type_id(
|
|||
}
|
||||
}
|
||||
// Not supported yet
|
||||
clean::Generic(_) | clean::ImplTrait(_) | clean::Infer => None,
|
||||
clean::Type::Pat(..) | clean::Generic(_) | clean::ImplTrait(_) | clean::Infer => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -573,6 +573,9 @@ impl FromWithTcx<clean::Type> for Type {
|
|||
Tuple(t) => Type::Tuple(t.into_tcx(tcx)),
|
||||
Slice(t) => Type::Slice(Box::new((*t).into_tcx(tcx))),
|
||||
Array(t, s) => Type::Array { type_: Box::new((*t).into_tcx(tcx)), len: s.to_string() },
|
||||
clean::Type::Pat(t, p) => {
|
||||
Type::Pat { type_: Box::new((*t).into_tcx(tcx)), pat: p.to_string() }
|
||||
}
|
||||
ImplTrait(g) => Type::ImplTrait(g.into_tcx(tcx)),
|
||||
Infer => Type::Infer,
|
||||
RawPointer(mutability, type_) => Type::RawPointer {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue