@@ -418,25 +418,28 @@ impl<'a,'tcx> Builder<'a,'tcx> {
418
418
len : Operand < ' tcx > ,
419
419
span : Span ) {
420
420
// fn(&(filename: &'static str, line: u32), index: usize, length: usize) -> !
421
+ let region = ty:: ReStatic ; // TODO(mir-borrowck): use a better region?
421
422
let func = self . lang_function ( lang_items:: PanicBoundsCheckFnLangItem ) ;
422
- let args = func. ty . fn_args ( ) ;
423
- let ref_ty = args. skip_binder ( ) [ 0 ] ;
424
- let ( region, tup_ty) = if let ty:: TyRef ( region, tyandmut) = ref_ty. sty {
425
- ( region, tyandmut. ty )
423
+ let args = self . hir . tcx ( ) . replace_late_bound_regions ( & func. ty . fn_args ( ) , |_| region) . 0 ;
424
+
425
+ let ref_ty = args[ 0 ] ;
426
+ let tup_ty = if let ty:: TyRef ( _, tyandmut) = ref_ty. sty {
427
+ tyandmut. ty
426
428
} else {
427
429
self . hir . span_bug ( span, & format ! ( "unexpected panic_bound_check type: {:?}" , func. ty) ) ;
428
430
} ;
431
+
429
432
let ( tuple, tuple_ref) = ( self . temp ( tup_ty) , self . temp ( ref_ty) ) ;
430
433
let ( file, line) = self . span_to_fileline_args ( span) ;
431
434
let elems = vec ! [ Operand :: Constant ( file) , Operand :: Constant ( line) ] ;
432
435
// FIXME: We should have this as a constant, rather than a stack variable (to not pollute
433
436
// icache with cold branch code), however to achieve that we either have to rely on rvalue
434
437
// promotion or have some way, in MIR, to create constants.
435
- self . cfg . push_assign ( block, DUMMY_SP , & tuple, // tuple = (file_arg, line_arg);
438
+ self . cfg . push_assign ( block, span , & tuple, // tuple = (file_arg, line_arg);
436
439
Rvalue :: Aggregate ( AggregateKind :: Tuple , elems) ) ;
437
440
// FIXME: is this region really correct here?
438
- self . cfg . push_assign ( block, DUMMY_SP , & tuple_ref, // tuple_ref = &tuple;
439
- Rvalue :: Ref ( * region, BorrowKind :: Unique , tuple) ) ;
441
+ self . cfg . push_assign ( block, span , & tuple_ref, // tuple_ref = &tuple;
442
+ Rvalue :: Ref ( region, BorrowKind :: Shared , tuple) ) ;
440
443
let cleanup = self . diverge_cleanup ( ) ;
441
444
self . cfg . terminate ( block, Terminator :: Call {
442
445
func : Operand :: Constant ( func) ,
@@ -449,18 +452,21 @@ impl<'a,'tcx> Builder<'a,'tcx> {
449
452
/// Create diverge cleanup and branch to it from `block`.
450
453
pub fn panic ( & mut self , block : BasicBlock , msg : & ' static str , span : Span ) {
451
454
// fn(&(msg: &'static str filename: &'static str, line: u32)) -> !
455
+ let region = ty:: ReStatic ; // TODO(mir-borrowck): use a better region?
452
456
let func = self . lang_function ( lang_items:: PanicFnLangItem ) ;
453
- let args = func. ty . fn_args ( ) ;
454
- let ref_ty = args. skip_binder ( ) [ 0 ] ;
455
- let ( region, tup_ty) = if let ty:: TyRef ( region, tyandmut) = ref_ty. sty {
456
- ( region, tyandmut. ty )
457
+ let args = self . hir . tcx ( ) . replace_late_bound_regions ( & func. ty . fn_args ( ) , |_| region) . 0 ;
458
+
459
+ let ref_ty = args[ 0 ] ;
460
+ let tup_ty = if let ty:: TyRef ( _, tyandmut) = ref_ty. sty {
461
+ tyandmut. ty
457
462
} else {
458
463
self . hir . span_bug ( span, & format ! ( "unexpected panic type: {:?}" , func. ty) ) ;
459
464
} ;
465
+
460
466
let ( tuple, tuple_ref) = ( self . temp ( tup_ty) , self . temp ( ref_ty) ) ;
461
467
let ( file, line) = self . span_to_fileline_args ( span) ;
462
468
let message = Constant {
463
- span : DUMMY_SP ,
469
+ span : span ,
464
470
ty : self . hir . tcx ( ) . mk_static_str ( ) ,
465
471
literal : self . hir . str_literal ( intern_and_get_ident ( msg) )
466
472
} ;
@@ -470,11 +476,11 @@ impl<'a,'tcx> Builder<'a,'tcx> {
470
476
// FIXME: We should have this as a constant, rather than a stack variable (to not pollute
471
477
// icache with cold branch code), however to achieve that we either have to rely on rvalue
472
478
// promotion or have some way, in MIR, to create constants.
473
- self . cfg . push_assign ( block, DUMMY_SP , & tuple, // tuple = (message_arg, file_arg, line_arg);
479
+ self . cfg . push_assign ( block, span , & tuple, // tuple = (message_arg, file_arg, line_arg);
474
480
Rvalue :: Aggregate ( AggregateKind :: Tuple , elems) ) ;
475
481
// FIXME: is this region really correct here?
476
- self . cfg . push_assign ( block, DUMMY_SP , & tuple_ref, // tuple_ref = &tuple;
477
- Rvalue :: Ref ( * region, BorrowKind :: Unique , tuple) ) ;
482
+ self . cfg . push_assign ( block, span , & tuple_ref, // tuple_ref = &tuple;
483
+ Rvalue :: Ref ( region, BorrowKind :: Shared , tuple) ) ;
478
484
let cleanup = self . diverge_cleanup ( ) ;
479
485
self . cfg . terminate ( block, Terminator :: Call {
480
486
func : Operand :: Constant ( func) ,
@@ -505,11 +511,11 @@ impl<'a,'tcx> Builder<'a,'tcx> {
505
511
fn span_to_fileline_args ( & mut self , span : Span ) -> ( Constant < ' tcx > , Constant < ' tcx > ) {
506
512
let span_lines = self . hir . tcx ( ) . sess . codemap ( ) . lookup_char_pos ( span. lo ) ;
507
513
( Constant {
508
- span : DUMMY_SP ,
514
+ span : span ,
509
515
ty : self . hir . tcx ( ) . mk_static_str ( ) ,
510
516
literal : self . hir . str_literal ( intern_and_get_ident ( & span_lines. file . name ) )
511
517
} , Constant {
512
- span : DUMMY_SP ,
518
+ span : span ,
513
519
ty : self . hir . tcx ( ) . types . u32 ,
514
520
literal : self . hir . usize_literal ( span_lines. line )
515
521
} )
0 commit comments