about summary refs log tree commit diff
path: root/src/librustdoc/visit_ast.rs
AgeCommit message (Collapse)AuthorLines
2025-08-12rustdoc: Minimal fixes to compile with `MacroKinds`Josh Triplett-4/+3
This makes the minimal fixes necessary for rustdoc to compile and pass existing tests with the switch to `MacroKinds`. It only works for macros that don't actually have multiple kinds, and will panic (with a `todo!`) if it encounters a macro with multiple kinds. rustdoc needs further fixes to handle macros with multiple kinds, and to handle attributes and derive macros that aren't proc macros.
2025-07-13Retire hir::ForeignItemRef.Camille GILLOT-2/+2
2025-07-08Fix weird rustdoc output when single and glob reexport conflict on a nameGuillaume Gomez-17/+47
2025-06-27rustdoc: fix attrs of locally reexported foreign itemsbinarycat-5/+15
2025-06-03Overhaul `UsePath`.Nicholas Nethercote-1/+1
`UsePath` contains a `SmallVec<[Res; 3]>`. This holds up to three `Res` results, one per namespace (type, value, or macro). `lower_import_res` takes a `PerNS<Option<Res<NodeId>>>` result and lowers it into the `SmallVec`. This is pretty weird. The input `PerNS` makes it clear which `Res` belongs to which namespace, but the `SmallVec` throws that information away. And code that operates on the `SmallVec` tends to use iteration (or even just grabbing the first entry!) without knowing which namespace the `Res` belongs to. Even weirder! Also, `SmallVec` is an overly flexible type to use here, because it can contain any number of elements (even though it's optimized for 3 in this case). This commit changes `UsePath` so it also contains a `PerNS<Option<Res<HirId>>>`. This type preserves more information and is more self-documenting. The commit also changes a lot of the use sites to access the result for a particular namespace. E.g. if you're looking up a trait, it will be in the `Res` for the type namespace if it's present; it's silly to look in the `Res` for the value namespace or macro namespace. Overall I find the new code much easier to understand. However, some use sites still iterate. These now use `present_items` because that filters out the `None` results. Also, `redundant_pub_crate.rs` gets a bigger change. A `UseKind:ListStem` item gets no `Res` results, which means the old `all` call in `is_not_macro_export` would succeed (because `all` succeeds on an empty iterator) and the `ListStem` would be ignored. This is what we want, but was more by luck than design. The new code detects `ListStem` explicitly. The commit generalizes the name of that function accordingly. Finally, the commit also removes the `use_path` arena, because `PerNS<Option<Res>>` impls `Copy` (unlike `SmallVec`) and it can be allocated in the arena shared by all `Copy` types.
2025-03-18Move `hir::Item::ident` into `hir::ItemKind`.Nicholas Nethercote-22/+19
`hir::Item` has an `ident` field. - It's always non-empty for these item kinds: `ExternCrate`, `Static`, `Const`, `Fn`, `Macro`, `Mod`, `TyAlias`, `Enum`, `Struct`, `Union`, Trait`, TraitAalis`. - It's always empty for these item kinds: `ForeignMod`, `GlobalAsm`, `Impl`. - For `Use`, it is non-empty for `UseKind::Single` and empty for `UseKind::{Glob,ListStem}`. All of this is quite non-obvious; the only documentation is a single comment saying "The name might be a dummy name in case of anonymous items". Some sites that handle items check for an empty ident, some don't. This is a very C-like way of doing things, but this is Rust, we have sum types, we can do this properly and never forget to check for the exceptional case and never YOLO possibly empty identifiers (or possibly dummy spans) around and hope that things will work out. The commit is large but it's mostly obvious plumbing work. Some notable things. - A similar transformation makes sense for `ast::Item`, but this is already a big change. That can be done later. - Lots of assertions are added to item lowering to ensure that identifiers are empty/non-empty as expected. These will be removable when `ast::Item` is done later. - `ItemKind::Use` doesn't get an `Ident`, but `UseKind::Single` does. - `lower_use_tree` is significantly simpler. No more confusing `&mut Ident` to deal with. - `ItemKind::ident` is a new method, it returns an `Option<Ident>`. It's used with `unwrap` in a few places; sometimes it's hard to tell exactly which item kinds might occur. None of these unwraps fail on the test suite. It's conceivable that some might fail on alternative input. We can deal with those if/when they happen. - In `trait_path` the `find_map`/`if let` is replaced with a loop, and things end up much clearer that way. - `named_span` no longer checks for an empty name; instead the call site now checks for a missing identifier if necessary. - `maybe_inline_local` doesn't need the `glob` argument, it can be computed in-function from the `renamed` argument. - `arbitrary_source_item_ordering::check_mod` had a big `if` statement that was just getting the ident from the item kinds that had one. It could be mostly replaced by a single call to the new `ItemKind::ident` method. - `ItemKind` grows from 56 to 64 bytes, but `Item` stays the same size, and that's what matters, because `ItemKind` only occurs within `Item`.
2025-03-12Move methods from `Map` to `TyCtxt`, part 4.Nicholas Nethercote-5/+4
Continuing the work from #137350. Removes the unused methods: `expect_variant`, `expect_field`, `expect_foreign_item`. Every method gains a `hir_` prefix.
2025-02-22Make asm a named fieldMichael Goulet-1/+1
2025-02-17Overhaul the `intravisit::Map` trait.Nicholas Nethercote-2/+2
First of all, note that `Map` has three different relevant meanings. - The `intravisit::Map` trait. - The `map::Map` struct. - The `NestedFilter::Map` associated type. The `intravisit::Map` trait is impl'd twice. - For `!`, where the methods are all unreachable. - For `map::Map`, which gets HIR stuff from the `TyCtxt`. As part of getting rid of `map::Map`, this commit changes `impl intravisit::Map for map::Map` to `impl intravisit::Map for TyCtxt`. It's fairly straightforward except various things are renamed, because the existing names would no longer have made sense. - `trait intravisit::Map` becomes `trait intravisit::HirTyCtxt`, so named because it gets some HIR stuff from a `TyCtxt`. - `NestedFilter::Map` assoc type becomes `NestedFilter::MaybeTyCtxt`, because it's always `!` or `TyCtxt`. - `Visitor::nested_visit_map` becomes `Visitor::maybe_tcx`. I deliberately made the new trait and associated type names different to avoid the old `type Map: Map` situation, which I found confusing. We now have `type MaybeTyCtxt: HirTyCtxt`.
2025-02-17Move some `Map` methods onto `TyCtxt`.Nicholas Nethercote-6/+6
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`.
2025-01-23Rustdog :3cBoxy-2/+7
2025-01-12rustdoc: Extract `AttributesExt::lists` trait method as functionNoah Lev-3/+3
The two implementations were identical, so there's no need to use a trait method.
2025-01-04turn hir::ItemKind::Fn into a named-field variantRalf Jung-1/+1
2024-11-28Fix new clippy lintsGuillaume Gomez-4/+4
2024-11-04Rename `DocContext::is_json` into `DocContext::is_json_output`Guillaume Gomez-1/+1
2024-11-04Fix invalid coverage computation when `--output-format=json` is enabledGuillaume Gomez-1/+1
2024-10-04rm `ItemKind::OpaqueTy`Noah Lev-10/+0
This introduce an additional collection of opaques on HIR, as they can no longer be listed using the free item list.
2024-10-04Rollup merge of #131034 - Urgau:cfg-true-false, r=nnethercoteGuillaume Gomez-1/+1
Implement RFC3695 Allow boolean literals as cfg predicates This PR implements https://github.com/rust-lang/rfcs/pull/3695: allow boolean literals as cfg predicates, i.e. `cfg(true)` and `cfg(false)`. r? `@nnethercote` *(or anyone with parser knowledge)* cc `@clubby789`
2024-10-04Adjust rustdoc for literal boolean supportUrgau-1/+1
2024-10-02Use named fields for OpaqueTyOriginMichael Goulet-1/+1
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-5/+5
2024-08-30Remove `#[macro_use] extern crate tracing` from rustdoc.Nicholas Nethercote-0/+1
2024-07-29Reformat `use` declarations.Nicholas Nethercote-3/+4
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-05-29Don't require `visit_body` to take a lifetime that must outlive the function ↵Oli Scherer-1/+1
call
2023-12-18Rename `Session::span_diagnostic` as `Session::dcx`.Nicholas Nethercote-1/+1
2023-12-15NFC don't convert types to identical typesMatthias Krüger-4/+5
2023-12-12Move some methods from `tcx.hir()` to `tcx`zetanumbers-1/+1
Renamings: - find -> opt_hir_node - get -> hir_node - find_by_def_id -> opt_hir_node_by_def_id - get_by_def_id -> hir_node_by_def_id Fix rebase changes using removed methods Use `tcx.hir_node_by_def_id()` whenever possible in compiler Fix clippy errors Fix compiler Apply suggestions from code review Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com> Add FIXME for `tcx.hir()` returned type about its removal Simplify with with `tcx.hir_node_by_def_id`
2023-11-26rustc: `hir().local_def_id_to_hir_id()` -> `tcx.local_def_id_to_hir_id()` ↵Vadim Petrochenkov-3/+2
cleanup
2023-11-15Re-format code with new rustfmtMark Rousskov-6/+8
2023-08-16Improve code readability by moving fmt args directly into the stringGuillaume Gomez-3/+3
2023-07-29Move `inherits_doc_hidden` and `should_ignore_res` into `clean/utils.rs`Guillaume Gomez-32/+1
2023-07-29Move Res check into `should_ignore_res`Guillaume Gomez-1/+6
2023-07-24Fix missing attribute merge on glob foreign re-exportsGuillaume Gomez-2/+2
2023-07-18Remove unneeded `Option<Symbol>` in `foreign_items`Guillaume Gomez-3/+2
2023-07-18Fix invalid display of inlined re-exportGuillaume Gomez-14/+26
2023-07-14Correctly handle `--document-hidden-items`Guillaume Gomez-3/+7
2023-06-20Fix invalid creation of files in rustdocGuillaume Gomez-2/+5
2023-06-06rustdoc: convert `if let Some()` that always matches to variableMichael Howell-18/+28
2023-06-05fix spelling errorLuca Scherzer-3/+3
2023-06-01Fix bug where private item with intermediate doc hidden re-export was not ↵Guillaume Gomez-1/+2
inlined
2023-05-30Fix re-export of doc hidden item inside private item not displayedGuillaume Gomez-25/+32
2023-05-27Rollup merge of #112018 - GuillaumeGomez:cleanup-tcx, r=notriddleMatthias Krüger-7/+6
Clean up usage of `cx.tcx` when `tcx` is already set into a variable I discovered a few cases where `cx.tcx` (and equivalents) was used whereas `tcx` was already stored into a variable. In those cases, better to just use `tcx` directly. r? `@notriddle`
2023-05-27Clean up usage of `cx.tcx` when `tcx` is already set into a variableGuillaume Gomez-7/+6
2023-05-27Correctly handle multiple re-exports of bang macros at the same levelGuillaume Gomez-3/+9
2023-05-26Fix re-export of doc hidden macro not showing upGuillaume Gomez-0/+10
2023-05-16Only keep impl blocks from bodiesGuillaume Gomez-1/+29
2023-05-12Require `impl Trait` in associated types to appear in method signaturesOli Scherer-1/+2
2023-05-10Rollup merge of #111095 - GuillaumeGomez:fix-assoc-item-trait-inside-hidden, ↵Matthias Krüger-15/+36
r=notriddle Correctly handle associated items of a trait inside a `#[doc(hidden)]` item Fixes https://github.com/rust-lang/rust/issues/111064. cc `@compiler-errors` r? `@notriddle`
2023-05-05Modules can be reexported and it should be handled by rustdocGuillaume Gomez-7/+33
2023-05-05Correctly handle associated items of a trait inside a `#[doc(hidden)]` itemGuillaume Gomez-8/+3