@@ -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,32 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1793
1794
) ;
1794
1795
}
1795
1796
}
1797
+
1798
+ // UNWRAP: parsing the attribute already ensured that it had a name and integer value
1799
+ // that is a power of 2 and less than 2^29
1800
+
1801
+ // if the attribute is malformed, it may return None from this
1802
+ // but an error will have already been emitted, so this code should just skip such attributes
1803
+
1804
+ if let Some ( (
1805
+ _,
1806
+ MetaItemLit {
1807
+ kind : ast:: LitKind :: Int ( literal, ast:: LitIntType :: Unsuffixed ) ,
1808
+ ..
1809
+ } ,
1810
+ ) ) = hint. singleton_lit_list ( )
1811
+ {
1812
+ {
1813
+ let max = Size :: from_bits ( self . tcx . sess . target . pointer_width )
1814
+ . signed_int_max ( ) as u64 ;
1815
+ if literal. get ( ) as u64 > max {
1816
+ self . dcx ( ) . emit_err ( errors:: InvalidReprAlignForTarget {
1817
+ span : hint. span ( ) ,
1818
+ size : max,
1819
+ } ) ;
1820
+ }
1821
+ }
1822
+ }
1796
1823
}
1797
1824
sym:: packed => {
1798
1825
if target != Target :: Struct && target != Target :: Union {
0 commit comments