@@ -765,6 +765,15 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
765
765
}
766
766
}
767
767
768
+ /// Returns whether an attribute needs to be recorded in metadata, that is, if it's usable and
769
+ /// useful in downstream crates. Local-only attributes are an obvious example, but some
770
+ /// rustdoc-specific attributes can equally be of use while documenting the current crate only.
771
+ ///
772
+ /// Removing these superfluous attributes speeds up compilation by making the metadata smaller.
773
+ ///
774
+ /// Note: the `is_def_id_public` parameter is used to cache whether the given `DefId` has a public
775
+ /// visibility: this is a piece of data that can be computed once per defid, and not once per
776
+ /// attribute. Some attributes would only be usable downstream if they are public.
768
777
#[ inline]
769
778
fn should_encode_attr (
770
779
tcx : TyCtxt < ' _ > ,
@@ -773,12 +782,17 @@ fn should_encode_attr(
773
782
is_def_id_public : & mut Option < bool > ,
774
783
) -> bool {
775
784
if rustc_feature:: is_builtin_only_local ( attr. name_or_empty ( ) ) {
785
+ // Attributes marked local-only don't need to be encoded for downstream crates.
776
786
false
777
787
} else if attr. doc_str ( ) . is_some ( ) {
788
+ // We keep all public doc comments because they might be "imported" into downstream crates
789
+ // if they use `#[doc(inline)]` to copy an item's documentation into their own.
778
790
* is_def_id_public. get_or_insert_with ( || {
779
791
tcx. privacy_access_levels ( ( ) ) . get_effective_vis ( def_id) . is_some ( )
780
792
} )
781
793
} else if attr. has_name ( sym:: doc) {
794
+ // If this is a `doc` attribute, and it's marked `inline` (as in `#[doc(inline)]`), we can
795
+ // remove it. It won't be inlinable in downstream crates.
782
796
attr. meta_item_list ( ) . map ( |l| l. iter ( ) . any ( |l| !l. has_name ( sym:: inline) ) ) . unwrap_or ( false )
783
797
} else {
784
798
true
0 commit comments