about summary refs log tree commit diff
path: root/src/librustdoc/json
AgeCommit message (Collapse)AuthorLines
2025-09-21Port #[macro_export] to the new attribute parsing infrastructureJonathan Brouwer-6/+3
Co-authored-by: Anne Stijns <anstijns@gmail.com>
2025-09-01Remove dead code stemming from an old effects desugaringLeón Orell Valerian Liehr-1/+1
2025-08-28Add new `doc(attribute = "...")` attributeGuillaume Gomez-5/+9
2025-08-24Auto merge of #137229 - GuillaumeGomez:expand-macro, r=lolbinarycatbors-9/+11
Add support for macro expansion in rustdoc source code pages This is what it looks like: ![Screenshot From 2025-02-18 18-08-51](https://github.com/user-attachments/assets/ce2b3806-6218-47df-94bf-e9e9ed40cd41) ![image](https://github.com/user-attachments/assets/891042db-8632-4dba-9343-e28570c058fe) You can test it [here](https://rustdoc.crud.net/imperio/macro-expansion/src/lib/lib.rs.html). In this case, I also enabled the `--generate-link-to-definition` to show that both options work well together. Note: <del>There is a bug currently in firefox where the line numbers are not displayed correctly if they're inside the "macro expansion" span: https://bugzilla.mozilla.org/show_bug.cgi?id=1949948<del> Found a workaround around this bug. r? `@notriddle`
2025-08-23Do macro expansion at AST level rather than HIRGuillaume Gomez-9/+11
2025-08-22Add an experimental unsafe(force_target_feature) attribute.Luca Versari-1/+1
This uses the feature gate for https://github.com/rust-lang/rust/issues/143352, but is described in https://github.com/rust-lang/rfcs/pull/3820 which is strongly tied to the experiment.
2025-08-01Rollup merge of #144700 - aDotInTheVoid:macro-rules-for-macro-fools, ↵Jacob Pratt-2/+6
r=GuillaumeGomez rustdoc-json: Move `#[macro_export]` from `Other` to it's own variant Followup to rust-lang/rust#142936. cargo-semver-checks [cares about this attribute](https://github.com/obi1kenobi/trustfall-rustdoc-adapter/blob/4a0d1b0ca19b3115bb65d0b6695c388d7f474ac9/src/visibility_tracker.rs#L459-L476), and it wasn't included in the initial PR for structured attributes CC `@obi1kenobi.` r? `@GuillaumeGomez`
2025-07-31remove rustc_attr_data_structuresJana Dönszelmann-1/+1
2025-07-30rustdoc-json: Move `#[macro_export]` from `Other` to it's own variantAlona Enraght-Moony-2/+6
2025-07-19Fix clippy lints in librustdocGuillaume Gomez-13/+13
2025-07-15rustdoc-json: Structured attributesAlona Enraght-Moony-1/+98
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-08Rollup merge of #143555 - ↵Matthias Krüger-1/+14
obi1kenobi:pg/target-feature-not-unsafe-rustdoc-json, r=aDotInTheVoid Don't mark `#[target_feature]` safe fns as unsafe in rustdoc JSON. Fixes https://github.com/rust-lang/rust/issues/142655 by explicitly checking whether functions are safe but using `#[target_feature]`, instead of relying on the `FnHeader::is_unsafe()` method which considers such functions unsafe. I don't believe this merits a bump of the rustdoc JSON `FORMAT_VERSION` constant, since the format is unchanged and this is just a small bugfix. r? aDotInTheVoid
2025-07-08Don't mark `#[target_feature]` safe fns as unsafe in rustdoc JSON.Predrag Gruevski-1/+14
2025-07-07Remove unused allow attrsYotam Ofek-2/+0
2025-06-24rustdoc-json: Keep empty generic args if parenthesizedMartin Nordholts-13/+16
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-22Port `#[no_mangle]` to new attribute parsing infrastructureJonathan Brouwer-1/+1
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-06-22Rename some methods.Nicholas Nethercote-8/+12
- `convert_static` -> `from_clean_static` - `from_function` -> `from_clean_function` To match the pre-existing `from_clean_item` and `FromClean::from_clean`. I left `JsonRenderer::convert_item` unchanged because it's a bit different.
2025-06-22Use `FromClean` more.Nicholas Nethercote-121/+156
The `FromClean` trait is used a lot for converting to rustdoc-json format. But it's not used universally; there are still some ad hoc functions and methods for converting. This commit fixes this inconsistency by using `FromClean` more. The commit also introduces `FromClean` for `Box` and `Option`. This lets a lot of `as_ref` and `map` calls be removed in favour of simple `into_json` calls.
2025-06-22Remove some code.Nicholas Nethercote-32/+1
It's just replicating exactly what is done by `<Vec<GenericParamDef> as FromClean>::into_json`
2025-06-22Remove some dead code.Nicholas Nethercote-11/+0
We currently have both `FromClean<clean::Constant> for Constant` and `FromClean<clean::ConstantKind> for Constant` which are basically identical, but the former is unused.
2025-06-22Use `sym::asterisk` to avoid a `Symbol::intern` call.Nicholas Nethercote-5/+2
2025-06-21rustdoc_json: represent generic args consistently.Nicholas Nethercote-10/+9
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-21rustdoc_json: Fix handling of paths with no generic args.Nicholas Nethercote-1/+18
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-21rustdoc_json: Add static asserts for the size of important types.Nicholas Nethercote-0/+30
A lot of these are large! Lots of room for improvement in the future.
2025-06-20Rollup merge of #142755 - aDotInTheVoid:rdj-shattrs, r=GuillaumeGomezTrevor Gross-6/+1
rustdoc: Remove `FormatRenderer::cache` We only called it it one place, which isn't generic and can be replaced with a field access.
2025-06-19rustdoc: Remove `FormatRenderer::cache`Alona Enraght-Moony-6/+1
We only called it it one place, which isn't generic and can be replaced with a field access.
2025-06-19move -Ctarget-feature handling into shared codeRalf Jung-3/+2
2025-06-14Auto merge of #142335 - nnethercote:rustdoc-json-allocations, r=aDotInTheVoidbors-131/+149
rustdoc_json: reduce allocations These commits reduce the number of allocations done for rustdoc_json, mostly by avoiding unnecessary clones. Best reviewed one commit at a time. r? `@aDotInTheVoid`
2025-06-11Don't clone `new_item` in `after_krate`.Nicholas Nethercote-7/+16
We can avoid it by using the `entry` API, which lets us do the `assert_eq` comparison before `new_item` is consumed.
2025-06-11Avoid more clones in rustdoc JSON output.Nicholas Nethercote-117/+125
By making `JsonRenderer::item` take `&clean::Item` instead of a `clean::Item`. This required also changing `FromClean` and `IntoJson` methods to take references, which required a lot of follow-on sigil wrangling that is mostly tedious.
2025-06-10Avoid cloning `self.index` in `after_krate`.Nicholas Nethercote-2/+4
It can be very big. This reduces peak memory usage for some `--output-format=json` runs by up to 8%.
2025-06-10Simplify `JsonRenderer`.Nicholas Nethercote-8/+7
- It doesn't need to be cloneable. - Some of the `Rc`s and `RefCell`s aren't doing anything. - `after_krate` can consume `self`.
2025-06-09-Zretpoline and -Zretpoline-external-thunk flags (target modifiers) to ↵Andrew Zhogin-2/+3
enable retpoline-related target features
2025-06-05Support middle::ty assoc const eq predicates againLeón Orell Valerian Liehr-6/+17
2025-05-25Split `Item::attributes` method into threeGuillaume Gomez-1/+1
2025-05-18Remove rustc_attr_data_structures re-export from rustc_attr_parsingmejrs-3/+3
2025-04-18Make rustdoc JSON Span column 1-based, just like line numbersGuillaume Gomez-2/+2
2025-04-18Rollup merge of #139913 - fmease:rustdoc-fix-fn-param-handling, r=GuillaumeGomezMatthias Krüger-4/+5
rustdoc/clean: Fix lowering of fn params (fixes correctness & HIR vs. middle parity regressions) **(0)** PR #136411 aimed to stop rendering unnamed params of fn ptr types as underscores in the common case (e.g., `fn(_: i32)` → `fn(i32)`) to make the rendered output stylistically more conventional. **(0.a)** However, since the cleaning fn that the PR modified is also used for lowering the HIR params of foreign fns and required assoc fns in traits, it accidentally butchered the rendering of the latter two: ```rs pub trait Trait { fn assoc_fn(_: i32); } // as well as (Rust 2015 only): fn assoc_fn(i32); unsafe extern "C" { pub fn foreign_fn(_: i32); } // Since 1.86 the fns above gets mis-rendered as: pub fn assoc_fn(: i32) // <-- BUTCHERED pub unsafe extern "C" fn foreign_fn(: i32) // <-- BUTCHERED ``` **(0.b)** Furthermore, it broke parity with middle cleaning (which includes inlined cross-crate re-exports) re-regressing parts of #44306 I once fixed in PR #103885. **(1)** Lastly, PR #139035 introduced an ICE triggered by the following input file: ```rs trait Trait { fn anon(()) {} } // internal error: entered unreachable code ``` --- This PR fixes all of these regressions and in the first commit renames several types and fns to be more ~~correct~~ descriptive and legible. ~~It also refactors `Param.name` to be of type `Option<Symbol>` instead `Symbol` (where `None` ~ `kw::Empty`), so rendering mistakes like that can no longer creep in like that (ignoring tests). CC #137978.~~ Independently done in PR #139846 a day prior.
2025-04-18Rollup merge of #139393 - ↵Matthias Krüger-0/+60
willglynn:rustdoc_output_target_feature_information, r=aDotInTheVoid rustdoc-json: 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. This change is motivated by https://github.com/obi1kenobi/cargo-semver-checks/issues/1246, which intends to detect semver hazards caused by `#[target_feature]`. try-job: aarch64-gnu try-job: armhf-gnu try-job: test-various try-job: x86_64-msvc-1 try-job: i686-msvc-1 try-job: x86_64-mingw-1 try-job: aarch64-apple
2025-04-17rustdoc/clean: Change terminology of items pertaining to (formal) fn params ↵León Orell Valerian Liehr-4/+5
from "argument" to "parameter"
2025-04-15rustdoc: Output target feature informationWill Glynn-0/+60
`#[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-15Remove another `kw::Empty` use in rustdoc.Nicholas Nethercote-2/+5
Again by using `Option<Symbol>` to represent "no name".
2025-03-26rustdoc: Rearrange `Item`/`ItemInner`.Nicholas Nethercote-1/+1
The `Item` struct is 48 bytes and contains a `Box<ItemInner>`; `ItemInner` is 104 bytes. This is an odd arrangement. Normally you'd have one of the following. - A single large struct, which avoids the allocation for the `Box`, but can result in lots of wasted space in unused parts of a container like `Vec<Item>`, `HashSet<Item>`, etc. - Or, something like `struct Item(Box<ItemInner>)`, which requires the `Box` allocation but gives a very small Item size, which is good for containers like `Vec<Item>`. `Item`/`ItemInner` currently gets the worst of both worlds: it always requires a `Box`, but `Item` is also pretty big and so wastes space in containers. It would make sense to push it in one direction or the other. #138916 showed that the first option is a regression for rustdoc, so this commit does the second option, which improves speed and reduces memory usage.
2025-03-15Add RTN support to rustdocMichael Goulet-0/+1
2025-03-13Auto merge of #138450 - matthiaskrgr:rollup-4im25vf, r=matthiaskrgrbors-1/+12
Rollup of 6 pull requests Successful merges: - #137816 (attempt to support `BinaryFormat::Xcoff` in `naked_asm!`) - #138109 (make precise capturing args in rustdoc Json typed) - #138343 (Enable `f16` tests for `powf`) - #138356 (bump libc to 0.2.171 to fix xous) - #138371 (Update compiletest's `has_asm_support` to match rustc) - #138404 (Cleanup sysroot locating a bit) r? `@ghost` `@rustbot` modify labels: rollup
2025-03-12rustdoc-json: Clean up & Document id handlingAlona Enraght-Moony-44/+85
Alot of the current id handling is weird and unnecessary. e.g: 1. The fully uninterned id type was (FullItemId, Option<FullItemId>) meaning it wasn't actually full! 2. None of the extra fields in Option<FullItemId> would ever be used 3. imported_item_id was a rustdoc_json_types::Id instead of a simpler DefId This commit removes the unnessessary complexity, and documents where the remaining complexity comes from. Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2025-03-12rustdoc-json: Extract Id handling into its own moduleAlona Enraght-Moony-74/+85
I want to work on this in a followup commit, so in this commit I make it self-contained. Contains no code changes, all functions are defined exactly as they were in conversions.rs.
2025-03-10make precise capturing args in rustdoc Json typedmorine0122-1/+12
2025-02-18Move methods from `Map` to `TyCtxt`, part 2.Nicholas Nethercote-1/+1
Continuing the work started in #136466. Every method gains a `hir_` prefix, though for the ones that already have a `par_` or `try_par_` prefix I added the `hir_` after that.
2025-02-17Move some `Map` methods onto `TyCtxt`.Nicholas Nethercote-1/+1
The end goal is to eliminate `Map` altogether. I added a `hir_` prefix to all of them, that seemed simplest. The exceptions are `module_items` which became `hir_module_free_items` because there was already a `hir_module_items`, and `items` which became `hir_free_items` for consistency with `hir_module_free_items`.