-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add #[track_caller] support to ?
#77474
Comments
For reference this idea was mentioned also in #87401 (comment) |
Is there anything preventing this addition? If not, then I can create a PR |
@c410-f3r Since my last comment in August, there has been further discussion about this in various places. IIRC, @yaahc resolved to add |
It was to Unless it has been since removed again, I think that means this issue can be closed? |
Thanks @BGR360 Unfortunately, such change did not prevent an error I am currently facing that also points stuff to But this can be reported in another issue with an appropriated reproducible snippet |
I was worried it would still be broken, I remember in the past it losing the location when it went through use thiserror::Error;
fn main() {
let err = inner().unwrap_err();
println!("Error: {:?}", err);
}
#[derive(Debug, Error)]
#[error("my error")]
struct MyError;
fn inner() -> eyre::Result<()> {
Err(MyError)?
} It might be that original issue I was referring to was just about explicitly calling
Which might be worth fixing, I'm not really sure. It would be a one line change and we'd need to perf test it but I'm not confident it would pass or be something we'd want to merge. 👍 @c410-f3r for opening a new issue for this specific issue. I'm gonna go ahead and close this one for now. |
…to, r=<try> Add `#[track_caller]` to the "From implies Into" impl This pr implements what was mentioned in rust-lang#77474 (comment) This follows from my URLO https://users.rust-lang.org/t/104497 ```rust #![allow(warnings)] fn main() { // Gives a good location let _: Result<(), Loc> = dbg!(Err::<(), _>(()).map_err(|e| e.into())); // still doesn't work, gives location of `FnOnce::call_once()` let _: Result<(), Loc> = dbg!(Err::<(), _>(()).map_err(Into::into)); } #[derive(Debug)] pub struct Loc { pub l: &'static std::panic::Location<'static>, } impl From<()> for Loc { #[track_caller] fn from(_: ()) -> Self { Loc { l: std::panic::Location::caller(), } } } ```
…to, r=Nilstrieb Add `#[track_caller]` to the "From implies Into" impl This pr implements what was mentioned in rust-lang#77474 (comment) This follows from my URLO https://users.rust-lang.org/t/104497 ```rust #![allow(warnings)] fn main() { // Gives a good location let _: Result<(), Loc> = dbg!(Err::<(), _>(()).map_err(|e| e.into())); // still doesn't work, gives location of `FnOnce::call_once()` let _: Result<(), Loc> = dbg!(Err::<(), _>(()).map_err(Into::into)); } #[derive(Debug)] pub struct Loc { pub l: &'static std::panic::Location<'static>, } impl From<()> for Loc { #[track_caller] fn from(_: ()) -> Self { Loc { l: std::panic::Location::caller(), } } } ```
…strieb Add `#[track_caller]` to the "From implies Into" impl This pr implements what was mentioned in rust-lang/rust#77474 (comment) This follows from my URLO https://users.rust-lang.org/t/104497 ```rust #![allow(warnings)] fn main() { // Gives a good location let _: Result<(), Loc> = dbg!(Err::<(), _>(()).map_err(|e| e.into())); // still doesn't work, gives location of `FnOnce::call_once()` let _: Result<(), Loc> = dbg!(Err::<(), _>(()).map_err(Into::into)); } #[derive(Debug)] pub struct Loc { pub l: &'static std::panic::Location<'static>, } impl From<()> for Loc { #[track_caller] fn from(_: ()) -> Self { Loc { l: std::panic::Location::caller(), } } } ```
…strieb Add `#[track_caller]` to the "From implies Into" impl This pr implements what was mentioned in rust-lang/rust#77474 (comment) This follows from my URLO https://users.rust-lang.org/t/104497 ```rust #![allow(warnings)] fn main() { // Gives a good location let _: Result<(), Loc> = dbg!(Err::<(), _>(()).map_err(|e| e.into())); // still doesn't work, gives location of `FnOnce::call_once()` let _: Result<(), Loc> = dbg!(Err::<(), _>(()).map_err(Into::into)); } #[derive(Debug)] pub struct Loc { pub l: &'static std::panic::Location<'static>, } impl From<()> for Loc { #[track_caller] fn from(_: ()) -> Self { Loc { l: std::panic::Location::caller(), } } } ```
…strieb Add `#[track_caller]` to the "From implies Into" impl This pr implements what was mentioned in rust-lang/rust#77474 (comment) This follows from my URLO https://users.rust-lang.org/t/104497 ```rust #![allow(warnings)] fn main() { // Gives a good location let _: Result<(), Loc> = dbg!(Err::<(), _>(()).map_err(|e| e.into())); // still doesn't work, gives location of `FnOnce::call_once()` let _: Result<(), Loc> = dbg!(Err::<(), _>(()).map_err(Into::into)); } #[derive(Debug)] pub struct Loc { pub l: &'static std::panic::Location<'static>, } impl From<()> for Loc { #[track_caller] fn from(_: ()) -> Self { Loc { l: std::panic::Location::caller(), } } } ```
Right now if you construct an error via its
Into
implementation as provided by the blanket implementation instd
it gives the following location.We should add
#[track_caller]
to this trait and possibily some of theTry
trait implementations so that errors that attempt to track their construction point can correctly point to user code.cc @anp
The text was updated successfully, but these errors were encountered: