diff options
Diffstat (limited to 'library/std')
| -rw-r--r-- | library/std/Cargo.toml | 8 | ||||
| -rw-r--r-- | library/std/src/fs.rs | 5 | ||||
| -rw-r--r-- | library/std/src/io/mod.rs | 40 | ||||
| -rw-r--r-- | library/std/src/lib.rs | 1 | ||||
| -rw-r--r-- | library/std/src/num/f128.rs | 69 | ||||
| -rw-r--r-- | library/std/src/num/f16.rs | 67 | ||||
| -rw-r--r-- | library/std/src/num/f32.rs | 34 | ||||
| -rw-r--r-- | library/std/src/num/f64.rs | 6 | ||||
| -rw-r--r-- | library/std/src/os/android/net.rs | 2 | ||||
| -rw-r--r-- | library/std/src/os/linux/net.rs | 2 | ||||
| -rw-r--r-- | library/std/src/os/net/linux_ext/mod.rs | 2 | ||||
| -rw-r--r-- | library/std/src/os/net/linux_ext/tcp.rs | 12 | ||||
| -rw-r--r-- | library/std/src/os/unix/net/addr.rs | 9 | ||||
| -rw-r--r-- | library/std/src/os/unix/net/tests.rs | 9 | ||||
| -rw-r--r-- | library/std/tests/floats/f32.rs | 33 | ||||
| -rw-r--r-- | library/std/tests/floats/f64.rs | 8 | ||||
| -rw-r--r-- | library/std/tests/sync/mpmc.rs | 11 | ||||
| -rw-r--r-- | library/std/tests/sync/mpsc.rs | 11 |
18 files changed, 129 insertions, 200 deletions
diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index 0419336e13a..ae7107938f3 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -18,7 +18,7 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] } panic_unwind = { path = "../panic_unwind", optional = true } panic_abort = { path = "../panic_abort" } core = { path = "../core", public = true } -compiler_builtins = { version = "=0.1.160" } +compiler_builtins = { path = "../compiler-builtins/compiler-builtins" } unwind = { path = "../unwind" } hashbrown = { version = "0.15", default-features = false, features = [ 'rustc-dep-of-std', @@ -32,7 +32,7 @@ rustc-demangle = { version = "0.1.24", features = ['rustc-dep-of-std'] } [target.'cfg(not(all(windows, target_env = "msvc", not(target_vendor = "uwp"))))'.dependencies] miniz_oxide = { version = "0.8.0", optional = true, default-features = false } -addr2line = { version = "0.24.0", optional = true, default-features = false } +addr2line = { version = "0.25.0", optional = true, default-features = false } [target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies] libc = { version = "0.2.172", default-features = false, features = [ @@ -40,7 +40,7 @@ libc = { version = "0.2.172", default-features = false, features = [ ], public = true } [target.'cfg(all(not(target_os = "aix"), not(all(windows, target_env = "msvc", not(target_vendor = "uwp")))))'.dependencies] -object = { version = "0.36.0", default-features = false, optional = true, features = [ +object = { version = "0.37.1", default-features = false, optional = true, features = [ 'read_core', 'elf', 'macho', @@ -50,7 +50,7 @@ object = { version = "0.36.0", default-features = false, optional = true, featur ] } [target.'cfg(target_os = "aix")'.dependencies] -object = { version = "0.36.0", default-features = false, optional = true, features = [ +object = { version = "0.37.1", default-features = false, optional = true, features = [ 'read_core', 'xcoff', 'unaligned', diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 6cbf8301e01..0cd794fd3ef 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -153,9 +153,8 @@ pub struct Metadata(fs_imp::FileAttr); /// dependent. /// /// # Errors -/// -/// This [`io::Result`] will be an [`Err`] if there's some sort of intermittent -/// IO error during iteration. +/// This [`io::Result`] will be an [`Err`] if an error occurred while fetching +/// the next entry from the OS. #[stable(feature = "rust1", since = "1.0.0")] #[derive(Debug)] pub struct ReadDir(fs_imp::ReadDir); diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 20c82b64bcc..a9a24681e7c 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -917,6 +917,19 @@ pub trait Read { /// # } /// ``` /// + /// # Usage Notes + /// + /// `read_to_end` attempts to read a source until EOF, but many sources are continuous streams + /// that do not send EOF. In these cases, `read_to_end` will block indefinitely. Standard input + /// is one such stream which may be finite if piped, but is typically continuous. For example, + /// `cat file | my-rust-program` will correctly terminate with an `EOF` upon closure of cat. + /// Reading user input or running programs that remain open indefinitely will never terminate + /// the stream with `EOF` (e.g. `yes | my-rust-program`). + /// + /// Using `.lines()` with a [`BufReader`] or using [`read`] can provide a better solution + /// + ///[`read`]: Read::read + /// /// [`Vec::try_reserve`]: crate::vec::Vec::try_reserve #[stable(feature = "rust1", since = "1.0.0")] fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize> { @@ -960,6 +973,19 @@ pub trait Read { /// (See also the [`std::fs::read_to_string`] convenience function for /// reading from a file.) /// + /// # Usage Notes + /// + /// `read_to_string` attempts to read a source until EOF, but many sources are continuous streams + /// that do not send EOF. In these cases, `read_to_string` will block indefinitely. Standard input + /// is one such stream which may be finite if piped, but is typically continuous. For example, + /// `cat file | my-rust-program` will correctly terminate with an `EOF` upon closure of cat. + /// Reading user input or running programs that remain open indefinitely will never terminate + /// the stream with `EOF` (e.g. `yes | my-rust-program`). + /// + /// Using `.lines()` with a [`BufReader`] or using [`read`] can provide a better solution + /// + ///[`read`]: Read::read + /// /// [`std::fs::read_to_string`]: crate::fs::read_to_string #[stable(feature = "rust1", since = "1.0.0")] fn read_to_string(&mut self, buf: &mut String) -> Result<usize> { @@ -1262,6 +1288,20 @@ pub trait Read { /// Ok(()) /// } /// ``` +/// +/// # Usage Notes +/// +/// `read_to_string` attempts to read a source until EOF, but many sources are continuous streams +/// that do not send EOF. In these cases, `read_to_string` will block indefinitely. Standard input +/// is one such stream which may be finite if piped, but is typically continuous. For example, +/// `cat file | my-rust-program` will correctly terminate with an `EOF` upon closure of cat. +/// Reading user input or running programs that remain open indefinitely will never terminate +/// the stream with `EOF` (e.g. `yes | my-rust-program`). +/// +/// Using `.lines()` with a [`BufReader`] or using [`read`] can provide a better solution +/// +///[`read`]: Read::read +/// #[stable(feature = "io_read_to_string", since = "1.65.0")] pub fn read_to_string<R: Read>(mut reader: R) -> Result<String> { let mut buf = String::new(); diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 7c54e731edc..2bb7a63772d 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -351,7 +351,6 @@ #![feature(lazy_get)] #![feature(maybe_uninit_slice)] #![feature(maybe_uninit_write_slice)] -#![feature(nonnull_provenance)] #![feature(panic_can_unwind)] #![feature(panic_internals)] #![feature(pin_coerce_unsized_trait)] diff --git a/library/std/src/num/f128.rs b/library/std/src/num/f128.rs index c0190de089f..64e604e35f7 100644 --- a/library/std/src/num/f128.rs +++ b/library/std/src/num/f128.rs @@ -5,6 +5,7 @@ //! Mathematically significant numbers are provided in the `consts` sub-module. #![unstable(feature = "f128", issue = "116909")] +#![doc(test(attr(feature(cfg_target_has_reliable_f16_f128), expect(internal_features))))] #[unstable(feature = "f128", issue = "116909")] pub use core::f128::consts; @@ -27,8 +28,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -59,8 +58,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -93,8 +90,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -127,8 +122,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -146,8 +139,6 @@ impl f128 { /// Non-positive values: /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -180,8 +171,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -197,8 +186,6 @@ impl f128 { /// Non-positive values: /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -227,8 +214,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -244,8 +229,6 @@ impl f128 { /// Non-positive values: /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -274,8 +257,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -291,8 +272,6 @@ impl f128 { /// Non-positive values: /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -323,8 +302,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -362,8 +339,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -395,8 +370,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -426,8 +399,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -460,8 +431,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -495,8 +464,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -533,8 +500,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -570,8 +535,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -611,8 +574,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -656,8 +617,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -694,8 +653,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -733,8 +690,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -751,8 +706,6 @@ impl f128 { /// Out-of-range values: /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -783,8 +736,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -821,8 +772,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -859,8 +808,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -894,8 +841,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -929,8 +874,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -966,8 +909,6 @@ impl f128 { /// /// ``` /// #![feature(f128)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -1003,8 +944,6 @@ impl f128 { /// ``` /// #![feature(f128)] /// #![feature(float_gamma)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -1041,8 +980,6 @@ impl f128 { /// ``` /// #![feature(f128)] /// #![feature(float_gamma)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// @@ -1079,8 +1016,6 @@ impl f128 { /// ``` /// #![feature(f128)] /// #![feature(float_erf)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// /// The error function relates what percent of a normal distribution lies @@ -1121,8 +1056,6 @@ impl f128 { /// ``` /// #![feature(f128)] /// #![feature(float_erf)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f128_math)] { /// let x: f128 = 0.123; diff --git a/library/std/src/num/f16.rs b/library/std/src/num/f16.rs index 4a4a8fd839a..7bdefb05858 100644 --- a/library/std/src/num/f16.rs +++ b/library/std/src/num/f16.rs @@ -5,6 +5,7 @@ //! Mathematically significant numbers are provided in the `consts` sub-module. #![unstable(feature = "f16", issue = "116909")] +#![doc(test(attr(feature(cfg_target_has_reliable_f16_f128), expect(internal_features))))] #[unstable(feature = "f16", issue = "116909")] pub use core::f16::consts; @@ -27,8 +28,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -59,8 +58,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -93,8 +90,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -127,8 +122,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -146,8 +139,6 @@ impl f16 { /// Non-positive values: /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -180,8 +171,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -197,8 +186,6 @@ impl f16 { /// Non-positive values: /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -227,8 +214,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -244,8 +229,6 @@ impl f16 { /// Non-positive values: /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -274,8 +257,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -291,8 +272,6 @@ impl f16 { /// Non-positive values: /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -325,8 +304,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -358,8 +335,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -389,8 +364,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -423,8 +396,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -458,8 +429,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -496,8 +465,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -533,8 +500,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -574,8 +539,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -619,8 +582,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -657,8 +618,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -696,8 +655,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -714,8 +671,6 @@ impl f16 { /// Out-of-range values: /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -746,8 +701,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -784,8 +737,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -822,8 +773,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -857,8 +806,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -892,8 +839,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -929,8 +874,6 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -966,8 +909,6 @@ impl f16 { /// ``` /// #![feature(f16)] /// #![feature(float_gamma)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -1004,8 +945,6 @@ impl f16 { /// ``` /// #![feature(f16)] /// #![feature(float_gamma)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// @@ -1042,8 +981,6 @@ impl f16 { /// ``` /// #![feature(f16)] /// #![feature(float_erf)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// /// The error function relates what percent of a normal distribution lies @@ -1084,8 +1021,6 @@ impl f16 { /// ``` /// #![feature(f16)] /// #![feature(float_erf)] - /// # #![feature(cfg_target_has_reliable_f16_f128)] - /// # #![expect(internal_features)] /// # #[cfg(not(miri))] /// # #[cfg(target_has_reliable_f16_math)] { /// let x: f16 = 0.123; diff --git a/library/std/src/num/f32.rs b/library/std/src/num/f32.rs index b7f6529ac40..e79ec2ae966 100644 --- a/library/std/src/num/f32.rs +++ b/library/std/src/num/f32.rs @@ -304,7 +304,7 @@ impl f32 { /// ``` /// let x = 2.0_f32; /// let abs_difference = (x.powi(2) - (x * x)).abs(); - /// assert!(abs_difference <= f32::EPSILON); + /// assert!(abs_difference <= 1e-5); /// /// assert_eq!(f32::powi(f32::NAN, 0), 1.0); /// ``` @@ -328,7 +328,7 @@ impl f32 { /// ``` /// let x = 2.0_f32; /// let abs_difference = (x.powf(2.0) - (x * x)).abs(); - /// assert!(abs_difference <= f32::EPSILON); + /// assert!(abs_difference <= 1e-5); /// /// assert_eq!(f32::powf(1.0, f32::NAN), 1.0); /// assert_eq!(f32::powf(f32::NAN, 0.0), 1.0); @@ -388,7 +388,7 @@ impl f32 { /// // ln(e) - 1 == 0 /// let abs_difference = (e.ln() - 1.0).abs(); /// - /// assert!(abs_difference <= f32::EPSILON); + /// assert!(abs_difference <= 1e-6); /// ``` #[rustc_allow_incoherent_impl] #[must_use = "method returns a new number and does not mutate the original value"] @@ -413,7 +413,7 @@ impl f32 { /// // 2^2 - 4 == 0 /// let abs_difference = (f.exp2() - 4.0).abs(); /// - /// assert!(abs_difference <= f32::EPSILON); + /// assert!(abs_difference <= 1e-5); /// ``` #[rustc_allow_incoherent_impl] #[must_use = "method returns a new number and does not mutate the original value"] @@ -442,7 +442,7 @@ impl f32 { /// // ln(e) - 1 == 0 /// let abs_difference = (e.ln() - 1.0).abs(); /// - /// assert!(abs_difference <= f32::EPSILON); + /// assert!(abs_difference <= 1e-6); /// ``` /// /// Non-positive values: @@ -479,7 +479,7 @@ impl f32 { /// // log5(5) - 1 == 0 /// let abs_difference = (five.log(5.0) - 1.0).abs(); /// - /// assert!(abs_difference <= f32::EPSILON); + /// assert!(abs_difference <= 1e-6); /// ``` /// /// Non-positive values: @@ -512,7 +512,7 @@ impl f32 { /// // log2(2) - 1 == 0 /// let abs_difference = (two.log2() - 1.0).abs(); /// - /// assert!(abs_difference <= f32::EPSILON); + /// assert!(abs_difference <= 1e-6); /// ``` /// /// Non-positive values: @@ -545,7 +545,7 @@ impl f32 { /// // log10(10) - 1 == 0 /// let abs_difference = (ten.log10() - 1.0).abs(); /// - /// assert!(abs_difference <= f32::EPSILON); + /// assert!(abs_difference <= 1e-6); /// ``` /// /// Non-positive values: @@ -652,7 +652,7 @@ impl f32 { /// // sqrt(x^2 + y^2) /// let abs_difference = (x.hypot(y) - (x.powi(2) + y.powi(2)).sqrt()).abs(); /// - /// assert!(abs_difference <= f32::EPSILON); + /// assert!(abs_difference <= 1e-6); /// ``` #[rustc_allow_incoherent_impl] #[must_use = "method returns a new number and does not mutate the original value"] @@ -676,7 +676,7 @@ impl f32 { /// /// let abs_difference = (x.sin() - 1.0).abs(); /// - /// assert!(abs_difference <= f32::EPSILON); + /// assert!(abs_difference <= 1e-6); /// ``` #[rustc_allow_incoherent_impl] #[must_use = "method returns a new number and does not mutate the original value"] @@ -700,7 +700,7 @@ impl f32 { /// /// let abs_difference = (x.cos() - 1.0).abs(); /// - /// assert!(abs_difference <= f32::EPSILON); + /// assert!(abs_difference <= 1e-6); /// ``` #[rustc_allow_incoherent_impl] #[must_use = "method returns a new number and does not mutate the original value"] @@ -754,7 +754,7 @@ impl f32 { /// // asin(sin(pi/2)) /// let abs_difference = (f.sin().asin() - std::f32::consts::FRAC_PI_2).abs(); /// - /// assert!(abs_difference <= f32::EPSILON); + /// assert!(abs_difference <= 1e-3); /// ``` #[doc(alias = "arcsin")] #[rustc_allow_incoherent_impl] @@ -784,7 +784,7 @@ impl f32 { /// // acos(cos(pi/4)) /// let abs_difference = (f.cos().acos() - std::f32::consts::FRAC_PI_4).abs(); /// - /// assert!(abs_difference <= f32::EPSILON); + /// assert!(abs_difference <= 1e-6); /// ``` #[doc(alias = "arccos")] #[rustc_allow_incoherent_impl] @@ -884,8 +884,8 @@ impl f32 { /// let abs_difference_0 = (f.0 - x.sin()).abs(); /// let abs_difference_1 = (f.1 - x.cos()).abs(); /// - /// assert!(abs_difference_0 <= f32::EPSILON); - /// assert!(abs_difference_1 <= f32::EPSILON); + /// assert!(abs_difference_0 <= 1e-6); + /// assert!(abs_difference_1 <= 1e-6); /// ``` #[doc(alias = "sincos")] #[rustc_allow_incoherent_impl] @@ -1067,7 +1067,7 @@ impl f32 { /// /// let abs_difference = (f - x).abs(); /// - /// assert!(abs_difference <= f32::EPSILON); + /// assert!(abs_difference <= 1e-7); /// ``` #[doc(alias = "arcsinh")] #[rustc_allow_incoherent_impl] @@ -1095,7 +1095,7 @@ impl f32 { /// /// let abs_difference = (f - x).abs(); /// - /// assert!(abs_difference <= f32::EPSILON); + /// assert!(abs_difference <= 1e-6); /// ``` #[doc(alias = "arccosh")] #[rustc_allow_incoherent_impl] diff --git a/library/std/src/num/f64.rs b/library/std/src/num/f64.rs index 75e35a8db33..853417825f9 100644 --- a/library/std/src/num/f64.rs +++ b/library/std/src/num/f64.rs @@ -304,7 +304,7 @@ impl f64 { /// ``` /// let x = 2.0_f64; /// let abs_difference = (x.powi(2) - (x * x)).abs(); - /// assert!(abs_difference <= f64::EPSILON); + /// assert!(abs_difference <= 1e-14); /// /// assert_eq!(f64::powi(f64::NAN, 0), 1.0); /// ``` @@ -328,7 +328,7 @@ impl f64 { /// ``` /// let x = 2.0_f64; /// let abs_difference = (x.powf(2.0) - (x * x)).abs(); - /// assert!(abs_difference <= f64::EPSILON); + /// assert!(abs_difference <= 1e-14); /// /// assert_eq!(f64::powf(1.0, f64::NAN), 1.0); /// assert_eq!(f64::powf(f64::NAN, 0.0), 1.0); @@ -754,7 +754,7 @@ impl f64 { /// // asin(sin(pi/2)) /// let abs_difference = (f.sin().asin() - std::f64::consts::FRAC_PI_2).abs(); /// - /// assert!(abs_difference < 1e-10); + /// assert!(abs_difference < 1e-7); /// ``` #[doc(alias = "arcsin")] #[rustc_allow_incoherent_impl] diff --git a/library/std/src/os/android/net.rs b/library/std/src/os/android/net.rs index 960a304fd0c..3a459ed8aee 100644 --- a/library/std/src/os/android/net.rs +++ b/library/std/src/os/android/net.rs @@ -6,5 +6,5 @@ pub use crate::os::net::linux_ext::addr::SocketAddrExt; #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] pub use crate::os::net::linux_ext::socket::UnixSocketExt; -#[unstable(feature = "tcp_quickack", issue = "96256")] +#[stable(feature = "tcp_quickack", since = "CURRENT_RUSTC_VERSION")] pub use crate::os::net::linux_ext::tcp::TcpStreamExt; diff --git a/library/std/src/os/linux/net.rs b/library/std/src/os/linux/net.rs index 1de120c8fd3..c14aba13bd1 100644 --- a/library/std/src/os/linux/net.rs +++ b/library/std/src/os/linux/net.rs @@ -6,5 +6,5 @@ pub use crate::os::net::linux_ext::addr::SocketAddrExt; #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] pub use crate::os::net::linux_ext::socket::UnixSocketExt; -#[unstable(feature = "tcp_quickack", issue = "96256")] +#[stable(feature = "tcp_quickack", since = "CURRENT_RUSTC_VERSION")] pub use crate::os::net::linux_ext::tcp::TcpStreamExt; diff --git a/library/std/src/os/net/linux_ext/mod.rs b/library/std/src/os/net/linux_ext/mod.rs index d0979640c32..bb9dfae2623 100644 --- a/library/std/src/os/net/linux_ext/mod.rs +++ b/library/std/src/os/net/linux_ext/mod.rs @@ -8,7 +8,7 @@ pub(crate) mod addr; #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] pub(crate) mod socket; -#[unstable(feature = "tcp_quickack", issue = "96256")] +#[stable(feature = "tcp_quickack", since = "CURRENT_RUSTC_VERSION")] pub(crate) mod tcp; #[cfg(test)] diff --git a/library/std/src/os/net/linux_ext/tcp.rs b/library/std/src/os/net/linux_ext/tcp.rs index 95dffb3bc43..167cfa62531 100644 --- a/library/std/src/os/net/linux_ext/tcp.rs +++ b/library/std/src/os/net/linux_ext/tcp.rs @@ -9,7 +9,7 @@ use crate::{io, net}; /// Os-specific extensions for [`TcpStream`] /// /// [`TcpStream`]: net::TcpStream -#[unstable(feature = "tcp_quickack", issue = "96256")] +#[stable(feature = "tcp_quickack", since = "CURRENT_RUSTC_VERSION")] pub trait TcpStreamExt: Sealed { /// Enable or disable `TCP_QUICKACK`. /// @@ -23,7 +23,6 @@ pub trait TcpStreamExt: Sealed { /// # Examples /// /// ```no_run - /// #![feature(tcp_quickack)] /// use std::net::TcpStream; /// #[cfg(target_os = "linux")] /// use std::os::linux::net::TcpStreamExt; @@ -34,7 +33,7 @@ pub trait TcpStreamExt: Sealed { /// .expect("Couldn't connect to the server..."); /// stream.set_quickack(true).expect("set_quickack call failed"); /// ``` - #[unstable(feature = "tcp_quickack", issue = "96256")] + #[stable(feature = "tcp_quickack", since = "CURRENT_RUSTC_VERSION")] fn set_quickack(&self, quickack: bool) -> io::Result<()>; /// Gets the value of the `TCP_QUICKACK` option on this socket. @@ -44,7 +43,6 @@ pub trait TcpStreamExt: Sealed { /// # Examples /// /// ```no_run - /// #![feature(tcp_quickack)] /// use std::net::TcpStream; /// #[cfg(target_os = "linux")] /// use std::os::linux::net::TcpStreamExt; @@ -56,7 +54,7 @@ pub trait TcpStreamExt: Sealed { /// stream.set_quickack(true).expect("set_quickack call failed"); /// assert_eq!(stream.quickack().unwrap_or(false), true); /// ``` - #[unstable(feature = "tcp_quickack", issue = "96256")] + #[stable(feature = "tcp_quickack", since = "CURRENT_RUSTC_VERSION")] fn quickack(&self) -> io::Result<bool>; /// A socket listener will be awakened solely when data arrives. @@ -105,10 +103,10 @@ pub trait TcpStreamExt: Sealed { fn deferaccept(&self) -> io::Result<u32>; } -#[unstable(feature = "tcp_quickack", issue = "96256")] +#[stable(feature = "tcp_quickack", since = "CURRENT_RUSTC_VERSION")] impl Sealed for net::TcpStream {} -#[unstable(feature = "tcp_quickack", issue = "96256")] +#[stable(feature = "tcp_quickack", since = "CURRENT_RUSTC_VERSION")] impl TcpStreamExt for net::TcpStream { fn set_quickack(&self, quickack: bool) -> io::Result<()> { self.as_inner().as_inner().set_quickack(quickack) diff --git a/library/std/src/os/unix/net/addr.rs b/library/std/src/os/unix/net/addr.rs index cb1246db310..fd6fe72dd24 100644 --- a/library/std/src/os/unix/net/addr.rs +++ b/library/std/src/os/unix/net/addr.rs @@ -1,3 +1,4 @@ +use crate::bstr::ByteStr; use crate::ffi::OsStr; #[cfg(any(doc, target_os = "android", target_os = "linux"))] use crate::os::net::linux_ext; @@ -61,7 +62,7 @@ pub(super) fn sockaddr_un(path: &Path) -> io::Result<(libc::sockaddr_un, libc::s enum AddressKind<'a> { Unnamed, Pathname(&'a Path), - Abstract(&'a [u8]), + Abstract(&'a ByteStr), } /// An address associated with a Unix socket. @@ -245,7 +246,7 @@ impl SocketAddr { { AddressKind::Unnamed } else if self.addr.sun_path[0] == 0 { - AddressKind::Abstract(&path[1..len]) + AddressKind::Abstract(ByteStr::from_bytes(&path[1..len])) } else { AddressKind::Pathname(OsStr::from_bytes(&path[..len - 1]).as_ref()) } @@ -260,7 +261,7 @@ impl Sealed for SocketAddr {} #[stable(feature = "unix_socket_abstract", since = "1.70.0")] impl linux_ext::addr::SocketAddrExt for SocketAddr { fn as_abstract_name(&self) -> Option<&[u8]> { - if let AddressKind::Abstract(name) = self.address() { Some(name) } else { None } + if let AddressKind::Abstract(name) = self.address() { Some(name.as_bytes()) } else { None } } fn from_abstract_name<N>(name: N) -> crate::io::Result<Self> @@ -295,7 +296,7 @@ impl fmt::Debug for SocketAddr { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { match self.address() { AddressKind::Unnamed => write!(fmt, "(unnamed)"), - AddressKind::Abstract(name) => write!(fmt, "\"{}\" (abstract)", name.escape_ascii()), + AddressKind::Abstract(name) => write!(fmt, "{name:?} (abstract)"), AddressKind::Pathname(path) => write!(fmt, "{path:?} (pathname)"), } } diff --git a/library/std/src/os/unix/net/tests.rs b/library/std/src/os/unix/net/tests.rs index 0398a535eb5..9a88687b1df 100644 --- a/library/std/src/os/unix/net/tests.rs +++ b/library/std/src/os/unix/net/tests.rs @@ -411,6 +411,15 @@ fn test_unix_datagram_timeout_zero_duration() { assert_eq!(err.kind(), ErrorKind::InvalidInput); } +#[cfg(any(target_os = "android", target_os = "linux"))] +#[test] +fn abstract_socket_addr_debug() { + assert_eq!( + r#""\0hello world\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x11\x12\r\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f \x7f\x80\x81\xfe\xff" (abstract)"#, + format!("{:?}", SocketAddr::from_abstract_name(b"\0hello world\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x11\x12\r\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f \x7f\x80\x81\xfe\xff").unwrap()), + ); +} + #[test] fn abstract_namespace_not_allowed_connect() { assert!(UnixStream::connect("\0asdf").is_err()); diff --git a/library/std/tests/floats/f32.rs b/library/std/tests/floats/f32.rs index e54f227bb77..38c906c1d87 100644 --- a/library/std/tests/floats/f32.rs +++ b/library/std/tests/floats/f32.rs @@ -1,5 +1,10 @@ use std::f32::consts; +/// Miri adds some extra errors to float functions; make sure the tests still pass. +/// These values are purely used as a canary to test against and are thus not a stable guarantee Rust provides. +/// They serve as a way to get an idea of the real precision of floating point operations on different platforms. +const APPROX_DELTA: f32 = if cfg!(miri) { 1e-3 } else { 1e-6 }; + #[allow(unused_macros)] macro_rules! assert_f32_biteq { ($left : expr, $right : expr) => { @@ -17,9 +22,9 @@ fn test_powf() { let inf: f32 = f32::INFINITY; let neg_inf: f32 = f32::NEG_INFINITY; assert_eq!(1.0f32.powf(1.0), 1.0); - assert_approx_eq!(3.4f32.powf(4.5), 246.408218); + assert_approx_eq!(3.4f32.powf(4.5), 246.408218, APPROX_DELTA); assert_approx_eq!(2.7f32.powf(-3.2), 0.041652); - assert_approx_eq!((-3.1f32).powf(2.0), 9.61); + assert_approx_eq!((-3.1f32).powf(2.0), 9.61, APPROX_DELTA); assert_approx_eq!(5.9f32.powf(-2.0), 0.028727); assert_eq!(8.3f32.powf(0.0), 1.0); assert!(nan.powf(2.0).is_nan()); @@ -30,8 +35,8 @@ fn test_powf() { #[test] fn test_exp() { assert_eq!(1.0, 0.0f32.exp()); - assert_approx_eq!(2.718282, 1.0f32.exp()); - assert_approx_eq!(148.413162, 5.0f32.exp()); + assert_approx_eq!(2.718282, 1.0f32.exp(), APPROX_DELTA); + assert_approx_eq!(148.413162, 5.0f32.exp(), APPROX_DELTA); let inf: f32 = f32::INFINITY; let neg_inf: f32 = f32::NEG_INFINITY; @@ -43,7 +48,7 @@ fn test_exp() { #[test] fn test_exp2() { - assert_eq!(32.0, 5.0f32.exp2()); + assert_approx_eq!(32.0, 5.0f32.exp2(), APPROX_DELTA); assert_eq!(1.0, 0.0f32.exp2()); let inf: f32 = f32::INFINITY; @@ -66,7 +71,7 @@ fn test_ln() { assert!((-2.3f32).ln().is_nan()); assert_eq!((-0.0f32).ln(), neg_inf); assert_eq!(0.0f32.ln(), neg_inf); - assert_approx_eq!(4.0f32.ln(), 1.386294); + assert_approx_eq!(4.0f32.ln(), 1.386294, APPROX_DELTA); } #[test] @@ -74,9 +79,9 @@ fn test_log() { let nan: f32 = f32::NAN; let inf: f32 = f32::INFINITY; let neg_inf: f32 = f32::NEG_INFINITY; - assert_eq!(10.0f32.log(10.0), 1.0); + assert_approx_eq!(10.0f32.log(10.0), 1.0); assert_approx_eq!(2.3f32.log(3.5), 0.664858); - assert_eq!(1.0f32.exp().log(1.0f32.exp()), 1.0); + assert_approx_eq!(1.0f32.exp().log(1.0f32.exp()), 1.0, APPROX_DELTA); assert!(1.0f32.log(1.0).is_nan()); assert!(1.0f32.log(-13.9).is_nan()); assert!(nan.log(2.3).is_nan()); @@ -92,9 +97,9 @@ fn test_log2() { let nan: f32 = f32::NAN; let inf: f32 = f32::INFINITY; let neg_inf: f32 = f32::NEG_INFINITY; - assert_approx_eq!(10.0f32.log2(), 3.321928); + assert_approx_eq!(10.0f32.log2(), 3.321928, APPROX_DELTA); assert_approx_eq!(2.3f32.log2(), 1.201634); - assert_approx_eq!(1.0f32.exp().log2(), 1.442695); + assert_approx_eq!(1.0f32.exp().log2(), 1.442695, APPROX_DELTA); assert!(nan.log2().is_nan()); assert_eq!(inf.log2(), inf); assert!(neg_inf.log2().is_nan()); @@ -108,7 +113,7 @@ fn test_log10() { let nan: f32 = f32::NAN; let inf: f32 = f32::INFINITY; let neg_inf: f32 = f32::NEG_INFINITY; - assert_eq!(10.0f32.log10(), 1.0); + assert_approx_eq!(10.0f32.log10(), 1.0); assert_approx_eq!(2.3f32.log10(), 0.361728); assert_approx_eq!(1.0f32.exp().log10(), 0.434294); assert_eq!(1.0f32.log10(), 0.0); @@ -158,7 +163,7 @@ fn test_acosh() { assert_approx_eq!(3.0f32.acosh(), 1.76274717403908605046521864995958461f32); // test for low accuracy from issue 104548 - assert_approx_eq!(60.0f32, 60.0f32.cosh().acosh()); + assert_approx_eq!(60.0f32, 60.0f32.cosh().acosh(), APPROX_DELTA); } #[test] @@ -237,7 +242,7 @@ fn test_real_consts() { let ln_10: f32 = consts::LN_10; assert_approx_eq!(frac_pi_2, pi / 2f32); - assert_approx_eq!(frac_pi_3, pi / 3f32); + assert_approx_eq!(frac_pi_3, pi / 3f32, APPROX_DELTA); assert_approx_eq!(frac_pi_4, pi / 4f32); assert_approx_eq!(frac_pi_6, pi / 6f32); assert_approx_eq!(frac_pi_8, pi / 8f32); @@ -249,5 +254,5 @@ fn test_real_consts() { assert_approx_eq!(log2_e, e.log2()); assert_approx_eq!(log10_e, e.log10()); assert_approx_eq!(ln_2, 2f32.ln()); - assert_approx_eq!(ln_10, 10f32.ln()); + assert_approx_eq!(ln_10, 10f32.ln(), APPROX_DELTA); } diff --git a/library/std/tests/floats/f64.rs b/library/std/tests/floats/f64.rs index 2d8dd1cf091..fccf2009727 100644 --- a/library/std/tests/floats/f64.rs +++ b/library/std/tests/floats/f64.rs @@ -43,7 +43,7 @@ fn test_exp() { #[test] fn test_exp2() { - assert_eq!(32.0, 5.0f64.exp2()); + assert_approx_eq!(32.0, 5.0f64.exp2()); assert_eq!(1.0, 0.0f64.exp2()); let inf: f64 = f64::INFINITY; @@ -74,9 +74,9 @@ fn test_log() { let nan: f64 = f64::NAN; let inf: f64 = f64::INFINITY; let neg_inf: f64 = f64::NEG_INFINITY; - assert_eq!(10.0f64.log(10.0), 1.0); + assert_approx_eq!(10.0f64.log(10.0), 1.0); assert_approx_eq!(2.3f64.log(3.5), 0.664858); - assert_eq!(1.0f64.exp().log(1.0f64.exp()), 1.0); + assert_approx_eq!(1.0f64.exp().log(1.0f64.exp()), 1.0); assert!(1.0f64.log(1.0).is_nan()); assert!(1.0f64.log(-13.9).is_nan()); assert!(nan.log(2.3).is_nan()); @@ -108,7 +108,7 @@ fn test_log10() { let nan: f64 = f64::NAN; let inf: f64 = f64::INFINITY; let neg_inf: f64 = f64::NEG_INFINITY; - assert_eq!(10.0f64.log10(), 1.0); + assert_approx_eq!(10.0f64.log10(), 1.0); assert_approx_eq!(2.3f64.log10(), 0.361728); assert_approx_eq!(1.0f64.exp().log10(), 0.434294); assert_eq!(1.0f64.log10(), 0.0); diff --git a/library/std/tests/sync/mpmc.rs b/library/std/tests/sync/mpmc.rs index 78abcb3bcbe..594fc2180d8 100644 --- a/library/std/tests/sync/mpmc.rs +++ b/library/std/tests/sync/mpmc.rs @@ -462,8 +462,8 @@ fn oneshot_single_thread_recv_timeout() { #[test] fn stress_recv_timeout_two_threads() { let (tx, rx) = channel(); - let stress = stress_factor() + 100; - let timeout = Duration::from_millis(100); + let stress = stress_factor() + 50; + let timeout = Duration::from_millis(5); thread::spawn(move || { for i in 0..stress { @@ -475,18 +475,23 @@ fn stress_recv_timeout_two_threads() { }); let mut recv_count = 0; + let mut got_timeout = false; loop { match rx.recv_timeout(timeout) { Ok(n) => { assert_eq!(n, 1usize); recv_count += 1; } - Err(RecvTimeoutError::Timeout) => continue, + Err(RecvTimeoutError::Timeout) => { + got_timeout = true; + continue; + } Err(RecvTimeoutError::Disconnected) => break, } } assert_eq!(recv_count, stress); + assert!(got_timeout); } #[test] diff --git a/library/std/tests/sync/mpsc.rs b/library/std/tests/sync/mpsc.rs index 1d8edfde44b..9de4a71987b 100644 --- a/library/std/tests/sync/mpsc.rs +++ b/library/std/tests/sync/mpsc.rs @@ -425,8 +425,8 @@ fn oneshot_single_thread_recv_timeout() { #[test] fn stress_recv_timeout_two_threads() { let (tx, rx) = channel(); - let stress = stress_factor() + 100; - let timeout = Duration::from_millis(100); + let stress = stress_factor() + 50; + let timeout = Duration::from_millis(5); thread::spawn(move || { for i in 0..stress { @@ -438,18 +438,23 @@ fn stress_recv_timeout_two_threads() { }); let mut recv_count = 0; + let mut got_timeout = false; loop { match rx.recv_timeout(timeout) { Ok(n) => { assert_eq!(n, 1usize); recv_count += 1; } - Err(RecvTimeoutError::Timeout) => continue, + Err(RecvTimeoutError::Timeout) => { + got_timeout = true; + continue; + } Err(RecvTimeoutError::Disconnected) => break, } } assert_eq!(recv_count, stress); + assert!(got_timeout); } #[test] |
