@@ -36,6 +36,7 @@ mod implicit_clone;
3636mod inefficient_to_string;
3737mod inspect_for_each;
3838mod into_iter_on_ref;
39+ mod io_other_error;
3940mod is_digit_ascii_radix;
4041mod is_empty;
4142mod iter_cloned_collect;
@@ -4461,6 +4462,28 @@ declare_clippy_lint! {
44614462 "unnecessary `iter().any()` on slices that can be replaced with `contains()`"
44624463}
44634464
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+
44644487#[ expect( clippy:: struct_excessive_bools) ]
44654488pub struct Methods {
44664489 avoid_breaking_exported_api : bool ,
@@ -4637,6 +4660,7 @@ impl_lint_pass!(Methods => [
46374660 RETURN_AND_THEN ,
46384661 UNBUFFERED_BYTES ,
46394662 MANUAL_CONTAINS ,
4663+ IO_OTHER_ERROR ,
46404664] ) ;
46414665
46424666/// Extracts a method call name, args, and `Span` of the method name.
@@ -4666,6 +4690,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
46664690 unnecessary_fallible_conversions:: check_function ( cx, expr, func) ;
46674691 manual_c_str_literals:: check ( cx, expr, func, args, & self . msrv ) ;
46684692 useless_nonzero_new_unchecked:: check ( cx, expr, func, args, & self . msrv ) ;
4693+ io_other_error:: check ( cx, expr, func, args, & self . msrv ) ;
46694694 } ,
46704695 ExprKind :: MethodCall ( method_call, receiver, args, _) => {
46714696 let method_span = method_call. ident . span ;
0 commit comments