diff --git a/build.rs b/build.rs index 9870166..85d46a6 100644 --- a/build.rs +++ b/build.rs @@ -28,7 +28,8 @@ fn main() { out_dir: PathBuf::from(cargo_env("OUT_DIR")), rustc: cargo_env("RUSTC"), }; - // env.check_feature(...); + // TryFrom is needed for some doc tests + env.check_feature("try_from", Optional(true), TRY_TRY_FROM, None); } #[derive(PartialEq)] @@ -130,3 +131,10 @@ fn create_file_or_panic(filename: &Path, contents: &str) { file.write_all(contents.as_bytes()) .unwrap_or_else(|_| panic!("Unable to write to file: {:?}", filename)); } + +const TRY_TRY_FROM: &str = r#"// try_try_from.rs +use std::convert::TryFrom; +fn main() { + let _ = i8::try_from(1u64); +} +"#; diff --git a/src/traits.rs b/src/traits.rs index 2061173..9dd46e4 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -164,6 +164,7 @@ depending on the crate’s [optional features]. /// is [`u8`] or [`i8`].) /// /// ```rust +/// # #[cfg(try_from)] { /// use fixed::{traits::Fixed, types::I12F4}; /// use std::convert::TryFrom; /// @@ -177,6 +178,7 @@ depending on the crate’s [optional features]. /// /// let val = checked_add_times_500(I12F4::from_float(0.25), Fixed::from_float(1.5)); /// assert_eq!(val, Some(Fixed::from_float(750.25))); +/// # } /// ``` /// /// [`None`]: https://doc.rust-lang.org/nightly/std/option/enum.Option.html#variant.None