@@ -1066,20 +1066,25 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
1066
1066
}
1067
1067
fcx. demand_suptype ( span, ret_ty, actual_return_ty) ;
1068
1068
1069
- if let Some ( ( id, _) ) = * fcx. tcx . sess . entry_fn . borrow ( ) {
1070
- if id == fn_id {
1071
- match fcx. sess ( ) . entry_type . get ( ) {
1072
- Some ( config:: EntryMain ) => {
1073
- let term_id = fcx. tcx . require_lang_item ( TerminationTraitLangItem ) ;
1074
-
1075
- let substs = fcx. tcx . mk_substs ( iter:: once ( Kind :: from ( ret_ty) ) ) ;
1076
- let trait_ref = ty:: TraitRef :: new ( term_id, substs) ;
1077
- let cause = traits:: ObligationCause :: new ( span, fn_id,
1078
- ObligationCauseCode :: MainFunctionType ) ;
1079
- inherited. register_predicate (
1080
- traits:: Obligation :: new ( cause, param_env, trait_ref. to_predicate ( ) ) ) ;
1081
- } ,
1082
- _ => { } ,
1069
+ // If the termination trait language item is activated, check that the main return type
1070
+ // implements the termination trait.
1071
+ if fcx. tcx . lang_items ( ) . termination ( ) . is_some ( ) {
1072
+ if let Some ( ( id, _) ) = * fcx. tcx . sess . entry_fn . borrow ( ) {
1073
+ if id == fn_id {
1074
+ match fcx. sess ( ) . entry_type . get ( ) {
1075
+ Some ( config:: EntryMain ) => {
1076
+ let term_id = fcx. tcx . require_lang_item ( TerminationTraitLangItem ) ;
1077
+
1078
+ let substs = fcx. tcx . mk_substs ( iter:: once ( Kind :: from ( ret_ty) ) ) ;
1079
+ let trait_ref = ty:: TraitRef :: new ( term_id, substs) ;
1080
+ let cause = traits:: ObligationCause :: new (
1081
+ span, fn_id, ObligationCauseCode :: MainFunctionType ) ;
1082
+
1083
+ inherited. register_predicate (
1084
+ traits:: Obligation :: new ( cause, param_env, trait_ref. to_predicate ( ) ) ) ;
1085
+ } ,
1086
+ _ => { } ,
1087
+ }
1083
1088
}
1084
1089
}
1085
1090
}
0 commit comments