Clamp function for primitive types

The clamp implementation has been reverted by https://github.com/rust-lang/rust/pull/44438 today. What will be necessary steps to bring this back in the future?

  • Make a rule when an inference failure is considered XIB (expected-impl-breakage) (like {f32, f64}::from_bits), and when is it unacceptable (like clamp here).

    Currently type inference change is considered acceptable by RFCs 1105 and 1122 as one could always use UFCS or other ways to force a type. But since the first try of T += &T was closed, clamp is reverted, and given the churn caused by PR #42496 (Ord::{min, max}) there are clearly something that cannot be disregarded as XIB.

  • Whenever we add a method to a std trait, there should be a crater run to ensure the name is not already existing.

  • When downstream crate did not specify #![feature(clamp)], the candidate Ord::clamp should never be considered (a future-compatible warning can still be issued). This will allow introduction of new trait methods not “insta-breaking”, but the problem will still come back when stabilizing.

1 Like