about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-01-21 14:17:25 +0000
committerbors <bors@rust-lang.org>2024-01-21 14:17:25 +0000
commitd9d89fd53dd18b7eeab0cc276353209eb8b073b2 (patch)
treeda64cc2a3a4ad25c3ac193640f0b936ea953d720
parentfa404339c9821b9c61661d63326d95e354b9753f (diff)
parent075f2e0345a00fcb3352ac9ece8a87817b73d305 (diff)
downloadrust-d9d89fd53dd18b7eeab0cc276353209eb8b073b2.tar.gz
rust-d9d89fd53dd18b7eeab0cc276353209eb8b073b2.zip
Auto merge of #119807 - Emilgardis:track_caller_from_impl_into, r=Nilstrieb
Add `#[track_caller]` to the "From implies Into" impl

This pr implements what was mentioned in https://github.com/rust-lang/rust/issues/77474#issuecomment-1074480790

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(),
        }
    }
}
```
-rw-r--r--library/core/src/convert/mod.rs1
1 files changed, 1 insertions, 0 deletions
diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs
index 8c01b0973d6..45f6e375e89 100644
--- a/library/core/src/convert/mod.rs
+++ b/library/core/src/convert/mod.rs
@@ -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)
     }