Walk back to the root context to compute the span (#14349)

Since the error kind (`io::ErrorKind::other`) is in the root context,
the error message must be found in the root context as well to compute
the correct span to remove.

Fix #14346

changelog: [`io_error_other`]: fix non-applicable suggestion

r? @llogiq
This commit is contained in:
llogiq 2025-03-05 05:52:19 +00:00 committed by GitHub
commit 9538e5bcd0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 2 deletions

View file

@ -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(_)`
}

View file

@ -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(_)`
}

View file

@ -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