Skip to content

Commit 843f5dd

Browse files
Add rustdoc support for use<> in (local) RPITs
1 parent 5315cbe commit 843f5dd

File tree

6 files changed

+41
-3
lines changed

6 files changed

+41
-3
lines changed

compiler/rustc_hir/src/hir.rs

+7
Original file line numberDiff line numberDiff line change
@@ -2708,6 +2708,13 @@ impl PreciseCapturingArg<'_> {
27082708
PreciseCapturingArg::Param(param) => param.hir_id,
27092709
}
27102710
}
2711+
2712+
pub fn name(self) -> Symbol {
2713+
match self {
2714+
PreciseCapturingArg::Lifetime(lt) => lt.ident.name,
2715+
PreciseCapturingArg::Param(param) => param.ident.name,
2716+
}
2717+
}
27112718
}
27122719

27132720
/// We need to have a [`Node`] for the [`HirId`] that we attach the type/const param

src/librustdoc/clean/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,9 @@ fn clean_generic_bound<'tcx>(
228228

229229
GenericBound::TraitBound(clean_poly_trait_ref(t, cx), modifier)
230230
}
231-
// FIXME(precise_capturing): Implement rustdoc support
232-
hir::GenericBound::Use(..) => return None,
231+
hir::GenericBound::Use(args, ..) => {
232+
GenericBound::Use(args.iter().map(|arg| arg.name()).collect())
233+
}
233234
})
234235
}
235236

src/librustdoc/clean/simplify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub(crate) fn merge_bounds(
7979
!bounds.iter_mut().any(|b| {
8080
let trait_ref = match *b {
8181
clean::GenericBound::TraitBound(ref mut tr, _) => tr,
82-
clean::GenericBound::Outlives(..) => return false,
82+
clean::GenericBound::Outlives(..) | clean::GenericBound::Use(_) => return false,
8383
};
8484
// If this QPath's trait `trait_did` is the same as, or a supertrait
8585
// of, the bound's trait `did` then we can keep going, otherwise

src/librustdoc/clean/types.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,8 @@ impl Eq for Attributes {}
12441244
pub(crate) enum GenericBound {
12451245
TraitBound(PolyTrait, hir::TraitBoundModifier),
12461246
Outlives(Lifetime),
1247+
/// `use<'a, T>` precise-capturing bound syntax
1248+
Use(Vec<Symbol>),
12471249
}
12481250

12491251
impl GenericBound {

src/librustdoc/html/format.rs

+14
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,20 @@ impl clean::GenericBound {
412412
})?;
413413
ty.print(cx).fmt(f)
414414
}
415+
clean::GenericBound::Use(args) => {
416+
if f.alternate() {
417+
f.write_str("use<")?;
418+
} else {
419+
f.write_str("use&lt;")?;
420+
}
421+
for (i, arg) in args.iter().enumerate() {
422+
if i > 0 {
423+
write!(f, ", ")?;
424+
}
425+
arg.fmt(f)?;
426+
}
427+
if f.alternate() { f.write_str(">") } else { f.write_str("&gt;") }
428+
}
415429
})
416430
}
417431
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![crate_name = "foo"]
2+
#![feature(precise_capturing)]
3+
4+
//@ has foo/fn.two.html '//section[@id="main-content"]//pre' "-> impl Sized + use<'b, 'a>"
5+
pub fn two<'a, 'b, 'c>() -> impl Sized + use<'b, 'a /* no 'c */> {}
6+
7+
//@ has foo/fn.params.html '//section[@id="main-content"]//pre' "-> impl Sized + use<'a, T, N>"
8+
pub fn params<'a, T, const N: usize>() -> impl Sized + use<'a, T, N> {}
9+
10+
//@ has foo/fn.none.html '//section[@id="main-content"]//pre' "-> impl Sized + use<>"
11+
pub fn none() -> impl Sized + use<> {}
12+
13+
//@ has foo/fn.first.html '//section[@id="main-content"]//pre' "-> impl use<> + Sized"
14+
pub fn first() -> impl use<> + Sized {}

0 commit comments

Comments
 (0)