about summary refs log tree commit diff
path: root/compiler/rustc_next_trait_solver/src
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-06-27 22:13:00 +0200
committerGitHub <noreply@github.com>2025-06-27 22:13:00 +0200
commit36c2b011cb4bb9bd34647486551e85a969773c8d (patch)
treee3b6cf9615355244e05cb699f6d3896217179a0c /compiler/rustc_next_trait_solver/src
parentfe5f3dedf7b4d6bea2cadb17343f747d70b4c66b (diff)
parent512ff9520666a952850d0a360a4310c5995f6991 (diff)
Rollup merge of #139858 - oli-obk:new-const-traits-syntax, r=fee1-dead
New const traits syntax

This PR only affects the AST and doesn't actually change anything semantically.

All occurrences of `~const` outside of libcore have been replaced by `[const]`. Within libcore we have to wait for rustfmt to be bumped in the bootstrap compiler. This will happen "automatically" (when rustfmt is run) during the bootstrap bump, as rustfmt converts `~const` into `[const]`. After this we can remove the `~const` support from the parser

Caveat discovered during impl: there is no legacy bare trait object recovery for `[const] Trait` as that snippet in type position goes down the slice /array parsing code and will error

r? ``@fee1-dead``

cc ``@nikomatsakis`` ``@traviscross`` ``@compiler-errors``
Diffstat (limited to 'compiler/rustc_next_trait_solver/src')
-rw-r--r--compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs16
-rw-r--r--compiler/rustc_next_trait_solver/src/solve/effect_goals.rs6
2 files changed, 11 insertions, 11 deletions
diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs
index 4c649225359..5b6f9785272 100644
--- a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs
+++ b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs
@@ -734,11 +734,11 @@ pub(in crate::solve) fn const_conditions_for_destruct<I: Interner>(
     let destruct_def_id = cx.require_lang_item(TraitSolverLangItem::Destruct);
 
     match self_ty.kind() {
-        // `ManuallyDrop` is trivially `~const Destruct` as we do not run any drop glue on it.
+        // `ManuallyDrop` is trivially `[const] Destruct` as we do not run any drop glue on it.
         ty::Adt(adt_def, _) if adt_def.is_manually_drop() => Ok(vec![]),
 
-        // An ADT is `~const Destruct` only if all of the fields are,
-        // *and* if there is a `Drop` impl, that `Drop` impl is also `~const`.
+        // An ADT is `[const] Destruct` only if all of the fields are,
+        // *and* if there is a `Drop` impl, that `Drop` impl is also `[const]`.
         ty::Adt(adt_def, args) => {
             let mut const_conditions: Vec<_> = adt_def
                 .all_field_tys(cx)
@@ -746,9 +746,9 @@ pub(in crate::solve) fn const_conditions_for_destruct<I: Interner>(
                 .map(|field_ty| ty::TraitRef::new(cx, destruct_def_id, [field_ty]))
                 .collect();
             match adt_def.destructor(cx) {
-                // `Drop` impl exists, but it's not const. Type cannot be `~const Destruct`.
+                // `Drop` impl exists, but it's not const. Type cannot be `[const] Destruct`.
                 Some(AdtDestructorKind::NotConst) => return Err(NoSolution),
-                // `Drop` impl exists, and it's const. Require `Ty: ~const Drop` to hold.
+                // `Drop` impl exists, and it's const. Require `Ty: [const] Drop` to hold.
                 Some(AdtDestructorKind::Const) => {
                     let drop_def_id = cx.require_lang_item(TraitSolverLangItem::Drop);
                     let drop_trait_ref = ty::TraitRef::new(cx, drop_def_id, [self_ty]);
@@ -769,7 +769,7 @@ pub(in crate::solve) fn const_conditions_for_destruct<I: Interner>(
             .map(|field_ty| ty::TraitRef::new(cx, destruct_def_id, [field_ty]))
             .collect()),
 
-        // Trivially implement `~const Destruct`
+        // Trivially implement `[const] Destruct`
         ty::Bool
         | ty::Char
         | ty::Int(..)
@@ -784,14 +784,14 @@ pub(in crate::solve) fn const_conditions_for_destruct<I: Interner>(
         | ty::Infer(ty::InferTy::FloatVar(_) | ty::InferTy::IntVar(_))
         | ty::Error(_) => Ok(vec![]),
 
-        // Coroutines and closures could implement `~const Drop`,
+        // Coroutines and closures could implement `[const] Drop`,
         // but they don't really need to right now.
         ty::Closure(_, _)
         | ty::CoroutineClosure(_, _)
         | ty::Coroutine(_, _)
         | ty::CoroutineWitness(_, _) => Err(NoSolution),
 
-        // FIXME(unsafe_binders): Unsafe binders could implement `~const Drop`
+        // FIXME(unsafe_binders): Unsafe binders could implement `[const] Drop`
         // if their inner type implements it.
         ty::UnsafeBinder(_) => Err(NoSolution),
 
diff --git a/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs b/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs
index 1690c908d12..0547eb77f8d 100644
--- a/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs
+++ b/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs
@@ -1,5 +1,5 @@
 //! Dealing with host effect goals, i.e. enforcing the constness in
-//! `T: const Trait` or `T: ~const Trait`.
+//! `T: const Trait` or `T: [const] Trait`.
 
 use rustc_type_ir::fast_reject::DeepRejectCtxt;
 use rustc_type_ir::inherent::*;
@@ -72,7 +72,7 @@ where
         then(ecx)
     }
 
-    /// Register additional assumptions for aliases corresponding to `~const` item bounds.
+    /// Register additional assumptions for aliases corresponding to `[const]` item bounds.
     ///
     /// Unlike item bounds, they are not simply implied by the well-formedness of the alias.
     /// Instead, they only hold if the const conditons on the alias also hold. This is why
@@ -161,7 +161,7 @@ where
                 .map(|pred| goal.with(cx, pred));
             ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds);
 
-            // For this impl to be `const`, we need to check its `~const` bounds too.
+            // For this impl to be `const`, we need to check its `[const]` bounds too.
             let const_conditions = cx
                 .const_conditions(impl_def_id)
                 .iter_instantiated(cx, impl_args)