-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Make Sub
, Mul
, Div
and Rem
const_traits
#143000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,12 +179,14 @@ add_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f64 f128 | |
/// ``` | ||
#[lang = "sub"] | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")] | ||
#[rustc_on_unimplemented( | ||
message = "cannot subtract `{Rhs}` from `{Self}`", | ||
label = "no implementation for `{Self} - {Rhs}`", | ||
append_const_msg | ||
)] | ||
#[doc(alias = "-")] | ||
#[const_trait] | ||
pub trait Sub<Rhs = Self> { | ||
/// The resulting type after applying the `-` operator. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
|
@@ -206,7 +208,8 @@ pub trait Sub<Rhs = Self> { | |
macro_rules! sub_impl { | ||
($($t:ty)*) => ($( | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl Sub for $t { | ||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")] | ||
impl const Sub for $t { | ||
type Output = $t; | ||
|
||
#[inline] | ||
|
@@ -310,11 +313,13 @@ sub_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f64 f128 | |
/// ``` | ||
#[lang = "mul"] | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")] | ||
#[diagnostic::on_unimplemented( | ||
message = "cannot multiply `{Self}` by `{Rhs}`", | ||
label = "no implementation for `{Self} * {Rhs}`" | ||
)] | ||
#[doc(alias = "*")] | ||
#[const_trait] | ||
pub trait Mul<Rhs = Self> { | ||
/// The resulting type after applying the `*` operator. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
|
@@ -336,7 +341,8 @@ pub trait Mul<Rhs = Self> { | |
macro_rules! mul_impl { | ||
($($t:ty)*) => ($( | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl Mul for $t { | ||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")] | ||
impl const Mul for $t { | ||
type Output = $t; | ||
|
||
#[inline] | ||
|
@@ -444,11 +450,13 @@ mul_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f64 f128 | |
/// ``` | ||
#[lang = "div"] | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")] | ||
#[diagnostic::on_unimplemented( | ||
message = "cannot divide `{Self}` by `{Rhs}`", | ||
label = "no implementation for `{Self} / {Rhs}`" | ||
)] | ||
#[doc(alias = "/")] | ||
#[const_trait] | ||
pub trait Div<Rhs = Self> { | ||
/// The resulting type after applying the `/` operator. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
|
@@ -476,7 +484,8 @@ macro_rules! div_impl_integer { | |
/// | ||
#[doc = $panic] | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl Div for $t { | ||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")] | ||
impl const Div for $t { | ||
type Output = $t; | ||
|
||
#[inline] | ||
|
@@ -496,7 +505,8 @@ div_impl_integer! { | |
macro_rules! div_impl_float { | ||
($($t:ty)*) => ($( | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl Div for $t { | ||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")] | ||
impl const Div for $t { | ||
type Output = $t; | ||
|
||
#[inline] | ||
|
@@ -546,11 +556,13 @@ div_impl_float! { f16 f32 f64 f128 } | |
/// ``` | ||
#[lang = "rem"] | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")] | ||
#[diagnostic::on_unimplemented( | ||
message = "cannot calculate the remainder of `{Self}` divided by `{Rhs}`", | ||
label = "no implementation for `{Self} % {Rhs}`" | ||
)] | ||
#[doc(alias = "%")] | ||
#[const_trait] | ||
pub trait Rem<Rhs = Self> { | ||
/// The resulting type after applying the `%` operator. | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
|
@@ -578,7 +590,8 @@ macro_rules! rem_impl_integer { | |
/// | ||
#[doc = $panic] | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl Rem for $t { | ||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")] | ||
impl const Rem for $t { | ||
type Output = $t; | ||
|
||
#[inline] | ||
|
@@ -613,6 +626,7 @@ macro_rules! rem_impl_float { | |
/// assert_eq!(x % y, remainder); | ||
/// ``` | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_const_unstable(feature = "const_ops", issue = "90080")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is apparently being addressed in #143040 |
||
impl Rem for $t { | ||
type Output = $t; | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This an ancient, closed tracking issue. Should we really be using it for new constifications?
I think there should be new tracking issue created, everything else is too confusing.