@@ -864,6 +864,11 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
864
864
}
865
865
}
866
866
867
+ fn metadata_output_only ( & self ) -> bool {
868
+ // MIR optimisation can be skipped when we're just interested in the metadata.
869
+ !self . tcx . sess . opts . output_types . should_trans ( )
870
+ }
871
+
867
872
fn encode_info_for_impl_item ( & mut self , def_id : DefId ) -> Entry < ' tcx > {
868
873
debug ! ( "IsolatedEncoder::encode_info_for_impl_item({:?})" , def_id) ;
869
874
let tcx = self . tcx ;
@@ -908,7 +913,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
908
913
} else if let hir:: ImplItemKind :: Method ( ref sig, body) = ast_item. node {
909
914
let generics = self . tcx . generics_of ( def_id) ;
910
915
let types = generics. parent_types as usize + generics. types . len ( ) ;
911
- let needs_inline = types > 0 || tcx. trans_fn_attrs ( def_id) . requests_inline ( ) ;
916
+ let needs_inline = ( types > 0 || tcx. trans_fn_attrs ( def_id) . requests_inline ( ) ) &&
917
+ !self . metadata_output_only ( ) ;
912
918
let is_const_fn = sig. constness == hir:: Constness :: Const ;
913
919
let ast = if is_const_fn { Some ( body) } else { None } ;
914
920
let always_encode_mir = self . tcx . sess . opts . debugging_opts . always_encode_mir ;
@@ -1199,7 +1205,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
1199
1205
hir:: ItemConst ( ..) => self . encode_optimized_mir ( def_id) ,
1200
1206
hir:: ItemFn ( _, _, constness, _, ref generics, _) => {
1201
1207
let has_tps = generics. ty_params ( ) . next ( ) . is_some ( ) ;
1202
- let needs_inline = has_tps || tcx. trans_fn_attrs ( def_id) . requests_inline ( ) ;
1208
+ let needs_inline = ( has_tps || tcx. trans_fn_attrs ( def_id) . requests_inline ( ) ) &&
1209
+ !self . metadata_output_only ( ) ;
1203
1210
let always_encode_mir = self . tcx . sess . opts . debugging_opts . always_encode_mir ;
1204
1211
if needs_inline || constness == hir:: Constness :: Const || always_encode_mir {
1205
1212
self . encode_optimized_mir ( def_id)
0 commit comments