@@ -261,7 +261,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
261
261
if let hir:: ExprKind :: MethodCall ( hir:: PathSegment { ident : method, .. } , recv_expr, & [ ] , _) =
262
262
expr. kind
263
263
&& let Some ( recv_ty) = self . typeck_results . borrow ( ) . expr_ty_opt ( recv_expr)
264
- && self . can_coerce ( recv_ty, expected)
264
+ && self . may_coerce ( recv_ty, expected)
265
265
&& let name = method. name . as_str ( )
266
266
&& ( name. starts_with ( "to_" ) || name. starts_with ( "as_" ) || name == "into" )
267
267
{
@@ -349,7 +349,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
349
349
return true ;
350
350
}
351
351
352
- if self . suggest_fn_call ( err, expr, found, |output| self . can_coerce ( output, expected) )
352
+ if self . suggest_fn_call ( err, expr, found, |output| self . may_coerce ( output, expected) )
353
353
&& let ty:: FnDef ( def_id, ..) = * found. kind ( )
354
354
&& let Some ( sp) = self . tcx . hir ( ) . span_if_local ( def_id)
355
355
{
@@ -568,7 +568,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
568
568
if self . tcx . hir ( ) . is_inside_const_context ( hir_id) || !expected. is_box ( ) || found. is_box ( ) {
569
569
return false ;
570
570
}
571
- if self . can_coerce ( Ty :: new_box ( self . tcx , found) , expected) {
571
+ if self . may_coerce ( Ty :: new_box ( self . tcx , found) , expected) {
572
572
let suggest_boxing = match found. kind ( ) {
573
573
ty:: Tuple ( tuple) if tuple. is_empty ( ) => {
574
574
errors:: SuggestBoxing :: Unit { start : span. shrink_to_lo ( ) , end : span }
@@ -663,7 +663,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
663
663
} ;
664
664
match expected. kind ( ) {
665
665
ty:: Adt ( def, _) if Some ( def. did ( ) ) == pin_did => {
666
- if self . can_coerce ( pin_box_found, expected) {
666
+ if self . may_coerce ( pin_box_found, expected) {
667
667
debug ! ( "can coerce {:?} to {:?}, suggesting Box::pin" , pin_box_found, expected) ;
668
668
match found. kind ( ) {
669
669
ty:: Adt ( def, _) if def. is_box ( ) => {
@@ -689,7 +689,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
689
689
}
690
690
}
691
691
true
692
- } else if self . can_coerce ( pin_found, expected) {
692
+ } else if self . may_coerce ( pin_found, expected) {
693
693
match found. kind ( ) {
694
694
ty:: Adt ( def, _) if def. is_box ( ) => {
695
695
err. help ( "use `Box::pin`" ) ;
@@ -701,7 +701,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
701
701
false
702
702
}
703
703
}
704
- ty:: Adt ( def, _) if def. is_box ( ) && self . can_coerce ( box_found, expected) => {
704
+ ty:: Adt ( def, _) if def. is_box ( ) && self . may_coerce ( box_found, expected) => {
705
705
// Check if the parent expression is a call to Pin::new. If it
706
706
// is and we were expecting a Box, ergo Pin<Box<expected>>, we
707
707
// can suggest Box::pin.
@@ -884,7 +884,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
884
884
let ty = Binder :: bind_with_vars ( ty, bound_vars) ;
885
885
let ty = self . normalize ( hir_ty. span , ty) ;
886
886
let ty = self . tcx . instantiate_bound_regions_with_erased ( ty) ;
887
- if self . can_coerce ( expected, ty) {
887
+ if self . may_coerce ( expected, ty) {
888
888
err. subdiagnostic ( errors:: ExpectedReturnTypeLabel :: Other {
889
889
span : hir_ty. span ,
890
890
expected,
@@ -1141,12 +1141,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1141
1141
ty:: Asyncness :: No => ty,
1142
1142
} ;
1143
1143
let ty = self . normalize ( expr. span , ty) ;
1144
- self . can_coerce ( found, ty)
1144
+ self . may_coerce ( found, ty)
1145
1145
}
1146
1146
hir:: FnRetTy :: DefaultReturn ( _) if in_closure => {
1147
1147
self . ret_coercion . as_ref ( ) . map_or ( false , |ret| {
1148
1148
let ret_ty = ret. borrow ( ) . expected_ty ( ) ;
1149
- self . can_coerce ( found, ret_ty)
1149
+ self . may_coerce ( found, ret_ty)
1150
1150
} )
1151
1151
}
1152
1152
_ => false ,
@@ -1510,7 +1510,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1510
1510
provided_ty
1511
1511
} ;
1512
1512
1513
- if !self . can_coerce ( expected_ty, dummy_ty) {
1513
+ if !self . may_coerce ( expected_ty, dummy_ty) {
1514
1514
return ;
1515
1515
}
1516
1516
let msg = format ! ( "use `{adt_name}::map_or` to deref inner value of `{adt_name}`" ) ;
@@ -1534,7 +1534,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1534
1534
expected_ty : Ty < ' tcx > ,
1535
1535
) {
1536
1536
if let ty:: Slice ( elem_ty) | ty:: Array ( elem_ty, _) = expected_ty. kind ( ) {
1537
- if self . can_coerce ( blk_ty, * elem_ty)
1537
+ if self . may_coerce ( blk_ty, * elem_ty)
1538
1538
&& blk. stmts . is_empty ( )
1539
1539
&& blk. rules == hir:: BlockCheckMode :: DefaultBlock
1540
1540
{
@@ -1744,7 +1744,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1744
1744
if item_ty. has_param ( ) {
1745
1745
return false ;
1746
1746
}
1747
- if self . can_coerce ( item_ty, expected_ty) {
1747
+ if self . may_coerce ( item_ty, expected_ty) {
1748
1748
err. span_suggestion_verbose (
1749
1749
segment. ident . span ,
1750
1750
format ! ( "try referring to the associated const `{capitalized_name}` instead" , ) ,
@@ -1804,7 +1804,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1804
1804
// diagnostic in cases where we have `(&&T).clone()` and we expect `T`).
1805
1805
&& !results. expr_adjustments ( callee_expr) . iter ( ) . any ( |adj| matches ! ( adj. kind, ty:: adjustment:: Adjust :: Deref ( ..) ) )
1806
1806
// Check that we're in fact trying to clone into the expected type
1807
- && self . can_coerce ( * pointee_ty, expected_ty)
1807
+ && self . may_coerce ( * pointee_ty, expected_ty)
1808
1808
&& let trait_ref = ty:: TraitRef :: new ( self . tcx , clone_trait_did, [ expected_ty] )
1809
1809
// And the expected type doesn't implement `Clone`
1810
1810
&& !self . predicate_must_hold_considering_regions ( & traits:: Obligation :: new (
@@ -2022,7 +2022,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2022
2022
} else {
2023
2023
return false ;
2024
2024
} ;
2025
- if is_ctor || !self . can_coerce ( args. type_at ( 0 ) , expected) {
2025
+ if is_ctor || !self . may_coerce ( args. type_at ( 0 ) , expected) {
2026
2026
return false ;
2027
2027
}
2028
2028
@@ -2293,7 +2293,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2293
2293
. then ( || " (its field is private, but it's local to this crate and its privacy can be changed)" . to_string ( ) ) ;
2294
2294
2295
2295
let sole_field_ty = sole_field. ty ( self . tcx , args) ;
2296
- if self . can_coerce ( expr_ty, sole_field_ty) {
2296
+ if self . may_coerce ( expr_ty, sole_field_ty) {
2297
2297
let variant_path =
2298
2298
with_no_trimmed_paths ! ( self . tcx. def_path_str( variant. def_id) ) ;
2299
2299
// FIXME #56861: DRYer prelude filtering
@@ -2401,7 +2401,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2401
2401
}
2402
2402
2403
2403
let int_type = args. type_at ( 0 ) ;
2404
- if !self . can_coerce ( expr_ty, int_type) {
2404
+ if !self . may_coerce ( expr_ty, int_type) {
2405
2405
return false ;
2406
2406
}
2407
2407
@@ -2585,7 +2585,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2585
2585
Ty :: new_imm_ref ( self . tcx , self . tcx . lifetimes . re_static , checked_ty)
2586
2586
}
2587
2587
} ;
2588
- if self . can_coerce ( ref_ty, expected) {
2588
+ if self . may_coerce ( ref_ty, expected) {
2589
2589
let mut sugg_sp = sp;
2590
2590
if let hir:: ExprKind :: MethodCall ( segment, receiver, args, _) = expr. kind {
2591
2591
let clone_trait =
0 commit comments