Skip to content

Stabilize the Saturating type #115477

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Sep 17, 2023
Merged

Conversation

kellerkindt
Copy link
Contributor

@kellerkindt kellerkindt commented Sep 2, 2023

Closes #87920
Closes #92354

Stabilization report #87920 (comment)
FCP #87920 (comment)

@rustbot
Copy link
Collaborator

rustbot commented Sep 2, 2023

r? @joshtriplett

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 2, 2023
@rustbot
Copy link
Collaborator

rustbot commented Sep 2, 2023

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@Noratrieb
Copy link
Member

Thank you for your PR! You have a merge commit in your PR. Merge commits are not allowed in this repository, please remove it.

Also stabilizes saturating_int_assign_impl, rust-langgh-92354.

And also make pub fns const where the underlying saturating_*
fns became const in the meantime since the Saturating type was
created.
@kellerkindt
Copy link
Contributor Author

kellerkindt commented Sep 2, 2023

Thanks, it should be fixed now.

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dtolnay
Copy link
Member

dtolnay commented Sep 16, 2023

@bors r+

@bors
Copy link
Collaborator

bors commented Sep 16, 2023

📌 Commit ad54426 has been approved by dtolnay

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 16, 2023
@dtolnay dtolnay assigned dtolnay and unassigned joshtriplett Sep 16, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 17, 2023
Rollup of 6 pull requests

Successful merges:

 - rust-lang#114965 (Remove Drop impl of mpsc Receiver and (Sync)Sender)
 - rust-lang#115434 (make `Debug` impl for `ascii::Char` match that of `char`)
 - rust-lang#115477 (Stabilize the `Saturating` type)
 - rust-lang#115611 (add diagnostic for raw identifiers in format string)
 - rust-lang#115654 (improve PassMode docs)
 - rust-lang#115862 (Migrate `compiler/rustc_hir_typeck/src/callee.rs` to translatable diagnostics)

r? `@ghost`
`@rustbot` modify labels: rollup
Comment on lines +84 to +208
// // #[inline]
// // fn shl_assign(&mut self, other: $f) {
// // *self = *self << other;
// // }
// // }
// // forward_ref_op_assign! { impl ShlAssign, shl_assign for Saturating<$t>, $f }
//
// #[unstable(feature = "saturating_int_impl", issue = "87920")]
// impl Shr<$f> for Saturating<$t> {
// type Output = Saturating<$t>;
//
// #[inline]
// fn shr(self, other: $f) -> Saturating<$t> {
// if other < 0 {
// Saturating(self.0.shl((-other & self::shift_max::$t as $f) as u32))
// } else {
// Saturating(self.0.shr((other & self::shift_max::$t as $f) as u32))
// }
// }
// }
// forward_ref_binop! { impl Shr, shr for Saturating<$t>, $f,
// #[unstable(feature = "saturating_int_impl", issue = "87920")] }
//
// #[unstable(feature = "saturating_int_impl", issue = "87920")]
// impl ShrAssign<$f> for Saturating<$t> {
// #[inline]
// fn shr_assign(&mut self, other: $f) {
// *self = *self >> other;
// }
// }
// forward_ref_op_assign! { impl ShrAssign, shr_assign for Saturating<$t>, $f }
// };
// }
//
// macro_rules! sh_impl_unsigned {
// ($t:ident, $f:ident) => {
// #[unstable(feature = "saturating_int_impl", issue = "87920")]
// impl Shl<$f> for Saturating<$t> {
// type Output = Saturating<$t>;
//
// #[inline]
// fn shl(self, other: $f) -> Saturating<$t> {
// Saturating(self.0.wrapping_shl(other as u32))
// }
// }
// forward_ref_binop! { impl Shl, shl for Saturating<$t>, $f,
// #[unstable(feature = "saturating_int_impl", issue = "87920")] }
//
// #[unstable(feature = "saturating_int_impl", issue = "87920")]
// impl ShlAssign<$f> for Saturating<$t> {
// #[inline]
// fn shl_assign(&mut self, other: $f) {
// *self = *self << other;
// }
// }
// forward_ref_op_assign! { impl ShlAssign, shl_assign for Saturating<$t>, $f }
//
// #[unstable(feature = "saturating_int_impl", issue = "87920")]
// impl Shr<$f> for Saturating<$t> {
// type Output = Saturating<$t>;
//
// #[inline]
// fn shr(self, other: $f) -> Saturating<$t> {
// Saturating(self.0.wrapping_shr(other as u32))
// }
// }
// forward_ref_binop! { impl Shr, shr for Saturating<$t>, $f,
// #[unstable(feature = "saturating_int_impl", issue = "87920")] }
//
// #[unstable(feature = "saturating_int_impl", issue = "87920")]
// impl ShrAssign<$f> for Saturating<$t> {
// #[inline]
// fn shr_assign(&mut self, other: $f) {
// *self = *self >> other;
// }
// }
// forward_ref_op_assign! { impl ShrAssign, shr_assign for Saturating<$t>, $f }
// };
// }
//
// // FIXME (#23545): uncomment the remaining impls
// macro_rules! sh_impl_all {
// ($($t:ident)*) => ($(
// //sh_impl_unsigned! { $t, u8 }
// //sh_impl_unsigned! { $t, u16 }
// //sh_impl_unsigned! { $t, u32 }
// //sh_impl_unsigned! { $t, u64 }
// //sh_impl_unsigned! { $t, u128 }
// sh_impl_unsigned! { $t, usize }
//
// //sh_impl_signed! { $t, i8 }
// //sh_impl_signed! { $t, i16 }
// //sh_impl_signed! { $t, i32 }
// //sh_impl_signed! { $t, i64 }
// //sh_impl_signed! { $t, i128 }
// //sh_impl_signed! { $t, isize }
// )*)
// }
//
// sh_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This chunk of commented out code is expected?

