@@ -23,7 +23,7 @@ use borrow_check::nll::renumber;
23
23
use borrow_check:: nll:: type_check:: free_region_relations:: {
24
24
CreateResult , UniversalRegionRelations ,
25
25
} ;
26
- use borrow_check:: nll:: universal_regions:: UniversalRegions ;
26
+ use borrow_check:: nll:: universal_regions:: { DefiningTy , UniversalRegions } ;
27
27
use borrow_check:: nll:: ToRegionVid ;
28
28
use dataflow:: move_paths:: MoveData ;
29
29
use dataflow:: FlowAtLocation ;
@@ -1209,7 +1209,21 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1209
1209
// of lowering. Assignments to other sorts of places *are* interesting
1210
1210
// though.
1211
1211
let category = match * place {
1212
- Place :: Local ( RETURN_PLACE ) => ConstraintCategory :: Return ,
1212
+ Place :: Local ( RETURN_PLACE ) => if let Some ( BorrowCheckContext {
1213
+ universal_regions : UniversalRegions {
1214
+ defining_ty : DefiningTy :: Const ( def_id, _) ,
1215
+ ..
1216
+ } ,
1217
+ ..
1218
+ } ) = self . borrowck_context {
1219
+ if tcx. is_static ( * def_id) . is_some ( ) {
1220
+ ConstraintCategory :: UseAsStatic
1221
+ } else {
1222
+ ConstraintCategory :: UseAsConst
1223
+ }
1224
+ } else {
1225
+ ConstraintCategory :: Return
1226
+ }
1213
1227
Place :: Local ( l) if !mir. local_decls [ l] . is_user_variable . is_some ( ) => {
1214
1228
ConstraintCategory :: Boring
1215
1229
}
@@ -1391,6 +1405,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1391
1405
ref func,
1392
1406
ref args,
1393
1407
ref destination,
1408
+ from_hir_call,
1394
1409
..
1395
1410
} => {
1396
1411
let func_ty = func. ty ( mir, tcx) ;
@@ -1435,7 +1450,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1435
1450
}
1436
1451
}
1437
1452
1438
- self . check_call_inputs ( mir, term, & sig, args, term_location) ;
1453
+ self . check_call_inputs ( mir, term, & sig, args, term_location, from_hir_call ) ;
1439
1454
}
1440
1455
TerminatorKind :: Assert {
1441
1456
ref cond, ref msg, ..
@@ -1493,7 +1508,23 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1493
1508
Some ( ( ref dest, _target_block) ) => {
1494
1509
let dest_ty = dest. ty ( mir, tcx) . to_ty ( tcx) ;
1495
1510
let category = match * dest {
1496
- Place :: Local ( RETURN_PLACE ) => ConstraintCategory :: Return ,
1511
+ Place :: Local ( RETURN_PLACE ) => {
1512
+ if let Some ( BorrowCheckContext {
1513
+ universal_regions : UniversalRegions {
1514
+ defining_ty : DefiningTy :: Const ( def_id, _) ,
1515
+ ..
1516
+ } ,
1517
+ ..
1518
+ } ) = self . borrowck_context {
1519
+ if tcx. is_static ( * def_id) . is_some ( ) {
1520
+ ConstraintCategory :: UseAsStatic
1521
+ } else {
1522
+ ConstraintCategory :: UseAsConst
1523
+ }
1524
+ } else {
1525
+ ConstraintCategory :: Return
1526
+ }
1527
+ } ,
1497
1528
Place :: Local ( l) if !mir. local_decls [ l] . is_user_variable . is_some ( ) => {
1498
1529
ConstraintCategory :: Boring
1499
1530
}
@@ -1538,18 +1569,24 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
1538
1569
sig : & ty:: FnSig < ' tcx > ,
1539
1570
args : & [ Operand < ' tcx > ] ,
1540
1571
term_location : Location ,
1572
+ from_hir_call : bool ,
1541
1573
) {
1542
1574
debug ! ( "check_call_inputs({:?}, {:?})" , sig, args) ;
1543
1575
if args. len ( ) < sig. inputs ( ) . len ( ) || ( args. len ( ) > sig. inputs ( ) . len ( ) && !sig. variadic ) {
1544
1576
span_mirbug ! ( self , term, "call to {:?} with wrong # of args" , sig) ;
1545
1577
}
1546
1578
for ( n, ( fn_arg, op_arg) ) in sig. inputs ( ) . iter ( ) . zip ( args) . enumerate ( ) {
1547
1579
let op_arg_ty = op_arg. ty ( mir, self . tcx ( ) ) ;
1580
+ let category = if from_hir_call {
1581
+ ConstraintCategory :: CallArgument
1582
+ } else {
1583
+ ConstraintCategory :: Boring
1584
+ } ;
1548
1585
if let Err ( terr) = self . sub_types (
1549
1586
op_arg_ty,
1550
1587
fn_arg,
1551
1588
term_location. to_locations ( ) ,
1552
- ConstraintCategory :: CallArgument ,
1589
+ category ,
1553
1590
) {
1554
1591
span_mirbug ! (
1555
1592
self ,
0 commit comments