@@ -2029,34 +2029,42 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2029
2029
err. help ( "the semantics of slice patterns changed recently; see issue #62254" ) ;
2030
2030
}
2031
2031
} else if Autoderef :: new ( & self . infcx , self . param_env , self . body_id , span, expected_ty, span)
2032
- . any ( |( ty, _) | matches ! ( ty. kind( ) , ty:: Slice ( ..) ) )
2032
+ . any ( |( ty, _) | matches ! ( ty. kind( ) , ty:: Slice ( ..) | ty :: Array ( .. ) ) )
2033
2033
{
2034
2034
if let ( Some ( span) , true ) = ( ti. span , ti. origin_expr ) {
2035
2035
if let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( span) {
2036
- let applicability = match self . resolve_vars_if_possible ( ti. expected ) . kind ( ) {
2037
- ty:: Adt ( adt_def, _)
2038
- if self . tcx . is_diagnostic_item ( sym:: Option , adt_def. did )
2039
- || self . tcx . is_diagnostic_item ( sym:: Result , adt_def. did ) =>
2040
- {
2041
- // Slicing won't work here, but `.as_deref()` might (issue #91328).
2042
- err. span_suggestion (
2043
- span,
2044
- "consider using `as_deref` here" ,
2045
- format ! ( "{}.as_deref()" , snippet) ,
2046
- Applicability :: MaybeIncorrect ,
2047
- ) ;
2048
- None
2049
- }
2050
- // FIXME: instead of checking for Vec only, we could check whether the
2051
- // type implements `Deref<Target=X>`; see
2052
- // https://github.com/rust-lang/rust/pull/91343#discussion_r761466979
2053
- ty:: Adt ( adt_def, _)
2054
- if self . tcx . is_diagnostic_item ( sym:: Vec , adt_def. did ) =>
2055
- {
2056
- Some ( Applicability :: MachineApplicable )
2036
+ let applicability = Autoderef :: new (
2037
+ & self . infcx ,
2038
+ self . param_env ,
2039
+ self . body_id ,
2040
+ span,
2041
+ self . resolve_vars_if_possible ( ti. expected ) ,
2042
+ span,
2043
+ )
2044
+ . find_map ( |( ty, _) | {
2045
+ match ty. kind ( ) {
2046
+ ty:: Adt ( adt_def, _)
2047
+ if self . tcx . is_diagnostic_item ( sym:: Option , adt_def. did )
2048
+ || self . tcx . is_diagnostic_item ( sym:: Result , adt_def. did ) =>
2049
+ {
2050
+ // Slicing won't work here, but `.as_deref()` might (issue #91328).
2051
+ err. span_suggestion (
2052
+ span,
2053
+ "consider using `as_deref` here" ,
2054
+ format ! ( "{}.as_deref()" , snippet) ,
2055
+ Applicability :: MaybeIncorrect ,
2056
+ ) ;
2057
+ Some ( None )
2058
+ }
2059
+
2060
+ ty:: Slice ( ..) | ty:: Array ( ..) => {
2061
+ Some ( Some ( Applicability :: MachineApplicable ) )
2062
+ }
2063
+
2064
+ _ => None ,
2057
2065
}
2058
- _ => Some ( Applicability :: MaybeIncorrect ) ,
2059
- } ;
2066
+ } )
2067
+ . unwrap_or ( Some ( Applicability :: MaybeIncorrect ) ) ;
2060
2068
2061
2069
if let Some ( applicability) = applicability {
2062
2070
err. span_suggestion (
0 commit comments