Skip to content

Commit d292dc6

Browse files
committed
Add const effect syntax to the parser for all function headers
1 parent 18f4cb1 commit d292dc6

File tree

236 files changed

+1403
-1318
lines changed

Some content is hidden

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

236 files changed

+1403
-1318
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: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ ast_passes_const_and_coroutine = functions cannot be both `const` and `{$corouti
6464
6565
ast_passes_const_bound_trait_object = const trait bounds are not allowed in trait object types
6666
67+
ast_passes_const_in_trait = `const fn` in traits is unstable
68+
6769
ast_passes_const_without_body =
6870
free constant item without body
6971
.suggestion = provide a definition for the constant
@@ -232,17 +234,17 @@ ast_passes_static_without_body =
232234
free static item without body
233235
.suggestion = provide a definition for the static
234236
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
237+
ast_passes_tilde_const_disallowed = `[const]` is not allowed here
238+
.closure = closures cannot have `[const]` trait bounds
239+
.function = this function is not `const`, so it cannot have `[const]` trait bounds
240+
.trait = this trait is not a `#[const_trait]`, so it cannot have `[const]` trait bounds
241+
.trait_impl = this impl is not `const`, so it cannot have `[const]` trait bounds
242+
.impl = inherent impls cannot have `[const]` trait bounds
243+
.trait_assoc_ty = associated types in non-`#[const_trait]` traits cannot have `[const]` trait bounds
244+
.trait_impl_assoc_ty = associated types in non-const impls cannot have `[const]` trait bounds
245+
.inherent_assoc_ty = inherent associated types cannot have `[const]` trait bounds
246+
.object = trait objects cannot have `[const]` trait bounds
247+
.item = this item cannot have `[const]` trait bounds
246248
247249
ast_passes_trait_fn_const =
248250
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)

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn associated_type_bounds<'tcx>(
5454
);
5555
icx.lowerer().add_default_traits(&mut bounds, item_ty, hir_bounds, None, span);
5656
}
57-
// `ConstIfConst` is only interested in `~const` bounds.
57+
// `ConstIfConst` is only interested in `[const]` bounds.
5858
PredicateFilter::ConstIfConst | PredicateFilter::SelfConstIfConst => {}
5959
}
6060

@@ -351,7 +351,7 @@ fn opaque_type_bounds<'tcx>(
351351
);
352352
icx.lowerer().add_default_traits(&mut bounds, item_ty, hir_bounds, None, span);
353353
}
354-
//`ConstIfConst` is only interested in `~const` bounds.
354+
//`ConstIfConst` is only interested in `[const]` bounds.
355355
PredicateFilter::ConstIfConst | PredicateFilter::SelfConstIfConst => {}
356356
}
357357
debug!(?bounds);

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
666666
item.span,
667667
);
668668
}
669-
//`ConstIfConst` is only interested in `~const` bounds.
669+
//`ConstIfConst` is only interested in `[const]` bounds.
670670
PredicateFilter::ConstIfConst | PredicateFilter::SelfConstIfConst => {}
671671
}
672672

@@ -821,7 +821,7 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
821821
assert_eq!(
822822
pred.constness,
823823
ty::BoundConstness::Maybe,
824-
"expected `~const` predicate when computing `{filter:?}` \
824+
"expected `[const]` predicate when computing `{filter:?}` \
825825
implied bounds: {clause:?}",
826826
);
827827
assert_eq!(
@@ -1009,7 +1009,7 @@ pub(super) fn const_conditions<'tcx>(
10091009
}
10101010
_ => bug!("const_conditions called on wrong item: {def_id:?}"),
10111011
},
1012-
// While associated types are not really const, we do allow them to have `~const`
1012+
// While associated types are not really const, we do allow them to have `[const]`
10131013
// bounds and where clauses. `const_conditions` is responsible for gathering
10141014
// these up so we can check them in `compare_type_predicate_entailment`, and
10151015
// in `HostEffect` goal computation.

compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
635635
self.suggest_adding_type_and_const_args(err);
636636
}
637637
ExcessTypesOrConsts { .. } => {
638-
// this can happen with `~const T` where T isn't a const_trait.
638+
// this can happen with `[const] T` where T isn't a const_trait.
639639
}
640640
_ => unreachable!(),
641641
}

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
492492
);
493493
}
494494
hir::GenericBound::Outlives(lifetime) => {
495-
// `ConstIfConst` is only interested in `~const` bounds.
495+
// `ConstIfConst` is only interested in `[const]` bounds.
496496
if matches!(
497497
predicate_filter,
498498
PredicateFilter::ConstIfConst | PredicateFilter::SelfConstIfConst
@@ -708,7 +708,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
708708
}
709709
// SelfTraitThatDefines is only interested in trait predicates.
710710
PredicateFilter::SelfTraitThatDefines(_) => {}
711-
// `ConstIfConst` is only interested in `~const` bounds.
711+
// `ConstIfConst` is only interested in `[const]` bounds.
712712
PredicateFilter::ConstIfConst | PredicateFilter::SelfConstIfConst => {}
713713
}
714714
}

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ pub enum PredicateFilter {
8080
/// and `<Self as Tr>::A: B`.
8181
SelfAndAssociatedTypeBounds,
8282

83-
/// Filter only the `~const` bounds, which are lowered into `HostEffect` clauses.
83+
/// Filter only the `[const]` bounds, which are lowered into `HostEffect` clauses.
8484
ConstIfConst,
8585

86-
/// Filter only the `~const` bounds which are *also* in the supertrait position.
86+
/// Filter only the `[const]` bounds which are *also* in the supertrait position.
8787
SelfConstIfConst,
8888
}
8989

