Skip to content

Commit dde93c9

Browse files
committed
rustdoc: clean QPath::LangItem
This commit adds support for cleaning `QPath::LangItem` and `hir::GenericBound::LangItemTrait` in rustdoc. `QPath::LangItem` does not require lowering, and `hir::GenericBound::LangItemTrait` is lowered to a `GenericBound::TraitBound`. Signed-off-by: David Wood <[email protected]>
1 parent 8367af4 commit dde93c9

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/librustdoc/clean/mod.rs

+20
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_hir::def::{CtorKind, DefKind, Res};
1717
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX};
1818
use rustc_index::vec::{Idx, IndexVec};
1919
use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData};
20+
use rustc_middle::bug;
2021
use rustc_middle::middle::resolve_lifetime as rl;
2122
use rustc_middle::middle::stability;
2223
use rustc_middle::ty::fold::TypeFolder;
@@ -291,6 +292,22 @@ impl Clean<GenericBound> for hir::GenericBound<'_> {
291292
fn clean(&self, cx: &DocContext<'_>) -> GenericBound {
292293
match *self {
293294
hir::GenericBound::Outlives(lt) => GenericBound::Outlives(lt.clean(cx)),
295+
hir::GenericBound::LangItemTrait(lang_item, span, _, generic_args) => {
296+
let def_id = cx.tcx.require_lang_item(lang_item, Some(span));
297+
298+
let trait_ref = ty::TraitRef::identity(cx.tcx, def_id);
299+
300+
let generic_args = generic_args.clean(cx);
301+
let bindings = match generic_args {
302+
GenericArgs::AngleBracketed { bindings, .. } => bindings,
303+
_ => bug!("clean: parenthesized `GenericBound::LangItemTrait`"),
304+
};
305+
306+
GenericBound::TraitBound(
307+
PolyTrait { trait_: (trait_ref, &*bindings).clean(cx), generic_params: vec![] },
308+
hir::TraitBoundModifier::None,
309+
)
310+
}
294311
hir::GenericBound::Trait(ref t, modifier) => {
295312
GenericBound::TraitBound(t.clean(cx), modifier)
296313
}
@@ -1504,6 +1521,9 @@ impl Clean<Type> for hir::Ty<'_> {
15041521
trait_: box resolve_type(cx, trait_path.clean(cx), self.hir_id),
15051522
}
15061523
}
1524+
TyKind::Path(hir::QPath::LangItem(..)) => {
1525+
bug!("clean: requiring documentation of lang item")
1526+
}
15071527
TyKind::TraitObject(ref bounds, ref lifetime) => {
15081528
match bounds[0].clean(cx).trait_ {
15091529
ResolvedPath { path, param_names: None, did, is_generic } => {

src/librustdoc/clean/utils.rs

+1
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ pub fn qpath_to_string(p: &hir::QPath<'_>) -> String {
335335
let segments = match *p {
336336
hir::QPath::Resolved(_, ref path) => &path.segments,
337337
hir::QPath::TypeRelative(_, ref segment) => return segment.ident.to_string(),
338+
hir::QPath::LangItem(lang_item, ..) => return lang_item.name().to_string(),
338339
};
339340

340341
let mut s = String::new();

0 commit comments

Comments
 (0)