Repository: rust-lang/rust
File: src/librustdoc/html/render/print_item.rs (Rust)

Code before:
                        tag
                    )
                )?;
                last_section = Some(my_section);
            }

            for (_, myitem) in &not_stripped_items[&type_] {
                let visibility_and_hidden = |item: &clean::Item| match item.visibility(tcx) {
                    Some(ty::Visibility::Restricted(_)) => {
                        if item.is_doc_hidden() {
                            // Don't separate with a space when there are two of them
                            "<span title=\"Restricted Visibility\">&nbsp;🔒</span><span title=\"Hidden item\">👻</span> "
                        } else {
                            "<span title=\"Restricted Visibility\">&nbsp;🔒</span> "
                        }
                    }
                    _ if item.is_doc_hidden() => "<span title=\"Hidden item\">&nbsp;👻</span> ",
                    _ => "",
                };

                match myitem.kind {
                    clean::ExternCrateItem { ref src } => {
                        use crate::html::format::print_anchor;

                        let visibility_and_hidden = visibility_and_hidden(myitem);
                        write!(w, "<dt><code>")?;
                        render_attributes_in_code(w, myitem, "", cx)?;
                        match *src {
                            Some(src) => {
                                write!(
                                    w,
                                    "{}extern crate {} as {};",
                                    visibility_print_with_space(myitem, cx),
                                    print_anchor(myitem.item_id.expect_def_id(), src, cx),
                                    EscapeBodyTextWithWbr(myitem.name.unwrap().as_str())
                                )?;
                            }
                            None => {
                                write!(
                                    w,
                                    "{}extern crate {};",
                                    visibility_print_with_space(myitem, cx),
                                    print_anchor(
                                        myitem.item_id.expect_def_id(),
                                        myitem.name.unwrap(),
                                        cx
                                    )
                                )?;
                            }
                        }
                        write!(w, "</code>{visibility_and_hidden}</dt>")?

Review comment (refactor):
Please move this into `render_attributes_in_code` so we don't write `<dt><code>` if there are no attributes.

Code after:
                    write_section_heading(
                        my_section.name(),
                        &cx.derive_id(my_section.id()),
                        None,
                        tag
                    )
                )?;
                last_section = Some(my_section);
            }

            for (_, myitem) in &not_stripped_items[&type_] {
                let visibility_and_hidden = |item: &clean::Item| match item.visibility(tcx) {
                    Some(ty::Visibility::Restricted(_)) => {
                        if item.is_doc_hidden() {
                            // Don't separate with a space when there are two of them
                            "<span title=\"Restricted Visibility\">&nbsp;🔒</span><span title=\"Hidden item\">👻</span> "
                        } else {
                            "<span title=\"Restricted Visibility\">&nbsp;🔒</span> "
                        }
                    }
                    _ if item.is_doc_hidden() => "<span title=\"Hidden item\">&nbsp;👻</span> ",
                    _ => "",
                };

                match myitem.kind {
                    clean::ExternCrateItem { ref src } => {
                        use crate::html::format::print_anchor;

                        let visibility_and_hidden = visibility_and_hidden(myitem);
                        // Module listings use the hidden marker, so skip doc(hidden) here.
                        super::render_attributes_in_code_with_options(
                            w,
                            myitem,
                            "",
                            cx,
                            false,
                            "<dt><code>",
                        )?;
                        match *src {
                            Some(src) => {
                                write!(
                                    w,
                                    "{}extern crate {} as {};",
                                    visibility_print_with_space(myitem, cx),
                                    print_anchor(myitem.item_id.expect_def_id(), src, cx),
                                    EscapeBodyTextWithWbr(myitem.name.unwrap().as_str())
                                )?;
                            }
                            None => {
                                write!(
                                    w,