-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
make precise capturing args in rustdoc Json typed #138109
base: master
Are you sure you want to change the base?
make precise capturing args in rustdoc Json typed #138109
Conversation
rustbot has assigned @GuillaumeGomez. Use |
rustdoc-json-types is a public (although nightly-only) API. If possible, consider changing cc @CraftSpider, @aDotInTheVoid, @Enselic, @obi1kenobi Some changes occurred in tests/rustdoc-json |
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.
Thanks for working to make rustdoc better! I'm a prospective user of this functionality, and had a couple of questions based on reading the code.
src/librustdoc/html/format.rs
Outdated
impl clean::PreciseCapturingArg { | ||
fn print(&self) -> impl Display + '_ { | ||
self.name().as_str() | ||
} | ||
} |
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.
(I'm not T-rustdoc, just a curious bystander) I'm a bit surprised by this code. It doesn't match the "usual" function signature of the other print()
functions here (it doesn't take the TyCtxt<'_>
argument) and it also isn't just a direct impl Display for PreciseCapturingArg
even though it could be with the current function signature.
This is just my curiosity speaking: I'd love to know your view on this design decision compared to those other two options.
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.
Well I agree with the previous comment: why bother making a method and not just directly put .name().as_str()
below?
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.
Um in fact this code is wrong. I guess I was confused. I wil fix this.
src/rustdoc-json-types/lib.rs
Outdated
/// A non-lifetime argument such as a generic parameter or a constant parameter. | ||
Param(String), |
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.
Do we have the means to distinguish between generic type and constant here?
As a prospective consumer of this API via cargo-semver-checks, that distinction would be very useful!
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.
This is not be realised with small code chage because generic type and constant aren't distinguished neither in AST nor in HIR.
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.
That's fine, I can make do on my end then. Thank you!
d2c79a6
to
9ece166
Compare
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.
Thanks for working on this!
rustdoc side looks mostly good, with a couple of small nitpicks.
I'm less confident on the rustc side, and would like someone else to take a look before merging, so CC @compiler-errors I guess.
//@ is "$.index[*][?(@.name=='hello')].inner.function.sig.output.impl_trait[1].use[0]" \"\'a\" | ||
//@ is "$.index[*][?(@.name=='hello')].inner.function.sig.output.impl_trait[1].use[1]" \"T\" | ||
//@ is "$.index[*][?(@.name=='hello')].inner.function.sig.output.impl_trait[1].use[2]" \"N\" | ||
// ignore-tidy-linelength |
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.
NIT: This isn't needed after #137955
src/librustdoc/clean/types.rs
Outdated
} | ||
|
||
impl PreciseCapturingArg { | ||
pub(crate) fn name(&self) -> &Symbol { |
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.
NIT: Symbol
is Copy
, so should be returned by value here.
src/rustdoc-json-types/lib.rs
Outdated
@@ -927,6 +927,16 @@ pub enum TraitBoundModifier { | |||
MaybeConst, | |||
} | |||
|
|||
/// One precise capturing argument. |
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.
NIT: This should link to the docs on precise capturing.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] | ||
#[serde(rename_all = "snake_case")] | ||
pub enum PreciseCapturingArg { | ||
/// A lifetime. |
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.
We should give an example here, eg:
pub fn hello<'a, T, const N: usize>() -> impl Sized + use<'a, T, N> {}
// ^^
src/rustdoc-json-types/lib.rs
Outdated
pub enum PreciseCapturingArg { | ||
/// A lifetime. | ||
Lifetime(String), | ||
/// A non-lifetime argument such as a generic parameter or a constant parameter. |
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.
Saying "such as" here can be read to mean there are other options not listed. Also, a "generic parameter" could refer to a constant parameter. It's clearer (to me at least) to say something like "A type or constant parameter".
I also don't love the name, but can't think of anything better off the top of my head. Curious if types people have any better ideas here. It does feel like we're leaking the HIR implementation details in that we differentiate lifetime, but not type vs generic parameters here.
Also: An example here would be nice.
Ya i took a look at it earlier but can take another look at it tomorrow when im not out lol |
This comment has been minimized.
This comment has been minimized.
bbe63cb
to
dc894e7
Compare
dc894e7
to
3e1927c
Compare
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.
Seems fine to me.
@@ -440,7 +441,7 @@ define_tables! { | |||
coerce_unsized_info: Table<DefIndex, LazyValue<ty::adjustment::CoerceUnsizedInfo>>, | |||
mir_const_qualif: Table<DefIndex, LazyValue<mir::ConstQualifs>>, | |||
rendered_const: Table<DefIndex, LazyValue<String>>, | |||
rendered_precise_capturing_args: Table<DefIndex, LazyArray<Symbol>>, | |||
rendered_precise_capturing_args: Table<DefIndex, LazyArray<PreciseCapturingArgKind<Symbol,Symbol>>>, |
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.
rendered_precise_capturing_args: Table<DefIndex, LazyArray<PreciseCapturingArgKind<Symbol,Symbol>>>, | |
rendered_precise_capturing_args: Table<DefIndex, LazyArray<PreciseCapturingArgKind<Symbol, Symbol>>>, |
src/librustdoc/clean/types.rs
Outdated
} | ||
|
||
impl PreciseCapturingArg { | ||
pub(crate) fn name(&self) -> Symbol { |
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.
pub(crate) fn name(&self) -> Symbol { | |
pub(crate) fn name(self) -> Symbol { |
@@ -30,7 +30,7 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc | |||
/// This integer is incremented with every breaking change to the API, | |||
/// and is returned along with the JSON blob as [`Crate::format_version`]. | |||
/// Consuming code should assert that this value matches the format version(s) that it supports. | |||
pub const FORMAT_VERSION: u32 = 40; | |||
pub const FORMAT_VERSION: u32 = 41; |
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.
3e1927c
to
112f7b0
Compare
close #137616
This PR includes below changes.
rustc_hir::PreciseCapturingArgKind
which allows the query system to return a arg's data.rustdoc::clean::types::PreciseCapturingArg
and change to use it.rustdoc-json-types::PreciseCapturingArg
and change to use it.tests/rustdoc-json/impl-trait-precise-capturing.rs
.rustdoc_json_types::FORMAT_VERSION
.