@@ -156,12 +156,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
156156 /// Note that inspecting a type's structure *directly* may expose the fact
157157 /// that there are actually multiple representations for `Error`, so avoid
158158 /// that when err needs to be handled differently.
159+ #[ instrument( skip( self ) , level = "debug" ) ]
159160 pub ( super ) fn check_expr_with_expectation (
160161 & self ,
161162 expr : & ' tcx hir:: Expr < ' tcx > ,
162163 expected : Expectation < ' tcx > ,
163164 ) -> Ty < ' tcx > {
164- debug ! ( ">> type-checking: expected={:?}, expr={:?} " , expected, expr) ;
165+ if self . tcx ( ) . sess . verbose ( ) {
166+ // make this code only run with -Zverbose because it is probably slow
167+ if let Ok ( lint_str) = self . tcx . sess . source_map ( ) . span_to_snippet ( expr. span ) {
168+ if !lint_str. contains ( "\n " ) {
169+ debug ! ( "expr text: {}" , lint_str) ;
170+ } else {
171+ let mut lines = lint_str. lines ( ) ;
172+ if let Some ( line0) = lines. next ( ) {
173+ let remaining_lines = lines. count ( ) ;
174+ debug ! ( "expr text: {}" , line0) ;
175+ debug ! ( "expr text: ...(and {} more lines)" , remaining_lines) ;
176+ }
177+ }
178+ }
179+ }
165180
166181 // True if `expr` is a `Try::from_ok(())` that is a result of desugaring a try block
167182 // without the final expr (e.g. `try { return; }`). We don't want to generate an
@@ -1039,7 +1054,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10391054 let t_cast = self . to_ty_saving_user_provided_ty ( t) ;
10401055 let t_cast = self . resolve_vars_if_possible ( t_cast) ;
10411056 let t_expr = self . check_expr_with_expectation ( e, ExpectCastableToType ( t_cast) ) ;
1042- let t_cast = self . resolve_vars_if_possible ( t_cast ) ;
1057+ let t_expr = self . resolve_vars_if_possible ( t_expr ) ;
10431058
10441059 // Eagerly check for some obvious errors.
10451060 if t_expr. references_error ( ) || t_cast. references_error ( ) {
@@ -1049,6 +1064,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10491064 let mut deferred_cast_checks = self . deferred_cast_checks . borrow_mut ( ) ;
10501065 match cast:: CastCheck :: new ( self , e, t_expr, t_cast, t. span , expr. span ) {
10511066 Ok ( cast_check) => {
1067+ debug ! (
1068+ "check_expr_cast: deferring cast from {:?} to {:?}: {:?}" ,
1069+ t_cast, t_expr, cast_check,
1070+ ) ;
10521071 deferred_cast_checks. push ( cast_check) ;
10531072 t_cast
10541073 }
0 commit comments