@@ -156,12 +156,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
156
156
/// Note that inspecting a type's structure *directly* may expose the fact
157
157
/// that there are actually multiple representations for `Error`, so avoid
158
158
/// that when err needs to be handled differently.
159
+ #[ instrument( skip( self ) , level = "debug" ) ]
159
160
pub ( super ) fn check_expr_with_expectation (
160
161
& self ,
161
162
expr : & ' tcx hir:: Expr < ' tcx > ,
162
163
expected : Expectation < ' tcx > ,
163
164
) -> 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
+ }
165
180
166
181
// True if `expr` is a `Try::from_ok(())` that is a result of desugaring a try block
167
182
// 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> {
1039
1054
let t_cast = self . to_ty_saving_user_provided_ty ( t) ;
1040
1055
let t_cast = self . resolve_vars_if_possible ( t_cast) ;
1041
1056
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 ) ;
1043
1058
1044
1059
// Eagerly check for some obvious errors.
1045
1060
if t_expr. references_error ( ) || t_cast. references_error ( ) {
@@ -1049,6 +1064,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1049
1064
let mut deferred_cast_checks = self . deferred_cast_checks . borrow_mut ( ) ;
1050
1065
match cast:: CastCheck :: new ( self , e, t_expr, t_cast, t. span , expr. span ) {
1051
1066
Ok ( cast_check) => {
1067
+ debug ! (
1068
+ "check_expr_cast: deferring cast from {:?} to {:?}: {:?}" ,
1069
+ t_cast, t_expr, cast_check,
1070
+ ) ;
1052
1071
deferred_cast_checks. push ( cast_check) ;
1053
1072
t_cast
1054
1073
}
0 commit comments