Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7af87d1
editorconfig: don't trim trailing whitespace in tests
lolbinarycat Jul 29, 2025
378dd7c
Add regression test for former ICE involving malformed meta items con…
fmease Aug 11, 2025
c1a31d8
Deprecate RUST_TEST_* env variables
epage Aug 11, 2025
e854013
Port `#[custom_mir(..)]` to the new attribute system
scrabsha Aug 10, 2025
db1a64c
simplify stack handling, be completely lazy
lcnr Aug 5, 2025
bd44d85
Link to payload_as_str() from payload().
m-ou-se Aug 12, 2025
0d72323
chore(ci): upgrade checkout to v5
rejected-l Aug 12, 2025
0b855bc
Switch to a bitflags `MacroKinds` to support macros with more than on…
joshtriplett Aug 8, 2025
d7b30be
Expand documentation of `GlobDelegation`
joshtriplett Aug 9, 2025
c81fcac
Only suggest changing `#[derive(mymacro)]` to `#[mymacro]` for attrib…
joshtriplett Aug 9, 2025
ba231db
Detect and report macro kind mismatches early, and more precisely
joshtriplett Aug 9, 2025
b74e1cb
mbe: Rename macro parsing state names to use `Bang` instead of `Not`
joshtriplett Aug 9, 2025
33ba4a2
clippy: Update for switch to `MacroKinds`
joshtriplett Aug 9, 2025
e1fc89a
rustdoc: Minimal fixes to compile with `MacroKinds`
joshtriplett Aug 9, 2025
0338842
Rollup merge of #144642 - lolbinarycat:editorconfig-no-run-make, r=lcnr
jhpratt Aug 12, 2025
7b66001
Rollup merge of #144955 - lcnr:lazily-update-non-parent-goals, r=BoxyUwU
jhpratt Aug 12, 2025
25a3df8
Rollup merge of #145153 - joshtriplett:macro-kinds-plural, r=petroche…
jhpratt Aug 12, 2025
044cdf2
Rollup merge of #145206 - scrabsha:push-uxovoqzrxnlx, r=jdonszelmann
jhpratt Aug 12, 2025
d7bf066
Rollup merge of #145250 - fmease:regr-test-for-attr-meta-ice, r=jdons…
jhpratt Aug 12, 2025
3cb4a98
Rollup merge of #145269 - epage:test-env, r=jhpratt
jhpratt Aug 12, 2025
581a7ce
Rollup merge of #145289 - rejected-l:master, r=Kobzol
jhpratt Aug 12, 2025
77fe3d6
Rollup merge of #145303 - m-ou-se:payload-as-str-doc, r=jhpratt
jhpratt Aug 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rustdoc: Minimal fixes to compile with MacroKinds
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.
  • Loading branch information
