Commit Graph

108 Commits

Author SHA1 Message Date
Guillaume Gomez
75cbd05d19 Add tests for doc(attribute = "...") attribute 2025-08-28 15:56:30 +02:00
Alona Enraght-Moony
a33e084afe rustdoc-json: Move #[macro_export] from Other to it's own variant 2025-07-30 19:57:32 +00:00
Alona Enraght-Moony
1a515e6949 rustdoc-json: Add test for #[macro_use] attribute 2025-07-30 19:54:23 +00:00
Alona Enraght-Moony
078332fdc8 rustdoc-json: Structured attributes
Implements https://www.github.com/rust-lang/rust/issues/141358.

This has 2 primary benefits:

1. For rustdoc-json consumers, they no longer need to parse strings of
   attributes, but it's there in a structured and normalized way.
2. For rustc contributors, the output of HIR pretty printing is no
   longer a versioned thing in the output. People can work on
   https://github.com/rust-lang/rust/issues/131229 without needing to
   bump `FORMAT_VERSION`.

(Over time, as the attribute refractor continues, I expect we'll add new
things to `rustdoc_json_types::Attribute`. But this can be done
separately to the rustc changes).
2025-07-15 16:52:41 +00:00
bors
7e310f4b9a Auto merge of #143617 - aDotInTheVoid:devdesktoptestattr, r=Mark-Simulacrum
Run `tests/rustdoc-json/attrs/target_features` on all hosts.

Makes it more convenient to test rustdoc on non x86_64. I mainly care about the aarch64 dev-desktops.

This works because rustdoc uses all target features, not just that of the target.
2025-07-13 12:28:47 +00:00
Fluid
ed96f00682 fix typos in function names in the target_feature test 2025-07-11 02:27:39 +03:00
Predrag Gruevski
27fb02c947 Add rustdoc JSON tests for #[doc(hidden)] handling of items. 2025-07-10 00:19:03 +00:00
Predrag Gruevski
717041232a Don't mark #[target_feature] safe fns as unsafe in rustdoc JSON. 2025-07-08 02:02:56 +00:00
Alona Enraght-Moony
45053e21b2 Run tests/rustdoc-json/attrs/target_features on all hosts.
Makes it more convenient to test rustdoc on non x86_64. I mainly care
about the aarch64 dev-desktops.

This works because rustdoc uses all target features, not just that of
the target.
2025-07-07 21:56:54 +00:00
Jonathan Brouwer
3d5d72b761 Port #[target_feature] to the new attribute parsing infrastructure
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-03 07:54:19 +02:00
Anne Stijns
54cec0cf5a Port #[link_section] to the new attribute parsing infrastructure 2025-06-29 16:23:46 +02:00
Guillaume Gomez
0512c82cfa Rollup merge of #142919 - aDotInTheVoid:cold-cold-attr-for-you, r=GuillaumeGomez
rustdoc-json: Add test for `#[cold]`

Follow-up to https://github.com/rust-lang/rust/pull/142491

r? `@GuillaumeGomez`

CC `@jdonszelmann`
2025-06-24 15:39:41 +02:00
Guillaume Gomez
4cdf492760 Rollup merge of #142916 - aDotInTheVoid:you-can-trip-on-my-optimizer, r=GuillaumeGomez
rustdoc-json: Add test for `#[optimize(..)]`

Follow up to https://github.com/rust-lang/rust/pull/138291

CC `@jdonszelmann`

r? `@GuillaumeGomez`
2025-06-24 15:39:40 +02:00
Martin Nordholts
7c0ef44d4f rustdoc-json: Keep empty generic args if parenthesized
Because in the case of for example

    pub fn my_fn3(f: impl FnMut()) {}

we want to keep `()` even if it is empty since that matches e.g. Rust
syntax requirements.
2025-06-24 00:03:05 +02:00
Alona Enraght-Moony
98fce2546d rustdoc-json: Add test for #[cold]
Follow-up to https://www.github.com/rust-lang/rust/pull/142491
2025-06-23 21:34:17 +00:00
Alona Enraght-Moony
bec2679e4e rustdoc-json: Add test for #[optimize(..)]
Follow up to https://www.github.com/rust-lang/rust/pull/138291
2025-06-23 17:23:20 +00:00
Jonathan Brouwer
b24df42488 Port #[must_use] to new attribute parsing infrastructure
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-06-22 14:51:58 +02:00
Nicholas Nethercote
7fa8901cd0 rustdoc_json: represent generic args consistently.
They show up in three places: once as `Option<Box<GenericArgs>>`, once
as `Box<GenericArgs>`, and once as `GenericArgs`. The first option is
best. It is more compact because generic args are often missing. This
commit changes the latter two to the former.

