@@ -33,38 +33,37 @@ pub(super) fn check_cast<'tcx>(
3333 let hir_id = e. hir_id ;
3434 let local_def_id = hir_id. owner . def_id ;
3535
36- Inherited :: build ( cx. tcx , local_def_id) . enter ( |inherited| {
37- let fn_ctxt = FnCtxt :: new ( inherited, cx. param_env , local_def_id) ;
36+ let inherited = Inherited :: new ( cx. tcx , local_def_id) ;
37+ let fn_ctxt = FnCtxt :: new ( & inherited, cx. param_env , local_def_id) ;
3838
39- // If we already have errors, we can't be sure we can pointer cast.
39+ // If we already have errors, we can't be sure we can pointer cast.
40+ assert ! (
41+ !fn_ctxt. errors_reported_since_creation( ) ,
42+ "Newly created FnCtxt contained errors"
43+ ) ;
44+
45+ if let Ok ( check) = cast:: CastCheck :: new (
46+ & fn_ctxt,
47+ e,
48+ from_ty,
49+ to_ty,
50+ // We won't show any error to the user, so we don't care what the span is here.
51+ DUMMY_SP ,
52+ DUMMY_SP ,
53+ hir:: Constness :: NotConst ,
54+ ) {
55+ let res = check. do_check ( & fn_ctxt) ;
56+
57+ // do_check's documentation says that it might return Ok and create
58+ // errors in the fcx instead of returning Err in some cases. Those cases
59+ // should be filtered out before getting here.
4060 assert ! (
4161 !fn_ctxt. errors_reported_since_creation( ) ,
42- "Newly created FnCtxt contained errors"
62+ "`fn_ctxt` contained errors after cast check! "
4363 ) ;
4464
45- if let Ok ( check) = cast:: CastCheck :: new (
46- & fn_ctxt,
47- e,
48- from_ty,
49- to_ty,
50- // We won't show any error to the user, so we don't care what the span is here.
51- DUMMY_SP ,
52- DUMMY_SP ,
53- hir:: Constness :: NotConst ,
54- ) {
55- let res = check. do_check ( & fn_ctxt) ;
56-
57- // do_check's documentation says that it might return Ok and create
58- // errors in the fcx instead of returning Err in some cases. Those cases
59- // should be filtered out before getting here.
60- assert ! (
61- !fn_ctxt. errors_reported_since_creation( ) ,
62- "`fn_ctxt` contained errors after cast check!"
63- ) ;
64-
65- res. ok ( )
66- } else {
67- None
68- }
69- } )
65+ res. ok ( )
66+ } else {
67+ None
68+ }
7069}
0 commit comments