@@ -8,7 +8,7 @@ use rustc_middle::hir::map::Map;
88use rustc_middle:: ty:: query:: Providers ;
99use rustc_middle:: ty:: TyCtxt ;
1010
11- use rustc_ast:: { Attribute , LitKind , NestedMetaItem } ;
11+ use rustc_ast:: { Attribute , Lit , LitKind , NestedMetaItem } ;
1212use rustc_errors:: { pluralize, struct_span_err} ;
1313use rustc_hir as hir;
1414use rustc_hir:: def_id:: LocalDefId ;
@@ -87,6 +87,10 @@ impl CheckAttrVisitor<'tcx> {
8787 self . check_export_name ( hir_id, & attr, span, target)
8888 } else if self . tcx . sess . check_name ( attr, sym:: rustc_args_required_const) {
8989 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)
9094 } else if self . tcx . sess . check_name ( attr, sym:: allow_internal_unstable) {
9195 self . check_allow_internal_unstable ( hir_id, & attr, span, target, & attrs)
9296 } else if self . tcx . sess . check_name ( attr, sym:: rustc_allow_const_fn_unstable) {
@@ -807,6 +811,37 @@ impl CheckAttrVisitor<'tcx> {
807811 }
808812 }
809813
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+
810845 /// Checks if `#[rustc_legacy_const_generics]` is applied to a function and has a valid argument.
811846 fn check_rustc_legacy_const_generics (
812847 & self ,
0 commit comments