Skip to content

#[track_caller] erroneously points to macro call #95152

Closed
@c410-f3r

Description

@c410-f3r
use core::num::TryFromIntError;

#[derive(Debug)]
pub struct Error {
  pub column: u32,
  pub file: &'static str,
  pub line: u32,
  pub ty: ErrorTy,
}

#[derive(Debug)]
pub enum ErrorTy {
  BadCast(TryFromIntError),
}

impl From<TryFromIntError> for Error {
  #[inline]
  #[track_caller]
  fn from(from: TryFromIntError) -> Self {
    let location = core::panic::Location::caller();
    Self {
      column: location.column(),
      file: location.file(),
      line: location.line(),
      ty: ErrorTy::BadCast(from)
    }
  }
}

macro_rules! foo {
    () => {{
        let rslt: u8 = (-1i8).try_into()?;
        rslt
    }};
}

fn main() -> Result<(), Error> {
    let _ = foo!();
    Ok(())
}

Error::line points to line 38 (let _ = foo!();) but should in fact point to line 32 (let rslt: u8 = (-1i8).try_into()?;).

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions