@@ -2142,15 +2142,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2142
2142
) -> bool {
2143
2143
let tcx = self . tcx ;
2144
2144
let ( adt, args, unwrap) = match expected. kind ( ) {
2145
- // In case Option<NonZero*> is wanted, but * is provided, suggest calling new
2145
+ // In case ` Option<NonZero<T>>` is wanted, but `T` is provided, suggest calling ` new`.
2146
2146
ty:: Adt ( adt, args) if tcx. is_diagnostic_item ( sym:: Option , adt. did ( ) ) => {
2147
2147
let nonzero_type = args. type_at ( 0 ) ; // Unwrap option type.
2148
2148
let ty:: Adt ( adt, args) = nonzero_type. kind ( ) else {
2149
2149
return false ;
2150
2150
} ;
2151
2151
( adt, args, "" )
2152
2152
}
2153
- // In case `NonZero<* >` is wanted but `* ` is provided, also add `.unwrap()` to satisfy types.
2153
+ // In case `NonZero<T >` is wanted but `T ` is provided, also add `.unwrap()` to satisfy types.
2154
2154
ty:: Adt ( adt, args) => ( adt, args, ".unwrap()" ) ,
2155
2155
_ => return false ,
2156
2156
} ;
@@ -2159,32 +2159,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2159
2159
return false ;
2160
2160
}
2161
2161
2162
- // FIXME: This can be simplified once `NonZero<T>` is stable.
2163
- let coercable_types = [
2164
- ( "NonZeroU8" , tcx. types . u8 ) ,
2165
- ( "NonZeroU16" , tcx. types . u16 ) ,
2166
- ( "NonZeroU32" , tcx. types . u32 ) ,
2167
- ( "NonZeroU64" , tcx. types . u64 ) ,
2168
- ( "NonZeroU128" , tcx. types . u128 ) ,
2169
- ( "NonZeroI8" , tcx. types . i8 ) ,
2170
- ( "NonZeroI16" , tcx. types . i16 ) ,
2171
- ( "NonZeroI32" , tcx. types . i32 ) ,
2172
- ( "NonZeroI64" , tcx. types . i64 ) ,
2173
- ( "NonZeroI128" , tcx. types . i128 ) ,
2174
- ] ;
2175
-
2176
2162
let int_type = args. type_at ( 0 ) ;
2177
-
2178
- let Some ( nonzero_alias) = coercable_types. iter ( ) . find_map ( |( nonzero_alias, t) | {
2179
- if * t == int_type && self . can_coerce ( expr_ty, * t) { Some ( nonzero_alias) } else { None }
2180
- } ) else {
2163
+ if !self . can_coerce ( expr_ty, int_type) {
2181
2164
return false ;
2182
- } ;
2165
+ }
2183
2166
2184
2167
err. multipart_suggestion (
2185
- format ! ( "consider calling `{nonzero_alias }::new`" ) ,
2168
+ format ! ( "consider calling `{}::new`" , sym :: NonZero ) ,
2186
2169
vec ! [
2187
- ( expr. span. shrink_to_lo( ) , format!( "{nonzero_alias }::new(" ) ) ,
2170
+ ( expr. span. shrink_to_lo( ) , format!( "{}::new(" , sym :: NonZero ) ) ,
2188
2171
( expr. span. shrink_to_hi( ) , format!( "){unwrap}" ) ) ,
2189
2172
] ,
2190
2173
Applicability :: MaybeIncorrect ,
0 commit comments