diff options
| author | Yuki Okushi <huyuumi.dev+love@gmail.com> | 2022-11-07 09:46:25 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-07 09:46:25 +0900 |
| commit | 63f78d17b4c302bcf96bae306ffb42eecb0a5e6f (patch) | |
| tree | 850c2afee8f691ccc11ad863490aa1ebf0178133 /src/librustdoc/clean/inline.rs | |
| parent | 7eef946fc0e0eff40e588eab77b09b287accbec3 (diff) | |
| parent | 5ccaed212e111e0850a764c1c090261c0c431413 (diff) | |
Rollup merge of #103885 - fmease:rustdoc-various-cross-crate-reexport-fixes, r=cjgillot,GuillaumeGomez
rustdoc: various cross-crate reexport fixes
Fixes for various smaller cross-crate reexport issues.
The PR is split into several commits for easier review. Will be squashed after approval.
Most notable changes:
* We finally render late-bound lifetimes in the generic parameter list of cross-crate functions & methods.
Previously, we would display the re-export of `pub fn f<'s>(x: &'s str) {}` as `pub fn f(x: &'s str)`
* We now render unnamed parameters of cross-crate functions and function pointers as underscores
since that's exactly what we do for local definitions, too. Mentioned as a bug in #44306.
* From now on, the rendering of cross-crate trait-object types is more correct:
* `for<>` parameter lists (for higher-ranked lifetimes) are now shown
* the return type of `Fn{,Mut,Once}` trait bounds is now displayed
Regarding the last list item, here is a diff for visualization (before vs. after):
```patch
- dyn FnOnce(&'any str) + 'static
+ dyn for<'any> FnOnce(&'any str) -> bool + 'static
```
The redundant `+ 'static` will be removed in a follow-up PR that will hide trait-object lifetime-bounds if they coincide with [their default](https://doc.rust-lang.org/reference/lifetime-elision.html#default-trait-object-lifetimes) (see [Zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/clean_middle_ty.3A.20I.20need.20to.20add.20a.20parameter/near/307143097)). `FIXME(fmease)`s were added.
``@rustbot`` label A-cross-crate-reexports
r? ``@GuillaumeGomez``
Diffstat (limited to 'src/librustdoc/clean/inline.rs')
| -rw-r--r-- | src/librustdoc/clean/inline.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 841c4f9d530..8a5463c10f2 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -243,10 +243,19 @@ pub(crate) fn build_external_trait(cx: &mut DocContext<'_>, did: DefId) -> clean fn build_external_function<'tcx>(cx: &mut DocContext<'tcx>, did: DefId) -> Box<clean::Function> { let sig = cx.tcx.fn_sig(did); - let predicates = cx.tcx.predicates_of(did); + let late_bound_regions = sig.bound_vars().into_iter().filter_map(|var| match var { + ty::BoundVariableKind::Region(ty::BrNamed(_, name)) if name != kw::UnderscoreLifetime => { + Some(clean::GenericParamDef::lifetime(name)) + } + _ => None, + }); + + let predicates = cx.tcx.explicit_predicates_of(did); let (generics, decl) = clean::enter_impl_trait(cx, |cx| { // NOTE: generics need to be cleaned before the decl! - let generics = clean_ty_generics(cx, cx.tcx.generics_of(did), predicates); + let mut generics = clean_ty_generics(cx, cx.tcx.generics_of(did), predicates); + // FIXME: This does not place parameters in source order (late-bound ones come last) + generics.params.extend(late_bound_regions); let decl = clean_fn_decl_from_did_and_sig(cx, Some(did), sig); (generics, decl) }); |
