skip TryFrom doc test if TryFrom not supported by rustc

This commit is contained in:
Trevor Spiteri 2019-08-12 13:16:50 +02:00
parent 49eca656df
commit 0840c4fcf0
2 changed files with 11 additions and 1 deletions

View File

@ -28,7 +28,8 @@ fn main() {
out_dir: PathBuf::from(cargo_env("OUT_DIR")), out_dir: PathBuf::from(cargo_env("OUT_DIR")),
rustc: cargo_env("RUSTC"), 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)] #[derive(PartialEq)]
@ -130,3 +131,10 @@ fn create_file_or_panic(filename: &Path, contents: &str) {
file.write_all(contents.as_bytes()) file.write_all(contents.as_bytes())
.unwrap_or_else(|_| panic!("Unable to write to file: {:?}", filename)); .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);
}
"#;

View File

@ -164,6 +164,7 @@ depending on the crates [optional features].
/// is [`u8`] or [`i8`].) /// is [`u8`] or [`i8`].)
/// ///
/// ```rust /// ```rust
/// # #[cfg(try_from)] {
/// use fixed::{traits::Fixed, types::I12F4}; /// use fixed::{traits::Fixed, types::I12F4};
/// use std::convert::TryFrom; /// use std::convert::TryFrom;
/// ///
@ -177,6 +178,7 @@ depending on the crates [optional features].
/// ///
/// let val = checked_add_times_500(I12F4::from_float(0.25), Fixed::from_float(1.5)); /// 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))); /// assert_eq!(val, Some(Fixed::from_float(750.25)));
/// # }
/// ``` /// ```
/// ///
/// [`None`]: https://doc.rust-lang.org/nightly/std/option/enum.Option.html#variant.None /// [`None`]: https://doc.rust-lang.org/nightly/std/option/enum.Option.html#variant.None