Skip to content

Commit eb7245a

Browse files
committed
Change const trait bound syntax from ~const to [const]
1 parent 18f4cb1 commit eb7245a

File tree

234 files changed

+1382
-1319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

234 files changed

+1382
-1319
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ impl ParenthesizedArgs {
323323

324324
pub use crate::node_id::{CRATE_NODE_ID, DUMMY_NODE_ID, NodeId};
325325

326-
/// Modifiers on a trait bound like `~const`, `?` and `!`.
326+
/// Modifiers on a trait bound like `[const]`, `?` and `!`.
327327
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug)]
328328
pub struct TraitBoundModifiers {
329329
pub constness: BoundConstness,
@@ -3111,7 +3111,7 @@ pub enum BoundConstness {
31113111
Never,
31123112
/// `Type: const Trait`
31133113
Always(Span),
3114-
/// `Type: ~const Trait`
3114+
/// `Type: [const] Trait`
31153115
Maybe(Span),
31163116
}
31173117

@@ -3120,7 +3120,7 @@ impl BoundConstness {
31203120
match self {
31213121
Self::Never => "",
31223122
Self::Always(_) => "const",
3123-
Self::Maybe(_) => "~const",
3123+
Self::Maybe(_) => "[const]",
31243124
}
31253125
}
31263126
}

compiler/rustc_ast_passes/messages.ftl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,17 @@ ast_passes_static_without_body =
232232
free static item without body
233233
.suggestion = provide a definition for the static
234234
235-
ast_passes_tilde_const_disallowed = `~const` is not allowed here
236-
.closure = closures cannot have `~const` trait bounds
237-
.function = this function is not `const`, so it cannot have `~const` trait bounds
238-
.trait = this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds
239-
.trait_impl = this impl is not `const`, so it cannot have `~const` trait bounds
240-
.impl = inherent impls cannot have `~const` trait bounds
241-
.trait_assoc_ty = associated types in non-`#[const_trait]` traits cannot have `~const` trait bounds
242-
.trait_impl_assoc_ty = associated types in non-const impls cannot have `~const` trait bounds
243-
.inherent_assoc_ty = inherent associated types cannot have `~const` trait bounds
244-
.object = trait objects cannot have `~const` trait bounds
245-
.item = this item cannot have `~const` trait bounds
235+
ast_passes_tilde_const_disallowed = `[const]` is not allowed here
236+
.closure = closures cannot have `[const]` trait bounds
237+
.function = this function is not `const`, so it cannot have `[const]` trait bounds
238+
.trait = this trait is not a `#[const_trait]`, so it cannot have `[const]` trait bounds
239+
.trait_impl = this impl is not `const`, so it cannot have `[const]` trait bounds
240+
.impl = inherent impls cannot have `[const]` trait bounds
241+
.trait_assoc_ty = associated types in non-`#[const_trait]` traits cannot have `[const]` trait bounds
242+
.trait_impl_assoc_ty = associated types in non-const impls cannot have `[const]` trait bounds
243+
.inherent_assoc_ty = inherent associated types cannot have `[const]` trait bounds
244+
.object = trait objects cannot have `[const]` trait bounds
245+
.item = this item cannot have `[const]` trait bounds
246246
247247
ast_passes_trait_fn_const =
248248
functions in {$in_impl ->

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
421421
Some(ConstConditionsHold::Yes)
422422
} else {
423423
tcx.dcx()
424-
.span_delayed_bug(call_span, "this should have reported a ~const error in HIR");
424+
.span_delayed_bug(call_span, "this should have reported a [const] error in HIR");
425425
Some(ConstConditionsHold::No)
426426
}
427427
}

compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
149149
debug!(?param_ty);
150150
if let Some(generics) = tcx.hir_node_by_def_id(caller).generics() {
151151
let constraint = with_no_trimmed_paths!(format!(
152-
"~const {}",
152+
"[const] {}",
153153
trait_ref.print_trait_sugared(),
154154
));
155155
suggest_constraining_type_param(

compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,14 @@ impl Qualif for NeedsNonConstDrop {
170170

171171
#[instrument(level = "trace", skip(cx), ret)]
172172
fn in_any_value_of_ty<'tcx>(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool {
173-
// If this doesn't need drop at all, then don't select `~const Destruct`.
173+
// If this doesn't need drop at all, then don't select `[const] Destruct`.
174174
if !ty.needs_drop(cx.tcx, cx.typing_env) {
175175
return false;
176176
}
177177

178-
// We check that the type is `~const Destruct` since that will verify that
179-
// the type is both `~const Drop` (if a drop impl exists for the adt), *and*
180-
// that the components of this type are also `~const Destruct`. This
178+
// We check that the type is `[const] Destruct` since that will verify that
179+
// the type is both `[const] Drop` (if a drop impl exists for the adt), *and*
180+
// that the components of this type are also `[const] Destruct`. This
181181
// amounts to verifying that there are no values in this ADT that may have
182182
// a non-const drop.
183183
let destruct_def_id = cx.tcx.require_lang_item(LangItem::Destruct, cx.body.span);
@@ -203,9 +203,9 @@ impl Qualif for NeedsNonConstDrop {
203203
fn is_structural_in_adt_value<'tcx>(cx: &ConstCx<'_, 'tcx>, adt: AdtDef<'tcx>) -> bool {
204204
// As soon as an ADT has a destructor, then the drop becomes non-structural
205205
// in its value since:
206-
// 1. The destructor may have `~const` bounds which are not present on the type.
206+
// 1. The destructor may have `[const]` bounds which are not present on the type.
207207
// Someone needs to check that those are satisfied.
208-
// While this could be instead satisfied by checking that the `~const Drop`
208+
// While this could be instead satisfied by checking that the `[const] Drop`
209209
// impl holds (i.e. replicating part of the `in_any_value_of_ty` logic above),
210210
// even in this case, we have another problem, which is,
211211
// 2. The destructor may *modify* the operand being dropped, so even if we

compiler/rustc_feature/src/removed.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ declare_features! (
8686
Some("at compile-time, pointers do not have an integer value, so these casts cannot be properly supported"), 87020),
8787
/// Allows `T: ?const Trait` syntax in bounds.
8888
(removed, const_trait_bound_opt_out, "1.56.0", Some(67794),
89-
Some("Removed in favor of `~const` bound in #![feature(const_trait_impl)]"), 88328),
89+
Some("Removed in favor of `[const]` bound in #![feature(const_trait_impl)]"), 88328),
9090
/// Allows using `crate` as visibility modifier, synonymous with `pub(crate)`.
9191
(removed, crate_visibility_modifier, "1.63.0", Some(53120), Some("removed in favor of `pub(crate)`"), 97254),
9292
/// Allows using custom attributes (RFC 572).
@@ -122,7 +122,7 @@ declare_features! (
122122
/// [^1]: Formerly known as "object safe".
123123
(removed, dyn_compatible_for_dispatch, "1.87.0", Some(43561),
124124
Some("removed, not used heavily and represented additional complexity in dyn compatibility"), 136522),
125-
/// Uses generic effect parameters for ~const bounds
125+
/// Uses generic effect parameters for [const] bounds
126126
(removed, effects, "1.84.0", Some(102090),
127127
Some("removed, redundant with `#![feature(const_trait_impl)]`"), 132479),
128128
/// Allows defining `existential type`s.

compiler/rustc_feature/src/unstable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ declare_features! (
437437
(unstable, const_async_blocks, "1.53.0", Some(85368)),
438438
/// Allows `const || {}` closures in const contexts.
439439
(incomplete, const_closures, "1.68.0", Some(106003)),
440-
/// Allows using `~const Destruct` bounds and calling drop impls in const contexts.
440+
/// Allows using `[const] Destruct` bounds and calling drop impls in const contexts.
441441
(unstable, const_destruct, "1.85.0", Some(133214)),
442442
/// Allows `for _ in _` loops in const contexts.
443443
(unstable, const_for, "1.56.0", Some(87575)),

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ fn check_opaque_meets_bounds<'tcx>(
344344
let misc_cause = ObligationCause::misc(span, def_id);
345345
// FIXME: We should just register the item bounds here, rather than equating.
346346
// FIXME(const_trait_impl): When we do that, please make sure to also register
347-
// the `~const` bounds.
347+
// the `[const]` bounds.
348348
match ocx.eq(&misc_cause, param_env, opaque_ty, hidden_ty) {
349349
Ok(()) => {}
350350
Err(ty_err) => {

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ fn compare_method_predicate_entailment<'tcx>(
264264
}
265265

266266
// If we're within a const implementation, we need to make sure that the method
267-
// does not assume stronger `~const` bounds than the trait definition.
267+
// does not assume stronger `[const]` bounds than the trait definition.
268268
//
269-
// This registers the `~const` bounds of the impl method, which we will prove
269+
// This registers the `[const]` bounds of the impl method, which we will prove
270270
// using the hybrid param-env that we earlier augmented with the const conditions
271271
// from the impl header and trait method declaration.
272272
if is_conditionally_const {
@@ -2335,7 +2335,7 @@ pub(super) fn check_type_bounds<'tcx>(
23352335
)
23362336
.collect();
23372337

2338-
// Only in a const implementation do we need to check that the `~const` item bounds hold.
2338+
// Only in a const implementation do we need to check that the `[const]` item bounds hold.
23392339
if tcx.is_conditionally_const(impl_ty_def_id) {
23402340
obligations.extend(util::elaborate(
23412341
tcx,

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ fn check_impl<'tcx>(
13991399
}
14001400
}
14011401

1402-
// Ensure that the `~const` where clauses of the trait hold for the impl.
1402+
// Ensure that the `[const]` where clauses of the trait hold for the impl.
14031403
if tcx.is_conditionally_const(item.owner_id.def_id) {
14041404
for (bound, _) in
14051405
tcx.const_conditions(trait_ref.def_id).instantiate(tcx, trait_ref.args)

0 commit comments

Comments
 (0)