@bors bors merged commit 6011fd4 into rust-lang:master Sep 17, 2023
@rustbot rustbot added this to the 1.74.0 milestone Sep 17, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Sep 17, 2023
Rollup merge of rust-lang#115477 - kellerkindt:stabilized_int_impl, r=dtolnay

Stabilize the `Saturating` type

Closes rust-lang#87920
Closes rust-lang#92354

Stabilization report rust-lang#87920 (comment)
FCP rust-lang#87920 (comment)
flip1995 pushed a commit to flip1995/rust that referenced this pull request Sep 25, 2023
@kellerkindt
Copy link
Contributor Author

@rustbot label: +relnotes

... I guess?

@rustbot rustbot added the relnotes Marks issues that should be documented in the release notes of the next release. label Oct 6, 2023
@XopheD
Copy link

XopheD commented Nov 2, 2023

Is there any reason why Saturating does not implement FromStr trait ?

@kellerkindt
Copy link
Contributor Author

I don't see the point as you can do Saturating(u16::from_str(...))?

@XopheD
Copy link

XopheD commented Nov 2, 2023

Yes, of course, I can do it but when I use a fn which relies on FromStr, I can't do it.

fn f<X:FromStr>(input: &str) { ... }

In other words, I can’t switch the use of u16 to Saturating::<u16>.

I would like to use it transparently, so stg like the following would be nice:

impl<X:FromStr> FromStr for Saturating<X> { ... }

in the same way you offer Debug or Display.

But, ok, I understand that it is not so easy to decide how many standard traits you need to reimplement.

@kellerkindt
Copy link
Contributor Author

I am not the one deciding whether this should be in the standard library or not, so I encourage you to just propose it in a separate PR to get some proper feedback :)

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Jan 8, 2024
Pkgsrc changes:

 * Remove NetBSD-8 support (embedded LLVm requires newer C++
   than what is in -8; it's conceivable that this could still
   build with an external LLVM)
 * undo powerpc 9.0 file naming tweak, since we no longer support -8.
 * Remove patch to LLVM for powerpc now included by upstream.
 * Minor adjustments, checksum changes etc.


Upstream changes:

Version 1.74.1 (2023-12-07)
===========================