joshtriplett committed Aug 12, 2025
commit e1fc89af5bb657acb45097cae15873de78210065
53 changes: 35 additions & 18 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::sync::Arc;
use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir;
use rustc_hir::Mutability;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def::{DefKind, MacroKinds, Res};
use rustc_hir::def_id::{DefId, DefIdSet, LocalDefId, LocalModDefId};
use rustc_metadata::creader::{CStore, LoadedMacro};
use rustc_middle::ty::fast_reject::SimplifiedType;
Expand Down Expand Up @@ -137,13 +137,16 @@ pub(crate) fn try_inline(
clean::ConstantItem(Box::new(ct))
})
}
Res::Def(DefKind::Macro(kind), did) => {
let mac = build_macro(cx, did, name, kind);

let type_kind = match kind {
MacroKind::Bang => ItemType::Macro,
MacroKind::Attr => ItemType::ProcAttribute,
MacroKind::Derive => ItemType::ProcDerive,
Res::Def(DefKind::Macro(kinds), did) => {
let mac = build_macro(cx, did, name, kinds);

// FIXME: handle attributes and derives that aren't proc macros, and macros with
// multiple kinds
let type_kind = match kinds {
MacroKinds::BANG => ItemType::Macro,
MacroKinds::ATTR => ItemType::ProcAttribute,
MacroKinds::DERIVE => ItemType::ProcDerive,
_ => todo!("Handle macros with multiple kinds"),
};
record_extern_fqn(cx, did, type_kind);
mac
Expand Down Expand Up @@ -749,22 +752,36 @@ fn build_macro(
cx: &mut DocContext<'_>,
def_id: DefId,
name: Symbol,
macro_kind: MacroKind,
macro_kinds: MacroKinds,
) -> clean::ItemKind {
match CStore::from_tcx(cx.tcx).load_macro_untracked(def_id, cx.tcx) {
LoadedMacro::MacroDef { def, .. } => match macro_kind {
MacroKind::Bang => clean::MacroItem(clean::Macro {
// FIXME: handle attributes and derives that aren't proc macros, and macros with multiple
// kinds
LoadedMacro::MacroDef { def, .. } => match macro_kinds {
MacroKinds::BANG => clean::MacroItem(clean::Macro {
source: utils::display_macro_source(cx, name, &def),
macro_rules: def.macro_rules,
}),
MacroKind::Derive | MacroKind::Attr => {
clean::ProcMacroItem(clean::ProcMacro { kind: macro_kind, helpers: Vec::new() })
}
MacroKinds::DERIVE => clean::ProcMacroItem(clean::ProcMacro {
kind: MacroKind::Derive,
helpers: Vec::new(),
}),
MacroKinds::ATTR => clean::ProcMacroItem(clean::ProcMacro {
kind: MacroKind::Attr,
helpers: Vec::new(),
}),
_ => todo!("Handle macros with multiple kinds"),
},
LoadedMacro::ProcMacro(ext) => clean::ProcMacroItem(clean::ProcMacro {
kind: ext.macro_kind(),
helpers: ext.helper_attrs,
}),
LoadedMacro::ProcMacro(ext) => {
// Proc macros can only have a single kind
let kind = match ext.macro_kinds() {
MacroKinds::BANG => MacroKind::Bang,
MacroKinds::ATTR => MacroKind::Attr,
MacroKinds::DERIVE => MacroKind::Derive,
_ => unreachable!(),
};
clean::ProcMacroItem(clean::ProcMacro { kind, helpers: ext.helper_attrs })
}
}
}

Expand Down
14 changes: 11 additions & 3 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet, In
use rustc_errors::codes::*;
use rustc_errors::{FatalError, struct_span_code_err};
use rustc_hir::attrs::AttributeKind;
use rustc_hir::def::{CtorKind, DefKind, Res};
use rustc_hir::def::{CtorKind, DefKind, MacroKinds, Res};
use rustc_hir::def_id::{DefId, DefIdMap, DefIdSet, LOCAL_CRATE, LocalDefId};
use rustc_hir::{LangItem, PredicateOrigin, find_attr};
use rustc_hir_analysis::hir_ty_lowering::FeedConstTy;
Expand Down Expand Up @@ -2845,11 +2845,19 @@ fn clean_maybe_renamed_item<'tcx>(
generics: clean_generics(generics, cx),
fields: variant_data.fields().iter().map(|x| clean_field(x, cx)).collect(),
}),
ItemKind::Macro(_, macro_def, MacroKind::Bang) => MacroItem(Macro {
// FIXME: handle attributes and derives that aren't proc macros, and macros with
// multiple kinds
ItemKind::Macro(_, macro_def, MacroKinds::BANG) => MacroItem(Macro {
source: display_macro_source(cx, name, macro_def),
macro_rules: macro_def.macro_rules,
}),
ItemKind::Macro(_, _, macro_kind) => clean_proc_macro(item, &mut name, macro_kind, cx),
ItemKind::Macro(_, _, MacroKinds::ATTR) => {
clean_proc_macro(item, &mut name, MacroKind::Attr, cx)
}
ItemKind::Macro(_, _, MacroKinds::DERIVE) => {
clean_proc_macro(item, &mut name, MacroKind::Derive, cx)
}
ItemKind::Macro(_, _, _) => todo!("Handle macros with multiple kinds"),
// proc macros can have a name set by attributes
ItemKind::Fn { ref sig, generics, body: body_id, .. } => {
clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx)
Expand Down
9 changes: 5 additions & 4 deletions src/librustdoc/formats/item_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use std::fmt;

use rustc_hir::def::{CtorOf, DefKind};
use rustc_hir::def::{CtorOf, DefKind, MacroKinds};
use rustc_span::hygiene::MacroKind;
use serde::{Serialize, Serializer};

Expand Down Expand Up @@ -134,9 +134,10 @@ impl ItemType {
DefKind::Trait => Self::Trait,
DefKind::TyAlias => Self::TypeAlias,
DefKind::TraitAlias => Self::TraitAlias,
DefKind::Macro(MacroKind::Bang) => ItemType::Macro,
DefKind::Macro(MacroKind::Attr) => ItemType::ProcAttribute,
DefKind::Macro(MacroKind::Derive) => ItemType::ProcDerive,
DefKind::Macro(MacroKinds::BANG) => ItemType::Macro,
DefKind::Macro(MacroKinds::ATTR) => ItemType::ProcAttribute,
DefKind::Macro(MacroKinds::DERIVE) => ItemType::ProcDerive,
DefKind::Macro(_) => todo!("Handle macros with multiple kinds"),
DefKind::ForeignTy => Self::ForeignType,
DefKind::Variant => Self::Variant,
DefKind::Field => Self::StructField,
Expand Down
28 changes: 16 additions & 12 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
use rustc_data_structures::intern::Interned;
use rustc_errors::{Applicability, Diag, DiagMessage};
use rustc_hir::def::Namespace::*;
use rustc_hir::def::{DefKind, Namespace, PerNS};
use rustc_hir::def::{DefKind, MacroKinds, Namespace, PerNS};
use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LOCAL_CRATE};
use rustc_hir::{Mutability, Safety};
use rustc_middle::ty::{Ty, TyCtxt};
Expand All @@ -25,7 +25,6 @@ use rustc_resolve::rustdoc::{
use rustc_session::config::CrateType;
use rustc_session::lint::Lint;
use rustc_span::BytePos;
use rustc_span::hygiene::MacroKind;
use rustc_span::symbol::{Ident, Symbol, sym};
use smallvec::{SmallVec, smallvec};
use tracing::{debug, info, instrument, trace};
Expand Down Expand Up @@ -115,9 +114,11 @@ impl Res {

let prefix = match kind {
DefKind::Fn | DefKind::AssocFn => return Suggestion::Function,
DefKind::Macro(MacroKind::Bang) => return Suggestion::Macro,
// FIXME: handle macros with multiple kinds, and attribute/derive macros that aren't
// proc macros
DefKind::Macro(MacroKinds::BANG) => return Suggestion::Macro,

DefKind::Macro(MacroKind::Derive) => "derive",
DefKind::Macro(MacroKinds::DERIVE) => "derive",
DefKind::Struct => "struct",
DefKind::Enum => "enum",
DefKind::Trait => "trait",
Expand Down Expand Up @@ -881,9 +882,12 @@ fn trait_impls_for<'a>(
fn is_derive_trait_collision<T>(ns: &PerNS<Result<Vec<(Res, T)>, ResolutionFailure<'_>>>) -> bool {
if let (Ok(type_ns), Ok(macro_ns)) = (&ns.type_ns, &ns.macro_ns) {
type_ns.iter().any(|(res, _)| matches!(res, Res::Def(DefKind::Trait, _)))
&& macro_ns
.iter()
.any(|(res, _)| matches!(res, Res::Def(DefKind::Macro(MacroKind::Derive), _)))
&& macro_ns.iter().any(|(res, _)| {
matches!(
res,
Res::Def(DefKind::Macro(kinds), _) if kinds.contains(MacroKinds::DERIVE)
)
})
} else {
false
}
Expand Down Expand Up @@ -1662,11 +1666,11 @@ impl Disambiguator {

let suffixes = [
// If you update this list, please also update the relevant rustdoc book section!
("!()", DefKind::Macro(MacroKind::Bang)),
("!{}", DefKind::Macro(MacroKind::Bang)),
("![]", DefKind::Macro(MacroKind::Bang)),
("!()", DefKind::Macro(MacroKinds::BANG)),
("!{}", DefKind::Macro(MacroKinds::BANG)),
("![]", DefKind::Macro(MacroKinds::BANG)),
("()", DefKind::Fn),
("!", DefKind::Macro(MacroKind::Bang)),
("!", DefKind::Macro(MacroKinds::BANG)),
];

if let Some(idx) = link.find('@') {
Expand All @@ -1685,7 +1689,7 @@ impl Disambiguator {
safety: Safety::Safe,
}),
"function" | "fn" | "method" => Kind(DefKind::Fn),
"derive" => Kind(DefKind::Macro(MacroKind::Derive)),
"derive" => Kind(DefKind::Macro(MacroKinds::DERIVE)),
"field" => Kind(DefKind::Field),
"variant" => Kind(DefKind::Variant),
"type" => NS(Namespace::TypeNS),
Expand Down
7 changes: 3 additions & 4 deletions src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ use std::mem;

use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def::{DefKind, MacroKinds, Res};
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, LocalDefIdSet};
use rustc_hir::intravisit::{Visitor, walk_body, walk_item};
use rustc_hir::{CRATE_HIR_ID, Node};
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::TyCtxt;
use rustc_span::Span;
use rustc_span::def_id::{CRATE_DEF_ID, LOCAL_CRATE};
use rustc_span::hygiene::MacroKind;
use rustc_span::symbol::{Symbol, kw, sym};
use tracing::debug;

Expand Down Expand Up @@ -325,7 +324,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {

let is_bang_macro = matches!(
item,
Node::Item(&hir::Item { kind: hir::ItemKind::Macro(_, _, MacroKind::Bang), .. })
Node::Item(&hir::Item { kind: hir::ItemKind::Macro(_, _, kinds), .. }) if kinds.contains(MacroKinds::BANG)
);

if !self.view_item_stack.insert(res_did) && !is_bang_macro {
Expand Down Expand Up @@ -406,7 +405,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
// attribute can still be visible.
|| match item.kind {
hir::ItemKind::Impl(..) => true,
hir::ItemKind::Macro(_, _, MacroKind::Bang) => {
hir::ItemKind::Macro(_, _, _) => {
self.cx.tcx.has_attr(item.owner_id.def_id, sym::macro_export)
}
_ => false,
Expand Down
Loading