Skip to content

f64::copysign claims support since 1.35.0 in core #147593

@zacknewman

Description

@zacknewman

Location (URL)

https://doc.rust-lang.org/core/primitive.f64.html#method.copysign

Summary

#131304 added f64::copysign to core which is long after 1.35.0. The following code using the much newer cargo 1.76.0 in a no_std environment causes a compilation failure:

#![no_std]
fn example() {
    _ = 0f64.copysign(0f64);
}
[zack@laptop src]$ cargo -V
cargo 1.76.0 (c84b36747 2024-01-18)
[zack@laptop src]$ cargo check
    Checking water v0.1.0 (/home/zack/projects/water)
error[E0599]: no method named `copysign` found for type `f64` in the current scope
 --> src/lib.rs:3:14
  |
3 |     _ = 0f64.copysign(0f64);
  |              ^^^^^^^^ method not found in `f64`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `water` (lib) due to 1 previous error

Commenting out #![no_std] fixes the problem showing that while the method was defined in std since 1.35.0, it wasn't added to core until far later:

[zack@laptop src]$ cargo check
    Checking water v0.1.0 (/home/zack/projects/water)
warning: function `example` is never used
 --> src/lib.rs:2:4
  |
2 | fn example() {
  |    ^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: `water` (lib) generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions