Skip to content

Commit 8610d3c

Browse files
workingjubileegitbot
authored and
gitbot
committed
Rollup merge of rust-lang#135423 - compiler-errors:enforce-const-trait-syntactical, r=oli-obk,RalfJung
Enforce syntactical stability of const traits in HIR This PR enforces what I'm calling *syntactical* const stability of traits. In other words, it enforces the ability to name `~const`/`const` traits in trait bounds in various syntax positions in HIR (including in the trait of an impl header). This functionality is analogous to the *regular* item stability checker, which is concerned with making sure that you cannot refer to unstable items by name, and is implemented as an extension of that pass. This is separate from enforcing the *recursive* const stability of const trait methods, which is implemented in MIR and runs on MIR bodies. That will require adding a new `NonConstOp` to the const checker and probably adjusting some logic to deduplicate redundant errors. However, this check is separate and necessary for making sure that users don't add `~const`/`const` bounds to items when the trait is not const-stable in the first place. I chose to separate enforcing recursive const stability out of this PR to make it easier to review. I'll probably open a follow-up following this one, blocked on this PR. r? `@RalfJung` cc `@rust-lang/project-const-traits`
2 parents df2e474 + 322d820 commit 8610d3c

File tree

5 files changed

+6
-0
lines changed

5 files changed

+6
-0
lines changed

core/src/intrinsics/fallback.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![allow(missing_docs)]
99

1010
#[const_trait]
11+
#[rustc_const_unstable(feature = "core_intrinsics_fallbacks", issue = "none")]
1112
pub trait CarryingMulAdd: Copy + 'static {
1213
type Unsigned: Copy + 'static;
1314
fn carrying_mul_add(

core/src/marker.rs

+1
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,7 @@ marker_impls! {
952952
/// This should be used for `~const` bounds,
953953
/// as non-const bounds will always hold for every type.
954954
#[unstable(feature = "const_destruct", issue = "133214")]
955+
#[rustc_const_unstable(feature = "const_destruct", issue = "133214")]
955956
#[lang = "destruct"]
956957
#[rustc_on_unimplemented(message = "can't drop `{Self}`", append_const_msg)]
957958
#[rustc_deny_explicit_impl]

core/src/ops/arith.rs

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
/// ```
6666
#[lang = "add"]
6767
#[stable(feature = "rust1", since = "1.0.0")]
68+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
6869
#[rustc_on_unimplemented(
6970
on(all(_Self = "{integer}", Rhs = "{float}"), message = "cannot add a float to an integer",),
7071
on(all(_Self = "{float}", Rhs = "{integer}"), message = "cannot add an integer to a float",),

core/src/ops/deref.rs

+2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
#[stable(feature = "rust1", since = "1.0.0")]
135135
#[rustc_diagnostic_item = "Deref"]
136136
#[const_trait]
137+
#[rustc_const_unstable(feature = "const_deref", issue = "88955")]
137138
pub trait Deref {
138139
/// The resulting type after dereferencing.
139140
#[stable(feature = "rust1", since = "1.0.0")]
@@ -263,6 +264,7 @@ impl<T: ?Sized> const Deref for &mut T {
263264
#[doc(alias = "*")]
264265
#[stable(feature = "rust1", since = "1.0.0")]
265266
#[const_trait]
267+
#[rustc_const_unstable(feature = "const_deref", issue = "88955")]
266268
pub trait DerefMut: ~const Deref {
267269
/// Mutably dereferences the value.
268270
#[stable(feature = "rust1", since = "1.0.0")]

core/src/ops/drop.rs

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
#[lang = "drop"]
205205
#[stable(feature = "rust1", since = "1.0.0")]
206206
#[const_trait]
207+
#[rustc_const_unstable(feature = "const_destruct", issue = "133214")]
207208
pub trait Drop {
208209
/// Executes the destructor for this type.
209210
///

0 commit comments

Comments
 (0)