@@ -885,7 +885,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
885885
}
886886
}
887887
// On the flip side, when filtering `ConstIfConst` bounds, we only need to convert
888-
// `~const` bounds. All other predicates are handled in their respective queries.
888+
// `[const]` bounds. All other predicates are handled in their respective queries.
889889
//
890890
// Note that like `PredicateFilter::SelfOnly`, we don't need to do any filtering
891891
// here because we only call this on self bounds, and deal with the recursive case

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,22 +402,22 @@ fn check_predicates<'tcx>(
402402
/// as some predicate on the base impl (`predicate2`).
403403
///
404404
/// This basically just checks syntactic equivalence, but is a little more
405-
/// forgiving since we want to equate `T: Tr` with `T: ~const Tr` so this can work:
405+
/// forgiving since we want to equate `T: Tr` with `T: [const] Tr` so this can work:
406406
///
407407
/// ```ignore (illustrative)
408408
/// #[rustc_specialization_trait]
409409
/// trait Specialize { }
410410
///
411411
/// impl<T: Bound> Tr for T { }
412-
/// impl<T: ~const Bound + Specialize> const Tr for T { }
412+
/// impl<T: [const] Bound + Specialize> const Tr for T { }
413413
/// ```
414414
///
415415
/// However, we *don't* want to allow the reverse, i.e., when the bound on the
416416
/// specializing impl is not as const as the bound on the base impl:
417417
///
418418
/// ```ignore (illustrative)
419-
/// impl<T: ~const Bound> const Tr for T { }
420-
/// impl<T: Bound + Specialize> const Tr for T { } // should be T: ~const Bound
419+
/// impl<T: [const] Bound> const Tr for T { }
420+
/// impl<T: Bound + Specialize> const Tr for T { } // should be T: [const] Bound
421421
/// ```
422422
///
423423
/// So we make that check in this function and try to raise a helpful error message.

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ impl<'a> State<'a> {
784784
match constness {
785785
hir::BoundConstness::Never => {}
786786
hir::BoundConstness::Always(_) => self.word("const"),
787-
hir::BoundConstness::Maybe(_) => self.word("~const"),
787+
hir::BoundConstness::Maybe(_) => self.word("[const]"),
788788
}
789789
match polarity {
790790
hir::BoundPolarity::Positive => {}

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
903903
return;
904904
}
905905

906-
// If we have `rustc_do_not_const_check`, do not check `~const` bounds.
906+
// If we have `rustc_do_not_const_check`, do not check `[const]` bounds.
907907
if self.tcx.has_attr(self.body_id, sym::rustc_do_not_const_check) {
908908
return;
909909
}

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
281281
);
282282
}
283283
Adjust::Deref(None) => {
284-
// FIXME(const_trait_impl): We *could* enforce `&T: ~const Deref` here.
284+
// FIXME(const_trait_impl): We *could* enforce `&T: [const] Deref` here.
285285
}
286286
Adjust::Pointer(_pointer_coercion) => {
287287
// FIXME(const_trait_impl): We should probably enforce these.

compiler/rustc_middle/src/middle/stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ impl<'tcx> TyCtxt<'tcx> {
620620
/// instead of regular stability.
621621
///
622622
/// This enforces *syntactical* const stability of const traits. In other words,
623-
/// it enforces the ability to name `~const`/`const` traits in trait bounds in various
623+
/// it enforces the ability to name `[const]`/`const` traits in trait bounds in various
624624
/// syntax positions in HIR (including in the trait of an impl header).
625625
pub fn check_const_stability(self, def_id: DefId, span: Span, const_kw_span: Span) {
626626
let is_staged_api = self.lookup_stability(def_id.krate.as_def_id()).is_some();

compiler/rustc_middle/src/query/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -850,14 +850,14 @@ rustc_queries! {
850850
}
851851

852852
/// Compute the conditions that need to hold for a conditionally-const item to be const.
853-
/// That is, compute the set of `~const` where clauses for a given item.
853+
/// That is, compute the set of `[const]` where clauses for a given item.
854854
///
855-
/// This can be thought of as the `~const` equivalent of `predicates_of`. These are the
855+
/// This can be thought of as the `[const]` equivalent of `predicates_of`. These are the
856856
/// predicates that need to be proven at usage sites, and can be assumed at definition.
857857
///
858-
/// This query also computes the `~const` where clauses for associated types, which are
859-
/// not "const", but which have item bounds which may be `~const`. These must hold for
860-
/// the `~const` item bound to hold.
858+
/// This query also computes the `[const]` where clauses for associated types, which are
859+
/// not "const", but which have item bounds which may be `[const]`. These must hold for
860+
/// the `[const]` item bound to hold.
861861
query const_conditions(
862862
key: DefId
863863
) -> ty::ConstConditions<'tcx> {
@@ -869,13 +869,13 @@ rustc_queries! {
869869

870870
/// Compute the const bounds that are implied for a conditionally-const item.
871871
///
872-
/// This can be though of as the `~const` equivalent of `explicit_item_bounds`. These
872+
/// This can be though of as the `[const]` equivalent of `explicit_item_bounds`. These
873873
/// are the predicates that need to proven at definition sites, and can be assumed at
874874
/// usage sites.
875875
query explicit_implied_const_bounds(
876876
key: DefId
877877
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::PolyTraitRef<'tcx>, Span)]> {
878-
desc { |tcx| "computing the implied `~const` bounds for `{}`",
878+
desc { |tcx| "computing the implied `[const]` bounds for `{}`",
879879
tcx.def_path_str(key)
880880
}
881881
separate_provide_extern

compiler/rustc_middle/src/ty/generics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ impl<'tcx> GenericPredicates<'tcx> {
419419
}
420420
}
421421

422-
/// `~const` bounds for a given item. This is represented using a struct much like
422+
/// `[const]` bounds for a given item. This is represented using a struct much like
423423
/// `GenericPredicates`, where you can either choose to only instantiate the "own"
424424
/// bounds or all of the bounds including those from the parent. This distinction
425425
/// is necessary for code like `compare_method_predicate_entailment`.

0 commit comments

Comments
 (0)