Auto merge of #140441 - GuillaumeGomez:iterator-instead-of-vec, r= · rust-lang/rust@1b81120 (original) (raw)
`@@ -759,47 +759,45 @@ impl Item {
`
759
759
`Some(tcx.visibility(def_id))
`
760
760
`}
`
761
761
``
762
``
`-
pub(crate) fn attributes(&self, tcx: TyCtxt<'_>, cache: &Cache, is_json: bool) -> Vec {
`
``
762
`+
pub(crate) fn attributes(
`
``
763
`+
&self,
`
``
764
`+
tcx: TyCtxt<'_>,
`
``
765
`+
cache: &Cache,
`
``
766
`+
is_json: bool,
`
``
767
`+
) -> impl Iterator<Item = String> {
`
763
768
`const ALLOWED_ATTRIBUTES: &[Symbol] =
`
764
769
`&[sym::export_name, sym::link_section, sym::no_mangle, sym::non_exhaustive];
`
765
770
``
766
771
`use rustc_abi::IntegerType;
`
767
772
``
768
``
`-
let mut attrs: Vec = self
`
769
``
`-
.attrs
`
770
``
`-
.other_attrs
`
771
``
`-
.iter()
`
772
``
`-
.filter_map(|attr| {
`
773
``
`-
if is_json {
`
774
``
`-
match attr {
`
775
``
`-
hir::Attribute::Parsed(AttributeKind::Deprecation { .. }) => {
`
776
``
`` -
// rustdoc-json stores this in Item::deprecation
, so we
``
777
``
`` -
// don't want it it Item::attrs
.
``
778
``
`-
None
`
779
``
`-
}
`
780
``
`-
rustc_hir::Attribute::Parsed(rustc_attr_parsing::AttributeKind::Repr(
`
781
``
`-
..,
`
782
``
`-
)) => {
`
783
``
`` -
// We have separate pretty-printing logic for #[repr(..)]
attributes.
``
784
``
`` -
// For example, there are circumstances where #[repr(transparent)]
``
785
``
`-
// is applied but should not be publicly shown in rustdoc
`
786
``
`-
// because it isn't public API.
`
787
``
`-
None
`
788
``
`-
}
`
789
``
`-
_ => Some(rustc_hir_pretty::attribute_to_string(&tcx, attr)),
`
``
773
`+
let attrs = self.attrs.other_attrs.iter().filter_map(move |attr| {
`
``
774
`+
if is_json {
`
``
775
`+
match attr {
`
``
776
`+
hir::Attribute::Parsed(AttributeKind::Deprecation { .. }) => {
`
``
777
`` +
// rustdoc-json stores this in Item::deprecation
, so we
``
``
778
`` +
// don't want it it Item::attrs
.
``
``
779
`+
None
`
790
780
`}
`
791
``
`-
} else if attr.has_any_name(ALLOWED_ATTRIBUTES) {
`
792
``
`-
Some(
`
793
``
`-
rustc_hir_pretty::attribute_to_string(&tcx, attr)
`
794
``
`-
.replace("\\n", "")
`
795
``
`-
.replace('\n', "")
`
796
``
`-
.replace(" ", " "),
`
797
``
`-
)
`
798
``
`-
} else {
`
799
``
`-
None
`
``
781
`+
rustc_hir::Attribute::Parsed(rustc_attr_parsing::AttributeKind::Repr(..)) => {
`
``
782
`` +
// We have separate pretty-printing logic for #[repr(..)]
attributes.
``
``
783
`` +
// For example, there are circumstances where #[repr(transparent)]
``
``
784
`+
// is applied but should not be publicly shown in rustdoc
`
``
785
`+
// because it isn't public API.
`
``
786
`+
None
`
``
787
`+
}
`
``
788
`+
_ => Some(rustc_hir_pretty::attribute_to_string(&tcx, attr)),
`
800
789
`}
`
801
``
`-
})
`
802
``
`-
.collect();
`
``
790
`+
} else if attr.has_any_name(ALLOWED_ATTRIBUTES) {
`
``
791
`+
Some(
`
``
792
`+
rustc_hir_pretty::attribute_to_string(&tcx, attr)
`
``
793
`+
.replace("\\n", "")
`
``
794
`+
.replace('\n', "")
`
``
795
`+
.replace(" ", " "),
`
``
796
`+
)
`
``
797
`+
} else {
`
``
798
`+
None
`
``
799
`+
}
`
``
800
`+
});
`
803
801
``
804
802
`// Add #[repr(...)]
`
805
803
`if let Some(def_id) = self.def_id()
`
`@@ -860,10 +858,10 @@ impl Item {
`
860
858
` out.push(&int_s);
`
861
859
`}
`
862
860
`if !out.is_empty() {
`
863
``
`-
attrs.push(format!("#[repr({})]", out.join(", ")));
`
``
861
`+
return attrs.chain(vec![format!("#[repr({})]", out.join(", "))].into_iter());
`
864
862
`}
`
865
863
`}
`
866
``
`-
attrs
`
``
864
`+
attrs.chain(Vec::::new().into_iter())
`
867
865
`}
`
868
866
``
869
867
`pub fn is_doc_hidden(&self) -> bool {
`