@@ -11,11 +11,12 @@ use rustc_data_structures::fx::FxHashMap;
11
11
use rustc_errors:: { Applicability , IntoDiagArg , MultiSpan } ;
12
12
use rustc_errors:: { DiagCtxtHandle , StashKey } ;
13
13
use rustc_feature:: { AttributeDuplicates , AttributeType , BuiltinAttribute , BUILTIN_ATTRIBUTE_MAP } ;
14
+ use rustc_hir as hir;
14
15
use rustc_hir:: def_id:: LocalModDefId ;
15
16
use rustc_hir:: intravisit:: { self , Visitor } ;
16
- use rustc_hir:: { self as hir} ;
17
17
use 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 ,
19
20
} ;
20
21
use rustc_hir:: { MethodKind , Safety , Target } ;
21
22
use rustc_macros:: LintDiagnostic ;
@@ -875,6 +876,30 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
875
876
true
876
877
}
877
878
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
+
878
903
/// Checks `#[doc(inline)]`/`#[doc(no_inline)]` attributes. Returns `true` if valid.
879
904
///
880
905
/// A doc inlining attribute is invalid if it is applied to a non-`use` item, or
@@ -1108,6 +1133,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1108
1133
is_valid = false
1109
1134
}
1110
1135
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
+
1111
1143
sym:: html_favicon_url
1112
1144
| sym:: html_logo_url
1113
1145
| sym:: html_playground_url
@@ -1165,6 +1197,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1165
1197
| sym:: notable_trait
1166
1198
| sym:: passes
1167
1199
| sym:: plugins
1200
+ | sym:: search_unbox
1168
1201
| sym:: fake_variadic => { }
1169
1202
1170
1203
sym:: rust_logo => {
0 commit comments