-
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
rustdoc-json: Improve Item::attrs
to not use debug representation.
#137645
Comments
So there's basically two options here:
Doing option 2 would require a lot more design work, but is probably worthwhile (even if we do option 1 initially). Some questions:
|
One advantage of option 1 is that it also improves hir pretty printing. I personally think having them available in a nice and structured way is pretty neat, and hir is not required to look nice. Furthermore, it's also a lot of code (I initially tried). But it in an advantage at least |
Tools attrs are still accessible as tokens. If you try to hir pretty print they even still look like they used to. So that would fit in with option 1 I guess |
@obi1kenobi are there any other attrs except repr you would care about with semver checks? Although I dont think thats the only reason to expose things like this (I'd be in favor of exposing things like inline) it'd be interesting to know if that's literally the only one right now. |
I'm in favor of Option 1 initially, and Option 2 in the long run as a nice-to-have. We already have code that does attribute parsing, so while I'd love to eliminate it eventually, that isn't really a priority. Option 1 sounds like it can be done with less work, and speed is good :)
No, unfortunately we need many more. At minimum (probably not an exhaustive list):
If we can keep
If we can keep it, it'd be great! There are some cases where in the future a warning may be desirable as a lint if e.g. Not a priority today though.
I have no opinion on this, since none of
It's possible |
Thank you both for looking into this issue and helping address it! ❤ |
for the record, although I played devil's advocate a little and posted some arguments for option, I think option 2 gives a lot more flexibility and although I agree you already have parsing for option 1, with option 2 you potentially won't need any parsing at all nor any other tool which I think is very valuable |
I agree option 2 would be nice! But my top priority is having whichever option we can ship faster :) |
I've been triaging the impact to I noticed that rustdoc already has some machinery for pretty-printing Vibe check on switching to using the existing |
We go through rust/src/librustdoc/json/conversions.rs Line 44 in f9e0239
Seems like a good approach for now, even if eventually we move to something more structured. It'd require careful explaining in the docs, but that's fine, they're not good here at the moment and I'm happy to accept incremental improvements that aren't perfect. While doing this, it's probably a good idea to add tests for the non- |
Apologies if I'm very mistaken here: is the
Based on my read of What might the tests for such attributes test? Just pin down the existing behavior (" Also, is it necessary to add those tests as part of the same work unit that changes |
D'oh, I got the negitives the wrong way round. rustdoc-json currently enables
Yeah. Also the handling of when we do & don't show Probably also worth having tests for attibutes we don't pass through. (e.g.
It'd be ok for them to be separate. The """best""" way would be to land the tests first, then change |
I very quickly threw together two draft PRs:
These are my first substantive attempts at code contributions in rustc, so while I've read the dev guide, I'd like to apologize in advance for my unfamiliarity with the codebase. There may be better ways of doing things that I've missed! If at a glance the changes seem to be in an acceptable direction, I'm happy to do more work to get them into a merge-ready state. I'd love some pointers as to the testing norms for |
My read of the code as it currently stands is that rustdoc JSON always shows
AFAICT, they do not appear to have suffered any changes as a result of the recent attributes change. I'm not sure about whether
I'd love to unbreak Also, if you're okay with it: there's a |
…trs, r=compiler-errors Pretty-print `#[deprecated]` attribute in HIR. Pretty-print `#[deprecated]` attribute in a form closer to how it might appear in Rust source code, rather than using a `Debug`-like representation. Consider the following Rust code: ```rust #[deprecated] pub struct PlainDeprecated; #[deprecated = "here's why this is deprecated"] pub struct DirectNote; #[deprecated(since = "1.2.3", note = "here's why this is deprecated")] pub struct SinceAndNote; ``` Here's the previous output: ``` #[attr="Deprecation{deprecation: Deprecation{since: Unspecifiednote: suggestion: }span: }")] struct PlainDeprecated; #[attr="Deprecation{deprecation: Deprecation{since: Unspecifiednote: here's why this is deprecatedsuggestion: }span: }")] struct DirectNote; #[attr="Deprecation{deprecation: Deprecation{since: NonStandard(1.2.3)note: here's why this is deprecatedsuggestion: }span: }")] struct SinceAndNote; ``` Here's the new output: ```rust #[deprecated] struct PlainDeprecated; #[deprecated = "here's why this is deprecated"] struct DirectNote; #[deprecated(since = "1.2.3", note = "here's why this is deprecated"] struct SinceAndNote; ``` Also includes a test for `#[diagnostic::(..)]` attributes, though their behavior is not changed here. I already wrote the test, so I figured it probably won't hurt to have it. Related to discussion in rust-lang#137645. r? `@jdonszelmann`
For any folks following along:
|
Rollup merge of rust-lang#138019 - obi1kenobi:pg/pretty-print-more-attrs, r=compiler-errors Pretty-print `#[deprecated]` attribute in HIR. Pretty-print `#[deprecated]` attribute in a form closer to how it might appear in Rust source code, rather than using a `Debug`-like representation. Consider the following Rust code: ```rust #[deprecated] pub struct PlainDeprecated; #[deprecated = "here's why this is deprecated"] pub struct DirectNote; #[deprecated(since = "1.2.3", note = "here's why this is deprecated")] pub struct SinceAndNote; ``` Here's the previous output: ``` #[attr="Deprecation{deprecation: Deprecation{since: Unspecifiednote: suggestion: }span: }")] struct PlainDeprecated; #[attr="Deprecation{deprecation: Deprecation{since: Unspecifiednote: here's why this is deprecatedsuggestion: }span: }")] struct DirectNote; #[attr="Deprecation{deprecation: Deprecation{since: NonStandard(1.2.3)note: here's why this is deprecatedsuggestion: }span: }")] struct SinceAndNote; ``` Here's the new output: ```rust #[deprecated] struct PlainDeprecated; #[deprecated = "here's why this is deprecated"] struct DirectNote; #[deprecated(since = "1.2.3", note = "here's why this is deprecated"] struct SinceAndNote; ``` Also includes a test for `#[diagnostic::(..)]` attributes, though their behavior is not changed here. I already wrote the test, so I figured it probably won't hurt to have it. Related to discussion in rust-lang#137645. r? `@jdonszelmann`
Heads up that after Monday of next week, I'll be travelling for a little while and won't be able to drive this work forward. I'm happy to promptly make any changes required to get #138033 and #138018 over the finish line before then, if that's feasible. #138019 was reverted, but isn't load-bearing for If we're not able to get this over the finish line before then, then for the avoidance of any doubt, let me explicitly opt into allowing @aDotInTheVoid and @GuillaumeGomez (or anyone they designate) to take over my open PRs, alter them as needed, and move them forward. I don't care whether my name is on the commit that fixes the problem, merely that the fix gets shipped :) |
Oof. See #110406. I think this is blocked on improving the test harness. Sorry!
I'm not sure rustdoc HTML's behavior is truly authoritative here, it also seems more of a heuristic to capture "authorial intent". I think we should always pass it through, and try to make sure consumers have enough information to make those decisions for themselves.
More than happy for you do to this. Tell them I apologize in advance for the state of things 😅 |
…aDotInTheVoid rustdoc: Add attribute-related tests for rustdoc JSON. Add rustdoc JSON tests covering the use of the following attributes: - `#[non_exhaustive]` applied to enums, variants, and structs - `#[must_use]`, both with and without a message - `#[no_mangle]`, in both edition 2021 and 2024 (`#[unsafe(no_mangle)]`) flavors - `#[export_name]`, also in both edition 2021 and 2024 flavors Related to rust-lang#137645; this is a subset of the attributes that `cargo-semver-checks` relies on and tests in its own test suite or in the test suites of its components such as `trustfall-rustdoc-adapter`. Helps with rust-lang#81359 r? `@aDotInTheVoid`
This is what the nomicon says about
AFAICT this is the same rule that the HTML behavior implements. Having rustdoc JSON list I don't feel strongly about this. If you think it's best to always include |
Rollup merge of rust-lang#138033 - obi1kenobi:pg/json-attrs-tests, r=aDotInTheVoid rustdoc: Add attribute-related tests for rustdoc JSON. Add rustdoc JSON tests covering the use of the following attributes: - `#[non_exhaustive]` applied to enums, variants, and structs - `#[must_use]`, both with and without a message - `#[no_mangle]`, in both edition 2021 and 2024 (`#[unsafe(no_mangle)]`) flavors - `#[export_name]`, also in both edition 2021 and 2024 flavors Related to rust-lang#137645; this is a subset of the attributes that `cargo-semver-checks` relies on and tests in its own test suite or in the test suites of its components such as `trustfall-rustdoc-adapter`. Helps with rust-lang#81359 r? `@aDotInTheVoid`
Currently, Item::attrs uses a debug-printing
https://github.com/rust-lang/rust/blame/85abb276361c424d64743c0965242dd0e7b866d1/src/rustdoc-json-types/lib.rs#L123-L126
This isn't particularly friendly to users, who need to deal with an internal (and undocumented 😱) attr representation.
This was changed in #135726, as part of the a larger attribute rework (#131229)
MCVE:
which produces (abridged):
CC @jdonszelmann @obi1kenobi
The text was updated successfully, but these errors were encountered: