extern crate numeric_literals; use numeric_literals::replace_numeric_literals; use std::convert::TryFrom; use std::fmt::Debug; use std::ops::Div; #[replace_numeric_literals(T::from(literal))] fn test() -> T where T: From + Div, { 3 / 2 / 2 } #[replace_numeric_literals(T::try_from(literal).expect("Must fit"))] fn test2() -> T where T: TryFrom + Div, >::Error: Debug, { 3 / 2 / 2 } #[replace_numeric_literals(T::try_from(literal).map_err(|_| ())?)] fn test3() -> Result where T: TryFrom + Div, { let res = 3 / 2 / 2; Ok(res) } #[replace_numeric_literals(f32::from(literal))] pub trait A {} #[allow(dead_code)] struct B; #[replace_numeric_literals(literal)] impl B {} fn main() { println!("{}", test::()); println!("{}", test2::()); println!("{}", test3::().unwrap()); }