@@ -34,6 +34,7 @@ use rustc_session::lint::builtin::{
34
34
use rustc_session:: parse:: feature_err;
35
35
use rustc_span:: symbol:: { Symbol , kw, sym} ;
36
36
use rustc_span:: { BytePos , DUMMY_SP , Span } ;
37
+ use rustc_target:: abi:: Size ;
37
38
use rustc_target:: spec:: abi:: Abi ;
38
39
use rustc_trait_selection:: error_reporting:: InferCtxtErrorExt ;
39
40
use rustc_trait_selection:: infer:: { TyCtxtInferExt , ValuePairs } ;
@@ -1783,7 +1784,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1783
1784
| Target :: Union
1784
1785
| Target :: Enum
1785
1786
| Target :: Fn
1786
- | Target :: Method ( _) => continue ,
1787
+ | Target :: Method ( _) => { }
1787
1788
_ => {
1788
1789
self . dcx ( ) . emit_err (
1789
1790
errors:: AttrApplication :: StructEnumFunctionMethodUnion {
@@ -1793,6 +1794,30 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1793
1794
) ;
1794
1795
}
1795
1796
}
1797
+
1798
+ // if the attribute is malformed, it may return None from this
1799
+ // but an error will have already been emitted, so this code should just skip such attributes
1800
+ if let Some ( (
1801
+ _,
1802
+ MetaItemLit {
1803
+ kind : ast:: LitKind :: Int ( literal, ast:: LitIntType :: Unsuffixed ) ,
1804
+ ..
1805
+ } ,
1806
+ ) ) = hint. singleton_lit_list ( )
1807
+ {
1808
+ let val = literal. get ( ) as u64 ;
1809
+ // ignore values greater than 2^29, a different error will be emitted
1810
+ if val <= 2_u64 . pow ( 29 ) {
1811
+ let max = Size :: from_bits ( self . tcx . sess . target . pointer_width )
1812
+ . signed_int_max ( ) as u64 ;
1813
+ if val > max {
1814
+ self . dcx ( ) . emit_err ( errors:: InvalidReprAlignForTarget {
1815
+ span : hint. span ( ) ,
1816
+ size : max,
1817
+ } ) ;
1818
+ }
1819
+ }
1820
+ }
1796
1821
}
1797
1822
sym:: packed => {
1798
1823
if target != Target :: Struct && target != Target :: Union {
0 commit comments