-
Notifications
You must be signed in to change notification settings - Fork 13.4k
HACKY/INCOMPLETE: Add implied bounds to rustdoc-json #142264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2830,9 +2830,13 @@ fn clean_maybe_renamed_item<'tcx>( | |
generics: clean_generics(generics, cx), | ||
fields: variant_data.fields().iter().map(|x| clean_field(x, cx)).collect(), | ||
}), | ||
ItemKind::Struct(_, generics, variant_data) => StructItem(Struct { | ||
ItemKind::Struct(_, _, variant_data) => StructItem(Struct { | ||
ctor_kind: variant_data.ctor_kind(), | ||
generics: clean_generics(generics, cx), | ||
generics: clean_ty_generics( | ||
cx, | ||
cx.tcx.generics_of(def_id), | ||
cx.tcx.predicates_of(def_id), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. I would just call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. d'oh that's much nicer, and solves all the problems with this approach, as we also get to keep using HIR for HTML! |
||
), | ||
fields: variant_data.fields().iter().map(|x| clean_field(x, cx)).collect(), | ||
}), | ||
ItemKind::Macro(_, macro_def, MacroKind::Bang) => MacroItem(Macro { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//@ count '$.index[?(@.name=="Foo")].inner.struct.generics.params[*]' 2 | ||
//@ is '$.index[?(@.name=="Foo")].inner.struct.generics.params[0].name' \"\'a\" | ||
//@ is '$.index[?(@.name=="Foo")].inner.struct.generics.params[0].kind.lifetime.outlives' [] | ||
//@ is '$.index[?(@.name=="Foo")].inner.struct.generics.params[1].name' '"T"' | ||
//@ is '$.index[?(@.name=="Foo")].inner.struct.generics.params[1].kind.type.bounds' '[]' | ||
//@ count '$.index[?(@.name=="Foo")].inner.struct.generics.where_predicates[*]' 1 | ||
//@ count '$.index[?(@.name=="Foo")].inner.struct.generics.where_predicates[*]' 1 | ||
//@ is '$.index[?(@.name=="Foo")].inner.struct.generics.where_predicates[0].bound_predicate.type.generic' '"T"' | ||
//@ count '$.index[?(@.name=="Foo")].inner.struct.generics.where_predicates[0].bound_predicate.bounds[*]' 2 | ||
//@ is '$.index[?(@.name=="Foo")].inner.struct.generics.where_predicates[0].bound_predicate.bounds[0].trait_bound.trait.path' '"Copy"' | ||
//@ is '$.index[?(@.name=="Foo")].inner.struct.generics.where_predicates[0].bound_predicate.bounds[1].outlives' \"\'a\" | ||
// ^^^^ The last bound donesn't exist anywhere in the source code ^^^^ | ||
|
||
pub struct Foo<'a, T: Copy>(&'a T); | ||
// Desguars to: | ||
// pub struct Foo<'a, T>(&'a T) where T: Copy + 'a; | ||
|
||
// FIXME: Needs more tests, at least | ||
// - Implied 'a: 'b |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<pre class="rust item-decl"><code>pub struct Struct<'a, B><div class="where">where | ||
B: <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a><<a class="primitive" href="{{channel}}/std/primitive.unit.html">()</a>> + ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + 'a,</div>{ | ||
B: 'a + <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a><<a class="primitive" href="{{channel}}/std/primitive.unit.html">()</a>> + ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div>{ | ||
pub a: <a class="primitive" href="{{channel}}/std/primitive.reference.html">&'a B</a>, | ||
pub b: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a>, | ||
}</code></pre> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<pre class="rust item-decl"><code>pub struct Struct2<'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><<a class="primitive" href="{{channel}}/std/primitive.unit.html">()</a>> + 'a> { | ||
<pre class="rust item-decl"><code>pub struct Struct2<'a, B><div class="where">where | ||
B: <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a><<a class="primitive" href="{{channel}}/std/primitive.unit.html">()</a>> + 'a + ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div>{ | ||
pub a: <a class="primitive" href="{{channel}}/std/primitive.reference.html">&'a B</a>, | ||
pub b: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a>, | ||
}</code></pre> |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is "fundamental" in that it doesn't work for functions which is the real question here. CC Jubilee's mention of implicit implied outlives-bounds.
For functions,
predicates_of
(more specifically,inferred_outlives_of
which is called under the hood) does not include implied outlives-bounds. CC https://rustc-dev-guide.rust-lang.org/traits/implied-bounds.html#implicit-implied-bounds