Skip to content

Commit 0e07904

Browse files
Prevent to compute Item attributes twice
1 parent 323fb71 commit 0e07904

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/librustdoc/clean/inline.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,10 @@ crate fn build_impl(
416416

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

419-
let mut item = clean::Item::from_def_id_and_parts(
419+
let attrs = box merge_attrs(cx, parent_module.into(), load_attrs(cx, did), attrs);
420+
debug!("merged_attrs={:?}", attrs);
421+
422+
ret.push(clean::Item::from_def_id_and_attrs_and_parts(
420423
did,
421424
None,
422425
clean::ImplItem(clean::Impl {
@@ -430,11 +433,9 @@ crate fn build_impl(
430433
synthetic: false,
431434
blanket_impl: None,
432435
}),
436+
attrs,
433437
cx,
434-
);
435-
item.attrs = box merge_attrs(cx, parent_module.into(), load_attrs(cx, did), attrs);
436-
debug!("merged_attrs={:?}", item.attrs);
437-
ret.push(item);
438+
));
438439
}
439440

440441
fn build_module(cx: &DocContext<'_>, did: DefId, visited: &mut FxHashSet<DefId>) -> clean::Module {

src/librustdoc/clean/types.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,22 @@ impl Item {
140140
name: Option<Symbol>,
141141
kind: ItemKind,
142142
cx: &DocContext<'_>,
143+
) -> Item {
144+
Self::from_def_id_and_attrs_and_parts(
145+
def_id,
146+
name,
147+
kind,
148+
box cx.tcx.get_attrs(def_id).clean(cx),
149+
cx,
150+
)
151+
}
152+
153+
pub fn from_def_id_and_attrs_and_parts(
154+
def_id: DefId,
155+
name: Option<Symbol>,
156+
kind: ItemKind,
157+
attrs: Box<Attributes>,
158+
cx: &DocContext<'_>,
143159
) -> Item {
144160
debug!("name={:?}, def_id={:?}", name, def_id);
145161

@@ -157,7 +173,7 @@ impl Item {
157173
kind: box kind,
158174
name,
159175
source: source.clean(cx),
160-
attrs: box cx.tcx.get_attrs(def_id).clean(cx),
176+
attrs,
161177
visibility: cx.tcx.visibility(def_id).clean(cx),
162178
}
163179
}

0 commit comments

Comments
 (0)