Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2994bb4

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

File tree

6 files changed

+37
-2
lines changed

6 files changed

+37
-2
lines changed

‎compiler/rustc_hir/src/hir.rs

Lines changed: 7 additions & 0 deletions
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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ fn clean_generic_bound<'tcx>(
229229
GenericBound::TraitBound(clean_poly_trait_ref(t, cx), modifier)
230230
}
231231
// FIXME(precise_capturing): Implement rustdoc support
232-
hir::GenericBound::Use(..) => return None,
232+
hir::GenericBound::Use(args, ..) => {
233+
GenericBound::Use(args.iter().map(|arg| arg.name()).collect())
234+
}
233235
})
234236
}
235237

‎src/librustdoc/clean/simplify.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,16 @@ impl clean::GenericBound {
412412
})?;
413413
ty.print(cx).fmt(f)
414414
}
415+
clean::GenericBound::Use(args) => {
416+
write!(f, "use<")?;
417+
for (i, arg) in args.iter().enumerate() {
418+
if i > 0 {
419+
write!(f, ", ")?;
420+
}
421+
arg.fmt(f)?;
422+
}
423+
write!(f, ">")
424+
}
415425
})
416426
}
417427
}
Lines changed: 14 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /