Skip to content

Commit 14fbe94

Browse files
Rollup merge of rust-lang#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`
2 parents 13c46fd + 512ff95 commit 14fbe94

File tree

243 files changed

+1641
-1571
lines changed

Some content is hidden

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

243 files changed

+1641
-1571
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,
@@ -3115,7 +3115,7 @@ pub enum BoundConstness {
31153115
Never,
31163116
/// `Type: const Trait`
31173117
Always(Span),
3118-
/// `Type: ~const Trait`
3118+
/// `Type: [const] Trait`
31193119
Maybe(Span),
31203120
}
31213121

@@ -3124,7 +3124,7 @@ impl BoundConstness {
31243124
match self {
31253125
Self::Never => "",
31263126
Self::Always(_) => "const",
3127-
Self::Maybe(_) => "~const",
3127+
Self::Maybe(_) => "[const]",
31283128
}
31293129
}
31303130
}

compiler/rustc_ast_passes/messages.ftl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,17 @@ ast_passes_static_without_body =
237237
free static item without body
238238
.suggestion = provide a definition for the static
239239
240-
ast_passes_tilde_const_disallowed = `~const` is not allowed here
241-
.closure = closures cannot have `~const` trait bounds
242-
.function = this function is not `const`, so it cannot have `~const` trait bounds
243-
.trait = this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds
244-
.trait_impl = this impl is not `const`, so it cannot have `~const` trait bounds
245-
.impl = inherent impls cannot have `~const` trait bounds
246-
.trait_assoc_ty = associated types in non-`#[const_trait]` traits cannot have `~const` trait bounds
247-
.trait_impl_assoc_ty = associated types in non-const impls cannot have `~const` trait bounds
248-
.inherent_assoc_ty = inherent associated types cannot have `~const` trait bounds
249-
.object = trait objects cannot have `~const` trait bounds
250-
.item = this item cannot have `~const` trait bounds
240+
ast_passes_tilde_const_disallowed = `[const]` is not allowed here
241+
.closure = closures cannot have `[const]` trait bounds
242+
.function = this function is not `const`, so it cannot have `[const]` trait bounds
243+
.trait = this trait is not a `#[const_trait]`, so it cannot have `[const]` trait bounds
244+
.trait_impl = this impl is not `const`, so it cannot have `[const]` trait bounds
245+
.impl = inherent impls cannot have `[const]` trait bounds
246+
.trait_assoc_ty = associated types in non-`#[const_trait]` traits cannot have `[const]` trait bounds
247+
.trait_impl_assoc_ty = associated types in non-const impls cannot have `[const]` trait bounds
248+
.inherent_assoc_ty = inherent associated types cannot have `[const]` trait bounds
249+
.object = trait objects cannot have `[const]` trait bounds
250+
.item = this item cannot have `[const]` trait bounds
251251
252252
ast_passes_trait_fn_const =
253253
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
@@ -87,7 +87,7 @@ declare_features! (
8787
Some("at compile-time, pointers do not have an integer value, so these casts cannot be properly supported"), 87020),
8888
/// Allows `T: ?const Trait` syntax in bounds.
8989
(removed, const_trait_bound_opt_out, "1.56.0", Some(67794),
90-
Some("Removed in favor of `~const` bound in #![feature(const_trait_impl)]"), 88328),
90+
Some("Removed in favor of `[const]` bound in #![feature(const_trait_impl)]"), 88328),
9191
/// Allows using `crate` as visibility modifier, synonymous with `pub(crate)`.
9292
(removed, crate_visibility_modifier, "1.63.0", Some(53120), Some("removed in favor of `pub(crate)`"), 97254),
9393
/// Allows using custom attributes (RFC 572).
@@ -123,7 +123,7 @@ declare_features! (
123123
/// [^1]: Formerly known as "object safe".
124124
(removed, dyn_compatible_for_dispatch, "1.87.0", Some(43561),
125125
Some("removed, not used heavily and represented additional complexity in dyn compatibility"), 136522),
126-
/// Uses generic effect parameters for ~const bounds
126+
/// Uses generic effect parameters for [const] bounds
127127
(removed, effects, "1.84.0", Some(102090),
128128
Some("removed, redundant with `#![feature(const_trait_impl)]`"), 132479),
129129
/// 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
@@ -1403,7 +1403,7 @@ fn check_impl<'tcx>(
14031403
}
14041404
}
14051405

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

0 commit comments

Comments
 (0)