Skip to content

Commit a5cf688

Browse files
committed
WIP: Add implied bounds to rustdoc
1 parent 14863ea commit a5cf688

File tree

7 files changed

+42
-9
lines changed

7 files changed

+42
-9
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2830,9 +2830,13 @@ fn clean_maybe_renamed_item<'tcx>(
28302830
generics: clean_generics(generics, cx),
28312831
fields: variant_data.fields().iter().map(|x| clean_field(x, cx)).collect(),
28322832
}),
2833-
ItemKind::Struct(_, generics, variant_data) => StructItem(Struct {
2833+
ItemKind::Struct(_, _, variant_data) => StructItem(Struct {
28342834
ctor_kind: variant_data.ctor_kind(),
2835-
generics: clean_generics(generics, cx),
2835+
generics: clean_ty_generics(
2836+
cx,
2837+
cx.tcx.generics_of(def_id),
2838+
cx.tcx.predicates_of(def_id),
2839+
),
28362840
fields: variant_data.fields().iter().map(|x| clean_field(x, cx)).collect(),
28372841
}),
28382842
ItemKind::Macro(_, macro_def, MacroKind::Bang) => MacroItem(Macro {

src/tools/compiletest/src/runtest.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,11 +1972,18 @@ impl<'test> TestCx<'test> {
19721972
config: &Config {
19731973
// FIXME: use beta or a user-specified rustdoc instead of
19741974
// hardcoding the default toolchain
1975-
rustdoc_path: Some("rustdoc".into()),
1975+
1976+
// GODAWFUL HAAACKS!!
1977+
rustdoc_path: Some("/home/gh-aDotInTheVoid/rust2/build/aarch64-unknown-linux-gnu/stage1/bin/rustdoc".into()),
19761978
// Needed for building auxiliary docs below
1977-
rustc_path: "rustc".into(),
1979+
rustc_path: "/home/gh-aDotInTheVoid/rust2/build/aarch64-unknown-linux-gnu/stage1/bin/rustc".into(),
1980+
run_lib_path: "/home/gh-aDotInTheVoid/rust2/build/aarch64-unknown-linux-gnu/stage1/lib/rustlib/aarch64-unknown-linux-gnu/lib".into(),
1981+
1982+
sysroot_base: "/home/gh-aDotInTheVoid/rust2/build/aarch64-unknown-linux-gnu/stage1".into(),
1983+
19781984
..self.config.clone()
19791985
},
1986+
revision: Some("compare-base"),
19801987
..*self
19811988
};
19821989

@@ -1990,11 +1997,13 @@ impl<'test> TestCx<'test> {
19901997
Vec::new(),
19911998
);
19921999
let aux_dir = new_rustdoc.aux_output_dir();
2000+
eprintln!("new aux dir = {aux_dir}");
19932001
new_rustdoc.build_all_auxiliary(&new_rustdoc.testpaths, &aux_dir, &mut rustc);
19942002

19952003
let proc_res = new_rustdoc.document(&compare_dir, &new_rustdoc.testpaths);
19962004
if !proc_res.status.success() {
19972005
eprintln!("failed to run nightly rustdoc");
2006+
proc_res.print_info();
19982007
return;
19992008
}
20002009

tests/rustdoc-json/implied-bounds.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//@ count '$.index[?(@.name=="Foo")].inner.struct.generics.params[*]' 2
2+
//@ is '$.index[?(@.name=="Foo")].inner.struct.generics.params[0].name' \"\'a\"
3+
//@ is '$.index[?(@.name=="Foo")].inner.struct.generics.params[0].kind.lifetime.outlives' []
4+
//@ is '$.index[?(@.name=="Foo")].inner.struct.generics.params[1].name' '"T"'
5+
//@ is '$.index[?(@.name=="Foo")].inner.struct.generics.params[1].kind.type.bounds' '[]'
6+
//@ count '$.index[?(@.name=="Foo")].inner.struct.generics.where_predicates[*]' 1
7+
//@ count '$.index[?(@.name=="Foo")].inner.struct.generics.where_predicates[*]' 1
8+
//@ is '$.index[?(@.name=="Foo")].inner.struct.generics.where_predicates[0].bound_predicate.type.generic' '"T"'
9+
//@ count '$.index[?(@.name=="Foo")].inner.struct.generics.where_predicates[0].bound_predicate.bounds[*]' 2
10+
//@ is '$.index[?(@.name=="Foo")].inner.struct.generics.where_predicates[0].bound_predicate.bounds[0].trait_bound.trait.path' '"Copy"'
11+
//@ is '$.index[?(@.name=="Foo")].inner.struct.generics.where_predicates[0].bound_predicate.bounds[1].outlives' \"\'a\"
12+
// ^^^^ The last bound donesn't exist anywhere in the source code ^^^^
13+
14+
pub struct Foo<'a, T: Copy>(&'a T);
15+
// Desguars to:
16+
// pub struct Foo<'a, T>(&'a T) where T: Copy + 'a;
17+
18+
// FIXME: Needs more tests, at least
19+
// - Implied 'a: 'b

tests/rustdoc/assoc/normalize-assoc-item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ impl<Inner: Trait> Trait for Generic<Inner> {
4949
// These can't be normalized because they depend on a generic parameter.
5050
// However the user can choose whether the text should be displayed as `Inner::X` or `<Inner as Trait>::X`.
5151

52-
//@ has 'normalize_assoc_item/struct.Unknown.html' '//pre[@class="rust item-decl"]' 'pub struct Unknown<Inner: Trait>(pub <Inner as Trait>::X);'
52+
//@ has 'normalize_assoc_item/struct.Unknown.html' '//pre[@class="rust item-decl"]' 'pub struct Unknown<Inner>(pub <Inner as Trait>::X) where Inner: Trait;'
5353
pub struct Unknown<Inner: Trait>(pub <Inner as Trait>::X);
5454

55-
//@ has 'normalize_assoc_item/struct.Unknown2.html' '//pre[@class="rust item-decl"]' 'pub struct Unknown2<Inner: Trait>(pub Inner::X);'
55+
//@ has 'normalize_assoc_item/struct.Unknown2.html' '//pre[@class="rust item-decl"]' 'pub struct Unknown2<Inner>(pub Inner::X) where Inner: Trait;'
5656
pub struct Unknown2<Inner: Trait>(pub Inner::X);
5757

5858
trait Lifetimes<'a> {

tests/rustdoc/const-generics/generic_const_exprs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#![allow(incomplete_features)]
44
// make sure that `ConstEvaluatable` predicates dont cause rustdoc to ICE #77647
55
//@ has foo/struct.Ice.html '//pre[@class="rust item-decl"]' \
6-
// 'pub struct Ice<const N: usize> where [(); { _ }]:;'
6+
// 'pub struct Ice<const N: usize>;'
77
pub struct Ice<const N: usize> where [(); N + 1]:;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<pre class="rust item-decl"><code>pub struct Struct&lt;'a, B&gt;<div class="where">where
2-
B: <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a>&lt;<a class="primitive" href="{{channel}}/std/primitive.unit.html">()</a>&gt; + ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + 'a,</div>{
2+
B: 'a + <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a>&lt;<a class="primitive" href="{{channel}}/std/primitive.unit.html">()</a>&gt; + ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div>{
33
pub a: <a class="primitive" href="{{channel}}/std/primitive.reference.html">&amp;'a B</a>,
44
pub b: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a>,
55
}</code></pre>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<pre class="rust item-decl"><code>pub struct Struct2&lt;'a, B: ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a>&lt;<a class="primitive" href="{{channel}}/std/primitive.unit.html">()</a>&gt; + 'a&gt; {
1+
<pre class="rust item-decl"><code>pub struct Struct2&lt;'a, B&gt;<div class="where">where
2+
B: <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a>&lt;<a class="primitive" href="{{channel}}/std/primitive.unit.html">()</a>&gt; + 'a + ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div>{
23
pub a: <a class="primitive" href="{{channel}}/std/primitive.reference.html">&amp;'a B</a>,
34
pub b: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a>,
45
}</code></pre>

0 commit comments

Comments
 (0)