Skip to content

Commit b36f770

Browse files
committed
Auto merge of rust-lang#82265 - GuillaumeGomez:cleanup-attrs-twice, r=jyn514
Prevent to compute Item attributes twice I came across this case when working on another part of rustdoc. Not a game changer but a nice little improvement. cc `@camelid` r? `@jyn514`
2 parents 89d32eb + cc0d531 commit b36f770

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
@@ -414,7 +414,10 @@ crate fn build_impl(
414414

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

417-
let mut item = clean::Item::from_def_id_and_parts(
417+
let attrs = box merge_attrs(cx, parent_module.into(), load_attrs(cx, did), attrs);
418+
debug!("merged_attrs={:?}", attrs);
419+
420+
ret.push(clean::Item::from_def_id_and_attrs_and_parts(
418421
did,
419422
None,
420423
clean::ImplItem(clean::Impl {
@@ -428,11 +431,9 @@ crate fn build_impl(
428431
synthetic: false,
429432
blanket_impl: None,
430433
}),
434+
attrs,
431435
cx,
432-
);
433-
item.attrs = box merge_attrs(cx, parent_module.into(), load_attrs(cx, did), attrs);
434-
debug!("merged_attrs={:?}", item.attrs);
435-
ret.push(item);
436+
));
436437
}
437438

438439
fn build_module(

src/librustdoc/clean/types.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,22 @@ impl Item {
147147
name: Option<Symbol>,
148148
kind: ItemKind,
149149
cx: &mut DocContext<'_>,
150+
) -> Item {
151+
Self::from_def_id_and_attrs_and_parts(
152+
def_id,
153+
name,
154+
kind,
155+
box cx.tcx.get_attrs(def_id).clean(cx),
156+
cx,
157+
)
158+
}
159+
160+
pub fn from_def_id_and_attrs_and_parts(
161+
def_id: DefId,
162+
name: Option<Symbol>,
163+
kind: ItemKind,
164+
attrs: Box<Attributes>,
165+
cx: &mut DocContext<'_>,
150166
) -> Item {
151167
debug!("name={:?}, def_id={:?}", name, def_id);
152168

@@ -164,7 +180,7 @@ impl Item {
164180
kind: box kind,
165181
name,
166182
source: source.clean(cx),
167-
attrs: box cx.tcx.get_attrs(def_id).clean(cx),
183+
attrs,
168184
visibility: cx.tcx.visibility(def_id).clean(cx),
169185
}
170186
}

0 commit comments

Comments
 (0)