about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/methods/io_other_error.rs2
-rw-r--r--tests/ui/io_other_error.fixed5
-rw-r--r--tests/ui/io_other_error.rs5
-rw-r--r--tests/ui/io_other_error.stderr14
4 files changed, 24 insertions, 2 deletions
diff --git a/clippy_lints/src/methods/io_other_error.rs b/clippy_lints/src/methods/io_other_error.rs
index 4659e9e163f..bdc834bd47a 100644
--- a/clippy_lints/src/methods/io_other_error.rs
+++ b/clippy_lints/src/methods/io_other_error.rs
@@ -27,7 +27,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, path: &Expr<'_>, args
                     "use `std::io::Error::other`",
                     vec![
                         (new_segment.ident.span, "other".to_owned()),
-                        (error_kind.span.until(error.span), String::new()),
+                        (error_kind.span.until(error.span.source_callsite()), String::new()),
                     ],
                     Applicability::MachineApplicable,
                 );
diff --git a/tests/ui/io_other_error.fixed b/tests/ui/io_other_error.fixed
index 0054c56fb62..ce7e8ef281f 100644
--- a/tests/ui/io_other_error.fixed
+++ b/tests/ui/io_other_error.fixed
@@ -53,3 +53,8 @@ mod paths {
 fn under_msrv() {
     let _err = std::io::Error::new(std::io::ErrorKind::Other, E);
 }
+
+pub fn issue14346(x: i32) -> std::io::Error {
+    std::io::Error::other(format!("{x}"))
+    //~^ ERROR: this can be `std::io::Error::other(_)`
+}
diff --git a/tests/ui/io_other_error.rs b/tests/ui/io_other_error.rs
index 8529fb9a77f..b66e7f88ab1 100644
--- a/tests/ui/io_other_error.rs
+++ b/tests/ui/io_other_error.rs
@@ -53,3 +53,8 @@ mod paths {
 fn under_msrv() {
     let _err = std::io::Error::new(std::io::ErrorKind::Other, E);
 }
+
+pub fn issue14346(x: i32) -> std::io::Error {
+    std::io::Error::new(std::io::ErrorKind::Other, format!("{x}"))
+    //~^ ERROR: this can be `std::io::Error::other(_)`
+}
diff --git a/tests/ui/io_other_error.stderr b/tests/ui/io_other_error.stderr
index e79e05ecd40..b37e3d15064 100644
--- a/tests/ui/io_other_error.stderr
+++ b/tests/ui/io_other_error.stderr
@@ -48,5 +48,17 @@ LL -         let _err = io::Error::new(io::ErrorKind::Other, super::E);
 LL +         let _err = io::Error::other(super::E);
    |
 
-error: aborting due to 4 previous errors
+error: this can be `std::io::Error::other(_)`
+  --> tests/ui/io_other_error.rs:58:5
+   |
+LL |     std::io::Error::new(std::io::ErrorKind::Other, format!("{x}"))
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+help: use `std::io::Error::other`
+   |
+LL -     std::io::Error::new(std::io::ErrorKind::Other, format!("{x}"))
+LL +     std::io::Error::other(format!("{x}"))
+   |
+
+error: aborting due to 5 previous errors