Skip to content

Commit 727d101

Browse files
committed
Auto merge of #84494 - tdelabro:84304-bis, r=jyn514
84304 - rustdoc: shrink Item::Attributes Helps with #84304
2 parents 83ebb00 + 727f904 commit 727d101

16 files changed

+158
-128
lines changed

src/librustdoc/clean/auto_trait.rs

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
126126
synthetic: true,
127127
blanket_impl: None,
128128
}),
129+
cfg: None,
129130
})
130131
}
131132

src/librustdoc/clean/blanket_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
128128
synthetic: false,
129129
blanket_impl: Some(trait_ref.self_ty().clean(self.cx)),
130130
}),
131+
cfg: None,
131132
});
132133
}
133134
}

src/librustdoc/clean/inline.rs

+28-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Support for inlining external documentation into the current AST.
22
33
use std::iter::once;
4+
use std::sync::Arc;
45

56
use rustc_ast as ast;
67
use rustc_data_structures::fx::FxHashSet;
@@ -14,7 +15,7 @@ use rustc_span::hygiene::MacroKind;
1415
use rustc_span::symbol::{kw, sym, Symbol};
1516
use rustc_span::Span;
1617

17-
use crate::clean::{self, Attributes, GetDefId, ToSource};
18+
use crate::clean::{self, Attributes, AttributesExt, GetDefId, ToSource};
1819
use crate::core::DocContext;
1920
use crate::formats::item_type::ItemType;
2021

@@ -119,12 +120,16 @@ crate fn try_inline(
119120
_ => return None,
120121
};
121122

122-
let target_attrs = load_attrs(cx, did);
123-
let attrs = box merge_attrs(cx, Some(parent_module), target_attrs, attrs_clone);
124-
123+
let (attrs, cfg) = merge_attrs(cx, Some(parent_module), load_attrs(cx, did), attrs_clone);
125124
cx.inlined.insert(did);
126-
let what_rustc_thinks = clean::Item::from_def_id_and_parts(did, Some(name), kind, cx);
127-
ret.push(clean::Item { attrs, ..what_rustc_thinks });
125+
ret.push(clean::Item::from_def_id_and_attrs_and_parts(
126+
did,
127+
Some(name),
128+
kind,
129+
box attrs,
130+
cx,
131+
cfg,
132+
));
128133
Some(ret)
129134
}
130135

@@ -288,22 +293,24 @@ fn merge_attrs(
288293
parent_module: Option<DefId>,
289294
old_attrs: Attrs<'_>,
290295
new_attrs: Option<Attrs<'_>>,
291-
) -> clean::Attributes {
296+
) -> (clean::Attributes, Option<Arc<clean::cfg::Cfg>>) {
292297
// NOTE: If we have additional attributes (from a re-export),
293298
// always insert them first. This ensure that re-export
294299
// doc comments show up before the original doc comments
295300
// when we render them.
296301
if let Some(inner) = new_attrs {
297-
if let Some(new_id) = parent_module {
298-
let diag = cx.sess().diagnostic();
299-
Attributes::from_ast(diag, old_attrs, Some((inner, new_id)))
300-
} else {
301-
let mut both = inner.to_vec();
302-
both.extend_from_slice(old_attrs);
303-
both.clean(cx)
304-
}
302+
let mut both = inner.to_vec();
303+
both.extend_from_slice(old_attrs);
304+
(
305+
if let Some(new_id) = parent_module {
306+
Attributes::from_ast(old_attrs, Some((inner, new_id)))
307+
} else {
308+
Attributes::from_ast(&both, None)
309+
},
310+
both.cfg(cx.sess().diagnostic()),
311+
)
305312
} else {
306-
old_attrs.clean(cx)
313+
(old_attrs.clean(cx), old_attrs.cfg(cx.sess().diagnostic()))
307314
}
308315
}
309316

@@ -414,8 +421,8 @@ crate fn build_impl(
414421

415422
debug!("build_impl: impl {:?} for {:?}", trait_.def_id(), for_.def_id());
416423

417-
let attrs = box merge_attrs(cx, parent_module.into(), load_attrs(cx, did), attrs);
418-
debug!("merged_attrs={:?}", attrs);
424+
let (merged_attrs, cfg) = merge_attrs(cx, parent_module.into(), load_attrs(cx, did), attrs);
425+
debug!("merged_attrs={:?}", merged_attrs);
419426

420427
ret.push(clean::Item::from_def_id_and_attrs_and_parts(
421428
did,
@@ -432,8 +439,9 @@ crate fn build_impl(
432439
synthetic: false,
433440
blanket_impl: None,
434441
}),
435-
attrs,
442+
box merged_attrs,
436443
cx,
444+
cfg,
437445
));
438446
}
439447

@@ -479,6 +487,7 @@ fn build_module(
479487
},
480488
true,
481489
)),
490+
cfg: None,
482491
});
483492
} else if let Some(i) = try_inline(cx, did, item.res, item.ident.name, None, visited) {
484493
items.extend(i)

src/librustdoc/clean/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ impl<T: Clean<U>, U> Clean<Option<U>> for Option<T> {
8484
}
8585

8686
impl Clean<ExternalCrate> for CrateNum {
87-
fn clean(&self, cx: &mut DocContext<'_>) -> ExternalCrate {
88-
let root = DefId { krate: *self, index: CRATE_DEF_INDEX };
89-
ExternalCrate { crate_num: *self, attrs: cx.tcx.get_attrs(root).clean(cx) }
87+
fn clean(&self, _cx: &mut DocContext<'_>) -> ExternalCrate {
88+
ExternalCrate { crate_num: *self }
9089
}
9190
}
9291

@@ -123,8 +122,8 @@ impl Clean<Item> for doctree::Module<'_> {
123122
}
124123

125124
impl Clean<Attributes> for [ast::Attribute] {
126-
fn clean(&self, cx: &mut DocContext<'_>) -> Attributes {
127-
Attributes::from_ast(cx.sess().diagnostic(), self, None)
125+
fn clean(&self, _cx: &mut DocContext<'_>) -> Attributes {
126+
Attributes::from_ast(self, None)
128127
}
129128
}
130129

@@ -850,7 +849,6 @@ where
850849
inputs: (self.0.inputs, self.1).clean(cx),
851850
output: self.0.output.clean(cx),
852851
c_variadic: self.0.c_variadic,
853-
attrs: Attributes::default(),
854852
}
855853
}
856854
}
@@ -862,7 +860,6 @@ impl<'tcx> Clean<FnDecl> for (DefId, ty::PolyFnSig<'tcx>) {
862860

863861
FnDecl {
864862
output: Return(sig.skip_binder().output().clean(cx)),
865-
attrs: Attributes::default(),
866863
c_variadic: sig.skip_binder().c_variadic,
867864
inputs: Arguments {
868865
values: sig
@@ -2001,13 +1998,15 @@ fn clean_extern_crate(
20011998
return items;
20021999
}
20032000
}
2001+
20042002
// FIXME: using `from_def_id_and_kind` breaks `rustdoc/masked` for some reason
20052003
vec![Item {
20062004
name: Some(name),
20072005
attrs: box attrs.clean(cx),
20082006
def_id: crate_def_id,
20092007
visibility: krate.vis.clean(cx),
20102008
kind: box ExternCrateItem { src: orig_name },
2009+
cfg: attrs.cfg(cx.sess().diagnostic()),
20112010
}]
20122011
}
20132012

0 commit comments

Comments
 (0)