Skip to content

Commit 854d2ab

Browse files
committed
fix pattern types rendering in rustdoc
1 parent 49b6ac0 commit 854d2ab

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/librustdoc/clean/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1808,7 +1808,15 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
18081808
BorrowedRef { lifetime, mutability: m.mutbl, type_: Box::new(clean_ty(m.ty, cx)) }
18091809
}
18101810
TyKind::Slice(ty) => Slice(Box::new(clean_ty(ty, cx))),
1811-
TyKind::Pat(ty, pat) => Type::Pat(Box::new(clean_ty(ty, cx)), format!("{pat:?}").into()),
1811+
TyKind::Pat(inner_ty, pat) => {
1812+
// Local HIR pattern types should print the same way as cross-crate inlined ones,
1813+
// so lower to the canonical `rustc_middle::ty::Pattern` representation first.
1814+
let pat = match lower_ty(cx.tcx, ty).kind() {
1815+
ty::Pat(_, pat) => format!("{pat:?}").into_boxed_str(),
1816+
_ => format!("{pat:?}").into(),
1817+
};
1818+
Type::Pat(Box::new(clean_ty(inner_ty, cx)), pat)
1819+
}
18121820
TyKind::FieldOf(ty, hir::TyFieldPath { variant, field }) => {
18131821
let field_str = if let Some(variant) = variant {
18141822
format!("{variant}.{field}")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(pattern_types, pattern_type_macro)]
2+
#![crate_name = "pattern_types_implementors"]
3+
4+
use std::pat::pattern_type;
5+
6+
pub trait MyTrait {}
7+
8+
impl MyTrait for pattern_type!(*const u8 is !null) {}
9+
10+
//@ has pattern_types_implementors/trait.MyTrait.html
11+
//@ has - '//*[@id="implementors-list"]/*[@class="impl"]' 'impl MyTrait for *const u8 is !null'
12+
//@ !has - '//*[@id="implementors-list"]/*[@class="impl"]' 'TyPat {'

0 commit comments

Comments
 (0)