@@ -11,11 +11,12 @@ use rustc_data_structures::fx::FxHashMap;
1111use rustc_errors:: { Applicability , IntoDiagArg , MultiSpan } ;
1212use rustc_errors:: { DiagCtxtHandle , StashKey } ;
1313use rustc_feature:: { AttributeDuplicates , AttributeType , BuiltinAttribute , BUILTIN_ATTRIBUTE_MAP } ;
14+ use rustc_hir as hir;
1415use rustc_hir:: def_id:: LocalModDefId ;
1516use rustc_hir:: intravisit:: { self , Visitor } ;
16- use rustc_hir:: { self as hir} ;
1717use rustc_hir:: {
18- self , FnSig , ForeignItem , HirId , Item , ItemKind , TraitItem , CRATE_HIR_ID , CRATE_OWNER_ID ,
18+ self , AssocItemKind , FnSig , ForeignItem , HirId , Item , ItemKind , TraitItem , CRATE_HIR_ID ,
19+ CRATE_OWNER_ID ,
1920} ;
2021use rustc_hir:: { MethodKind , Safety , Target } ;
2122use rustc_macros:: LintDiagnostic ;
@@ -875,6 +876,30 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
875876 true
876877 }
877878
879+ fn check_doc_search_unbox ( & self , meta : & NestedMetaItem , hir_id : HirId ) -> bool {
880+ let hir:: Node :: Item ( item) = self . tcx . hir_node ( hir_id) else {
881+ self . dcx ( ) . emit_err ( errors:: DocSearchUnboxInvalid { span : meta. span ( ) } ) ;
882+ return false ;
883+ } ;
884+ match item. kind {
885+ ItemKind :: Enum ( _, generics) | ItemKind :: Struct ( _, generics)
886+ if generics. params . len ( ) != 0 =>
887+ {
888+ true
889+ }
890+ ItemKind :: Trait ( _, _, generics, _, items)
891+ if generics. params . len ( ) != 0
892+ || items. iter ( ) . any ( |item| matches ! ( item. kind, AssocItemKind :: Type ) ) =>
893+ {
894+ true
895+ }
896+ _ => {
897+ self . dcx ( ) . emit_err ( errors:: DocSearchUnboxInvalid { span : meta. span ( ) } ) ;
898+ false
899+ }
900+ }
901+ }
902+
878903 /// Checks `#[doc(inline)]`/`#[doc(no_inline)]` attributes. Returns `true` if valid.
879904 ///
880905 /// A doc inlining attribute is invalid if it is applied to a non-`use` item, or
@@ -1108,6 +1133,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
11081133 is_valid = false
11091134 }
11101135
1136+ sym:: search_unbox
1137+ if !self . check_attr_not_crate_level ( meta, hir_id, "search_unbox" )
1138+ || !self . check_doc_search_unbox ( meta, hir_id) =>
1139+ {
1140+ is_valid = false
1141+ }
1142+
11111143 sym:: html_favicon_url
11121144 | sym:: html_logo_url
11131145 | sym:: html_playground_url
@@ -1165,6 +1197,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
11651197 | sym:: notable_trait
11661198 | sym:: passes
11671199 | sym:: plugins
1200+ | sym:: search_unbox
11681201 | sym:: fake_variadic => { }
11691202
11701203 sym:: rust_logo => {
0 commit comments