Skip to content

Commit c0ca97f

Browse files
committed
rustdoc support for FRTs
1 parent 3a33d16 commit c0ca97f

File tree

6 files changed

+23
-3
lines changed

6 files changed

+23
-3
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,9 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
18341834
TyKind::UnsafeBinder(unsafe_binder_ty) => {
18351835
UnsafeBinder(Box::new(clean_unsafe_binder_ty(unsafe_binder_ty, cx)))
18361836
}
1837+
TyKind::FieldOf(container, field_path) => Field(Box::new(clean_ty(container, cx)), {
1838+
field_path.iter().map(|field| field.as_str()).intersperse(".").collect()
1839+
}),
18371840
// Rustdoc handles `TyKind::Err`s by turning them into `Type::Infer`s.
18381841
TyKind::Infer(())
18391842
| TyKind::Err(_)
@@ -2077,6 +2080,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
20772080
let path = clean_middle_path(cx, did, false, ThinVec::new(), bound_ty.rebind(args));
20782081
Type::Path { path }
20792082
}
2083+
ty::Field(..) => todo!("FIXME(field_projections): no idea what to do here"),
20802084
ty::Foreign(did) => {
20812085
inline::record_extern_fqn(cx, did, ItemType::ForeignType);
20822086
let path = clean_middle_path(

src/librustdoc/clean/types.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use {rustc_ast as ast, rustc_hir as hir};
3030

3131
pub(crate) use self::ItemKind::*;
3232
pub(crate) use self::Type::{
33-
Array, BareFunction, BorrowedRef, DynTrait, Generic, ImplTrait, Infer, Primitive, QPath,
33+
Array, BareFunction, BorrowedRef, DynTrait, Field, Generic, ImplTrait, Infer, Primitive, QPath,
3434
RawPointer, SelfTy, Slice, Tuple, UnsafeBinder,
3535
};
3636
use crate::clean::cfg::Cfg;
@@ -1568,6 +1568,9 @@ pub(crate) enum Type {
15681568
ImplTrait(Vec<GenericBound>),
15691569

15701570
UnsafeBinder(Box<UnsafeBinderTy>),
1571+
1572+
/// Field representing type `field_of!(container, field_path)`
1573+
Field(Box<Type>, Box<str>),
15711574
}
15721575

15731576
impl Type {
@@ -1764,7 +1767,9 @@ impl Type {
17641767
Type::Pat(..) => PrimitiveType::Pat,
17651768
RawPointer(..) => PrimitiveType::RawPointer,
17661769
QPath(box QPathData { self_type, .. }) => return self_type.def_id(cache),
1767-
Generic(_) | SelfTy | Infer | ImplTrait(_) | UnsafeBinder(_) => return None,
1770+
Field(..) | Generic(_) | SelfTy | Infer | ImplTrait(_) | UnsafeBinder(_) => {
1771+
return None;
1772+
}
17681773
};
17691774
Primitive(t).def_id(cache)
17701775
}

src/librustdoc/html/format.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,13 @@ fn fmt_type(
10341034
print_generic_bounds(bounds, cx).fmt(f)
10351035
}
10361036
clean::QPath(qpath) => qpath.print(cx).fmt(f),
1037+
clean::Field(container, field_path) => {
1038+
f.write_str("field_of!(")?;
1039+
fmt_type(&container, f, use_absolute, cx)?;
1040+
f.write_str(", ")?;
1041+
f.write_str(field_path)?;
1042+
f.write_str(")")
1043+
}
10371044
}
10381045
}
10391046

src/librustdoc/html/render/search_index.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,6 +2050,7 @@ fn get_index_type_id(
20502050
}
20512051
// Not supported yet
20522052
clean::Type::Pat(..)
2053+
| clean::Field(..)
20532054
| clean::Generic(_)
20542055
| clean::SelfTy
20552056
| clean::ImplTrait(_)

src/librustdoc/json/conversions.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ impl FromClean<rustc_hir::TraitBoundModifiers> for TraitBoundModifier {
554554
impl FromClean<clean::Type> for Type {
555555
fn from_clean(ty: &clean::Type, renderer: &JsonRenderer<'_>) -> Self {
556556
use clean::Type::{
557-
Array, BareFunction, BorrowedRef, Generic, ImplTrait, Infer, Primitive, QPath,
557+
Array, BareFunction, BorrowedRef, Field, Generic, ImplTrait, Infer, Primitive, QPath,
558558
RawPointer, SelfTy, Slice, Tuple, UnsafeBinder,
559559
};
560560

@@ -592,6 +592,8 @@ impl FromClean<clean::Type> for Type {
592592
QPath(qpath) => qpath.into_json(renderer),
593593
// FIXME(unsafe_binder): Implement rustdoc-json.
594594
UnsafeBinder(_) => todo!(),
595+
// FIXME(field_projections): Implement
596+
Field(..) => todo!(),
595597
}
596598
}
597599
}

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ impl<'tcx> LinkCollector<'_, 'tcx> {
564564
ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did, .. }, _)), _) | ty::Foreign(did) => {
565565
Res::from_def_id(self.cx.tcx, did)
566566
}
567+
ty::Field(..) => bug!("FIXME(field_projections): what to do here?"),
567568
ty::Alias(..)
568569
| ty::Closure(..)
569570
| ty::CoroutineClosure(..)

0 commit comments

Comments
 (0)