Skip to content

Commit

Permalink
Auto merge of #119807 - Emilgardis:track_caller_from_impl_into, r=Nil…
Browse files Browse the repository at this point in the history
…strieb

Add `#[track_caller]` to the "From implies Into" impl

This pr implements what was mentioned in #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(),
        }
    }
}
```
  • Loading branch information
bors committed Jan 21, 2024
2 parents fa40433 + 075f2e0 commit d9d89fd
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions library/core/src/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ where
/// That is, this conversion is whatever the implementation of
/// <code>[From]&lt;T&gt; for U</code> chooses to do.
#[inline]
#[track_caller]
fn into(self) -> U {
U::from(self)
}
Expand Down

0 comments on commit d9d89fd

Please sign in to comment.