@@ -13,7 +13,7 @@ use rustc_errors::{pluralize, struct_span_err};
13
13
use rustc_hir as hir;
14
14
use rustc_hir:: def_id:: LocalDefId ;
15
15
use rustc_hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
16
- use rustc_hir:: { self , FnSig , ForeignItem , ForeignItemKind , HirId , Item , ItemKind , TraitItem } ;
16
+ use rustc_hir:: { self , FnSig , ForeignItem , ForeignItemKind , HirId , Item , ItemKind , TraitItem , CRATE_HIR_ID } ;
17
17
use rustc_hir:: { MethodKind , Target } ;
18
18
use rustc_session:: lint:: builtin:: { CONFLICTING_REPR_HINTS , UNUSED_ATTRIBUTES } ;
19
19
use rustc_session:: parse:: feature_err;
@@ -333,6 +333,17 @@ impl CheckAttrVisitor<'tcx> {
333
333
. emit ( ) ;
334
334
return false ;
335
335
}
336
+ if CRATE_HIR_ID == hir_id {
337
+ self . tcx
338
+ . sess
339
+ . struct_span_err (
340
+ meta. span ( ) ,
341
+ "`#![doc(alias = \" ...\" )]` isn't allowed as a crate \
342
+ level attribute",
343
+ )
344
+ . emit ( ) ;
345
+ return false ;
346
+ }
336
347
}
337
348
}
338
349
}
@@ -811,6 +822,11 @@ fn is_c_like_enum(item: &Item<'_>) -> bool {
811
822
fn check_mod_attrs ( tcx : TyCtxt < ' _ > , module_def_id : LocalDefId ) {
812
823
tcx. hir ( )
813
824
. visit_item_likes_in_module ( module_def_id, & mut CheckAttrVisitor { tcx } . as_deep_visitor ( ) ) ;
825
+ if module_def_id. is_top_level_module ( ) {
826
+ for attr in tcx. hir ( ) . krate_attrs ( ) {
827
+ CheckAttrVisitor { tcx } . check_doc_alias ( attr, CRATE_HIR_ID , Target :: Mod ) ;
828
+ }
829
+ }
814
830
}
815
831
816
832
pub ( crate ) fn provide ( providers : & mut Providers ) {
0 commit comments