@@ -834,6 +834,11 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
834
834
}
835
835
}
836
836
837
+ fn metadata_output_only ( & self ) -> bool {
838
+ // MIR optimisation can be skipped when we're just interested in the metadata.
839
+ !self . tcx . sess . opts . output_types . should_trans ( )
840
+ }
841
+
837
842
fn encode_info_for_impl_item ( & mut self , def_id : DefId ) -> Entry < ' tcx > {
838
843
debug ! ( "IsolatedEncoder::encode_info_for_impl_item({:?})" , def_id) ;
839
844
let tcx = self . tcx ;
@@ -878,7 +883,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
878
883
} else if let hir:: ImplItemKind :: Method ( ref sig, body) = ast_item. node {
879
884
let generics = self . tcx . generics_of ( def_id) ;
880
885
let types = generics. parent_types as usize + generics. types . len ( ) ;
881
- let needs_inline = types > 0 || tcx. trans_fn_attrs ( def_id) . requests_inline ( ) ;
886
+ let needs_inline = ( types > 0 || tcx. trans_fn_attrs ( def_id) . requests_inline ( ) ) &&
887
+ !self . metadata_output_only ( ) ;
882
888
let is_const_fn = sig. constness == hir:: Constness :: Const ;
883
889
let ast = if is_const_fn { Some ( body) } else { None } ;
884
890
let always_encode_mir = self . tcx . sess . opts . debugging_opts . always_encode_mir ;
@@ -1169,7 +1175,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
1169
1175
hir:: ItemConst ( ..) => self . encode_optimized_mir ( def_id) ,
1170
1176
hir:: ItemFn ( _, _, constness, _, ref generics, _) => {
1171
1177
let has_tps = generics. ty_params ( ) . next ( ) . is_some ( ) ;
1172
- let needs_inline = has_tps || tcx. trans_fn_attrs ( def_id) . requests_inline ( ) ;
1178
+ let needs_inline = ( has_tps || tcx. trans_fn_attrs ( def_id) . requests_inline ( ) ) &&
1179
+ !self . metadata_output_only ( ) ;
1173
1180
let always_encode_mir = self . tcx . sess . opts . debugging_opts . always_encode_mir ;
1174
1181
if needs_inline || constness == hir:: Constness :: Const || always_encode_mir {
1175
1182
self . encode_optimized_mir ( def_id)
0 commit comments