Example output, before and after, for the `AssocItemConstraint` change:
```
{"name":"Offset","args":{"angle_bracketed":{"args":[],"constraints":[]}},"binding":{...}}
{"name":"Offset","args":null,"binding":{...}}
```
Example output, before and after, for the `Type::QualifiedPath` change:
```
{"qualified_path":{"name":"Offset","args":{"angle_bracketed":{"args":[],"constraints":[]}}, ...}}
{"qualified_path":{"name":"Offset","args":null, ...}}
```
This reduces JSON output size, but not by much (e.g. 0.5%), because
`AssocItemConstraint` and `Type::QualifiedPath` are uncommon.
2025-06-21 13:52:46 +10:00
Nicholas Nethercote
40ba7913fc rustdoc_json: Fix handling of paths with no generic args.
A path without generic args, like `Reader`, currently has JSON produced
like this:
```
{"path":"Reader","id":286,"args":{"angle_bracketed":{"args":[],"constraints":[]}}}
```
Even though `types::Path::args` is `Option` and allows for "no args",
instead it gets represented as "empty args". (More like `Reader<>` than
`Reader`.)

This is due to a problem in `clean::Path::from_clean`. It only produces
`None` if the path is an empty string. This commit changes it to also
produce `None` if there are no generic args. The example above becomes:
```
{"path":"Reader","id":286,"args":null}
```
I looked at a few examples and saw this reduce the size of the JSON
output by 3-9%.

The commit also adds an assertion that non-final segments don't have any
generics; something the old code was implicitly relying on.

Note: the original sin here is that `clean::PathSegment::args` is not an
`Option`, unlike `{ast,hir}::PathSegment::args`. I want to fix that, but
it can be done separately.
2025-06-21 13:50:52 +10:00
Nicholas Nethercote
18d742bda0 rustdoc_json: Add a test for some GenericArgs cases. 2025-06-21 13:50:51 +10:00
Jana Dönszelmann
780b902111 fix clippy 2025-06-17 23:22:51 +02:00
David Wood
da47753496 rustdoc: {Meta,Pointee,}Sized in non-minicore
Some rustdoc tests are `no_core` and need to have `MetaSized` and
`PointeeSized` added to them.
2025-06-16 23:04:36 +00:00
Jubilee Young
518eb0d5dd rustdoc-json: Rearrange deck chairs in ABI testing
We move the vectorcall ABI tests into their own file which is now
only run on x86-64, while replacing them with rust-cold ABI tests
so that aarch64 hosts continue to test an unstable ABI.

A better solution might be cross-compiling or something but
I really don't have time for that right now.
2025-06-09 16:11:06 -07:00
beetrees
467eeabbb5 Stabilise repr128 2025-05-28 15:14:34 +01:00
León Orell Valerian Liehr
98bd1a6a3a rustdoc JSON: Don't apply #[repr] privacy heuristics 2025-05-22 21:26:48 +02:00
Alona Enraght-Moony
8cdfabd230 rustdoc-json: Remove false docs and add test for inline attribute
The docs about how `#[inline]` was represented isn't true. Updates the
comment, and adds a test.

CC https://www.github.com/rust-lang/rust/issues/137645
2025-05-21 19:47:41 +00:00
Alona Enraght-Moony
aeb70c710a rustdoc-json: Remove newlines from attributes 2025-05-07 18:45:58 +00:00
Nicholas Nethercote
e1a177bbba Improve hir pretty-printing of attributes. 2025-05-03 12:46:48 +10:00
Chris Denton
df9e15e69f Rollup merge of #140076 - aDotInTheVoid:jsondocline, r=GuillaumeGomez
jsondocck: Require command is at start of line

In one place we use `///``@``` instead of `//``@`.`` The test-runner allowed it, but it probably shouldn't. Ran into by ``@lolbinarycat`` in https://github.com/rust-lang/rust/pull/132748#issuecomment-2816469322:

