@@ -4,8 +4,8 @@ use crate::check::method::MethodCallee;
4
4
use crate :: check:: Expectation :: * ;
5
5
use crate :: check:: TupleArgumentsFlag :: * ;
6
6
use crate :: check:: {
7
- struct_span_err, BreakableCtxt , Diverges , Expectation , FnCtxt ,
8
- LocalTy , Needs , TupleArgumentsFlag ,
7
+ struct_span_err, BreakableCtxt , Diverges , Expectation , FnCtxt , LocalTy , Needs ,
8
+ TupleArgumentsFlag ,
9
9
} ;
10
10
11
11
use rustc_ast as ast;
@@ -19,13 +19,16 @@ use rustc_middle::ty::adjustment::AllowTwoPhase;
19
19
use rustc_middle:: ty:: fold:: TypeFoldable ;
20
20
use rustc_middle:: ty:: { self , Ty } ;
21
21
use rustc_session:: Session ;
22
- use rustc_span:: { BytePos , Pos , symbol:: { sym, Ident } } ;
23
22
use rustc_span:: { self , MultiSpan , Span } ;
23
+ use rustc_span:: {
24
+ symbol:: { sym, Ident } ,
25
+ BytePos , Pos ,
26
+ } ;
24
27
use rustc_trait_selection:: traits:: { self , ObligationCauseCode , StatementAsExpression } ;
25
28
29
+ use std:: cmp;
26
30
use std:: mem:: replace;
27
31
use std:: slice;
28
- use std:: cmp;
29
32
30
33
impl < ' a , ' tcx > FnCtxt < ' a , ' tcx > {
31
34
pub ( in super :: super ) fn check_casts ( & self ) {
@@ -96,12 +99,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
96
99
& self ,
97
100
call_span : Span , // Span enclosing the call site
98
101
call_expr : & ' tcx hir:: Expr < ' tcx > , // Expression of the call site
99
- formal_input_tys : & [ Ty < ' tcx > ] , // Types (as defined in the *signature* of the target function)
100
- expected_input_tys : & [ Ty < ' tcx > ] , // More specific expected types, after unifying with caller output types
102
+ formal_input_tys : & [ Ty < ' tcx > ] , // Types (as defined in the *signature* of the target function)
103
+ expected_input_tys : & [ Ty < ' tcx > ] , // More specific expected types, after unifying with caller output types
101
104
provided_args : & ' tcx [ hir:: Expr < ' tcx > ] , // The expressions for each provided argument
102
- c_variadic : bool , // Whether the function is variadic, for example when imported from C
103
- tuple_arguments : TupleArgumentsFlag , // Whether the arguments have been bundled in a tuple (ex: closures)
104
- fn_def_id : Option < DefId > , // The DefId for the function being called, for better error messages
105
+ c_variadic : bool , // Whether the function is variadic, for example when imported from C
106
+ tuple_arguments : TupleArgumentsFlag , // Whether the arguments have been bundled in a tuple (ex: closures)
107
+ fn_def_id : Option < DefId > , // The DefId for the function being called, for better error messages
105
108
) {
106
109
let tcx = self . tcx ;
107
110
@@ -198,7 +201,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
198
201
let coerced_ty = expectation. only_has_type ( self ) . unwrap_or ( formal_input_ty) ;
199
202
let coerced_ty = self . resolve_vars_with_obligations ( coerced_ty) ;
200
203
201
- let coerce_error = self . try_coerce ( provided_arg, checked_ty, coerced_ty, AllowTwoPhase :: Yes ) ;
204
+ let coerce_error =
205
+ self . try_coerce ( provided_arg, checked_ty, coerced_ty, AllowTwoPhase :: Yes ) ;
202
206
203
207
// 3. Check if the formal type is a supertype of the checked one
204
208
// and register any such obligations for future type checks
@@ -262,7 +266,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
262
266
self . warn_if_unreachable (
263
267
provided_args[ idx] . hir_id ,
264
268
provided_args[ idx] . span ,
265
- "expression"
269
+ "expression" ,
266
270
) ;
267
271
268
272
// If we're past the end of the expected inputs, we won't have anything to check against
@@ -327,14 +331,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
327
331
// First, fill in the rest of our compatibility matrix
328
332
for i in 0 ..provided_arg_count {
329
333
for j in 0 ..minimum_input_count {
330
- if i == j { continue ; }
334
+ if i == j {
335
+ continue ;
336
+ }
331
337
compatibility_matrix[ i] [ j] = check_compatible ( i, j) ;
332
338
}
333
339
}
334
340
335
341
// Obviously, detecting exact user intention is impossible, so the goal here is to
336
342
// come up with as likely of a story as we can to be helpful.
337
- //
343
+ //
338
344
// We'll iteratively removed "satisfied" input/argument paris,
339
345
// then check for the cases above, until we've eliminated the entire grid
340
346
//
@@ -398,7 +404,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
398
404
// This is a satisfied input, so move along
399
405
continue ;
400
406
}
401
-
407
+
402
408
let mut useless = true ;
403
409
let mut unsatisfiable = true ;
404
410
if is_arg {
@@ -473,12 +479,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
473
479
loop {
474
480
stack. push ( j) ;
475
481
// Look for params this one could slot into
476
- let compat: Vec < _ > = mat[ j]
477
- . iter ( )
478
- . enumerate ( )
479
- . filter ( |( _, & c) | c)
480
- . map ( |( i, _) | i)
481
- . collect ( ) ;
482
+ let compat: Vec < _ > =
483
+ mat[ j] . iter ( ) . enumerate ( ) . filter ( |( _, & c) | c) . map ( |( i, _) | i) . collect ( ) ;
482
484
if compat. len ( ) != 1 {
483
485
// this could go into multipl slots, don't bother exploring both
484
486
is_cycle = false ;
@@ -491,7 +493,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
491
493
}
492
494
}
493
495
if stack. len ( ) <= 2 {
494
- // If we encounter a cycle of 1 or 2 elements, we'll let the
496
+ // If we encounter a cycle of 1 or 2 elements, we'll let the
495
497
// "satisfy" and "swap" code above handle those
496
498
}
497
499
// We've built up some chain, some of which might be a cycle
@@ -541,7 +543,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
541
543
}
542
544
Some ( Issue :: Missing ( idx) ) => {
543
545
// FIXME: improve these with help from code reviewers
544
- let input_ty = self . resolve_vars_if_possible ( expected_input_tys[ input_indexes[ idx] ] ) ;
546
+ let input_ty =
547
+ self . resolve_vars_if_possible ( expected_input_tys[ input_indexes[ idx] ] ) ;
545
548
if input_ty. is_unit ( ) {
546
549
info ! ( "~~~ Issue: Maybe use ()?" ) ; // FIXME
547
550
}
@@ -555,7 +558,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
555
558
& mut compatibility_matrix,
556
559
& mut input_indexes,
557
560
& mut arg_indexes,
558
- min, max,
561
+ min,
562
+ max,
559
563
) ;
560
564
satisfy_input (
561
565
& mut compatibility_matrix,
@@ -569,7 +573,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
569
573
// FIXME: If satisfy_input ever did anything non-trivial (emit obligations to help type checking, for example)
570
574
// we'd want to call this function with the correct arg/input pairs, but for now, we just throw them in a bucket.
571
575
// This works because they force a cycle, so each row is guaranteed to also be a column
572
- let mut idxs: Vec < usize > = args. iter ( ) . filter ( |a| a. is_some ( ) ) . map ( |a| a. unwrap ( ) ) . collect ( ) ;
576
+ let mut idxs: Vec < usize > =
577
+ args. iter ( ) . filter ( |a| a. is_some ( ) ) . map ( |a| a. unwrap ( ) ) . collect ( ) ;
573
578
// FIXME: Is there a cleaner way to do this?
574
579
let mut real_idxs = vec ! [ None ; provided_args. len( ) ] ;
575
580
for ( src, dst) in args. iter ( ) . enumerate ( ) {
@@ -591,7 +596,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
591
596
None => {
592
597
// We didn't find any issues, so we need to push the algorithm forward
593
598
// First, eliminate any arguments that currently satisfy their inputs
594
- let mut i = cmp:: min ( arg_indexes. len ( ) , input_indexes. len ( ) ) ;
599
+ let mut i = cmp:: min ( arg_indexes. len ( ) , input_indexes. len ( ) ) ;
595
600
while i > 0 {
596
601
let idx = i - 1 ;
597
602
if compatibility_matrix[ idx] [ idx] {
@@ -677,7 +682,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
677
682
E0059 , // FIXME: Choose a different code?
678
683
"multiple arguments to this function are incorrect"
679
684
) ;
680
-
685
+
681
686
// Call out where the function is defined
682
687
if let Some ( def_id) = fn_def_id {
683
688
if let Some ( node) = tcx. hir ( ) . get_if_local ( def_id) {
0 commit comments