@@ -1097,9 +1097,7 @@ fn check_fn<'a, 'tcx>(
1097
1097
* fcx. ps . borrow_mut ( ) = UnsafetyState :: function ( fn_sig. unsafety , fn_id) ;
1098
1098
1099
1099
let declared_ret_ty = fn_sig. output ( ) ;
1100
- if !declared_ret_ty. references_error ( ) {
1101
- fcx. require_type_is_sized ( declared_ret_ty, decl. output . span ( ) , traits:: SizedReturnType ) ;
1102
- }
1100
+ fcx. require_type_is_sized ( declared_ret_ty, decl. output . span ( ) , traits:: SizedReturnType ) ;
1103
1101
let revealed_ret_ty = fcx. instantiate_opaque_types_from_value (
1104
1102
fn_id,
1105
1103
& declared_ret_ty,
@@ -2700,30 +2698,39 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2700
2698
traits:: ObligationCause :: new ( span, self . body_id , code) ) ;
2701
2699
}
2702
2700
2703
- pub fn require_type_is_sized ( & self ,
2704
- ty : Ty < ' tcx > ,
2705
- span : Span ,
2706
- code : traits:: ObligationCauseCode < ' tcx > )
2707
- {
2708
- let lang_item = self . tcx . require_lang_item ( lang_items:: SizedTraitLangItem , None ) ;
2709
- self . require_type_meets ( ty, span, code, lang_item) ;
2701
+ pub fn require_type_is_sized (
2702
+ & self ,
2703
+ ty : Ty < ' tcx > ,
2704
+ span : Span ,
2705
+ code : traits:: ObligationCauseCode < ' tcx > ,
2706
+ ) {
2707
+ if !ty. references_error ( ) {
2708
+ let lang_item = self . tcx . require_lang_item ( lang_items:: SizedTraitLangItem , None ) ;
2709
+ self . require_type_meets ( ty, span, code, lang_item) ;
2710
+ }
2710
2711
}
2711
2712
2712
- pub fn require_type_is_sized_deferred ( & self ,
2713
- ty : Ty < ' tcx > ,
2714
- span : Span ,
2715
- code : traits:: ObligationCauseCode < ' tcx > )
2716
- {
2717
- self . deferred_sized_obligations . borrow_mut ( ) . push ( ( ty, span, code) ) ;
2713
+ pub fn require_type_is_sized_deferred (
2714
+ & self ,
2715
+ ty : Ty < ' tcx > ,
2716
+ span : Span ,
2717
+ code : traits:: ObligationCauseCode < ' tcx > ,
2718
+ ) {
2719
+ if !ty. references_error ( ) {
2720
+ self . deferred_sized_obligations . borrow_mut ( ) . push ( ( ty, span, code) ) ;
2721
+ }
2718
2722
}
2719
2723
2720
- pub fn register_bound ( & self ,
2721
- ty : Ty < ' tcx > ,
2722
- def_id : DefId ,
2723
- cause : traits:: ObligationCause < ' tcx > )
2724
- {
2725
- self . fulfillment_cx . borrow_mut ( )
2726
- . register_bound ( self , self . param_env , ty, def_id, cause) ;
2724
+ pub fn register_bound (
2725
+ & self ,
2726
+ ty : Ty < ' tcx > ,
2727
+ def_id : DefId ,
2728
+ cause : traits:: ObligationCause < ' tcx > ,
2729
+ ) {
2730
+ if !ty. references_error ( ) {
2731
+ self . fulfillment_cx . borrow_mut ( )
2732
+ . register_bound ( self , self . param_env , ty, def_id, cause) ;
2733
+ }
2727
2734
}
2728
2735
2729
2736
pub fn to_ty ( & self , ast_t : & hir:: Ty ) -> Ty < ' tcx > {
@@ -2782,22 +2789,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2782
2789
2783
2790
/// Registers an obligation for checking later, during regionck, that the type `ty` must
2784
2791
/// outlive the region `r`.
2785
- pub fn register_wf_obligation ( & self ,
2786
- ty : Ty < ' tcx > ,
2787
- span : Span ,
2788
- code : traits:: ObligationCauseCode < ' tcx > )
2789
- {
2792
+ pub fn register_wf_obligation (
2793
+ & self ,
2794
+ ty : Ty < ' tcx > ,
2795
+ span : Span ,
2796
+ code : traits:: ObligationCauseCode < ' tcx > ,
2797
+ ) {
2790
2798
// WF obligations never themselves fail, so no real need to give a detailed cause:
2791
2799
let cause = traits:: ObligationCause :: new ( span, self . body_id , code) ;
2792
- self . register_predicate ( traits :: Obligation :: new ( cause ,
2793
- self . param_env ,
2794
- ty :: Predicate :: WellFormed ( ty ) ) ) ;
2800
+ self . register_predicate (
2801
+ traits :: Obligation :: new ( cause , self . param_env , ty :: Predicate :: WellFormed ( ty ) ) ,
2802
+ ) ;
2795
2803
}
2796
2804
2797
2805
/// Registers obligations that all types appearing in `substs` are well-formed.
2798
2806
pub fn add_wf_bounds ( & self , substs : SubstsRef < ' tcx > , expr : & hir:: Expr ) {
2799
2807
for ty in substs. types ( ) {
2800
- self . register_wf_obligation ( ty, expr. span , traits:: MiscObligation ) ;
2808
+ if !ty. references_error ( ) {
2809
+ self . register_wf_obligation ( ty, expr. span , traits:: MiscObligation ) ;
2810
+ }
2801
2811
}
2802
2812
}
2803
2813
@@ -2836,12 +2846,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2836
2846
// FIXME(arielb1): use this instead of field.ty everywhere
2837
2847
// Only for fields! Returns <none> for methods>
2838
2848
// Indifferent to privacy flags
2839
- pub fn field_ty ( & self ,
2840
- span : Span ,
2841
- field : & ' tcx ty :: FieldDef ,
2842
- substs : SubstsRef < ' tcx > )
2843
- -> Ty < ' tcx >
2844
- {
2849
+ pub fn field_ty (
2850
+ & self ,
2851
+ span : Span ,
2852
+ field : & ' tcx ty :: FieldDef ,
2853
+ substs : SubstsRef < ' tcx > ,
2854
+ ) -> Ty < ' tcx > {
2845
2855
self . normalize_associated_types_in ( span, & field. ty ( self . tcx , substs) )
2846
2856
}
2847
2857
0 commit comments