```
error: unknown disambiguator `?(`
##[error] --> /checkout/tests/rustdoc-json/fns/return_type_alias.rs:3:25
  |
3 | ///@ set foo = "$.index[?(``@.name=='Foo')].id"``
  |                         ^^
  |
```

Maybe it's also worth erroring on this like we added in #137103

r? ``@GuillaumeGomez``
2025-04-21 18:53:19 +00:00
Alona Enraght-Moony
fd4a093a4e jsondocck: Require command is at start of line 2025-04-20 11:37:00 +00:00
Alona Enraght-Moony
c7e976eb1e rustdoc-json: Improve test for auto-trait impls 2025-04-20 11:28:16 +00:00
Guillaume Gomez
ba9a008d90 Add regression test for span 1-indexed check 2025-04-18 20:32:40 +02:00
Will Glynn
8c50f95cf0 rustdoc: Output target feature information
`#[target_feature]` attributes refer to a target-specific list of
features. Enabling certain features can imply enabling other features.
Certain features are always enabled on certain targets, since they are
required by the target's ABI. Features can also be enabled indirectly
based on other compiler flags.

Feature information is ultimately known to `rustc`. Rather than force
external tools to track it -- which may be wildly impractical due to
`-C target-cpu` -- have `rustdoc` output `rustc`'s feature data.
2025-04-15 21:26:14 -05:00
Alona Enraght-Moony
7feac15ca7 rustdoc-json: Add test for #[automatically_derived] attribute 2025-03-31 20:42:49 +00:00
Predrag Gruevski
bafdbcadd5 rustdoc: Use own logic to print #[repr(..)] attributes in JSON output. 2025-03-22 18:47:12 +00:00
Alona Enraght-Moony
13335e313c tests/rustdoc-json: change assertions to use RFC 9535 jsonpath 2025-03-21 00:48:09 +00:00
Alona Enraght-Moony
42631d8027 tests/rustdoc-json: replace $.paths[*][? with $.paths[?
This fixes all 3 of these tests. Done automatically in VSCode.
2025-03-21 00:48:09 +00:00
Alona Enraght-Moony
7ab71c417b tests/rustdoc-json: replace $.index[*][? with $.index[?
Done automatically with VSCode.
2025-03-21 00:48:09 +00:00
Matthias Krüger
bf98654e6c Rollup merge of #138569 - aDotInTheVoid:reprdoc-json, r=GuillaumeGomez
rustdoc-json: Add tests for `#[repr(...)]`

Works towards #137645 and #81359

Based on #138018, but with only the test changes. CC ```@obi1kenobi```

r? ```@GuillaumeGomez```
2025-03-18 10:09:30 +01:00
Alona Enraght-Moony
677489fb3e rustdoc-json: Don't also include #[deprecated] in Item::attrs 2025-03-16 21:27:54 +00:00
Alona Enraght-Moony
2ff28159d3 rustdoc-json: Add tests for #[deprecated(...)] 2025-03-16 21:09:46 +00:00
Alona Enraght-Moony
f5ecb74bf9 rustdoc-json: Add tests for #[repr(...)]
Co-authored-by: Predrag Gruevski <obi1kenobi82@gmail.com>
2025-03-16 20:28:17 +00:00
Michael Goulet
e3ac1fa81a Add RTN support to rustdoc 2025-03-15 18:13:27 +00:00
Matthias Krüger
1a7d2b9219 Rollup merge of #138109 - Kohei316:feat/rust-doc-precise-capturing-arg, r=aDotInTheVoid,compiler-errors
make precise capturing args in rustdoc Json typed

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`.
2025-03-13 11:28:26 +01:00
morine0122
112f7b01a1 make precise capturing args in rustdoc Json typed 2025-03-10 21:40:09 +09:00
Michael Goulet
279377f87a Fix pretty printing of parsed attrs in hir_pretty 2025-03-10 02:04:26 +00:00
Predrag Gruevski
e07d9a8200 rustdoc: Add attribute-related tests for rustdoc JSON. 2025-03-05 04:46:14 +00:00
Noratrieb
dfed028e78 Always allow rustdoc-json tests to contain long lines
The rustdoc-json test syntax often requires very long lines, so the checks
for long lines aren't really useful.
2025-03-03 19:59:54 +01:00
Jana Dönszelmann
f321f107e3 Fix rustdoc and clippy 2025-02-24 14:31:19 +01:00
Michael Goulet
36839759ce Add missing lang items in no_core tests in rustdoc 2025-02-04 01:05:31 +00:00