-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #112463 - fmease:rustdoc-elide-x-crate-def-gen-args, …
…r=GuillaumeGomez rustdoc: elide cross-crate default generic arguments Elide cross-crate generic arguments if they coincide with their default. TL;DR: Most notably, no more `Box<…, Global>` in `std`'s docs, just `Box<…>` from now on. Fixes #80379. Also helps with #44306. Follow-up to #103885, #107637. r? ``@ghost``
- Loading branch information
Showing
9 changed files
with
272 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
tests/rustdoc/inline_cross/auxiliary/default-generic-args.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
pub type BoxedStr = Box<str>; | ||
pub type IntMap = std::collections::HashMap<i64, u64>; | ||
|
||
pub struct TyPair<T, U = T>(T, U); | ||
|
||
pub type T0 = TyPair<i32>; | ||
pub type T1 = TyPair<i32, u32>; | ||
pub type T2<K> = TyPair<i32, K>; | ||
pub type T3<Q> = TyPair<Q, Q>; | ||
|
||
pub struct CtPair<const C: u32, const D: u32 = C>; | ||
|
||
pub type C0 = CtPair<43, 43>; | ||
pub type C1 = CtPair<0, 1>; | ||
pub type C2 = CtPair<{1 + 2}, 3>; | ||
|
||
pub struct Re<'a, U = &'a ()>(&'a (), U); | ||
|
||
pub type R0<'q> = Re<'q>; | ||
pub type R1<'q> = Re<'q, &'q ()>; | ||
pub type R2<'q> = Re<'q, &'static ()>; | ||
pub type H0 = fn(for<'a> fn(Re<'a>)); | ||
pub type H1 = for<'b> fn(for<'a> fn(Re<'a, &'b ()>)); | ||
pub type H2 = for<'a> fn(for<'b> fn(Re<'a, &'b ()>)); | ||
|
||
pub struct Proj<T: Basis, U = <T as Basis>::Assoc>(T, U); | ||
pub trait Basis { type Assoc; } | ||
impl Basis for () { type Assoc = bool; } | ||
|
||
pub type P0 = Proj<()>; | ||
pub type P1 = Proj<(), bool>; | ||
pub type P2 = Proj<(), ()>; | ||
|
||
pub struct Alpha<T = for<'any> fn(&'any ())>(T); | ||
|
||
pub type A0 = Alpha; | ||
pub type A1 = Alpha<for<'arbitrary> fn(&'arbitrary ())>; | ||
|
||
pub struct Multi<A = u64, B = u64>(A, B); | ||
|
||
pub type M0 = Multi<u64, ()>; | ||
|
||
pub trait Trait<'a, T = &'a ()> {} | ||
|
||
pub type F = dyn for<'a> Trait<'a>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#![crate_name = "user"] | ||
// aux-crate:default_generic_args=default-generic-args.rs | ||
// edition:2021 | ||
|
||
// @has user/type.BoxedStr.html | ||
// @has - '//*[@class="rust item-decl"]//code' "Box<str>" | ||
pub use default_generic_args::BoxedStr; | ||
|
||
// @has user/type.IntMap.html | ||
// @has - '//*[@class="rust item-decl"]//code' "HashMap<i64, u64>" | ||
pub use default_generic_args::IntMap; | ||
|
||
// @has user/type.T0.html | ||
// @has - '//*[@class="rust item-decl"]//code' "TyPair<i32>" | ||
pub use default_generic_args::T0; | ||
|
||
// @has user/type.T1.html | ||
// @has - '//*[@class="rust item-decl"]//code' "TyPair<i32, u32>" | ||
pub use default_generic_args::T1; | ||
|
||
// @has user/type.T2.html | ||
// @has - '//*[@class="rust item-decl"]//code' "TyPair<i32, K>" | ||
pub use default_generic_args::T2; | ||
|
||
// @has user/type.T3.html | ||
// @has - '//*[@class="rust item-decl"]//code' "TyPair<Q>" | ||
pub use default_generic_args::T3; | ||
|
||
// @has user/type.C0.html | ||
// @has - '//*[@class="rust item-decl"]//code' "CtPair<43>" | ||
pub use default_generic_args::C0; | ||
|
||
// @has user/type.C1.html | ||
// @has - '//*[@class="rust item-decl"]//code' "CtPair<0, 1>" | ||
pub use default_generic_args::C1; | ||
|
||
// @has user/type.C2.html | ||
// @has - '//*[@class="rust item-decl"]//code' "CtPair<default_generic_args::::C2::{constant#0}, 3>" | ||
pub use default_generic_args::C2; | ||
|
||
// @has user/type.R0.html | ||
// @has - '//*[@class="rust item-decl"]//code' "Re<'q>" | ||
pub use default_generic_args::R0; | ||
|
||
// @has user/type.R1.html | ||
// @has - '//*[@class="rust item-decl"]//code' "Re<'q>" | ||
pub use default_generic_args::R1; | ||
|
||
// @has user/type.R2.html | ||
// Check that we consider regions: | ||
// @has - '//*[@class="rust item-decl"]//code' "Re<'q, &'static ()>" | ||
pub use default_generic_args::R2; | ||
|
||
// @has user/type.H0.html | ||
// Check that we handle higher-ranked regions correctly: | ||
// @has - '//*[@class="rust item-decl"]//code' "fn(_: for<'a> fn(_: Re<'a>))" | ||
pub use default_generic_args::H0; | ||
|
||
// @has user/type.H1.html | ||
// Check that we don't conflate distinct universially quantified regions (#1): | ||
// @has - '//*[@class="rust item-decl"]//code' "for<'b> fn(_: for<'a> fn(_: Re<'a, &'b ()>))" | ||
pub use default_generic_args::H1; | ||
|
||
// @has user/type.H2.html | ||
// Check that we don't conflate distinct universially quantified regions (#2): | ||
// @has - '//*[@class="rust item-decl"]//code' "for<'a> fn(_: for<'b> fn(_: Re<'a, &'b ()>))" | ||
pub use default_generic_args::H2; | ||
|
||
// @has user/type.P0.html | ||
// @has - '//*[@class="rust item-decl"]//code' "Proj<()>" | ||
pub use default_generic_args::P0; | ||
|
||
// @has user/type.P1.html | ||
// @has - '//*[@class="rust item-decl"]//code' "Proj<(), bool>" | ||
pub use default_generic_args::P1; | ||
|
||
// @has user/type.P2.html | ||
// @has - '//*[@class="rust item-decl"]//code' "Proj<(), ()>" | ||
pub use default_generic_args::P2; | ||
|
||
// @has user/type.A0.html | ||
// Ensure that we elide generic arguments that are alpha-equivalent to their respective | ||
// generic parameter (modulo substs) (#1): | ||
// @has - '//*[@class="rust item-decl"]//code' "Alpha" | ||
pub use default_generic_args::A0; | ||
|
||
// @has user/type.A1.html | ||
// Ensure that we elide generic arguments that are alpha-equivalent to their respective | ||
// generic parameter (modulo substs) (#1): | ||
// @has - '//*[@class="rust item-decl"]//code' "Alpha" | ||
pub use default_generic_args::A1; | ||
|
||
// @has user/type.M0.html | ||
// Test that we don't elide `u64` even if it coincides with `A`'s default precisely because | ||
// `()` is not the default of `B`. Mindlessly eliding `u64` would lead to `M<()>` which is a | ||
// different type (`M<(), u64>` versus `M<u64, ()>`). | ||
// @has - '//*[@class="rust item-decl"]//code' "Multi<u64, ()>" | ||
pub use default_generic_args::M0; | ||
|
||
// @has user/type.F.html | ||
// FIXME: Ideally, we would elide `&'a ()` but `'a` is an escaping bound var which we can't reason | ||
// about at the moment since we don't keep track of bound vars. | ||
// @has - '//*[@class="rust item-decl"]//code' "dyn for<'a> Trait<'a, &'a ()>" | ||
pub use default_generic_args::F; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.