@@ -2055,35 +2055,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2055
2055
&& let ( Some ( span) , true ) = ( ti. span , ti. origin_expr )
2056
2056
&& let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( span)
2057
2057
{
2058
- let any_target_ty = Autoderef :: new (
2059
- & self . infcx ,
2060
- self . param_env ,
2061
- self . body_id ,
2062
- span,
2063
- self . resolve_vars_if_possible ( ti. expected ) ,
2064
- span,
2065
- )
2066
- . any ( |( ty, _) | {
2067
- debug ! ( "kind={:?}" , ty. kind( ) ) ;
2068
- match ty. kind ( ) {
2069
- ty:: Adt ( adt_def, _)
2070
- if self . tcx . is_diagnostic_item ( sym:: Option , adt_def. did ( ) )
2071
- || self . tcx . is_diagnostic_item ( sym:: Result , adt_def. did ( ) ) =>
2072
- {
2073
- // Slicing won't work here, but `.as_deref()` might (issue #91328).
2074
- err. span_suggestion (
2075
- span,
2076
- "consider using `as_deref` here" ,
2077
- format ! ( "{snippet}.as_deref()" ) ,
2078
- Applicability :: MaybeIncorrect ,
2079
- ) ;
2080
- false
2081
- }
2082
- _ => self . is_slice_or_array_or_vector ( ty) ,
2058
+ let ty = self . resolve_vars_if_possible ( ti. expected ) ;
2059
+ let is_slice_or_array_or_vector = self . is_slice_or_array_or_vector ( & mut err, snippet. clone ( ) , ty) ;
2060
+ match is_slice_or_array_or_vector. 1 . kind ( ) {
2061
+ ty:: Adt ( adt_def, _)
2062
+ if self . tcx . is_diagnostic_item ( sym:: Option , adt_def. did ( ) )
2063
+ || self . tcx . is_diagnostic_item ( sym:: Result , adt_def. did ( ) ) =>
2064
+ {
2065
+ // Slicing won't work here, but `.as_deref()` might (issue #91328).
2066
+ err. span_suggestion (
2067
+ span,
2068
+ "consider using `as_deref` here" ,
2069
+ format ! ( "{snippet}.as_deref()" ) ,
2070
+ Applicability :: MaybeIncorrect ,
2071
+ ) ;
2083
2072
}
2084
- } ) ;
2085
-
2086
- if any_target_ty {
2073
+ _ => ( )
2074
+ }
2075
+ if is_slice_or_array_or_vector . 0 {
2087
2076
err. span_suggestion (
2088
2077
span,
2089
2078
"consider slicing here" ,
@@ -2096,12 +2085,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2096
2085
err. emit ( ) ;
2097
2086
}
2098
2087
2099
- fn is_slice_or_array_or_vector ( & self , ty : Ty < ' tcx > ) -> bool {
2088
+ fn is_slice_or_array_or_vector (
2089
+ & self ,
2090
+ err : & mut Diagnostic ,
2091
+ snippet : String ,
2092
+ ty : Ty < ' tcx > ,
2093
+ ) -> ( bool , Ty < ' tcx > ) {
2100
2094
match ty. kind ( ) {
2101
- ty:: Adt ( adt_def, _) if self . tcx . is_diagnostic_item ( sym:: Vec , adt_def. did ( ) ) => true ,
2102
- ty:: Ref ( _, ty, _) => self . is_slice_or_array_or_vector ( * ty) ,
2103
- ty:: Slice ( ..) | ty:: Array ( ..) => true ,
2104
- _ => false ,
2095
+ ty:: Adt ( adt_def, _) if self . tcx . is_diagnostic_item ( sym:: Vec , adt_def. did ( ) ) => {
2096
+ ( true , ty)
2097
+ }
2098
+ ty:: Ref ( _, ty, _) => self . is_slice_or_array_or_vector ( err, snippet, * ty) ,
2099
+ ty:: Slice ( ..) | ty:: Array ( ..) => ( true , ty) ,
2100
+ _ => ( false , ty) ,
2105
2101
}
2106
2102
}
2107
2103
}
0 commit comments