@@ -2227,15 +2227,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2227
2227
) -> bool {
2228
2228
let tcx = self . tcx ;
2229
2229
let ( adt, args, unwrap) = match expected. kind ( ) {
2230
- // In case Option<NonZero*> is wanted, but * is provided, suggest calling new
2230
+ // In case ` Option<NonZero<T>>` is wanted, but `T` is provided, suggest calling ` new`.
2231
2231
ty:: Adt ( adt, args) if tcx. is_diagnostic_item ( sym:: Option , adt. did ( ) ) => {
2232
2232
let nonzero_type = args. type_at ( 0 ) ; // Unwrap option type.
2233
2233
let ty:: Adt ( adt, args) = nonzero_type. kind ( ) else {
2234
2234
return false ;
2235
2235
} ;
2236
2236
( adt, args, "" )
2237
2237
}
2238
- // In case `NonZero<* >` is wanted but `* ` is provided, also add `.unwrap()` to satisfy types.
2238
+ // In case `NonZero<T >` is wanted but `T ` is provided, also add `.unwrap()` to satisfy types.
2239
2239
ty:: Adt ( adt, args) => ( adt, args, ".unwrap()" ) ,
2240
2240
_ => return false ,
2241
2241
} ;
@@ -2244,32 +2244,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2244
2244
return false ;
2245
2245
}
2246
2246
2247
- // FIXME: This can be simplified once `NonZero<T>` is stable.
2248
- let coercable_types = [
2249
- ( "NonZeroU8" , tcx. types . u8 ) ,
2250
- ( "NonZeroU16" , tcx. types . u16 ) ,
2251
- ( "NonZeroU32" , tcx. types . u32 ) ,
2252
- ( "NonZeroU64" , tcx. types . u64 ) ,
2253
- ( "NonZeroU128" , tcx. types . u128 ) ,
2254
- ( "NonZeroI8" , tcx. types . i8 ) ,
2255
- ( "NonZeroI16" , tcx. types . i16 ) ,
2256
- ( "NonZeroI32" , tcx. types . i32 ) ,
2257
- ( "NonZeroI64" , tcx. types . i64 ) ,
2258
- ( "NonZeroI128" , tcx. types . i128 ) ,
2259
- ] ;
2260
-
2261
2247
let int_type = args. type_at ( 0 ) ;
2262
-
2263
- let Some ( nonzero_alias) = coercable_types. iter ( ) . find_map ( |( nonzero_alias, t) | {
2264
- if * t == int_type && self . can_coerce ( expr_ty, * t) { Some ( nonzero_alias) } else { None }
2265
- } ) else {
2248
+ if !self . can_coerce ( expr_ty, int_type) {
2266
2249
return false ;
2267
- } ;
2250
+ }
2268
2251
2269
2252
err. multipart_suggestion (
2270
- format ! ( "consider calling `{nonzero_alias }::new`" ) ,
2253
+ format ! ( "consider calling `{}::new`" , sym :: NonZero ) ,
2271
2254
vec ! [
2272
- ( expr. span. shrink_to_lo( ) , format!( "{nonzero_alias }::new(" ) ) ,
2255
+ ( expr. span. shrink_to_lo( ) , format!( "{}::new(" , sym :: NonZero ) ) ,
2273
2256
( expr. span. shrink_to_hi( ) , format!( "){unwrap}" ) ) ,
2274
2257
] ,
2275
2258
Applicability :: MaybeIncorrect ,
0 commit comments