Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Kohei316
Copy link
Contributor

@Kohei316 Kohei316 commented Mar 6, 2025

close #137616

This PR includes below changes.

  • Add rustc_hir::PreciseCapturingArgKind which allows the query system to return a arg's data.
  • Add rustdoc::clean::types::PreciseCapturingArg and change to use it.
  • Add rustdoc-json-types::PreciseCapturingArg and change to use it.
  • Update tests/rustdoc-json/impl-trait-precise-capturing.rs.
  • Bump rustdoc_json_types::FORMAT_VERSION.

@rustbot
Copy link
Collaborator

rustbot commented Mar 6, 2025

r? @GuillaumeGomez

rustbot has assigned @GuillaumeGomez.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend A-rustdoc-search Area: Rustdoc's search feature S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Mar 6, 2025
@rustbot
Copy link
Collaborator

rustbot commented Mar 6, 2025

rustdoc-json-types is a public (although nightly-only) API. If possible, consider changing src/librustdoc/json/conversions.rs; otherwise, make sure you bump the FORMAT_VERSION constant.

cc @CraftSpider, @aDotInTheVoid, @Enselic, @obi1kenobi

Some changes occurred in tests/rustdoc-json

cc @aDotInTheVoid

Copy link
Member

@obi1kenobi obi1kenobi left a 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.

Comment on lines 248 to 252
impl clean::PreciseCapturingArg {
fn print(&self) -> impl Display + '_ {
self.name().as_str()
}
}
Copy link
Member

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

Comment on lines 936 to 943
/// A non-lifetime argument such as a generic parameter or a constant parameter.
Param(String),
Copy link
Member

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!

Copy link
Contributor Author

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.

Copy link
Member

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!

@Kohei316 Kohei316 force-pushed the feat/rust-doc-precise-capturing-arg branch from d2c79a6 to 9ece166 Compare March 6, 2025 17:30
@aDotInTheVoid aDotInTheVoid removed A-rustdoc-search Area: Rustdoc's search feature T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Mar 7, 2025
@aDotInTheVoid aDotInTheVoid added the F-precise_capturing `#![feature(precise_capturing)]` label Mar 8, 2025
Copy link
Member

@aDotInTheVoid aDotInTheVoid left a 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
Copy link
Member

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

}

impl PreciseCapturingArg {
pub(crate) fn name(&self) -> &Symbol {
Copy link
Member

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.

@@ -927,6 +927,16 @@ pub enum TraitBoundModifier {
MaybeConst,
}

/// One precise capturing argument.
Copy link
Member

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.
Copy link
Member

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> {}
//                                                        ^^

pub enum PreciseCapturingArg {
/// A lifetime.
Lifetime(String),
/// A non-lifetime argument such as a generic parameter or a constant parameter.
Copy link
Member

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.

@compiler-errors
Copy link
Member

Ya i took a look at it earlier but can take another look at it tomorrow when im not out lol

@compiler-errors compiler-errors self-assigned this Mar 8, 2025
@rustbot rustbot added A-rustdoc-search Area: Rustdoc's search feature T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 8, 2025
@rustbot

This comment has been minimized.

@Kohei316 Kohei316 force-pushed the feat/rust-doc-precise-capturing-arg branch from bbe63cb to dc894e7 Compare March 8, 2025 15:38
@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 8, 2025
@Kohei316 Kohei316 force-pushed the feat/rust-doc-precise-capturing-arg branch from dc894e7 to 3e1927c Compare March 9, 2025 07:50
Copy link
Member

@compiler-errors compiler-errors left a 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>>>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rendered_precise_capturing_args: Table<DefIndex, LazyArray<PreciseCapturingArgKind<Symbol,Symbol>>>,
rendered_precise_capturing_args: Table<DefIndex, LazyArray<PreciseCapturingArgKind<Symbol, Symbol>>>,

}

impl PreciseCapturingArg {
pub(crate) fn name(&self) -> Symbol {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is taking place at the same time as #137956, which also (currently) makes the 40->41 change. Once one of these merges, the other should rebase then bump again. See #94591 for details.

@Kohei316 Kohei316 force-pushed the feat/rust-doc-precise-capturing-arg branch from 3e1927c to 112f7b0 Compare March 10, 2025 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-json Area: Rustdoc JSON backend A-rustdoc-search Area: Rustdoc's search feature F-precise_capturing `#![feature(precise_capturing)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rustdoc-json: Precise capturing JSON is untyped
6 participants