@@ -36,6 +36,7 @@ mod implicit_clone;
36
36
mod inefficient_to_string;
37
37
mod inspect_for_each;
38
38
mod into_iter_on_ref;
39
+ mod io_other_error;
39
40
mod is_digit_ascii_radix;
40
41
mod is_empty;
41
42
mod iter_cloned_collect;
@@ -4461,6 +4462,28 @@ declare_clippy_lint! {
4461
4462
"unnecessary `iter().any()` on slices that can be replaced with `contains()`"
4462
4463
}
4463
4464
4465
+ declare_clippy_lint ! {
4466
+ /// This lint warns on calling `io::Error::new(..)` with a kind of
4467
+ /// `io::ErrorKind::Other`.
4468
+ ///
4469
+ /// ### Why is this bad?
4470
+ /// Since Rust 1.74, there's the `io::Error::other(_)` shortcut.
4471
+ ///
4472
+ /// ### Example
4473
+ /// ```no_run
4474
+ /// use std::io;
4475
+ /// let _ = io::Error::new(io::ErrorKind::Other, "bad".to_string());
4476
+ /// ```
4477
+ /// Use instead:
4478
+ /// ```no_run
4479
+ /// let _ = std::io::Error::other("bad".to_string());
4480
+ /// ```
4481
+ #[ clippy:: version = "1.86.0" ]
4482
+ pub IO_OTHER_ERROR ,
4483
+ style,
4484
+ "calling `std::io::Error::new(std::io::ErrorKind::Other, _)`"
4485
+ }
4486
+
4464
4487
#[ expect( clippy:: struct_excessive_bools) ]
4465
4488
pub struct Methods {
4466
4489
avoid_breaking_exported_api : bool ,
@@ -4637,6 +4660,7 @@ impl_lint_pass!(Methods => [
4637
4660
RETURN_AND_THEN ,
4638
4661
UNBUFFERED_BYTES ,
4639
4662
MANUAL_CONTAINS ,
4663
+ IO_OTHER_ERROR ,
4640
4664
] ) ;
4641
4665
4642
4666
/// Extracts a method call name, args, and `Span` of the method name.
@@ -4666,6 +4690,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
4666
4690
unnecessary_fallible_conversions:: check_function ( cx, expr, func) ;
4667
4691
manual_c_str_literals:: check ( cx, expr, func, args, & self . msrv ) ;
4668
4692
useless_nonzero_new_unchecked:: check ( cx, expr, func, args, & self . msrv ) ;
4693
+ io_other_error:: check ( cx, expr, func, args, & self . msrv ) ;
4669
4694
} ,
4670
4695
ExprKind :: MethodCall ( method_call, receiver, args, _) => {
4671
4696
let method_span = method_call. ident . span ;
0 commit comments