@@ -8,7 +8,7 @@ use rustc_middle::hir::map::Map;
8
8
use rustc_middle:: ty:: query:: Providers ;
9
9
use rustc_middle:: ty:: TyCtxt ;
10
10
11
- use rustc_ast:: { Attribute , LitKind , NestedMetaItem } ;
11
+ use rustc_ast:: { Attribute , Lit , LitKind , NestedMetaItem } ;
12
12
use rustc_errors:: { pluralize, struct_span_err} ;
13
13
use rustc_hir as hir;
14
14
use rustc_hir:: def_id:: LocalDefId ;
@@ -87,6 +87,10 @@ impl CheckAttrVisitor<'tcx> {
87
87
self . check_export_name ( hir_id, & attr, span, target)
88
88
} else if self . tcx . sess . check_name ( attr, sym:: rustc_args_required_const) {
89
89
self . check_rustc_args_required_const ( & attr, span, target, item)
90
+ } else if self . tcx . sess . check_name ( attr, sym:: rustc_layout_scalar_valid_range_start) {
91
+ self . check_rustc_layout_scalar_valid_range ( & attr, span, target)
92
+ } else if self . tcx . sess . check_name ( attr, sym:: rustc_layout_scalar_valid_range_end) {
93
+ self . check_rustc_layout_scalar_valid_range ( & attr, span, target)
90
94
} else if self . tcx . sess . check_name ( attr, sym:: allow_internal_unstable) {
91
95
self . check_allow_internal_unstable ( hir_id, & attr, span, target, & attrs)
92
96
} else if self . tcx . sess . check_name ( attr, sym:: rustc_allow_const_fn_unstable) {
@@ -807,6 +811,37 @@ impl CheckAttrVisitor<'tcx> {
807
811
}
808
812
}
809
813
814
+ fn check_rustc_layout_scalar_valid_range (
815
+ & self ,
816
+ attr : & Attribute ,
817
+ span : & Span ,
818
+ target : Target ,
819
+ ) -> bool {
820
+ if target != Target :: Struct {
821
+ self . tcx
822
+ . sess
823
+ . struct_span_err ( attr. span , "attribute should be applied to a struct" )
824
+ . span_label ( * span, "not a struct" )
825
+ . emit ( ) ;
826
+ return false ;
827
+ }
828
+
829
+ let list = match attr. meta_item_list ( ) {
830
+ None => return false ,
831
+ Some ( it) => it,
832
+ } ;
833
+
834
+ if matches ! ( & list[ ..] , & [ NestedMetaItem :: Literal ( Lit { kind: LitKind :: Int ( ..) , .. } ) ] ) {
835
+ true
836
+ } else {
837
+ self . tcx
838
+ . sess
839
+ . struct_span_err ( attr. span , "expected exactly one integer literal argument" )
840
+ . emit ( ) ;
841
+ false
842
+ }
843
+ }
844
+
810
845
/// Checks if `#[rustc_legacy_const_generics]` is applied to a function and has a valid argument.
811
846
fn check_rustc_legacy_const_generics (
812
847
& self ,
0 commit comments