Closed
Description
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()?;
).