- [Resolved spurious STATUS_ACCESS_VIOLATIONs in LLVM]
  (rust-lang/rust#118464)
- [Clarify guarantees for std::mem::discriminant]
  (rust-lang/rust#118006)
- [Fix some subtyping-related regressions]
  (rust-lang/rust#116415)

Version 1.74.0 (2023-11-16)
==========================

Language
--------

- [Codify that `std::mem::Discriminant<T>` does not depend on any
  lifetimes in T]
  (rust-lang/rust#104299)
- [Replace `private_in_public` lint with `private_interfaces` and
  `private_bounds` per RFC 2145]
  (rust-lang/rust#113126)
  Read more in
  [RFC 2145](https://rust-lang.github.io/rfcs/2145-type-privacy.html).
- [Allow explicit `#[repr(Rust)]`]
  (rust-lang/rust#114201)
- [closure field capturing: don't depend on alignment of packed fields]
  (rust-lang/rust#115315)
- [Enable MIR-based drop-tracking for `async` blocks]
  (rust-lang/rust#107421)

Compiler
--------

- [stabilize combining +bundle and +whole-archive link modifiers]
  (rust-lang/rust#113301)
- [Stabilize `PATH` option for `--print KIND=PATH`]
  (rust-lang/rust#114183)
- [Enable ASAN/LSAN/TSAN for `*-apple-ios-macabi`]
  (rust-lang/rust#115644)
- [Promote loongarch64-unknown-none* to Tier 2]
  (rust-lang/rust#115368)
- [Add `i686-pc-windows-gnullvm` as a tier 3 target]
  (rust-lang/rust#115687)

Libraries
---------

- [Implement `From<OwnedFd/Handle>` for ChildStdin/out/err]
  (rust-lang/rust#98704)
- [Implement `From<{&,&mut} [T; N]>` for `Vec<T>` where `T: Clone`]
  (rust-lang/rust#111278)
- [impl Step for IP addresses]
  (rust-lang/rust#113748)
- [Implement `From<[T; N]>` for `Rc<[T]>` and `Arc<[T]>`]
  (rust-lang/rust#114041)
- [`impl TryFrom<char> for u16`]
  (rust-lang/rust#114065)
- [Stabilize `io_error_other` feature]
  (rust-lang/rust#115453)
- [Stabilize the `Saturating` type]
  (rust-lang/rust#115477)
- [Stabilize const_transmute_copy]
  (rust-lang/rust#115520)

Stabilized APIs
---------------

- [`core::num::Saturating`]
  (https://doc.rust-lang.org/stable/std/num/struct.Saturating.html)
- [`impl From<io::Stdout> for std::process::Stdio`]
  (https://doc.rust-lang.org/stable/std/process/struct.Stdio.html#impl-From%3CStdout%3E-for-Stdio)
- [`impl From<io::Stderr> for std::process::Stdio`]
  (https://doc.rust-lang.org/stable/std/process/struct.Stdio.html#impl-From%3CStderr%3E-for-Stdio)
- [`impl From<OwnedHandle> for std::process::Child{Stdin, Stdout, Stderr}`]
  (https://doc.rust-lang.org/stable/std/process/struct.Stdio.html#impl-From%3CStderr%3E-for-Stdio)
- [`impl From<OwnedFd> for std::process::Child{Stdin, Stdout, Stderr}`]
  (https://doc.rust-lang.org/stable/std/process/struct.Stdio.html#impl-From%3CStderr%3E-for-Stdio)
- [`std::ffi::OsString::from_encoded_bytes_unchecked`]
  (https://doc.rust-lang.org/stable/std/ffi/struct.OsString.html#method.from_encoded_bytes_unchecked)
- [`std::ffi::OsString::into_encoded_bytes`]
  (https://doc.rust-lang.org/stable/std/ffi/struct.OsString.html#method.into_encoded_bytes)
- [`std::ffi::OsStr::from_encoded_bytes_unchecked`]
  (https://doc.rust-lang.org/stable/std/ffi/struct.OsStr.html#method.from_encoded_bytes_unchecked)
- [`std::ffi::OsStr::as_encoded_bytes`]
  (https://doc.rust-lang.org/stable/std/ffi/struct.OsStr.html#method.as_encoded_bytes)
- [`std::io::Error::other`]
  (https://doc.rust-lang.org/stable/std/io/struct.Error.html#method.other)
- [`impl TryFrom<char> for u16`]
  (https://doc.rust-lang.org/stable/std/primitive.u16.html#impl-TryFrom%3Cchar%3E-for-u16)
- [`impl<T: Clone, const N: usize> From<&[T; N]> for Vec<T>`]
  (https://doc.rust-lang.org/stable/std/vec/struct.Vec.html#impl-From%3C%26%5BT;+N%5D%3E-for-Vec%3CT,+Global%3E)
- [`impl<T: Clone, const N: usize> From<&mut [T; N]> for Vec<T>`]
  (https://doc.rust-lang.org/stable/std/vec/struct.Vec.html#impl-From%3C%26mut+%5BT;+N%5D%3E-for-Vec%3CT,+Global%3E)
- [`impl<T, const N: usize> From<[T; N]> for Arc<[T]>`]
  (https://doc.rust-lang.org/stable/std/sync/struct.Arc.html#impl-From%3C%5BT;+N%5D%3E-for-Arc%3C%5BT%5D,+Global%3E)
- [`impl<T, const N: usize> From<[T; N]> for Rc<[T]>`]
  (https://doc.rust-lang.org/stable/std/rc/struct.Rc.html#impl-From%3C%5BT;+N%5D%3E-for-Rc%3C%5BT%5D,+Global%3E)

These APIs are now stable in const contexts:

- [`core::mem::transmute_copy`]
  (https://doc.rust-lang.org/beta/std/mem/fn.transmute_copy.html)
- [`str::is_ascii`]
  (https://doc.rust-lang.org/beta/std/primitive.str.html#method.is_ascii)
- [`[u8]::is_ascii`]
  (https://doc.rust-lang.org/beta/std/primitive.slice.html#method.is_ascii)

Cargo
-----

- [fix: Set MSRV for internal packages]
  (rust-lang/cargo#12381)
- [config: merge lists in precedence order]
  (rust-lang/cargo#12515)
- [fix(update): Clarify meaning of --aggressive as --recursive]
  (rust-lang/cargo#12544)
- [fix(update): Make `-p` more convenient by being positional]
  (rust-lang/cargo#12545)
- [feat(help): Add styling to help output ]
  (rust-lang/cargo#12578)
- [feat(pkgid): Allow incomplete versions when unambigious]
  (rust-lang/cargo#12614)
- [feat: stabilize credential-process and registry-auth]
  (rust-lang/cargo#12649)
- [feat(cli): Add '-n' to dry-run]
  (rust-lang/cargo#12660)
- [Add support for `target.'cfg(..)'.linker`]
  (rust-lang/cargo#12535)
- [Stabilize `--keep-going`]
  (rust-lang/cargo#12568)
- [feat: Stabilize lints]
  (rust-lang/cargo#12648)

Rustdoc
-------

- [Add warning block support in rustdoc]
  (rust-lang/rust#106561)
- [Accept additional user-defined syntax classes in fenced code blocks]
  (rust-lang/rust#110800)
- [rustdoc-search: add support for type parameters]
  (rust-lang/rust#112725)
- [rustdoc: show inner enum and struct in type definition for concrete type]
  (rust-lang/rust#114855)

Compatibility Notes
-------------------

- [Raise minimum supported Apple OS versions]
  (rust-lang/rust#104385)
- [make Cell::swap panic if the Cells partially overlap]
  (rust-lang/rust#114795)
- [Reject invalid crate names in `--extern`]
  (rust-lang/rust#116001)
- [Don't resolve generic impls that may be shadowed by dyn built-in impls]
  (rust-lang/rust#114941)

Internal Changes
----------------

These changes do not affect any public interfaces of Rust, but they represent
significant improvements to the performance or internals of rustc and related
tools.

None this cycle.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracking Issue for saturating_int_assign_impl Tracking Issue for Saturating type
8 participants