@@ -18,7 +18,7 @@ use rustc_feature::BUILTIN_ATTRIBUTE_MAP;
1818use rustc_hir:: attrs:: diagnostic:: Directive ;
1919use rustc_hir:: attrs:: {
2020 AttributeKind , DocAttribute , DocInline , EiiDecl , EiiImpl , EiiImplResolution , InlineAttr ,
21- ReprAttr ,
21+ OptimizeAttr , ReprAttr ,
2222} ;
2323use rustc_hir:: def:: DefKind ;
2424use rustc_hir:: def_id:: LocalModDefId ;
@@ -163,6 +163,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
163163 self . check_repr ( attrs, span, target, item, hir_id) ;
164164 self . check_rustc_force_inline ( hir_id, attrs, target) ;
165165 self . check_mix_no_mangle_export ( hir_id, attrs) ;
166+ self . check_optimize_and_inline ( attrs) ;
166167 }
167168
168169 /// Called by [`Self::check_attributes()`] to check a single attribute which is
@@ -1582,6 +1583,17 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
15821583 }
15831584 }
15841585
1586+ fn check_optimize_and_inline ( & self , attrs : & [ Attribute ] ) {
1587+ if let Some ( optimize_span) =
1588+ find_attr ! ( attrs, Optimize ( OptimizeAttr :: DoNotOptimize , span) => * span)
1589+ && let Some ( ( inline_attr, inline_span) ) =
1590+ find_attr ! ( attrs, Inline ( inline_attr, span) => ( inline_attr, * span) )
1591+ && inline_attr != & InlineAttr :: Never
1592+ {
1593+ self . dcx ( ) . emit_err ( errors:: BothOptimizeNoneAndInline { optimize_span, inline_span } ) ;
1594+ }
1595+ }
1596+
15851597 fn check_loop_match ( & self , hir_id : HirId , attr_span : Span , target : Target ) {
15861598 let node_span = self . tcx . hir_span ( hir_id) ;
15871599
0 commit comments