@@ -19,6 +19,7 @@ use syntax_pos::{self, Span};
1919use rustc:: hir;
2020use rustc:: hir:: def:: Def ;
2121use rustc:: ty:: { self , AssociatedItem } ;
22+ use errors:: DiagnosticBuilder ;
2223
2324use super :: method:: probe;
2425
@@ -38,20 +39,29 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
3839 }
3940
4041 pub fn demand_eqtype ( & self , sp : Span , expected : Ty < ' tcx > , actual : Ty < ' tcx > ) {
41- self . demand_eqtype_with_origin ( & self . misc ( sp) , expected, actual) ;
42+ if let Some ( mut err) = self . demand_eqtype_diag ( sp, expected, actual) {
43+ err. emit ( ) ;
44+ }
45+ }
46+
47+ pub fn demand_eqtype_diag ( & self ,
48+ sp : Span ,
49+ expected : Ty < ' tcx > ,
50+ actual : Ty < ' tcx > ) -> Option < DiagnosticBuilder < ' tcx > > {
51+ self . demand_eqtype_with_origin ( & self . misc ( sp) , expected, actual)
4252 }
4353
4454 pub fn demand_eqtype_with_origin ( & self ,
4555 cause : & ObligationCause < ' tcx > ,
4656 expected : Ty < ' tcx > ,
47- actual : Ty < ' tcx > )
48- {
57+ actual : Ty < ' tcx > ) -> Option < DiagnosticBuilder < ' tcx > > {
4958 match self . eq_types ( false , cause, actual, expected) {
5059 Ok ( InferOk { obligations, value : ( ) } ) => {
5160 self . register_predicates ( obligations) ;
61+ None
5262 } ,
5363 Err ( e) => {
54- self . report_mismatched_types ( cause, expected, actual, e) . emit ( ) ;
64+ Some ( self . report_mismatched_types ( cause, expected, actual, e) )
5565 }
5666 }
5767 }
0 commit comments