From 73a991fb9d7f68f497f047d4e948bde463f2f6eb Mon Sep 17 00:00:00 2001 From: Keith-Cancel Date: Thu, 5 Feb 2026 22:01:57 -0800 Subject: [PATCH] Allow provisional mgca syntax of type const = to be reconized. Revert, but without type const. Update symbol for feature err, then update suggestion output, and lastly update tests that change because of those. Update these new tests with the correct syntax, and few existing tests with the new outputs the merge with main added. Fix for tidyfmt and some errors when manually resolving a merge conflicts. Update these tests to use update error messages and type const syntax. Update comments and error message to use new syntax instead of old type_const attribute. Remove the type_const attribute update some more tests to use the new syntax. Update these test cases. update feature gate test Change gate logic for `mgca_type_const_syntax` to work also if `min_generic_const_args` is enabled. Create a new feature gate that checks for the feature before expansion. Make rustfmt handle the `type const` syntax correctly. Add a convience method to check if a RhsKind is type const. Rename `Const` discriminant to `Body` for `ConstItemRhsKind` Give the `TraitItemKind` flag an enum instead of a simple bool to better describe what the flag is for. Update formatting for these match statements. Update clippy test to use type const syntax. Update test to use type const syntax. update rustfmt to match ast items. Update clippy to match ast and hir items. Few more test cases that used old attribute, instead of 'type const' Update to match the output from the feature gate checks. tidyfmt adjustments. Update the is_type_const, so I can constrain record!(..) in encoder.rs Update conditional compilation test. Move the feature gate to after expansion to allow for cfg(...) to work. Update some more tests to use the new syntax. Update type const tests in associated-const-bindings to use new syntax. Don't check based off the attribute, but the item here. Update some tests outside of the const_generics folder that were using #[type_const] update the tests in associated consts that use #[type_const] to use type const Update these mgca tests with the type const syntax. Add a flag to TraitItemKind for detecting type const for now. Maybe later change ItemConstRhs to have optional consts but that touches a lot more lines of code. Don't need into for these now that it's a query. Add is_type_const query to handle foreign def ids. update this test to use type const syntax. Fix logic here, we only want to lower if there is expression in this case. Update built-in macros to use ConstItemRhsKind Update more instance of the old ConstItemRhs. Rename ConstItemKind to ConstItemRhsKind, I noticed there is a typed called ConstantItemKind, so add the Rhs to the name to avoid confusion. Update lower to use ConstItemKind Add an other helper method to check if the rhs kinda has an expr. Update item parse to use ConstItemKind enum. Felt the field name could a be little clear when editing a few other things. Change the ConstItem struct see know if we have a type const or regular const. Make sure this syntax is properly feature gated. --- compiler/rustc_ast/src/ast.rs | 37 ++++++--- compiler/rustc_ast/src/visit.rs | 2 +- compiler/rustc_ast_lowering/src/item.rs | 35 +++++--- compiler/rustc_ast_lowering/src/lib.rs | 19 ++--- .../rustc_ast_passes/src/ast_validation.rs | 16 ++-- compiler/rustc_ast_passes/src/feature_gate.rs | 43 ++++++++++ .../rustc_ast_pretty/src/pprust/state/item.rs | 8 +- .../src/attributes/traits.rs | 9 --- compiler/rustc_attr_parsing/src/context.rs | 1 - .../src/alloc_error_handler.rs | 2 +- compiler/rustc_builtin_macros/src/eii.rs | 2 +- .../src/global_allocator.rs | 2 +- .../src/proc_macro_harness.rs | 2 +- compiler/rustc_builtin_macros/src/test.rs | 4 +- .../src/check_consts/qualifs.rs | 2 +- .../src/const_eval/eval_queries.rs | 2 +- compiler/rustc_expand/src/build.rs | 4 +- compiler/rustc_feature/src/builtin_attrs.rs | 7 -- compiler/rustc_feature/src/unstable.rs | 2 + .../rustc_hir/src/attrs/data_structures.rs | 3 - .../rustc_hir/src/attrs/encode_cross_crate.rs | 1 - compiler/rustc_hir/src/hir.rs | 31 +++++-- compiler/rustc_hir/src/intravisit.rs | 2 +- .../rustc_hir_analysis/src/check/check.rs | 2 +- .../src/check/compare_impl_item.rs | 4 +- .../rustc_hir_analysis/src/check/wfcheck.rs | 2 +- compiler/rustc_hir_analysis/src/collect.rs | 25 +++++- .../src/collect/resolve_bound_vars.rs | 2 +- .../rustc_hir_analysis/src/collect/type_of.rs | 8 +- .../src/hir_ty_lowering/bounds.rs | 6 +- .../src/hir_ty_lowering/mod.rs | 13 +-- .../rustc_hir_analysis/src/hir_wf_check.rs | 2 +- compiler/rustc_hir_analysis/src/lib.rs | 2 +- compiler/rustc_hir_pretty/src/lib.rs | 2 +- compiler/rustc_lint/src/unused.rs | 4 +- .../src/rmeta/decoder/cstore_impl.rs | 1 + compiler/rustc_metadata/src/rmeta/encoder.rs | 3 + compiler/rustc_metadata/src/rmeta/mod.rs | 1 + compiler/rustc_middle/src/queries.rs | 10 ++- compiler/rustc_middle/src/traits/mod.rs | 4 +- compiler/rustc_middle/src/ty/context.rs | 22 +++-- compiler/rustc_mir_build/src/builder/mod.rs | 2 +- compiler/rustc_parse/src/parser/item.rs | 80 ++++++++++++------- compiler/rustc_passes/src/check_attr.rs | 1 - compiler/rustc_passes/src/reachable.rs | 8 +- compiler/rustc_resolve/src/late.rs | 63 +++++++-------- compiler/rustc_span/src/symbol.rs | 2 +- .../src/traits/normalize.rs | 2 +- src/librustdoc/clean/mod.rs | 4 +- .../clippy/clippy_lints/src/non_copy_const.rs | 4 +- .../clippy/clippy_lints/src/types/mod.rs | 2 +- .../clippy/clippy_utils/src/ast_utils/mod.rs | 28 ++++--- ...duplication_in_bounds_assoc_const_eq.fixed | 4 +- ...it_duplication_in_bounds_assoc_const_eq.rs | 4 +- src/tools/rustfmt/src/items.rs | 56 ++++++++----- tests/crashes/149809.rs | 3 +- tests/debuginfo/associated-const-bindings.rs | 6 +- .../ice-associated-const-equality-105952.rs | 3 +- .../auxiliary/assoc-const-equality.rs | 3 +- .../associated-constant-not-allowed-102467.rs | 3 +- tests/ui/associated-consts/issue-110933.rs | 3 +- .../type-const-in-array-len-wrong-type.rs | 3 +- .../type-const-in-array-len-wrong-type.stderr | 2 +- .../type-const-in-array-len.rs | 9 +-- .../duplicate-bound-err.rs | 12 +-- .../duplicate-bound-err.stderr | 42 +++++----- .../associated-type-bounds/duplicate-bound.rs | 6 +- .../type-const-inherent-impl-normalize.rs | 6 +- .../type-const-inherent-impl-normalize.stderr | 18 ++++- tests/ui/attributes/malformed-attrs.rs | 2 - tests/ui/attributes/malformed-attrs.stderr | 61 ++++++-------- .../associated-const-bindings/ambiguity.rs | 9 +-- .../ambiguity.stderr | 16 ++-- .../associated-const-bindings/assoc-const.rs | 6 +- .../bound-var-in-ty-not-wf.rs | 3 +- .../bound-var-in-ty-not-wf.stderr | 4 +- .../bound-var-in-ty.rs | 3 +- .../coexisting-with-type-binding.rs | 6 +- .../associated-const-bindings/coherence.rs | 6 +- .../coherence.stderr | 2 +- .../const-projection-err.rs | 3 +- .../const-projection-err.stderr | 4 +- .../const_evaluatable_unchecked.rs | 3 +- ...dyn-compat-assoc-const-ty-mentions-self.rs | 6 +- ...compat-assoc-const-ty-mentions-self.stderr | 12 +-- .../dyn-compat-basic.rs | 15 ++-- .../dyn-compat-const-mismatch.rs | 6 +- .../dyn-compat-const-mismatch.stderr | 2 +- ...ompat-const-param-default-mentions-self.rs | 6 +- ...t-const-param-default-mentions-self.stderr | 2 +- ...ection-behind-trait-alias-mentions-self.rs | 3 +- ...on-behind-trait-alias-mentions-self.stderr | 2 +- ...rojection-from-supertrait-mentions-self.rs | 6 +- ...ction-from-supertrait-mentions-self.stderr | 6 +- .../dyn-compat-non-type-assoc-const.rs | 4 +- .../dyn-compat-non-type-assoc-const.stderr | 8 +- ...und-on-assoc-const-allowed-and-enforced.rs | 6 +- ...on-assoc-const-allowed-and-enforced.stderr | 10 +-- ...elf-const-projections-in-assoc-const-ty.rs | 6 +- ...const-projections-in-assoc-const-ty.stderr | 8 +- ...ompat-self-const-projections-in-methods.rs | 9 +-- ...-const-projections-in-supertrait-bounds.rs | 3 +- ...st-projections-in-supertrait-bounds.stderr | 2 +- .../dyn-compat-symbol-mangling.rs | 3 +- .../dyn-compat-symbol-mangling.v0.stderr | 6 +- .../dyn-compat-unspecified-assoc-consts.rs | 3 +- ...dyn-compat-unspecified-assoc-consts.stderr | 18 ++--- .../equality-unused-issue-126729.rs | 24 ++---- .../equality_bound_with_infer.rs | 6 +- .../esc-bound-var-in-ty.rs | 3 +- .../esc-bound-var-in-ty.stderr | 2 +- .../issue-102335-const.rs | 3 +- .../mismatched-types-with-generic-in-ace.rs | 6 +- ...ismatched-types-with-generic-in-ace.stderr | 16 ++-- .../normalization-via-param-env.rs | 3 +- .../associated-const-bindings/param-in-ty.rs | 6 +- .../param-in-ty.stderr | 22 ++--- .../projection-unspecified-but-bounded.rs | 3 +- .../projection-unspecified-but-bounded.stderr | 4 +- .../associated-const-bindings/supertraits.rs | 3 +- .../using-fnptr-as-type_const.rs | 3 +- .../using-fnptr-as-type_const.stderr | 6 +- .../auxiliary/non_local_type_const.rs | 3 +- .../mgca/adt_expr_arg_simple.rs | 4 +- .../mgca/adt_expr_arg_tuple_expr_fail.rs | 4 +- .../mgca/adt_expr_infers_from_value.rs | 3 +- .../mgca/array-expr-with-assoc-const.rs | 3 +- .../mgca/assoc-const-projection-in-bound.rs | 6 +- .../mgca/assoc-const-without-type_const.rs | 4 +- .../assoc-const-without-type_const.stderr | 22 ++--- tests/ui/const-generics/mgca/assoc-const.rs | 3 +- .../mgca/bad-type_const-syntax.rs | 14 ++-- .../mgca/bad-type_const-syntax.stderr | 40 ++++++---- .../concrete-expr-with-generics-in-env.rs | 18 ++--- ...const-arg-coherence-conflicting-methods.rs | 4 +- .../mgca/cyclic-type-const-151251.rs | 3 +- .../mgca/cyclic-type-const-151251.stderr | 6 +- .../mgca/explicit_anon_consts.rs | 24 +++--- .../mgca/explicit_anon_consts.stderr | 12 +-- .../explicit_anon_consts_literals_hack.rs | 3 +- .../mgca/multi_braced_direct_const_args.rs | 3 +- .../non-local-const-without-type_const.rs | 2 +- .../non-local-const-without-type_const.stderr | 4 +- .../printing_valtrees_supports_non_values.rs | 4 +- .../const-generics/mgca/projection-error.rs | 4 +- .../mgca/projection-error.stderr | 4 +- .../mgca/tuple_ctor_arg_simple.rs | 3 +- .../mgca/tuple_ctor_erroneous.rs | 4 +- .../mgca/tuple_expr_arg_complex.rs | 4 +- .../mgca/tuple_expr_arg_simple.rs | 3 +- .../type-const-assoc-const-without-body.rs | 6 +- ...type-const-assoc-const-without-body.stderr | 10 +-- ...const-inherent-assoc-const-without-body.rs | 3 +- ...t-inherent-assoc-const-without-body.stderr | 10 +-- .../mgca/type-const-used-in-trait.rs | 3 +- .../mgca/type_const-array-return.rs | 6 +- ...pe_const-generic-param-in-type.gate.stderr | 36 ++++----- ..._const-generic-param-in-type.nogate.stderr | 54 ++++++------- .../mgca/type_const-generic-param-in-type.rs | 27 +++---- .../mgca/type_const-incemental-compile.rs | 3 +- .../type_const-inherent-const-omitted-type.rs | 3 +- ...e_const-inherent-const-omitted-type.stderr | 10 +-- .../mgca/type_const-mismatched-types.rs | 12 +-- .../mgca/type_const-mismatched-types.stderr | 22 ++--- .../mgca/type_const-not-constparamty.rs | 9 +-- .../mgca/type_const-not-constparamty.stderr | 18 ++--- .../mgca/type_const-on-generic-expr.rs | 8 +- .../mgca/type_const-on-generic-expr.stderr | 12 +-- .../mgca/type_const-on-generic_expr-2.rs | 18 ++--- .../mgca/type_const-on-generic_expr-2.stderr | 18 ++--- .../type_const-only-in-impl-omitted-type.rs | 5 +- ...ype_const-only-in-impl-omitted-type.stderr | 12 +-- .../mgca/type_const-only-in-impl.rs | 5 +- .../mgca/type_const-only-in-impl.stderr | 6 +- .../mgca/type_const-only-in-trait.rs | 5 +- .../mgca/type_const-only-in-trait.stderr | 12 ++- .../ui/const-generics/mgca/type_const-pub.rs | 3 +- .../mgca/type_const-recursive.rs | 4 +- .../mgca/type_const-recursive.stderr | 4 +- .../ui/const-generics/mgca/type_const-use.rs | 3 +- .../unbraced_const_block_const_arg_gated.rs | 7 +- ...nbraced_const_block_const_arg_gated.stderr | 20 +++-- .../mgca/unmarked-free-const.rs | 2 +- .../mgca/unmarked-free-const.stderr | 11 +-- .../mgca/wrong_type_const_arr_diag_trait.rs | 4 +- tests/ui/const-generics/ogca/basic-fail.rs | 12 +-- .../ui/const-generics/ogca/basic-fail.stderr | 2 +- tests/ui/const-generics/ogca/basic.rs | 12 +-- .../ogca/coherence-ambiguous.rs | 6 +- .../const-generics/ogca/rhs-but-not-root.rs | 6 +- .../ogca/rhs-but-not-root.stderr | 6 +- .../type-relative-path-144547.rs | 14 ++-- .../feature-gate-mgca-type-const-syntax.rs | 17 ++++ ...feature-gate-mgca-type-const-syntax.stderr | 63 +++++++++++++++ .../feature-gate-min-generic-const-args.rs | 6 +- ...feature-gate-min-generic-const-args.stderr | 18 ++++- .../feature-gate-opaque-generic-const-args.rs | 3 +- ...ture-gate-opaque-generic-const-args.stderr | 6 +- .../assoc-const-bindings.rs | 12 +-- .../assoc-const-no-infer-ice-115806.rs | 3 +- .../assoc-const-no-infer-ice-115806.stderr | 2 +- .../assoc-const-projection-issue-151878.rs | 3 +- .../overlap-due-to-unsatisfied-const-bound.rs | 7 +- ...rlap-due-to-unsatisfied-const-bound.stderr | 2 +- 204 files changed, 1014 insertions(+), 906 deletions(-) create mode 100644 tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.rs create mode 100644 tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.stderr diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index fea87c2360f13..fa323b7cf581a 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -3869,27 +3869,44 @@ pub struct ConstItem { pub ident: Ident, pub generics: Generics, pub ty: Box, - pub rhs: Option, + pub rhs_kind: ConstItemRhsKind, pub define_opaque: Option>, } #[derive(Clone, Encodable, Decodable, Debug, Walkable)] -pub enum ConstItemRhs { - TypeConst(AnonConst), - Body(Box), +pub enum ConstItemRhsKind { + Body { rhs: Option> }, + TypeConst { rhs: Option }, } -impl ConstItemRhs { - pub fn span(&self) -> Span { - self.expr().span +impl ConstItemRhsKind { + pub fn new_body(rhs: Box) -> Self { + Self::Body { rhs: Some(rhs) } + } + + pub fn span(&self) -> Option { + Some(self.expr()?.span) + } + + pub fn expr(&self) -> Option<&Expr> { + match self { + Self::Body { rhs: Some(body) } => Some(&body), + Self::TypeConst { rhs: Some(anon) } => Some(&anon.value), + _ => None, + } } - pub fn expr(&self) -> &Expr { + pub fn has_expr(&self) -> bool { match self { - ConstItemRhs::TypeConst(anon_const) => &anon_const.value, - ConstItemRhs::Body(expr) => expr, + Self::Body { rhs: Some(_) } => true, + Self::TypeConst { rhs: Some(_) } => true, + _ => false, } } + + pub fn is_type_const(&self) -> bool { + matches!(self, &Self::TypeConst { .. }) + } } #[derive(Clone, Encodable, Decodable, Debug, Walkable)] diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 51614460d3c4e..8556e8288670f 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -427,7 +427,7 @@ macro_rules! common_visitor_and_walkers { Const, ConstBlockItem, ConstItem, - ConstItemRhs, + ConstItemRhsKind, Defaultness, Delegation, DelegationMac, diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 12eaa99143e90..9922ed8a5c588 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -288,7 +288,7 @@ impl<'hir> LoweringContext<'_, 'hir> { ident, generics, ty, - rhs, + rhs_kind, define_opaque, }) => { let ident = self.lower_ident(*ident); @@ -301,7 +301,7 @@ impl<'hir> LoweringContext<'_, 'hir> { ty, ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy), ); - let rhs = this.lower_const_item_rhs(attrs, rhs.as_ref(), span); + let rhs = this.lower_const_item_rhs(rhs_kind, span); (ty, rhs) }, ); @@ -941,7 +941,12 @@ impl<'hir> LoweringContext<'_, 'hir> { let (ident, generics, kind, has_default) = match &i.kind { AssocItemKind::Const(box ConstItem { - ident, generics, ty, rhs, define_opaque, .. + ident, + generics, + ty, + rhs_kind, + define_opaque, + .. }) => { let (generics, kind) = self.lower_generics( generics, @@ -952,15 +957,18 @@ impl<'hir> LoweringContext<'_, 'hir> { ty, ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy), ); - let rhs = rhs - .as_ref() - .map(|rhs| this.lower_const_item_rhs(attrs, Some(rhs), i.span)); - hir::TraitItemKind::Const(ty, rhs) + // Trait associated consts don't need an expression/body. + let rhs = if rhs_kind.has_expr() { + Some(this.lower_const_item_rhs(rhs_kind, i.span)) + } else { + None + }; + hir::TraitItemKind::Const(ty, rhs, rhs_kind.is_type_const().into()) }, ); if define_opaque.is_some() { - if rhs.is_some() { + if rhs_kind.has_expr() { self.lower_define_opaque(hir_id, &define_opaque); } else { self.dcx().span_err( @@ -970,7 +978,7 @@ impl<'hir> LoweringContext<'_, 'hir> { } } - (*ident, generics, kind, rhs.is_some()) + (*ident, generics, kind, rhs_kind.has_expr()) } AssocItemKind::Fn(box Fn { sig, ident, generics, body: None, define_opaque, .. @@ -1154,7 +1162,12 @@ impl<'hir> LoweringContext<'_, 'hir> { let (ident, (generics, kind)) = match &i.kind { AssocItemKind::Const(box ConstItem { - ident, generics, ty, rhs, define_opaque, .. + ident, + generics, + ty, + rhs_kind, + define_opaque, + .. }) => ( *ident, self.lower_generics( @@ -1167,7 +1180,7 @@ impl<'hir> LoweringContext<'_, 'hir> { ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy), ); this.lower_define_opaque(hir_id, &define_opaque); - let rhs = this.lower_const_item_rhs(attrs, rhs.as_ref(), i.span); + let rhs = this.lower_const_item_rhs(rhs_kind, i.span); hir::ImplItemKind::Const(ty, rhs) }, ), diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 6dded9936fbac..ff5edfc799439 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -2374,15 +2374,20 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { fn lower_const_item_rhs( &mut self, - attrs: &[hir::Attribute], - rhs: Option<&ConstItemRhs>, + rhs_kind: &ConstItemRhsKind, span: Span, ) -> hir::ConstItemRhs<'hir> { - match rhs { - Some(ConstItemRhs::TypeConst(anon)) => { + match rhs_kind { + ConstItemRhsKind::Body { rhs: Some(body) } => { + hir::ConstItemRhs::Body(self.lower_const_body(span, Some(body))) + } + ConstItemRhsKind::Body { rhs: None } => { + hir::ConstItemRhs::Body(self.lower_const_body(span, None)) + } + ConstItemRhsKind::TypeConst { rhs: Some(anon) } => { hir::ConstItemRhs::TypeConst(self.lower_anon_const_to_const_arg_and_alloc(anon)) } - None if find_attr!(attrs, AttributeKind::TypeConst(_)) => { + ConstItemRhsKind::TypeConst { rhs: None } => { let const_arg = ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Error( @@ -2392,10 +2397,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { }; hir::ConstItemRhs::TypeConst(self.arena.alloc(const_arg)) } - Some(ConstItemRhs::Body(body)) => { - hir::ConstItemRhs::Body(self.lower_const_body(span, Some(body))) - } - None => hir::ConstItemRhs::Body(self.lower_const_body(span, None)), } } diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 2457e0a777e44..b9fb20b68971d 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -1361,9 +1361,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> { } }); } - ItemKind::Const(box ConstItem { defaultness, ident, rhs, .. }) => { + ItemKind::Const(box ConstItem { defaultness, ident, rhs_kind, .. }) => { self.check_defaultness(item.span, *defaultness); - if rhs.is_none() { + if !rhs_kind.has_expr() { self.dcx().emit_err(errors::ConstWithoutBody { span: item.span, replace_span: self.ending_semi_or_hi(item.span), @@ -1715,11 +1715,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> { if let AssocCtxt::Impl { .. } = ctxt { match &item.kind { - AssocItemKind::Const(box ConstItem { rhs: None, .. }) => { - self.dcx().emit_err(errors::AssocConstWithoutBody { - span: item.span, - replace_span: self.ending_semi_or_hi(item.span), - }); + AssocItemKind::Const(box ConstItem { rhs_kind, .. }) => { + if !rhs_kind.has_expr() { + self.dcx().emit_err(errors::AssocConstWithoutBody { + span: item.span, + replace_span: self.ending_semi_or_hi(item.span), + }); + } } AssocItemKind::Fn(box Fn { body, .. }) => { if body.is_none() && !self.is_sdylib_interface { diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index ce9001d659318..eac7f03d8450c 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -249,6 +249,14 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { ast::ItemKind::TyAlias(box ast::TyAlias { ty: Some(ty), .. }) => { self.check_impl_trait(ty, false) } + ast::ItemKind::Const(box ast::ConstItem { + rhs_kind: ast::ConstItemRhsKind::TypeConst { .. }, + .. + }) => { + // Make sure this is only allowed if the feature gate is enabled. + // #![feature(min_generic_const_args)] + gate!(&self, min_generic_const_args, i.span, "top-level `type const` are unstable"); + } _ => {} } @@ -422,6 +430,20 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { } false } + ast::AssocItemKind::Const(box ast::ConstItem { + rhs_kind: ast::ConstItemRhsKind::TypeConst { .. }, + .. + }) => { + // Make sure this is only allowed if the feature gate is enabled. + // #![feature(min_generic_const_args)] + gate!( + &self, + min_generic_const_args, + i.span, + "associated `type const` are unstable" + ); + false + } _ => false, }; if let ast::Defaultness::Default(_) = i.kind.defaultness() { @@ -528,6 +550,27 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) { } } } + // `mgca_type_const_syntax` is part of `min_generic_const_args` so either + // or both are enabled we don't need to emit a feature error. + if let Some(spans) = spans.get(&sym::mgca_type_const_syntax) { + for span in spans { + if visitor.features.min_generic_const_args() + || visitor.features.mgca_type_const_syntax() + || span.allows_unstable(sym::min_generic_const_args) + || span.allows_unstable(sym::mgca_type_const_syntax) + { + continue; + } + feature_err( + &visitor.sess, + sym::min_generic_const_args, + *span, + "`type const` syntax is experimental", + ) + .emit(); + } + } + gate_all!(global_registration, "global registration is experimental"); gate_all!(return_type_notation, "return type notation is experimental"); gate_all!(pin_ergonomics, "pinned reference syntax is experimental"); diff --git a/compiler/rustc_ast_pretty/src/pprust/state/item.rs b/compiler/rustc_ast_pretty/src/pprust/state/item.rs index 68054b06e39ff..c7f110a2e0034 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/item.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/item.rs @@ -221,7 +221,7 @@ impl<'a> State<'a> { ident, generics, ty, - rhs, + rhs_kind, define_opaque, }) => { self.print_item_const( @@ -229,7 +229,7 @@ impl<'a> State<'a> { None, generics, ty, - rhs.as_ref().map(|ct| ct.expr()), + rhs_kind.expr(), &item.vis, ast::Safety::Default, *defaultness, @@ -573,7 +573,7 @@ impl<'a> State<'a> { ident, generics, ty, - rhs, + rhs_kind, define_opaque, }) => { self.print_item_const( @@ -581,7 +581,7 @@ impl<'a> State<'a> { None, generics, ty, - rhs.as_ref().map(|ct| ct.expr()), + rhs_kind.expr(), vis, ast::Safety::Default, *defaultness, diff --git a/compiler/rustc_attr_parsing/src/attributes/traits.rs b/compiler/rustc_attr_parsing/src/attributes/traits.rs index bfea02e789a03..ceaa43948d676 100644 --- a/compiler/rustc_attr_parsing/src/attributes/traits.rs +++ b/compiler/rustc_attr_parsing/src/attributes/traits.rs @@ -66,15 +66,6 @@ impl NoArgsAttributeParser for ParenSugarParser { const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcParenSugar; } -pub(crate) struct TypeConstParser; -impl NoArgsAttributeParser for TypeConstParser { - const PATH: &[Symbol] = &[sym::type_const]; - const ON_DUPLICATE: OnDuplicate = OnDuplicate::Error; - const ALLOWED_TARGETS: AllowedTargets = - AllowedTargets::AllowList(&[Allow(Target::Const), Allow(Target::AssocConst)]); - const CREATE: fn(Span) -> AttributeKind = AttributeKind::TypeConst; -} - // Markers pub(crate) struct MarkerParser; diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index afbb70654f4d0..5c3368e4c9300 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -297,7 +297,6 @@ attribute_parsers!( Single>, Single>, Single>, - Single>, Single>, // tidy-alphabetical-end ]; diff --git a/compiler/rustc_builtin_macros/src/alloc_error_handler.rs b/compiler/rustc_builtin_macros/src/alloc_error_handler.rs index 12ccc4a6de043..c87f1e41043d2 100644 --- a/compiler/rustc_builtin_macros/src/alloc_error_handler.rs +++ b/compiler/rustc_builtin_macros/src/alloc_error_handler.rs @@ -43,7 +43,7 @@ pub(crate) fn expand( // Generate anonymous constant serving as container for the allocator methods. let const_ty = ecx.ty(sig_span, TyKind::Tup(ThinVec::new())); - let const_body = ast::ConstItemRhs::Body(ecx.expr_block(ecx.block(span, stmts))); + let const_body = ast::ConstItemRhsKind::new_body(ecx.expr_block(ecx.block(span, stmts))); let const_item = ecx.item_const(span, Ident::new(kw::Underscore, span), const_ty, const_body); let const_item = if is_stmt { Annotatable::Stmt(Box::new(ecx.stmt_item(span, const_item))) diff --git a/compiler/rustc_builtin_macros/src/eii.rs b/compiler/rustc_builtin_macros/src/eii.rs index 538f5afae5fc4..7b651ed848288 100644 --- a/compiler/rustc_builtin_macros/src/eii.rs +++ b/compiler/rustc_builtin_macros/src/eii.rs @@ -232,7 +232,7 @@ fn generate_default_impl( span, underscore, unit, - ast::ConstItemRhs::Body(ecx.expr_block(ecx.block(span, stmts))), + ast::ConstItemRhsKind::new_body(ecx.expr_block(ecx.block(span, stmts))), ) }; diff --git a/compiler/rustc_builtin_macros/src/global_allocator.rs b/compiler/rustc_builtin_macros/src/global_allocator.rs index bb031dafdcfd5..9e22d408c125a 100644 --- a/compiler/rustc_builtin_macros/src/global_allocator.rs +++ b/compiler/rustc_builtin_macros/src/global_allocator.rs @@ -47,7 +47,7 @@ pub(crate) fn expand( // Generate anonymous constant serving as container for the allocator methods. let const_ty = ecx.ty(ty_span, TyKind::Tup(ThinVec::new())); - let const_body = ast::ConstItemRhs::Body(ecx.expr_block(ecx.block(span, stmts))); + let const_body = ast::ConstItemRhsKind::new_body(ecx.expr_block(ecx.block(span, stmts))); let const_item = ecx.item_const(span, Ident::new(kw::Underscore, span), const_ty, const_body); let const_item = if is_stmt { Annotatable::Stmt(Box::new(ecx.stmt_item(span, const_item))) diff --git a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs index e30d506a31b9e..24a5d79958c60 100644 --- a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs +++ b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs @@ -385,7 +385,7 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> Box { cx.attr_nested_word(sym::allow, sym::deprecated, span), ]); - let block = ast::ConstItemRhs::Body(cx.expr_block( + let block = ast::ConstItemRhsKind::new_body(cx.expr_block( cx.block(span, thin_vec![cx.stmt_item(span, krate), cx.stmt_item(span, decls_static)]), )); diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index d5f774865a9e1..a9718d53ac491 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -289,7 +289,7 @@ pub(crate) fn expand_test_or_bench( ty: cx.ty(sp, ast::TyKind::Path(None, test_path("TestDescAndFn"))), define_opaque: None, // test::TestDescAndFn { - rhs: Some(ast::ConstItemRhs::Body( + rhs_kind: ast::ConstItemRhsKind::new_body( cx.expr_struct( sp, test_path("TestDescAndFn"), @@ -371,7 +371,7 @@ pub(crate) fn expand_test_or_bench( field("testfn", test_fn), // } ], ), // } - )), + ), } .into(), ), diff --git a/compiler/rustc_const_eval/src/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/check_consts/qualifs.rs index fe3891d0dd7e0..462254f064cf3 100644 --- a/compiler/rustc_const_eval/src/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/check_consts/qualifs.rs @@ -345,7 +345,7 @@ where let uneval = match constant.const_ { Const::Ty(_, ct) => match ct.kind() { ty::ConstKind::Param(_) | ty::ConstKind::Error(_) => None, - // Unevaluated consts in MIR bodies don't have associated MIR (e.g. `#[type_const]`). + // Unevaluated consts in MIR bodies don't have associated MIR (e.g. `type const`). ty::ConstKind::Unevaluated(_) => None, // FIXME(mgca): Investigate whether using `None` for `ConstKind::Value` is overly // strict, and if instead we should be doing some kind of value-based analysis. diff --git a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs index 25da902987912..9f39750d81252 100644 --- a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs @@ -394,7 +394,7 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>( typing_env: ty::TypingEnv<'tcx>, ) -> Result { let def = cid.instance.def.def_id(); - // #[type_const] don't have bodys + // `type const` don't have bodys debug_assert!(!tcx.is_type_const(def), "CTFE tried to evaluate type-const: {:?}", def); let is_static = tcx.is_static(def); diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs index e5c06889f3e06..7320ee12abe3b 100644 --- a/compiler/rustc_expand/src/build.rs +++ b/compiler/rustc_expand/src/build.rs @@ -727,7 +727,7 @@ impl<'a> ExtCtxt<'a> { span: Span, ident: Ident, ty: Box, - rhs: ast::ConstItemRhs, + rhs_kind: ast::ConstItemRhsKind, ) -> Box { let defaultness = ast::Defaultness::Final; self.item( @@ -740,7 +740,7 @@ impl<'a> ExtCtxt<'a> { // FIXME(generic_const_items): Pass the generics as a parameter. generics: ast::Generics::default(), ty, - rhs: Some(rhs), + rhs_kind, define_opaque: None, } .into(), diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 182ef6816337f..d74e8442545b7 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -888,13 +888,6 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ EncodeCrossCrate::Yes, experimental!(patchable_function_entry) ), - // Probably temporary component of min_generic_const_args. - // `#[type_const] const ASSOC: usize;` - gated!( - type_const, Normal, template!(Word), ErrorFollowing, - EncodeCrossCrate::Yes, min_generic_const_args, experimental!(type_const), - ), - // The `#[loop_match]` and `#[const_continue]` attributes are part of the // lang experiment for RFC 3720 tracked in: // diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index a941eb1f459ed..add09c3ea58b0 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -561,6 +561,8 @@ declare_features! ( (unstable, macro_metavar_expr_concat, "1.81.0", Some(124225)), /// Allows `#[marker]` on certain traits allowing overlapping implementations. (unstable, marker_trait_attr, "1.30.0", Some(29864)), + /// Enable mgca `type const` syntax before expansion. + (incomplete, mgca_type_const_syntax, "CURRENT_RUSTC_VERSION", Some(132980)), /// Enables the generic const args MVP (only bare paths, not arbitrary computation). (incomplete, min_generic_const_args, "1.84.0", Some(132980)), /// A minimal, sound subset of specialization intended to be used by the diff --git a/compiler/rustc_hir/src/attrs/data_structures.rs b/compiler/rustc_hir/src/attrs/data_structures.rs index ef790fe76b74f..58a748b9568aa 100644 --- a/compiler/rustc_hir/src/attrs/data_structures.rs +++ b/compiler/rustc_hir/src/attrs/data_structures.rs @@ -1292,9 +1292,6 @@ pub enum AttributeKind { /// Represents `#[track_caller]` TrackCaller(Span), - /// Represents `#[type_const]`. - TypeConst(Span), - /// Represents `#[type_length_limit]` TypeLengthLimit { attr_span: Span, limit_span: Span, limit: Limit }, diff --git a/compiler/rustc_hir/src/attrs/encode_cross_crate.rs b/compiler/rustc_hir/src/attrs/encode_cross_crate.rs index cba7679d2df31..7d8ac6df9e3ad 100644 --- a/compiler/rustc_hir/src/attrs/encode_cross_crate.rs +++ b/compiler/rustc_hir/src/attrs/encode_cross_crate.rs @@ -169,7 +169,6 @@ impl AttributeKind { TargetFeature { .. } => No, ThreadLocal => No, TrackCaller(..) => Yes, - TypeConst(..) => Yes, TypeLengthLimit { .. } => No, UnstableFeatureBound(..) => No, Used { .. } => No, diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index cf96f33e98918..68fc7653b6368 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -3199,7 +3199,7 @@ impl<'hir> TraitItem<'hir> { expect_methods_self_kind! { expect_const, (&'hir Ty<'hir>, Option>), - TraitItemKind::Const(ty, rhs), (ty, *rhs); + TraitItemKind::Const(ty, rhs, _), (ty, *rhs); expect_fn, (&FnSig<'hir>, &TraitFn<'hir>), TraitItemKind::Fn(ty, trfn), (ty, trfn); @@ -3219,11 +3219,32 @@ pub enum TraitFn<'hir> { Provided(BodyId), } +#[derive(Debug, Clone, Copy, PartialEq, Eq, HashStable_Generic)] +pub enum IsTypeConst { + No, + Yes, +} + +impl From for IsTypeConst { + fn from(value: bool) -> Self { + if value { Self::Yes } else { Self::No } + } +} + +impl From for bool { + fn from(value: IsTypeConst) -> Self { + matches!(value, IsTypeConst::Yes) + } +} + /// Represents a trait method or associated constant or type #[derive(Debug, Clone, Copy, HashStable_Generic)] pub enum TraitItemKind<'hir> { + // FIXME(mgca) eventually want to move the option that is around `ConstItemRhs<'hir>` + // into `ConstItemRhs`, much like `ast::ConstItemRhsKind`, but for now mark whether + // this node is a TypeConst with a flag. /// An associated constant with an optional value (otherwise `impl`s must contain a value). - Const(&'hir Ty<'hir>, Option>), + Const(&'hir Ty<'hir>, Option>, IsTypeConst), /// An associated function with an optional body. Fn(FnSig<'hir>, TraitFn<'hir>), /// An associated type with (possibly empty) bounds and optional concrete @@ -4686,7 +4707,7 @@ impl<'hir> OwnerNode<'hir> { | OwnerNode::TraitItem(TraitItem { kind: TraitItemKind::Fn(_, TraitFn::Provided(body)) - | TraitItemKind::Const(_, Some(ConstItemRhs::Body(body))), + | TraitItemKind::Const(_, Some(ConstItemRhs::Body(body)), _), .. }) | OwnerNode::ImplItem(ImplItem { @@ -4913,7 +4934,7 @@ impl<'hir> Node<'hir> { _ => None, }, Node::TraitItem(it) => match it.kind { - TraitItemKind::Const(ty, _) => Some(ty), + TraitItemKind::Const(ty, _, _) => Some(ty), TraitItemKind::Type(_, ty) => ty, _ => None, }, @@ -4956,7 +4977,7 @@ impl<'hir> Node<'hir> { | Node::TraitItem(TraitItem { owner_id, kind: - TraitItemKind::Const(.., Some(ConstItemRhs::Body(body))) + TraitItemKind::Const(_, Some(ConstItemRhs::Body(body)), _) | TraitItemKind::Fn(_, TraitFn::Provided(body)), .. }) diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index bd863abaceb4c..21bcf53b5619f 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -1271,7 +1271,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>( try_visit!(visitor.visit_defaultness(&defaultness)); try_visit!(visitor.visit_id(hir_id)); match *kind { - TraitItemKind::Const(ref ty, default) => { + TraitItemKind::Const(ref ty, default, _) => { try_visit!(visitor.visit_ty_unambig(ty)); visit_opt!(visitor, visit_const_item_rhs, default); } diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index e0bfae9617ff1..1bee7a72229a1 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -923,7 +923,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ); check_where_clauses(wfcx, def_id); - if tcx.is_type_const(def_id.into()) { + if tcx.is_type_const(def_id) { wfcheck::check_type_const(wfcx, def_id, ty, true)?; } Ok(()) diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index cd9fdcb59fb5c..c29ebe67a158e 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -2060,14 +2060,14 @@ fn compare_type_const<'tcx>( .dcx() .struct_span_err( tcx.def_span(impl_const_item.def_id), - "implementation of `#[type_const]` const must be marked with `#[type_const]`", + "implementation of a `type const` must also be marked as `type const`", ) .with_span_note( MultiSpan::from_spans(vec![ tcx.def_span(trait_const_item.def_id), trait_type_const_span, ]), - "trait declaration of const is marked with `#[type_const]`", + "trait declaration of const is marked as `type const`", ) .emit()); } diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index f917c799ef5a1..ceb0e138a0dae 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -955,7 +955,7 @@ pub(crate) fn check_associated_item( wfcx.register_wf_obligation(span, loc, ty.into()); let has_value = item.defaultness(tcx).has_value(); - if tcx.is_type_const(def_id.into()) { + if tcx.is_type_const(def_id) { check_type_const(wfcx, def_id, ty, has_value)?; } diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index f3086266eec00..e72fde9f05688 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -95,6 +95,7 @@ pub(crate) fn provide(providers: &mut Providers) { const_param_default, anon_const_kind, const_of_item, + is_rhs_type_const, ..*providers }; } @@ -1549,7 +1550,8 @@ fn is_anon_const_rhs_of_const_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) let (Node::Item(hir::Item { kind: hir::ItemKind::Const(_, _, _, ct_rhs), .. }) | Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Const(_, ct_rhs), .. }) | Node::TraitItem(hir::TraitItem { - kind: hir::TraitItemKind::Const(_, Some(ct_rhs)), .. + kind: hir::TraitItemKind::Const(_, Some(ct_rhs), _), + .. })) = grandparent_node else { return false; @@ -1594,7 +1596,7 @@ fn const_of_item<'tcx>( let ct_rhs = match tcx.hir_node_by_def_id(def_id) { hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(.., ct), .. }) => *ct, hir::Node::TraitItem(hir::TraitItem { - kind: hir::TraitItemKind::Const(.., ct), .. + kind: hir::TraitItemKind::Const(_, ct, _), .. }) => ct.expect("no default value for trait assoc const"), hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Const(.., ct), .. }) => *ct, _ => { @@ -1624,3 +1626,22 @@ fn const_of_item<'tcx>( ty::EarlyBinder::bind(ct) } } + +/// Check if a Const or AssocConst is a type const (mgca) +fn is_rhs_type_const<'tcx>(tcx: TyCtxt<'tcx>, def: LocalDefId) -> bool { + match tcx.hir_node_by_def_id(def) { + hir::Node::Item(hir::Item { + kind: hir::ItemKind::Const(_, _, _, hir::ConstItemRhs::TypeConst(_)), + .. + }) + | hir::Node::ImplItem(hir::ImplItem { + kind: hir::ImplItemKind::Const(_, hir::ConstItemRhs::TypeConst(_)), + .. + }) + | hir::Node::TraitItem(hir::TraitItem { + kind: hir::TraitItemKind::Const(_, _, hir::IsTypeConst::Yes), + .. + }) => return true, + _ => return false, + } +} diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index d4a01d26a1fc4..3e687700f11c6 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -859,7 +859,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> { } }) } - Const(_, _) => self.visit_early(trait_item.hir_id(), trait_item.generics, |this| { + Const(_, _, _) => self.visit_early(trait_item.hir_id(), trait_item.generics, |this| { intravisit::walk_trait_item(this, trait_item) }), } diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 910176a0689c7..23df419d06a70 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -63,7 +63,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_ let args = ty::GenericArgs::identity_for_item(tcx, def_id); Ty::new_fn_def(tcx, def_id.to_def_id(), args) } - TraitItemKind::Const(ty, rhs) => rhs + TraitItemKind::Const(ty, rhs, _) => rhs .and_then(|rhs| { ty.is_suggestable_infer_ty().then(|| { infer_placeholder_type( @@ -420,9 +420,9 @@ fn infer_placeholder_type<'tcx>( kind: &'static str, ) -> Ty<'tcx> { let tcx = cx.tcx(); - // If the type is omitted on a #[type_const] we can't run + // If the type is omitted on a `type const` we can't run // type check on since that requires the const have a body - // which type_consts don't. + // which `type const`s don't. let ty = if tcx.is_type_const(def_id.to_def_id()) { if let Some(trait_item_def_id) = tcx.trait_item_of(def_id.to_def_id()) { tcx.type_of(trait_item_def_id).instantiate_identity() @@ -430,7 +430,7 @@ fn infer_placeholder_type<'tcx>( Ty::new_error_with_message( tcx, ty_span, - "constant with #[type_const] requires an explicit type", + "constant with `type const` requires an explicit type", ) } } else { diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs index a1c3af5f999d4..4a03b290c33dc 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs @@ -607,14 +607,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { if tcx.features().min_generic_const_args() { let mut err = self.dcx().struct_span_err( constraint.span, - "use of trait associated const without `#[type_const]`", + "use of trait associated const not defined as `type const`", ); - err.note("the declaration in the trait must be marked with `#[type_const]`"); + err.note("the declaration in the trait must begin with `type const` not just `const` alone"); return Err(err.emit()); } else { let err = self.dcx().span_delayed_bug( constraint.span, - "use of trait associated const without `#[type_const]`", + "use of trait associated const defined as `type const`", ); return Err(err); } diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 7a03d8b220c5c..f58461e5d0e13 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -2849,19 +2849,20 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { if tcx.is_type_const(def_id) { Ok(()) } else { - let mut err = self - .dcx() - .struct_span_err(span, "use of `const` in the type system without `#[type_const]`"); + let mut err = self.dcx().struct_span_err( + span, + "use of `const` in the type system not defined as `type const`", + ); if def_id.is_local() { let name = tcx.def_path_str(def_id); err.span_suggestion( tcx.def_span(def_id).shrink_to_lo(), - format!("add `#[type_const]` attribute to `{name}`"), - format!("#[type_const]\n"), + format!("add `type` before `const` for `{name}`"), + format!("type "), Applicability::MaybeIncorrect, ); } else { - err.note("only consts marked with `#[type_const]` may be used in types"); + err.note("only consts marked defined as `type const` may be used in types"); } Err(err.emit()) } diff --git a/compiler/rustc_hir_analysis/src/hir_wf_check.rs b/compiler/rustc_hir_analysis/src/hir_wf_check.rs index d414f4dbcc240..08da8d19344da 100644 --- a/compiler/rustc_hir_analysis/src/hir_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/hir_wf_check.rs @@ -139,7 +139,7 @@ pub(super) fn diagnostic_hir_wf_check<'tcx>( }, hir::Node::TraitItem(item) => match item.kind { hir::TraitItemKind::Type(_, ty) => ty.into_iter().collect(), - hir::TraitItemKind::Const(ty, _) => vec![ty], + hir::TraitItemKind::Const(ty, _, _) => vec![ty], ref item => bug!("Unexpected TraitItem {:?}", item), }, hir::Node::Item(item) => match item.kind { diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 28130383e94c9..6214106d422b5 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -233,7 +233,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) { } DefKind::Const if !tcx.generics_of(item_def_id).own_requires_monomorphization() - && !tcx.is_type_const(item_def_id.into()) => + && !tcx.is_type_const(item_def_id) => { // FIXME(generic_const_items): Passing empty instead of identity args is fishy but // seems to be fine for now. Revisit this! diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index d045ec0eb6c76..fc6cc4e672517 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -937,7 +937,7 @@ impl<'a> State<'a> { self.maybe_print_comment(ti.span.lo()); self.print_attrs(self.attrs(ti.hir_id())); match ti.kind { - hir::TraitItemKind::Const(ty, default) => { + hir::TraitItemKind::Const(ty, default, _) => { self.print_associated_const(ti.ident, ti.generics, ty, default); } hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(arg_idents)) => { diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 51d9a4641cd52..8b2a6d1d2ab53 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -1058,8 +1058,8 @@ trait UnusedDelimLint { fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) { use ast::ItemKind::*; - let expr = if let Const(box ast::ConstItem { rhs: Some(rhs), .. }) = &item.kind { - rhs.expr() + let expr = if let Const(box ast::ConstItem { rhs_kind, .. }) = &item.kind { + if let Some(e) = rhs_kind.expr() { e } else { return } } else if let Static(box ast::StaticItem { expr: Some(expr), .. }) = &item.kind { expr } else { diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index c6c87534851cd..6ea9a28528042 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -418,6 +418,7 @@ provide! { tcx, def_id, other, cdata, } anon_const_kind => { table } const_of_item => { table } + is_rhs_type_const => { table } } pub(in crate::rmeta) fn provide(providers: &mut Providers) { diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index d8652539d0c51..4988cafdd3637 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1630,6 +1630,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { let table = tcx.associated_types_for_impl_traits_in_trait_or_impl(def_id); record!(self.tables.associated_types_for_impl_traits_in_trait_or_impl[def_id] <- table); } + if let DefKind::AssocConst | DefKind::Const = def_kind { + record!(self.tables.is_rhs_type_const[def_id] <- self.tcx.is_rhs_type_const(def_id)); + } } for (def_id, impls) in &tcx.crate_inherent_impls(()).0.inherent_impls { diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index af6df0cd6eb61..408b50ae48df1 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -476,6 +476,7 @@ define_tables! { anon_const_kind: Table>, const_of_item: Table>>>, associated_types_for_impl_traits_in_trait_or_impl: Table>>>, + is_rhs_type_const: Table>, } #[derive(TyEncodable, TyDecodable)] diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index de22989144389..771c300989f2a 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -293,13 +293,13 @@ rustc_queries! { separate_provide_extern } - /// Returns the const of the RHS of a (free or assoc) const item, if it is a `#[type_const]`. + /// Returns the const of the RHS of a (free or assoc) const item, if it is a `type const`. /// /// When a const item is used in a type-level expression, like in equality for an assoc const /// projection, this allows us to retrieve the typesystem-appropriate representation of the /// const value. /// - /// This query will ICE if given a const that is not marked with `#[type_const]`. + /// This query will ICE if given a const that is not marked with `type const`. query const_of_item(def_id: DefId) -> ty::EarlyBinder<'tcx, ty::Const<'tcx>> { desc { |tcx| "computing the type-level value for `{}`", tcx.def_path_str(def_id) } cache_on_disk_if { def_id.is_local() } @@ -2764,6 +2764,12 @@ rustc_queries! { cache_on_disk_if { *cnum == LOCAL_CRATE } separate_provide_extern } + + query is_rhs_type_const(def_id: DefId) -> bool { + desc { |tcx| "checking whether `{}` is a rhs type const", tcx.def_path_str(def_id) } + cache_on_disk_if { def_id.is_local() } + separate_provide_extern + } } rustc_with_all_queries! { define_callbacks! } diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 75323bf5c8cc9..2fca85c9f2f19 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -845,7 +845,7 @@ impl DynCompatibilityViolation { format!("it contains generic associated const `{name}`").into() } Self::AssocConst(name, AssocConstViolation::NonType, _) => { - format!("it contains associated const `{name}` that's not marked `#[type_const]`") + format!("it contains associated const `{name}` that's not defined as `type const`") .into() } Self::AssocConst(name, AssocConstViolation::TypeReferencesSelf, _) => format!( @@ -999,7 +999,7 @@ pub enum AssocConstViolation { /// Has own generic parameters (GAC). Generic, - /// Isn't marked `#[type_const]`. + /// Isn't defined as `type const`. NonType, /// Its type mentions the `Self` type parameter. diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 1bb83530487df..45bb584bf5952 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1890,14 +1890,22 @@ impl<'tcx> TyCtxt<'tcx> { } pub fn type_const_span(self, def_id: DefId) -> Option { - matches!(self.def_kind(def_id), DefKind::Const | DefKind::AssocConst) - .then(|| find_attr!(self.get_all_attrs(def_id), AttributeKind::TypeConst(sp) => *sp)) - .flatten() + if !self.is_type_const(def_id) { + return None; + } + Some(self.def_span(def_id)) } - /// Check if the given `def_id` is a const with the `#[type_const]` attribute. - pub fn is_type_const(self, def_id: DefId) -> bool { - self.type_const_span(def_id).is_some() + /// Check if the given `def_id` is a `type const` (mgca) + pub fn is_type_const>(self, def_id: I) -> bool { + // No need to call the query directly in this case always false. + if !(matches!( + self.def_kind(def_id.into_query_param()), + DefKind::Const | DefKind::AssocConst + )) { + return false; + } + self.is_rhs_type_const(def_id) } /// Returns the movability of the coroutine of `def_id`, or panics @@ -2923,7 +2931,7 @@ impl<'tcx> TyCtxt<'tcx> { ) -> bool { let generics = self.generics_of(def_id); - // IATs and IACs (inherent associated types/consts with #[type_const]) themselves have a + // IATs and IACs (inherent associated types/consts with `type const`) themselves have a // weird arg setup (self + own args), but nested items *in* IATs (namely: opaques, i.e. // ATPITs) do not. let is_inherent_assoc_ty = matches!(self.def_kind(def_id), DefKind::AssocTy) diff --git a/compiler/rustc_mir_build/src/builder/mod.rs b/compiler/rustc_mir_build/src/builder/mod.rs index 317df4e64fdb3..fbd7aa90f49c4 100644 --- a/compiler/rustc_mir_build/src/builder/mod.rs +++ b/compiler/rustc_mir_build/src/builder/mod.rs @@ -578,7 +578,7 @@ fn construct_const<'a, 'tcx>( }) | Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Const(ty, _), span, .. }) | Node::TraitItem(hir::TraitItem { - kind: hir::TraitItemKind::Const(ty, Some(_)), + kind: hir::TraitItemKind::Const(ty, Some(_), _), span, .. }) => (*span, ty.span), diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 9ac9bd5c0e466..5b81acb0f91f0 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -6,9 +6,7 @@ use rustc_ast::ast::*; use rustc_ast::token::{self, Delimiter, InvisibleOrigin, MetaVarKind, TokenKind}; use rustc_ast::tokenstream::{DelimSpan, TokenStream, TokenTree}; use rustc_ast::util::case::Case; -use rustc_ast::{ - attr, {self as ast}, -}; +use rustc_ast::{self as ast}; use rustc_ast_pretty::pprust; use rustc_errors::codes::*; use rustc_errors::{Applicability, PResult, StashKey, inline_fluent, struct_span_code_err}; @@ -286,13 +284,13 @@ impl<'a> Parser<'a> { // CONST ITEM self.recover_const_mut(const_span); self.recover_missing_kw_before_item()?; - let (ident, generics, ty, rhs) = self.parse_const_item(attrs)?; + let (ident, generics, ty, rhs_kind) = self.parse_const_item(false)?; ItemKind::Const(Box::new(ConstItem { defaultness: def_(), ident, generics, ty, - rhs, + rhs_kind, define_opaque: None, })) } else if let Some(kind) = self.is_reuse_item() { @@ -303,8 +301,26 @@ impl<'a> Parser<'a> { // MODULE ITEM self.parse_item_mod(attrs)? } else if self.eat_keyword_case(exp!(Type), case) { - // TYPE ITEM - self.parse_type_alias(def_())? + if let Const::Yes(const_span) = self.parse_constness(case) { + // TYPE CONST (mgca) + self.recover_const_mut(const_span); + self.recover_missing_kw_before_item()?; + let (ident, generics, ty, rhs_kind) = self.parse_const_item(true)?; + // Make sure this is only allowed if the feature gate is enabled. + // #![feature(mgca_type_const_syntax)] + self.psess.gated_spans.gate(sym::mgca_type_const_syntax, lo.to(const_span)); + ItemKind::Const(Box::new(ConstItem { + defaultness: def_(), + ident, + generics, + ty, + rhs_kind, + define_opaque: None, + })) + } else { + // TYPE ITEM + self.parse_type_alias(def_())? + } } else if self.eat_keyword_case(exp!(Enum), case) { // ENUM ITEM self.parse_item_enum()? @@ -1113,13 +1129,12 @@ impl<'a> Parser<'a> { define_opaque, }) => { self.dcx().emit_err(errors::AssociatedStaticItemNotAllowed { span }); - let rhs = expr.map(ConstItemRhs::Body); AssocItemKind::Const(Box::new(ConstItem { defaultness: Defaultness::Final, ident, generics: Generics::default(), ty, - rhs, + rhs_kind: ConstItemRhsKind::Body { rhs: expr }, define_opaque, })) } @@ -1360,7 +1375,7 @@ impl<'a> Parser<'a> { let kind = match ForeignItemKind::try_from(kind) { Ok(kind) => kind, Err(kind) => match kind { - ItemKind::Const(box ConstItem { ident, ty, rhs, .. }) => { + ItemKind::Const(box ConstItem { ident, ty, rhs_kind, .. }) => { let const_span = Some(span.with_hi(ident.span.lo())) .filter(|span| span.can_be_used_for_suggestions()); self.dcx().emit_err(errors::ExternItemCannotBeConst { @@ -1371,10 +1386,13 @@ impl<'a> Parser<'a> { ident, ty, mutability: Mutability::Not, - expr: rhs.map(|b| match b { - ConstItemRhs::TypeConst(anon_const) => anon_const.value, - ConstItemRhs::Body(expr) => expr, - }), + expr: match rhs_kind { + ConstItemRhsKind::Body { rhs } => rhs, + ConstItemRhsKind::TypeConst { rhs: Some(anon) } => { + Some(anon.value) + } + ConstItemRhsKind::TypeConst { rhs: None } => None, + }, safety: Safety::Default, define_opaque: None, })) @@ -1516,13 +1534,16 @@ impl<'a> Parser<'a> { /// Parse a constant item with the prefix `"const"` already parsed. /// + /// If `const_arg` is true, any expression assigned to the const will be parsed + /// as a const_arg instead of a body expression. + /// /// ```ebnf /// Const = "const" ($ident | "_") Generics ":" $ty (= $expr)? WhereClause ";" ; /// ``` fn parse_const_item( &mut self, - attrs: &[Attribute], - ) -> PResult<'a, (Ident, Generics, Box, Option)> { + const_arg: bool, + ) -> PResult<'a, (Ident, Generics, Box, ConstItemRhsKind)> { let ident = self.parse_ident_or_underscore()?; let mut generics = self.parse_generics()?; @@ -1549,16 +1570,15 @@ impl<'a> Parser<'a> { let before_where_clause = if self.may_recover() { self.parse_where_clause()? } else { WhereClause::default() }; - let rhs = if self.eat(exp!(Eq)) { - if attr::contains_name(attrs, sym::type_const) { - let ct = - self.parse_expr_anon_const(|this, expr| this.mgca_direct_lit_hack(expr))?; - Some(ConstItemRhs::TypeConst(ct)) - } else { - Some(ConstItemRhs::Body(self.parse_expr()?)) - } - } else { - None + let rhs = match (self.eat(exp!(Eq)), const_arg) { + (true, true) => ConstItemRhsKind::TypeConst { + rhs: Some( + self.parse_expr_anon_const(|this, expr| this.mgca_direct_lit_hack(expr))?, + ), + }, + (true, false) => ConstItemRhsKind::Body { rhs: Some(self.parse_expr()?) }, + (false, true) => ConstItemRhsKind::TypeConst { rhs: None }, + (false, false) => ConstItemRhsKind::Body { rhs: None }, }; let after_where_clause = self.parse_where_clause()?; @@ -1567,18 +1587,18 @@ impl<'a> Parser<'a> { // Users may be tempted to write such code if they are still used to the deprecated // where-clause location on type aliases and associated types. See also #89122. if before_where_clause.has_where_token - && let Some(rhs) = &rhs + && let Some(rhs_span) = rhs.span() { self.dcx().emit_err(errors::WhereClauseBeforeConstBody { span: before_where_clause.span, name: ident.span, - body: rhs.span(), + body: rhs_span, sugg: if !after_where_clause.has_where_token { - self.psess.source_map().span_to_snippet(rhs.span()).ok().map(|body_s| { + self.psess.source_map().span_to_snippet(rhs_span).ok().map(|body_s| { errors::WhereClauseBeforeConstBodySugg { left: before_where_clause.span.shrink_to_lo(), snippet: body_s, - right: before_where_clause.span.shrink_to_hi().to(rhs.span()), + right: before_where_clause.span.shrink_to_hi().to(rhs_span), } }) } else { diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index dd0de90d575b5..e53922e3734bd 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -356,7 +356,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { | AttributeKind::RustcVarianceOfOpaques | AttributeKind::ShouldPanic { .. } | AttributeKind::ThreadLocal - | AttributeKind::TypeConst{..} | AttributeKind::TypeLengthLimit { .. } | AttributeKind::UnstableFeatureBound(..) | AttributeKind::Used { .. } diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index d9565e2dae0ef..225487cc989f0 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -145,7 +145,7 @@ impl<'tcx> ReachableContext<'tcx> { _ => false, }, Node::TraitItem(trait_method) => match trait_method.kind { - hir::TraitItemKind::Const(_, ref default) => default.is_some(), + hir::TraitItemKind::Const(_, ref default, _) => default.is_some(), hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)) => true, hir::TraitItemKind::Fn(_, hir::TraitFn::Required(_)) | hir::TraitItemKind::Type(..) => false, @@ -209,7 +209,7 @@ impl<'tcx> ReachableContext<'tcx> { self.visit_nested_body(body); } } - // For #[type_const] we want to evaluate the RHS. + // For `type const` we want to evaluate the RHS. hir::ItemKind::Const(_, _, _, init @ hir::ConstItemRhs::TypeConst(_)) => { self.visit_const_item_rhs(init); } @@ -258,11 +258,11 @@ impl<'tcx> ReachableContext<'tcx> { } Node::TraitItem(trait_method) => { match trait_method.kind { - hir::TraitItemKind::Const(_, None) + hir::TraitItemKind::Const(_, None, _) | hir::TraitItemKind::Fn(_, hir::TraitFn::Required(_)) => { // Keep going, nothing to get exported } - hir::TraitItemKind::Const(_, Some(rhs)) => self.visit_const_item_rhs(rhs), + hir::TraitItemKind::Const(_, Some(rhs), _) => self.visit_const_item_rhs(rhs), hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(body_id)) => { self.visit_nested_body(body_id); } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 4faf7715de6eb..fe6346f6c6e92 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -2847,11 +2847,10 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { ident, generics, ty, - rhs, + rhs_kind, define_opaque, defaultness: _, }) => { - let is_type_const = attr::contains_name(&item.attrs, sym::type_const); self.with_generic_param_rib( &generics.params, RibKind::Item( @@ -2871,7 +2870,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { this.with_lifetime_rib( LifetimeRibKind::Elided(LifetimeRes::Static), |this| { - if is_type_const + if rhs_kind.is_type_const() && !this.r.tcx.features().generic_const_parameter_types() { this.with_rib(TypeNS, RibKind::ConstParamTy, |this| { @@ -2888,12 +2887,10 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { }, ); - if let Some(rhs) = rhs { - this.resolve_const_item_rhs( - rhs, - Some((*ident, ConstantItemKind::Const)), - ); - } + this.resolve_const_item_rhs( + rhs_kind, + Some((*ident, ConstantItemKind::Const)), + ); }, ); self.resolve_define_opaques(define_opaque); @@ -3242,11 +3239,10 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { AssocItemKind::Const(box ast::ConstItem { generics, ty, - rhs, + rhs_kind, define_opaque, .. }) => { - let is_type_const = attr::contains_name(&item.attrs, sym::type_const); self.with_generic_param_rib( &generics.params, RibKind::AssocItem, @@ -3261,7 +3257,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { }, |this| { this.visit_generics(generics); - if is_type_const + if rhs_kind.is_type_const() && !this.r.tcx.features().generic_const_parameter_types() { this.with_rib(TypeNS, RibKind::ConstParamTy, |this| { @@ -3278,14 +3274,13 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { // Only impose the restrictions of `ConstRibKind` for an // actual constant expression in a provided default. - if let Some(rhs) = rhs { - // We allow arbitrary const expressions inside of associated consts, - // even if they are potentially not const evaluatable. - // - // Type parameters can already be used and as associated consts are - // not used as part of the type system, this is far less surprising. - this.resolve_const_item_rhs(rhs, None); - } + // + // We allow arbitrary const expressions inside of associated consts, + // even if they are potentially not const evaluatable. + // + // Type parameters can already be used and as associated consts are + // not used as part of the type system, this is far less surprising. + this.resolve_const_item_rhs(rhs_kind, None); }, ) }, @@ -3463,12 +3458,11 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { ident, generics, ty, - rhs, + rhs_kind, define_opaque, .. }) => { debug!("resolve_implementation AssocItemKind::Const"); - let is_type_const = attr::contains_name(&item.attrs, sym::type_const); self.with_generic_param_rib( &generics.params, RibKind::AssocItem, @@ -3505,7 +3499,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { ); this.visit_generics(generics); - if is_type_const + if rhs_kind.is_type_const() && !this .r .tcx @@ -3527,14 +3521,12 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { } else { this.visit_ty(ty); } - if let Some(rhs) = rhs { - // We allow arbitrary const expressions inside of associated consts, - // even if they are potentially not const evaluatable. - // - // Type parameters can already be used and as associated consts are - // not used as part of the type system, this is far less surprising. - this.resolve_const_item_rhs(rhs, None); - } + // We allow arbitrary const expressions inside of associated consts, + // even if they are potentially not const evaluatable. + // + // Type parameters can already be used and as associated consts are + // not used as part of the type system, this is far less surprising. + this.resolve_const_item_rhs(rhs_kind, None); }, ) }, @@ -3756,18 +3748,19 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { fn resolve_const_item_rhs( &mut self, - rhs: &'ast ConstItemRhs, + rhs_kind: &'ast ConstItemRhsKind, item: Option<(Ident, ConstantItemKind)>, ) { - self.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Infer), |this| match rhs { - ConstItemRhs::TypeConst(anon_const) => { + self.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Infer), |this| match rhs_kind { + ConstItemRhsKind::TypeConst { rhs: Some(anon_const) } => { this.resolve_anon_const(anon_const, AnonConstKind::ConstArg(IsRepeatExpr::No)); } - ConstItemRhs::Body(expr) => { + ConstItemRhsKind::Body { rhs: Some(expr) } => { this.with_constant_rib(IsRepeatExpr::No, ConstantHasGenerics::Yes, item, |this| { this.visit_expr(expr) }); } + _ => (), }) } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 6aa2eae556e25..2c34c99b0539c 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1453,6 +1453,7 @@ symbols! { meta, meta_sized, metadata_type, + mgca_type_const_syntax, min_const_fn, min_const_generics, min_const_unsafe_fn, @@ -2339,7 +2340,6 @@ symbols! { type_ascribe, type_ascription, type_changing_struct_update, - type_const, type_id, type_id_eq, type_info, diff --git a/compiler/rustc_trait_selection/src/traits/normalize.rs b/compiler/rustc_trait_selection/src/traits/normalize.rs index 46d95fdfabfed..3f4c75a5b133a 100644 --- a/compiler/rustc_trait_selection/src/traits/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/normalize.rs @@ -453,7 +453,7 @@ impl<'a, 'b, 'tcx> TypeFolder> for AssocTypeNormalizer<'a, 'b, 'tcx // been emitted earlier in compilation. // // That's because we can only end up with an Unevaluated ty::Const for a const item - // if it was marked with `#[type_const]`. Using this attribute without the mgca + // if it was marked with `type const`. Using this attribute without the mgca // feature gate causes a parse error. let ct = match tcx.def_kind(uv.def) { DefKind::AssocConst => match tcx.def_kind(tcx.parent(uv.def)) { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 753fba3ed4825..c09e17d3787e1 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1209,14 +1209,14 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext let local_did = trait_item.owner_id.to_def_id(); cx.with_param_env(local_did, |cx| { let inner = match trait_item.kind { - hir::TraitItemKind::Const(ty, Some(default)) => { + hir::TraitItemKind::Const(ty, Some(default), _) => { ProvidedAssocConstItem(Box::new(Constant { generics: enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx)), kind: clean_const_item_rhs(default, local_did), type_: clean_ty(ty, cx), })) } - hir::TraitItemKind::Const(ty, None) => { + hir::TraitItemKind::Const(ty, None, _) => { let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx)); RequiredAssocConstItem(generics, Box::new(clean_ty(ty, cx))) } diff --git a/src/tools/clippy/clippy_lints/src/non_copy_const.rs b/src/tools/clippy/clippy_lints/src/non_copy_const.rs index f99748127a8f6..e09fc0a763665 100644 --- a/src/tools/clippy/clippy_lints/src/non_copy_const.rs +++ b/src/tools/clippy/clippy_lints/src/non_copy_const.rs @@ -739,7 +739,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst<'tcx> { } fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) { - if let TraitItemKind::Const(_, ct_rhs_opt) = item.kind + if let TraitItemKind::Const(_, ct_rhs_opt, _) = item.kind && let ty = cx.tcx.type_of(item.owner_id).instantiate_identity() && match self.is_ty_freeze(cx.tcx, cx.typing_env(), ty) { IsFreeze::No => true, @@ -931,7 +931,7 @@ fn get_const_hir_value<'tcx>( { match tcx.hir_node(tcx.local_def_id_to_hir_id(did)) { Node::ImplItem(item) if let ImplItemKind::Const(.., ct_rhs) = item.kind => (did, ct_rhs), - Node::TraitItem(item) if let TraitItemKind::Const(.., Some(ct_rhs)) = item.kind => (did, ct_rhs), + Node::TraitItem(item) if let TraitItemKind::Const(_, Some(ct_rhs), _) = item.kind => (did, ct_rhs), _ => return None, } }, diff --git a/src/tools/clippy/clippy_lints/src/types/mod.rs b/src/tools/clippy/clippy_lints/src/types/mod.rs index 7018146f184b2..7d97ce97f4870 100644 --- a/src/tools/clippy/clippy_lints/src/types/mod.rs +++ b/src/tools/clippy/clippy_lints/src/types/mod.rs @@ -514,7 +514,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { }; match item.kind { - TraitItemKind::Const(ty, _) | TraitItemKind::Type(_, Some(ty)) => { + TraitItemKind::Const(ty, _, _) | TraitItemKind::Type(_, Some(ty)) => { self.check_ty(cx, ty, context); }, TraitItemKind::Fn(ref sig, trait_method) => { diff --git a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs index cf8716398efb3..3b043f7565ef9 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs @@ -355,7 +355,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { ident: li, generics: lg, ty: lt, - rhs: lb, + rhs_kind: lb, define_opaque: _, }), Const(box ConstItem { @@ -363,7 +363,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { ident: ri, generics: rg, ty: rt, - rhs: rb, + rhs_kind: rb, define_opaque: _, }), ) => { @@ -371,7 +371,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { && eq_id(*li, *ri) && eq_generics(lg, rg) && eq_ty(lt, rt) - && both(lb.as_ref(), rb.as_ref(), eq_const_item_rhs) + && both(Some(lb), Some(rb), eq_const_item_rhs) }, ( Fn(box ast::Fn { @@ -615,7 +615,7 @@ pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { ident: li, generics: lg, ty: lt, - rhs: lb, + rhs_kind: lb, define_opaque: _, }), Const(box ConstItem { @@ -623,7 +623,7 @@ pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { ident: ri, generics: rg, ty: rt, - rhs: rb, + rhs_kind: rb, define_opaque: _, }), ) => { @@ -631,7 +631,7 @@ pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { && eq_id(*li, *ri) && eq_generics(lg, rg) && eq_ty(lt, rt) - && both(lb.as_ref(), rb.as_ref(), eq_const_item_rhs) + && both(Some(lb), Some(rb), eq_const_item_rhs) }, ( Fn(box ast::Fn { @@ -791,12 +791,18 @@ pub fn eq_anon_const(l: &AnonConst, r: &AnonConst) -> bool { eq_expr(&l.value, &r.value) } -pub fn eq_const_item_rhs(l: &ConstItemRhs, r: &ConstItemRhs) -> bool { - use ConstItemRhs::*; +pub fn eq_const_item_rhs(l: &ConstItemRhsKind, r: &ConstItemRhsKind) -> bool { + use ConstItemRhsKind::*; match (l, r) { - (TypeConst(l), TypeConst(r)) => eq_anon_const(l, r), - (Body(l), Body(r)) => eq_expr(l, r), - (TypeConst(..), Body(..)) | (Body(..), TypeConst(..)) => false, + (TypeConst { rhs: Some(l) }, TypeConst { rhs: Some(r) }) => eq_anon_const(l, r), + (TypeConst { rhs: None }, TypeConst { rhs: None }) => true, + (TypeConst { rhs: Some(..) }, TypeConst { rhs: None }) => false, + (TypeConst { rhs: None }, TypeConst { rhs: Some(..) }) => false, + (Body { rhs: Some(l) }, Body { rhs: Some(r) }) => eq_expr(l, r), + (Body { rhs: None }, Body { rhs: None }) => true, + (Body { rhs: None }, Body { rhs: Some(..) }) => false, + (Body { rhs: Some(..) }, Body { rhs: None }) => false, + (TypeConst {..}, Body { .. }) | ( Body { .. }, TypeConst { .. }) => false, } } diff --git a/src/tools/clippy/tests/ui/trait_duplication_in_bounds_assoc_const_eq.fixed b/src/tools/clippy/tests/ui/trait_duplication_in_bounds_assoc_const_eq.fixed index f8be3331317c7..8d63fc44e7f83 100644 --- a/src/tools/clippy/tests/ui/trait_duplication_in_bounds_assoc_const_eq.fixed +++ b/src/tools/clippy/tests/ui/trait_duplication_in_bounds_assoc_const_eq.fixed @@ -3,8 +3,8 @@ #![feature(min_generic_const_args)] trait AssocConstTrait { - #[type_const] - const ASSOC: usize; + + type const ASSOC: usize; } fn assoc_const_args() where diff --git a/src/tools/clippy/tests/ui/trait_duplication_in_bounds_assoc_const_eq.rs b/src/tools/clippy/tests/ui/trait_duplication_in_bounds_assoc_const_eq.rs index a0d7a653993f2..36a83619c0f94 100644 --- a/src/tools/clippy/tests/ui/trait_duplication_in_bounds_assoc_const_eq.rs +++ b/src/tools/clippy/tests/ui/trait_duplication_in_bounds_assoc_const_eq.rs @@ -3,8 +3,8 @@ #![feature(min_generic_const_args)] trait AssocConstTrait { - #[type_const] - const ASSOC: usize; + + type const ASSOC: usize; } fn assoc_const_args() where diff --git a/src/tools/rustfmt/src/items.rs b/src/tools/rustfmt/src/items.rs index c9e32492c50b0..1aa85ce2ce550 100644 --- a/src/tools/rustfmt/src/items.rs +++ b/src/tools/rustfmt/src/items.rs @@ -2028,12 +2028,16 @@ impl<'a> StaticParts<'a> { ), ast::ItemKind::Const(c) => ( Some(c.defaultness), - "const", + if c.rhs_kind.is_type_const() { + "type const" + } else { + "const" + }, ast::Safety::Default, c.ident, &c.ty, ast::Mutability::Not, - c.rhs.as_ref().map(|rhs| rhs.expr()), + c.rhs_kind.expr(), Some(&c.generics), ), _ => unreachable!(), @@ -2053,17 +2057,25 @@ impl<'a> StaticParts<'a> { } pub(crate) fn from_trait_item(ti: &'a ast::AssocItem, ident: Ident) -> Self { - let (defaultness, ty, expr_opt, generics) = match &ti.kind { - ast::AssocItemKind::Const(c) => ( - c.defaultness, - &c.ty, - c.rhs.as_ref().map(|rhs| rhs.expr()), - Some(&c.generics), - ), + let (defaultness, ty, expr_opt, generics, prefix) = match &ti.kind { + ast::AssocItemKind::Const(c) => { + let prefix = if c.rhs_kind.is_type_const() { + "type const" + } else { + "const" + }; + ( + c.defaultness, + &c.ty, + c.rhs_kind.expr(), + Some(&c.generics), + prefix, + ) + } _ => unreachable!(), }; StaticParts { - prefix: "const", + prefix, safety: ast::Safety::Default, vis: &ti.vis, ident, @@ -2077,17 +2089,25 @@ impl<'a> StaticParts<'a> { } pub(crate) fn from_impl_item(ii: &'a ast::AssocItem, ident: Ident) -> Self { - let (defaultness, ty, expr_opt, generics) = match &ii.kind { - ast::AssocItemKind::Const(c) => ( - c.defaultness, - &c.ty, - c.rhs.as_ref().map(|rhs| rhs.expr()), - Some(&c.generics), - ), + let (defaultness, ty, expr_opt, generics, prefix) = match &ii.kind { + ast::AssocItemKind::Const(c) => { + let prefix = if c.rhs_kind.is_type_const() { + "type const" + } else { + "const" + }; + ( + c.defaultness, + &c.ty, + c.rhs_kind.expr(), + Some(&c.generics), + prefix, + ) + } _ => unreachable!(), }; StaticParts { - prefix: "const", + prefix, safety: ast::Safety::Default, vis: &ii.vis, ident, diff --git a/tests/crashes/149809.rs b/tests/crashes/149809.rs index 2b948e9079c3c..f70498f11c878 100644 --- a/tests/crashes/149809.rs +++ b/tests/crashes/149809.rs @@ -5,8 +5,7 @@ struct Qux<'a> { x: &'a (), } impl<'a> Qux<'a> { - #[type_const] - const LEN: usize = 4; + type const LEN: usize = 4; fn foo(_: [u8; Qux::LEN]) {} } diff --git a/tests/debuginfo/associated-const-bindings.rs b/tests/debuginfo/associated-const-bindings.rs index b60fd66235afc..88c17cee8025c 100644 --- a/tests/debuginfo/associated-const-bindings.rs +++ b/tests/debuginfo/associated-const-bindings.rs @@ -14,12 +14,10 @@ #![expect(unused_variables, incomplete_features)] trait Trait { - #[type_const] - const N: usize; + type const N: usize; } impl Trait for () { - #[type_const] - const N: usize = 101; + type const N: usize = 101; } fn main() { diff --git a/tests/rustdoc-html/constant/ice-associated-const-equality-105952.rs b/tests/rustdoc-html/constant/ice-associated-const-equality-105952.rs index 310e56b917fc3..bdb82b91ec275 100644 --- a/tests/rustdoc-html/constant/ice-associated-const-equality-105952.rs +++ b/tests/rustdoc-html/constant/ice-associated-const-equality-105952.rs @@ -10,8 +10,7 @@ pub enum ParseMode { Raw, } pub trait Parse { - #[type_const] - const PARSE_MODE: ParseMode; + type const PARSE_MODE: ParseMode; } pub trait RenderRaw {} diff --git a/tests/rustdoc-html/inline_cross/auxiliary/assoc-const-equality.rs b/tests/rustdoc-html/inline_cross/auxiliary/assoc-const-equality.rs index 598d2b5bf29d8..939740d8f918a 100644 --- a/tests/rustdoc-html/inline_cross/auxiliary/assoc-const-equality.rs +++ b/tests/rustdoc-html/inline_cross/auxiliary/assoc-const-equality.rs @@ -4,6 +4,5 @@ pub fn accept(_: impl Trait) {} pub trait Trait { - #[type_const] - const K: i32; + type const K: i32; } diff --git a/tests/rustdoc-ui/associated-constant-not-allowed-102467.rs b/tests/rustdoc-ui/associated-constant-not-allowed-102467.rs index 5b8a90d64121d..4168a5653dd5c 100644 --- a/tests/rustdoc-ui/associated-constant-not-allowed-102467.rs +++ b/tests/rustdoc-ui/associated-constant-not-allowed-102467.rs @@ -11,8 +11,7 @@ trait T { } trait S { - #[type_const] - const C: i32; + type const C: i32; } fn main() {} diff --git a/tests/ui/associated-consts/issue-110933.rs b/tests/ui/associated-consts/issue-110933.rs index 9a013ee712741..0115fb7d6e655 100644 --- a/tests/ui/associated-consts/issue-110933.rs +++ b/tests/ui/associated-consts/issue-110933.rs @@ -4,8 +4,7 @@ #![allow(incomplete_features)] pub trait Trait { - #[type_const] - const ASSOC: usize; + type const ASSOC: usize; } pub fn foo< diff --git a/tests/ui/associated-consts/type-const-in-array-len-wrong-type.rs b/tests/ui/associated-consts/type-const-in-array-len-wrong-type.rs index 1a37f5957f25c..cb0b8a102eb47 100644 --- a/tests/ui/associated-consts/type-const-in-array-len-wrong-type.rs +++ b/tests/ui/associated-consts/type-const-in-array-len-wrong-type.rs @@ -8,8 +8,7 @@ struct OnDiskDirEntry<'a>(&'a ()); impl<'a> OnDiskDirEntry<'a> { - #[type_const] - const LFN_FRAGMENT_LEN: i64 = 2; + type const LFN_FRAGMENT_LEN: i64 = 2; fn lfn_contents() -> [char; Self::LFN_FRAGMENT_LEN] { //~^ ERROR the constant `2` is not of type `usize` diff --git a/tests/ui/associated-consts/type-const-in-array-len-wrong-type.stderr b/tests/ui/associated-consts/type-const-in-array-len-wrong-type.stderr index 607b7789ae677..b69a1b7fd7dec 100644 --- a/tests/ui/associated-consts/type-const-in-array-len-wrong-type.stderr +++ b/tests/ui/associated-consts/type-const-in-array-len-wrong-type.stderr @@ -24,7 +24,7 @@ LL | #![feature(inherent_associated_types)] = note: see issue #8995 for more information error: the constant `2` is not of type `usize` - --> $DIR/type-const-in-array-len-wrong-type.rs:14:26 + --> $DIR/type-const-in-array-len-wrong-type.rs:13:26 | LL | fn lfn_contents() -> [char; Self::LFN_FRAGMENT_LEN] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `i64` diff --git a/tests/ui/associated-consts/type-const-in-array-len.rs b/tests/ui/associated-consts/type-const-in-array-len.rs index 69dd3f443b874..d33eacaade2df 100644 --- a/tests/ui/associated-consts/type-const-in-array-len.rs +++ b/tests/ui/associated-consts/type-const-in-array-len.rs @@ -8,8 +8,7 @@ // Test case from #138226: generic impl with multiple type parameters struct Foo(A, B); impl Foo { - #[type_const] - const LEN: usize = 4; + type const LEN: usize = 4; fn foo() { let _ = [5; Self::LEN]; @@ -19,8 +18,7 @@ impl Foo { // Test case from #138226: generic impl with const parameter struct Bar; impl Bar { - #[type_const] - const LEN: usize = 4; + type const LEN: usize = 4; fn bar() { let _ = [0; Self::LEN]; @@ -30,8 +28,7 @@ impl Bar { // Test case from #150960: non-generic impl with const block struct Baz; impl Baz { - #[type_const] - const LEN: usize = 4; + type const LEN: usize = 4; fn baz() { let _ = [0; { Self::LEN }]; diff --git a/tests/ui/associated-type-bounds/duplicate-bound-err.rs b/tests/ui/associated-type-bounds/duplicate-bound-err.rs index 07eb86108bff4..56403fdf6630c 100644 --- a/tests/ui/associated-type-bounds/duplicate-bound-err.rs +++ b/tests/ui/associated-type-bounds/duplicate-bound-err.rs @@ -50,8 +50,7 @@ fn mismatch_2() -> impl Iterator { trait Trait { type Gat; - #[type_const] - const ASSOC: i32; + type const ASSOC: i32; fn foo() -> impl Sized; } @@ -59,8 +58,7 @@ trait Trait { impl Trait for () { type Gat = (); - #[type_const] - const ASSOC: i32 = 3; + type const ASSOC: i32 = 3; fn foo() {} } @@ -68,8 +66,7 @@ impl Trait for () { impl Trait for u32 { type Gat = (); - #[type_const] - const ASSOC: i32 = 4; + type const ASSOC: i32 = 4; fn foo() -> u32 { 42 @@ -89,8 +86,7 @@ type MustFail = dyn Iterator; //~| ERROR conflicting associated type bindings trait Trait2 { - #[type_const] - const ASSOC: u32; + type const ASSOC: u32; } type MustFail2 = dyn Trait2; diff --git a/tests/ui/associated-type-bounds/duplicate-bound-err.stderr b/tests/ui/associated-type-bounds/duplicate-bound-err.stderr index 695bb8ad60666..e6bf93970d0a4 100644 --- a/tests/ui/associated-type-bounds/duplicate-bound-err.stderr +++ b/tests/ui/associated-type-bounds/duplicate-bound-err.stderr @@ -100,7 +100,7 @@ LL | iter::empty::() | ----------------------- return type was inferred to be `std::iter::Empty` here error[E0271]: expected `IntoIter` to be an iterator that yields `i32`, but it yields `u32` - --> $DIR/duplicate-bound-err.rs:111:17 + --> $DIR/duplicate-bound-err.rs:107:17 | LL | fn foo() -> impl Iterator { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32` @@ -109,19 +109,19 @@ LL | [2u32].into_iter() | ------------------ return type was inferred to be `std::array::IntoIter` here error[E0271]: expected `impl Iterator` to be an iterator that yields `i32`, but it yields `u32` - --> $DIR/duplicate-bound-err.rs:111:17 + --> $DIR/duplicate-bound-err.rs:107:17 | LL | fn foo() -> impl Iterator { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32` | note: required by a bound in `Trait3::foo::{anon_assoc#0}` - --> $DIR/duplicate-bound-err.rs:107:31 + --> $DIR/duplicate-bound-err.rs:103:31 | LL | fn foo() -> impl Iterator; | ^^^^^^^^^^ required by this bound in `Trait3::foo::{anon_assoc#0}` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate-bound-err.rs:87:42 + --> $DIR/duplicate-bound-err.rs:84:42 | LL | type MustFail = dyn Iterator; | ---------- ^^^^^^^^^^ re-bound here @@ -129,7 +129,7 @@ LL | type MustFail = dyn Iterator; | `Item` bound here first error: conflicting associated type bindings for `Item` - --> $DIR/duplicate-bound-err.rs:87:17 + --> $DIR/duplicate-bound-err.rs:84:17 | LL | type MustFail = dyn Iterator; | ^^^^^^^^^^^^^----------^^----------^ @@ -138,7 +138,7 @@ LL | type MustFail = dyn Iterator; | `Item` is specified to be `i32` here error[E0719]: the value of the associated type `ASSOC` in trait `Trait2` is already specified - --> $DIR/duplicate-bound-err.rs:96:43 + --> $DIR/duplicate-bound-err.rs:92:43 | LL | type MustFail2 = dyn Trait2; | ------------ ^^^^^^^^^^^^ re-bound here @@ -146,7 +146,7 @@ LL | type MustFail2 = dyn Trait2; | `ASSOC` bound here first error: conflicting associated constant bindings for `ASSOC` - --> $DIR/duplicate-bound-err.rs:96:18 + --> $DIR/duplicate-bound-err.rs:92:18 | LL | type MustFail2 = dyn Trait2; | ^^^^^^^^^^^------------^^------------^ @@ -155,7 +155,7 @@ LL | type MustFail2 = dyn Trait2; | `ASSOC` is specified to be `3` here error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate-bound-err.rs:100:43 + --> $DIR/duplicate-bound-err.rs:96:43 | LL | type MustFail3 = dyn Iterator; | ---------- ^^^^^^^^^^ re-bound here @@ -163,7 +163,7 @@ LL | type MustFail3 = dyn Iterator; | `Item` bound here first error[E0719]: the value of the associated type `ASSOC` in trait `Trait2` is already specified - --> $DIR/duplicate-bound-err.rs:103:43 + --> $DIR/duplicate-bound-err.rs:99:43 | LL | type MustFail4 = dyn Trait2; | ------------ ^^^^^^^^^^^^ re-bound here @@ -171,7 +171,7 @@ LL | type MustFail4 = dyn Trait2; | `ASSOC` bound here first error[E0271]: expected `Empty` to be an iterator that yields `i32`, but it yields `u32` - --> $DIR/duplicate-bound-err.rs:119:16 + --> $DIR/duplicate-bound-err.rs:115:16 | LL | uncallable(iter::empty::()); | ---------- ^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32` @@ -179,13 +179,13 @@ LL | uncallable(iter::empty::()); | required by a bound introduced by this call | note: required by a bound in `uncallable` - --> $DIR/duplicate-bound-err.rs:79:32 + --> $DIR/duplicate-bound-err.rs:76:32 | LL | fn uncallable(_: impl Iterator) {} | ^^^^^^^^^^ required by this bound in `uncallable` error[E0271]: expected `Empty` to be an iterator that yields `u32`, but it yields `i32` - --> $DIR/duplicate-bound-err.rs:120:16 + --> $DIR/duplicate-bound-err.rs:116:16 | LL | uncallable(iter::empty::()); | ---------- ^^^^^^^^^^^^^^^^^^^^ expected `u32`, found `i32` @@ -193,13 +193,13 @@ LL | uncallable(iter::empty::()); | required by a bound introduced by this call | note: required by a bound in `uncallable` - --> $DIR/duplicate-bound-err.rs:79:44 + --> $DIR/duplicate-bound-err.rs:76:44 | LL | fn uncallable(_: impl Iterator) {} | ^^^^^^^^^^ required by this bound in `uncallable` error[E0271]: type mismatch resolving `<() as Trait>::ASSOC == 4` - --> $DIR/duplicate-bound-err.rs:121:22 + --> $DIR/duplicate-bound-err.rs:117:22 | LL | uncallable_const(()); | ---------------- ^^ expected `4`, found `3` @@ -209,13 +209,13 @@ LL | uncallable_const(()); = note: expected constant `4` found constant `3` note: required by a bound in `uncallable_const` - --> $DIR/duplicate-bound-err.rs:81:46 + --> $DIR/duplicate-bound-err.rs:78:46 | LL | fn uncallable_const(_: impl Trait) {} | ^^^^^^^^^ required by this bound in `uncallable_const` error[E0271]: type mismatch resolving `::ASSOC == 3` - --> $DIR/duplicate-bound-err.rs:122:22 + --> $DIR/duplicate-bound-err.rs:118:22 | LL | uncallable_const(4u32); | ---------------- ^^^^ expected `3`, found `4` @@ -225,13 +225,13 @@ LL | uncallable_const(4u32); = note: expected constant `3` found constant `4` note: required by a bound in `uncallable_const` - --> $DIR/duplicate-bound-err.rs:81:35 + --> $DIR/duplicate-bound-err.rs:78:35 | LL | fn uncallable_const(_: impl Trait) {} | ^^^^^^^^^ required by this bound in `uncallable_const` error[E0271]: type mismatch resolving `<() as Trait>::ASSOC == 4` - --> $DIR/duplicate-bound-err.rs:123:20 + --> $DIR/duplicate-bound-err.rs:119:20 | LL | uncallable_rtn(()); | -------------- ^^ expected `4`, found `3` @@ -241,7 +241,7 @@ LL | uncallable_rtn(()); = note: expected constant `4` found constant `3` note: required by a bound in `uncallable_rtn` - --> $DIR/duplicate-bound-err.rs:84:61 + --> $DIR/duplicate-bound-err.rs:81:61 | LL | fn uncallable_rtn( | -------------- required by a bound in this function @@ -249,7 +249,7 @@ LL | _: impl Trait, foo(..): Trait> | ^^^^^^^^^ required by this bound in `uncallable_rtn` error[E0271]: type mismatch resolving `::ASSOC == 3` - --> $DIR/duplicate-bound-err.rs:124:20 + --> $DIR/duplicate-bound-err.rs:120:20 | LL | uncallable_rtn(17u32); | -------------- ^^^^^ expected `3`, found `4` @@ -259,7 +259,7 @@ LL | uncallable_rtn(17u32); = note: expected constant `3` found constant `4` note: required by a bound in `uncallable_rtn` - --> $DIR/duplicate-bound-err.rs:84:34 + --> $DIR/duplicate-bound-err.rs:81:34 | LL | fn uncallable_rtn( | -------------- required by a bound in this function diff --git a/tests/ui/associated-type-bounds/duplicate-bound.rs b/tests/ui/associated-type-bounds/duplicate-bound.rs index 1aeb0022a04fe..39cfa9db072c4 100644 --- a/tests/ui/associated-type-bounds/duplicate-bound.rs +++ b/tests/ui/associated-type-bounds/duplicate-bound.rs @@ -189,8 +189,7 @@ trait Tra3 { trait Trait { type Gat; - #[type_const] - const ASSOC: i32; + type const ASSOC: i32; fn foo() -> impl Sized; } @@ -198,8 +197,7 @@ trait Trait { impl Trait for () { type Gat = (); - #[type_const] - const ASSOC: i32 = 3; + type const ASSOC: i32 = 3; fn foo() {} } diff --git a/tests/ui/associated-types/type-const-inherent-impl-normalize.rs b/tests/ui/associated-types/type-const-inherent-impl-normalize.rs index 70eea70db4c68..a9c7373b4f448 100644 --- a/tests/ui/associated-types/type-const-inherent-impl-normalize.rs +++ b/tests/ui/associated-types/type-const-inherent-impl-normalize.rs @@ -1,8 +1,8 @@ struct S; impl S { - #[type_const] - //~^ ERROR: the `#[type_const]` attribute is an experimental feature - const LEN: usize = 1; + type const LEN: usize = 1; + //~^ ERROR: associated `type const` are unstable [E0658] + //~| ERROR: `type const` syntax is experimental [E0658] fn arr() { [8; Self::LEN] //~^ WARN: cannot use constants which depend on generic parameters in types diff --git a/tests/ui/associated-types/type-const-inherent-impl-normalize.stderr b/tests/ui/associated-types/type-const-inherent-impl-normalize.stderr index 958d38e855eaf..b86859f4a993f 100644 --- a/tests/ui/associated-types/type-const-inherent-impl-normalize.stderr +++ b/tests/ui/associated-types/type-const-inherent-impl-normalize.stderr @@ -1,8 +1,18 @@ -error[E0658]: the `#[type_const]` attribute is an experimental feature +error[E0658]: `type const` syntax is experimental --> $DIR/type-const-inherent-impl-normalize.rs:3:5 | -LL | #[type_const] - | ^^^^^^^^^^^^^ +LL | type const LEN: usize = 1; + | ^^^^^^^^^^ + | + = note: see issue #132980 for more information + = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: associated `type const` are unstable + --> $DIR/type-const-inherent-impl-normalize.rs:3:5 + | +LL | type const LEN: usize = 1; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #132980 for more information = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable @@ -36,7 +46,7 @@ LL | fn arr() { LL | [8; Self::LEN] | ^^^^^^^^^^^^^^ expected `()`, found `[{integer}; 1]` -error: aborting due to 2 previous errors; 2 warnings emitted +error: aborting due to 3 previous errors; 2 warnings emitted Some errors have detailed explanations: E0308, E0658. For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/attributes/malformed-attrs.rs b/tests/ui/attributes/malformed-attrs.rs index 6dc3086b63e11..489c8bf9f4954 100644 --- a/tests/ui/attributes/malformed-attrs.rs +++ b/tests/ui/attributes/malformed-attrs.rs @@ -145,8 +145,6 @@ struct Test; #[diagnostic::on_unimplemented = 1] //~^ WARN malformed trait Hey { - #[type_const = 1] - //~^ ERROR malformed const HEY: usize = 5; } diff --git a/tests/ui/attributes/malformed-attrs.stderr b/tests/ui/attributes/malformed-attrs.stderr index 22e222efa4358..009da1d12a16e 100644 --- a/tests/ui/attributes/malformed-attrs.stderr +++ b/tests/ui/attributes/malformed-attrs.stderr @@ -21,13 +21,13 @@ LL | #[cfg_attr] = note: for more information, visit error[E0463]: can't find crate for `wloop` - --> $DIR/malformed-attrs.rs:217:1 + --> $DIR/malformed-attrs.rs:215:1 | LL | extern crate wloop; | ^^^^^^^^^^^^^^^^^^^ can't find crate error: malformed `allow` attribute input - --> $DIR/malformed-attrs.rs:183:1 + --> $DIR/malformed-attrs.rs:181:1 | LL | #[allow] | ^^^^^^^^ @@ -43,7 +43,7 @@ LL | #[allow(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `expect` attribute input - --> $DIR/malformed-attrs.rs:185:1 + --> $DIR/malformed-attrs.rs:183:1 | LL | #[expect] | ^^^^^^^^^ @@ -59,7 +59,7 @@ LL | #[expect(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `warn` attribute input - --> $DIR/malformed-attrs.rs:187:1 + --> $DIR/malformed-attrs.rs:185:1 | LL | #[warn] | ^^^^^^^ @@ -75,7 +75,7 @@ LL | #[warn(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `deny` attribute input - --> $DIR/malformed-attrs.rs:189:1 + --> $DIR/malformed-attrs.rs:187:1 | LL | #[deny] | ^^^^^^^ @@ -91,7 +91,7 @@ LL | #[deny(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `forbid` attribute input - --> $DIR/malformed-attrs.rs:191:1 + --> $DIR/malformed-attrs.rs:189:1 | LL | #[forbid] | ^^^^^^^^^ @@ -125,7 +125,7 @@ LL | #[proc_macro_derive] | ^^^^^^^^^^^^^^^^^^^^ error[E0658]: allow_internal_unsafe side-steps the unsafe_code lint - --> $DIR/malformed-attrs.rs:222:1 + --> $DIR/malformed-attrs.rs:220:1 | LL | #[allow_internal_unsafe = 1] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -541,7 +541,7 @@ LL | #[cfi_encoding = ""] | help: must be of the form: `#[cfi_encoding = "encoding"]` error[E0565]: malformed `marker` attribute input - --> $DIR/malformed-attrs.rs:160:1 + --> $DIR/malformed-attrs.rs:158:1 | LL | #[marker = 3] | ^^^^^^^^^---^ @@ -550,7 +550,7 @@ LL | #[marker = 3] | help: must be of the form: `#[marker]` error[E0565]: malformed `fundamental` attribute input - --> $DIR/malformed-attrs.rs:162:1 + --> $DIR/malformed-attrs.rs:160:1 | LL | #[fundamental()] | ^^^^^^^^^^^^^--^ @@ -559,7 +559,7 @@ LL | #[fundamental()] | help: must be of the form: `#[fundamental]` error[E0565]: malformed `ffi_pure` attribute input - --> $DIR/malformed-attrs.rs:170:5 + --> $DIR/malformed-attrs.rs:168:5 | LL | #[unsafe(ffi_pure = 1)] | ^^^^^^^^^^^^^^^^^^---^^ @@ -568,7 +568,7 @@ LL | #[unsafe(ffi_pure = 1)] | help: must be of the form: `#[ffi_pure]` error[E0539]: malformed `link_ordinal` attribute input - --> $DIR/malformed-attrs.rs:172:5 + --> $DIR/malformed-attrs.rs:170:5 | LL | #[link_ordinal] | ^^^^^^^^^^^^^^^ @@ -579,7 +579,7 @@ LL | #[link_ordinal] = note: for more information, visit error[E0565]: malformed `ffi_const` attribute input - --> $DIR/malformed-attrs.rs:176:5 + --> $DIR/malformed-attrs.rs:174:5 | LL | #[unsafe(ffi_const = 1)] | ^^^^^^^^^^^^^^^^^^^---^^ @@ -588,13 +588,13 @@ LL | #[unsafe(ffi_const = 1)] | help: must be of the form: `#[ffi_const]` error[E0539]: malformed `linkage` attribute input - --> $DIR/malformed-attrs.rs:178:5 + --> $DIR/malformed-attrs.rs:176:5 | LL | #[linkage] | ^^^^^^^^^^ expected this to be of the form `linkage = "..."` error[E0539]: malformed `debugger_visualizer` attribute input - --> $DIR/malformed-attrs.rs:193:1 + --> $DIR/malformed-attrs.rs:191:1 | LL | #[debugger_visualizer] | ^^^^^^^^^^^^^^^^^^^^^^ @@ -605,7 +605,7 @@ LL | #[debugger_visualizer] = note: for more information, visit error[E0565]: malformed `automatically_derived` attribute input - --> $DIR/malformed-attrs.rs:195:1 + --> $DIR/malformed-attrs.rs:193:1 | LL | #[automatically_derived = 18] | ^^^^^^^^^^^^^^^^^^^^^^^^----^ @@ -614,7 +614,7 @@ LL | #[automatically_derived = 18] | help: must be of the form: `#[automatically_derived]` error[E0565]: malformed `non_exhaustive` attribute input - --> $DIR/malformed-attrs.rs:203:1 + --> $DIR/malformed-attrs.rs:201:1 | LL | #[non_exhaustive = 1] | ^^^^^^^^^^^^^^^^^---^ @@ -623,7 +623,7 @@ LL | #[non_exhaustive = 1] | help: must be of the form: `#[non_exhaustive]` error[E0565]: malformed `thread_local` attribute input - --> $DIR/malformed-attrs.rs:209:1 + --> $DIR/malformed-attrs.rs:207:1 | LL | #[thread_local()] | ^^^^^^^^^^^^^^--^ @@ -632,7 +632,7 @@ LL | #[thread_local()] | help: must be of the form: `#[thread_local]` error[E0565]: malformed `no_link` attribute input - --> $DIR/malformed-attrs.rs:213:1 + --> $DIR/malformed-attrs.rs:211:1 | LL | #[no_link()] | ^^^^^^^^^--^ @@ -641,7 +641,7 @@ LL | #[no_link()] | help: must be of the form: `#[no_link]` error[E0539]: malformed `macro_use` attribute input - --> $DIR/malformed-attrs.rs:215:1 + --> $DIR/malformed-attrs.rs:213:1 | LL | #[macro_use = 1] | ^^^^^^^^^^^^---^ @@ -659,7 +659,7 @@ LL + #[macro_use] | error[E0539]: malformed `macro_export` attribute input - --> $DIR/malformed-attrs.rs:220:1 + --> $DIR/malformed-attrs.rs:218:1 | LL | #[macro_export = 18] | ^^^^^^^^^^^^^^^----^ @@ -676,7 +676,7 @@ LL + #[macro_export] | error[E0565]: malformed `allow_internal_unsafe` attribute input - --> $DIR/malformed-attrs.rs:222:1 + --> $DIR/malformed-attrs.rs:220:1 | LL | #[allow_internal_unsafe = 1] | ^^^^^^^^^^^^^^^^^^^^^^^^---^ @@ -684,15 +684,6 @@ LL | #[allow_internal_unsafe = 1] | | didn't expect any arguments here | help: must be of the form: `#[allow_internal_unsafe]` -error[E0565]: malformed `type_const` attribute input - --> $DIR/malformed-attrs.rs:148:5 - | -LL | #[type_const = 1] - | ^^^^^^^^^^^^^---^ - | | | - | | didn't expect any arguments here - | help: must be of the form: `#[type_const]` - error: attribute should be applied to `const fn` --> $DIR/malformed-attrs.rs:32:1 | @@ -820,13 +811,13 @@ LL | #[no_implicit_prelude = 23] = help: `#[no_implicit_prelude]` can be applied to crates and modules warning: `#[diagnostic::do_not_recommend]` does not expect any arguments - --> $DIR/malformed-attrs.rs:154:1 + --> $DIR/malformed-attrs.rs:152:1 | LL | #[diagnostic::do_not_recommend()] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: `#[automatically_derived]` attribute cannot be used on modules - --> $DIR/malformed-attrs.rs:195:1 + --> $DIR/malformed-attrs.rs:193:1 | LL | #[automatically_derived = 18] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -835,7 +826,7 @@ LL | #[automatically_derived = 18] = help: `#[automatically_derived]` can only be applied to trait impl blocks error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]` - --> $DIR/malformed-attrs.rs:229:1 + --> $DIR/malformed-attrs.rs:227:1 | LL | #[ignore = 1] | ^^^^^^^^^^^^^ @@ -854,7 +845,7 @@ LL | #[coroutine = 63] || {} = note: expected unit type `()` found coroutine `{coroutine@$DIR/malformed-attrs.rs:116:23: 116:25}` -error: aborting due to 76 previous errors; 8 warnings emitted +error: aborting due to 75 previous errors; 8 warnings emitted Some errors have detailed explanations: E0308, E0463, E0539, E0565, E0658, E0805. For more information about an error, try `rustc --explain E0308`. @@ -882,7 +873,7 @@ LL | #[ignore()] Future breakage diagnostic: error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]` - --> $DIR/malformed-attrs.rs:229:1 + --> $DIR/malformed-attrs.rs:227:1 | LL | #[ignore = 1] | ^^^^^^^^^^^^^ diff --git a/tests/ui/const-generics/associated-const-bindings/ambiguity.rs b/tests/ui/const-generics/associated-const-bindings/ambiguity.rs index 785d43e51b3d8..6871a028de5f3 100644 --- a/tests/ui/const-generics/associated-const-bindings/ambiguity.rs +++ b/tests/ui/const-generics/associated-const-bindings/ambiguity.rs @@ -6,8 +6,7 @@ trait Trait0: Parent0 + Parent0 {} trait Parent0 { - #[type_const] - const K: (); + type const K: (); } fn take0(_: impl Trait0) {} @@ -15,12 +14,10 @@ fn take0(_: impl Trait0) {} trait Trait1: Parent1 + Parent2 {} trait Parent1 { - #[type_const] - const C: i32; + type const C: i32; } trait Parent2 { - #[type_const] - const C: &'static str; + type const C: &'static str; } fn take1(_: impl Trait1) {} diff --git a/tests/ui/const-generics/associated-const-bindings/ambiguity.stderr b/tests/ui/const-generics/associated-const-bindings/ambiguity.stderr index 806708f18d654..9dcb30d6b737b 100644 --- a/tests/ui/const-generics/associated-const-bindings/ambiguity.stderr +++ b/tests/ui/const-generics/associated-const-bindings/ambiguity.stderr @@ -1,8 +1,8 @@ error[E0222]: ambiguous associated constant `K` in bounds of `Trait0` - --> $DIR/ambiguity.rs:13:25 + --> $DIR/ambiguity.rs:12:25 | -LL | const K: (); - | ----------- +LL | type const K: (); + | ---------------- | | | ambiguous `K` from `Parent0` | ambiguous `K` from `Parent0` @@ -17,13 +17,13 @@ LL | fn take0(_: impl Trait0) {} T: Parent0::K = const { } error[E0222]: ambiguous associated constant `C` in bounds of `Trait1` - --> $DIR/ambiguity.rs:26:25 + --> $DIR/ambiguity.rs:23:25 | -LL | const C: i32; - | ------------ ambiguous `C` from `Parent1` +LL | type const C: i32; + | ----------------- ambiguous `C` from `Parent1` ... -LL | const C: &'static str; - | --------------------- ambiguous `C` from `Parent2` +LL | type const C: &'static str; + | -------------------------- ambiguous `C` from `Parent2` ... LL | fn take1(_: impl Trait1) {} | ^^^^^^^ ambiguous associated constant `C` diff --git a/tests/ui/const-generics/associated-const-bindings/assoc-const.rs b/tests/ui/const-generics/associated-const-bindings/assoc-const.rs index ac9f7e53b3cb5..3f8353b6914d0 100644 --- a/tests/ui/const-generics/associated-const-bindings/assoc-const.rs +++ b/tests/ui/const-generics/associated-const-bindings/assoc-const.rs @@ -3,15 +3,13 @@ #![allow(unused, incomplete_features)] pub trait Foo { - #[type_const] - const N: usize; + type const N: usize; } pub struct Bar; impl Foo for Bar { - #[type_const] - const N: usize = 3; + type const N: usize = 3; } const TEST: usize = 3; diff --git a/tests/ui/const-generics/associated-const-bindings/bound-var-in-ty-not-wf.rs b/tests/ui/const-generics/associated-const-bindings/bound-var-in-ty-not-wf.rs index 803cc59cc93d1..53f65319db9da 100644 --- a/tests/ui/const-generics/associated-const-bindings/bound-var-in-ty-not-wf.rs +++ b/tests/ui/const-generics/associated-const-bindings/bound-var-in-ty-not-wf.rs @@ -11,8 +11,7 @@ use std::marker::ConstParamTy_; trait Trait { - #[type_const] - const K: T; + type const K: T; } fn take( diff --git a/tests/ui/const-generics/associated-const-bindings/bound-var-in-ty-not-wf.stderr b/tests/ui/const-generics/associated-const-bindings/bound-var-in-ty-not-wf.stderr index a4f97525b5156..f2f69aad4ee65 100644 --- a/tests/ui/const-generics/associated-const-bindings/bound-var-in-ty-not-wf.stderr +++ b/tests/ui/const-generics/associated-const-bindings/bound-var-in-ty-not-wf.stderr @@ -1,11 +1,11 @@ error: higher-ranked subtype error - --> $DIR/bound-var-in-ty-not-wf.rs:21:13 + --> $DIR/bound-var-in-ty-not-wf.rs:20:13 | LL | K = const { () } | ^^^^^^^^^^^^ error: higher-ranked subtype error - --> $DIR/bound-var-in-ty-not-wf.rs:21:13 + --> $DIR/bound-var-in-ty-not-wf.rs:20:13 | LL | K = const { () } | ^^^^^^^^^^^^ diff --git a/tests/ui/const-generics/associated-const-bindings/bound-var-in-ty.rs b/tests/ui/const-generics/associated-const-bindings/bound-var-in-ty.rs index e6fd5bdad0027..a509fe0d52e37 100644 --- a/tests/ui/const-generics/associated-const-bindings/bound-var-in-ty.rs +++ b/tests/ui/const-generics/associated-const-bindings/bound-var-in-ty.rs @@ -14,8 +14,7 @@ use std::marker::ConstParamTy_; trait Trait { - #[type_const] - const K: T; + type const K: T; } fn take( diff --git a/tests/ui/const-generics/associated-const-bindings/coexisting-with-type-binding.rs b/tests/ui/const-generics/associated-const-bindings/coexisting-with-type-binding.rs index 0af91bfe7da80..149755bad4ca3 100644 --- a/tests/ui/const-generics/associated-const-bindings/coexisting-with-type-binding.rs +++ b/tests/ui/const-generics/associated-const-bindings/coexisting-with-type-binding.rs @@ -12,13 +12,11 @@ trait Trait: SuperTrait { type N; type Q; - #[type_const] - const N: usize; + type const N: usize; } trait SuperTrait { - #[type_const] - const Q: &'static str; + type const Q: &'static str; } fn take0(_: impl Trait) {} diff --git a/tests/ui/const-generics/associated-const-bindings/coherence.rs b/tests/ui/const-generics/associated-const-bindings/coherence.rs index f4081fae6144f..e9296f3a8df0a 100644 --- a/tests/ui/const-generics/associated-const-bindings/coherence.rs +++ b/tests/ui/const-generics/associated-const-bindings/coherence.rs @@ -2,12 +2,10 @@ #![expect(incomplete_features)] pub trait IsVoid { - #[type_const] - const IS_VOID: bool; + type const IS_VOID: bool; } impl IsVoid for () { - #[type_const] - const IS_VOID: bool = true; + type const IS_VOID: bool = true; } pub trait Maybe {} diff --git a/tests/ui/const-generics/associated-const-bindings/coherence.stderr b/tests/ui/const-generics/associated-const-bindings/coherence.stderr index 23d6495a16a44..df6781f2f9a27 100644 --- a/tests/ui/const-generics/associated-const-bindings/coherence.stderr +++ b/tests/ui/const-generics/associated-const-bindings/coherence.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `Maybe` for type `()` - --> $DIR/coherence.rs:15:1 + --> $DIR/coherence.rs:13:1 | LL | impl Maybe for () {} | ----------------- first implementation here diff --git a/tests/ui/const-generics/associated-const-bindings/const-projection-err.rs b/tests/ui/const-generics/associated-const-bindings/const-projection-err.rs index d485316ce3718..8e871ddf90ce5 100644 --- a/tests/ui/const-generics/associated-const-bindings/const-projection-err.rs +++ b/tests/ui/const-generics/associated-const-bindings/const-projection-err.rs @@ -2,8 +2,7 @@ #![allow(incomplete_features)] trait TraitWAssocConst { - #[type_const] - const A: usize; + type const A: usize; } fn foo>() {} diff --git a/tests/ui/const-generics/associated-const-bindings/const-projection-err.stderr b/tests/ui/const-generics/associated-const-bindings/const-projection-err.stderr index 552b1579e6183..c533a7d65b90e 100644 --- a/tests/ui/const-generics/associated-const-bindings/const-projection-err.stderr +++ b/tests/ui/const-generics/associated-const-bindings/const-projection-err.stderr @@ -1,5 +1,5 @@ error[E0271]: type mismatch resolving `::A == 1` - --> $DIR/const-projection-err.rs:12:11 + --> $DIR/const-projection-err.rs:11:11 | LL | foo::(); | ^ expected `1`, found `0` @@ -7,7 +7,7 @@ LL | foo::(); = note: expected constant `1` found constant `0` note: required by a bound in `foo` - --> $DIR/const-projection-err.rs:9:28 + --> $DIR/const-projection-err.rs:8:28 | LL | fn foo>() {} | ^^^^^ required by this bound in `foo` diff --git a/tests/ui/const-generics/associated-const-bindings/const_evaluatable_unchecked.rs b/tests/ui/const-generics/associated-const-bindings/const_evaluatable_unchecked.rs index 161eef63d36f5..578904ea18918 100644 --- a/tests/ui/const-generics/associated-const-bindings/const_evaluatable_unchecked.rs +++ b/tests/ui/const-generics/associated-const-bindings/const_evaluatable_unchecked.rs @@ -8,8 +8,7 @@ #![allow(incomplete_features)] pub trait TraitA { - #[type_const] - const K: u8 = 0; + type const K: u8 = 0; } pub trait TraitB {} diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-assoc-const-ty-mentions-self.rs b/tests/ui/const-generics/associated-const-bindings/dyn-compat-assoc-const-ty-mentions-self.rs index bd26acce681fc..771f48cba0684 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-assoc-const-ty-mentions-self.rs +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-assoc-const-ty-mentions-self.rs @@ -14,14 +14,12 @@ trait Trait { // NOTE: The `ConstParamTy_` bound is intentionally on the assoc const and not on the trait as // doing the latter would already render the trait dyn incompatible due to it being // bounded by `PartialEq` and supertrait bounds cannot mention `Self` like this. - #[type_const] - const K: Self where Self: std::marker::ConstParamTy_; + type const K: Self where Self: std::marker::ConstParamTy_; //~^ NOTE it contains associated const `K` whose type references the `Self` type // This is not a "`Self` projection" in our sense (which would be allowed) // since the trait is not the principal trait or a supertrait thereof. - #[type_const] - const Q: ::Output; + type const Q: ::Output; //~^ NOTE it contains associated const `Q` whose type references the `Self` type } diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-assoc-const-ty-mentions-self.stderr b/tests/ui/const-generics/associated-const-bindings/dyn-compat-assoc-const-ty-mentions-self.stderr index dedbdd7f82bbb..19cd8bf5af99b 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-assoc-const-ty-mentions-self.stderr +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-assoc-const-ty-mentions-self.stderr @@ -1,21 +1,21 @@ error[E0038]: the trait `Trait` is not dyn compatible - --> $DIR/dyn-compat-assoc-const-ty-mentions-self.rs:38:16 + --> $DIR/dyn-compat-assoc-const-ty-mentions-self.rs:36:16 | LL | let _: dyn Trait; | ^^^^^ `Trait` is not dyn compatible | note: for a trait to be dyn compatible it needs to allow building a vtable for more information, visit - --> $DIR/dyn-compat-assoc-const-ty-mentions-self.rs:18:11 + --> $DIR/dyn-compat-assoc-const-ty-mentions-self.rs:17:16 | LL | trait Trait { | ----- this trait is not dyn compatible... ... -LL | const K: Self where Self: std::marker::ConstParamTy_; - | ^ ...because it contains associated const `K` whose type references the `Self` type +LL | type const K: Self where Self: std::marker::ConstParamTy_; + | ^ ...because it contains associated const `K` whose type references the `Self` type ... -LL | const Q: ::Output; - | ^ ...because it contains associated const `Q` whose type references the `Self` type +LL | type const Q: ::Output; + | ^ ...because it contains associated const `Q` whose type references the `Self` type = help: consider moving `K` to another trait = help: consider moving `Q` to another trait diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-basic.rs b/tests/ui/const-generics/associated-const-bindings/dyn-compat-basic.rs index 6e35d56dc6e7d..8de8cb1a60db5 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-basic.rs +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-basic.rs @@ -7,25 +7,20 @@ #![expect(incomplete_features)] trait Trait: SuperTrait { - #[type_const] - const K: usize; + type const K: usize; } trait SuperTrait { - #[type_const] - const Q: usize; - #[type_const] - const C: usize; + type const Q: usize; + type const C: usize; } trait Bound { - #[type_const] - const N: usize; + type const N: usize; } impl Bound for () { - #[type_const] - const N: usize = 10; + type const N: usize = 10; } fn main() { diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-mismatch.rs b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-mismatch.rs index be41906a4f2f2..ad5c4b679117c 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-mismatch.rs +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-mismatch.rs @@ -4,13 +4,11 @@ #![expect(incomplete_features)] trait Trait { - #[type_const] - const N: usize; + type const N: usize; } impl Trait for () { - #[type_const] - const N: usize = 1; + type const N: usize = 1; } fn main() { diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-mismatch.stderr b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-mismatch.stderr index 2ab02068eb34a..282504e3bc356 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-mismatch.stderr +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-mismatch.stderr @@ -1,5 +1,5 @@ error[E0271]: type mismatch resolving `<() as Trait>::N == 0` - --> $DIR/dyn-compat-const-mismatch.rs:17:32 + --> $DIR/dyn-compat-const-mismatch.rs:15:32 | LL | let _: &dyn Trait = &(); | ^^^ expected `0`, found `1` diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-param-default-mentions-self.rs b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-param-default-mentions-self.rs index 30e7a78c2a857..8130960195d9d 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-param-default-mentions-self.rs +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-param-default-mentions-self.rs @@ -7,13 +7,11 @@ trait X::N }> {} trait Y { - #[type_const] - const N: usize; + type const N: usize; } impl Y for T { - #[type_const] - const N: usize = 1; + type const N: usize = 1; } fn main() { diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-param-default-mentions-self.stderr b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-param-default-mentions-self.stderr index d92fd620f0ea7..a22545fcd8d21 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-param-default-mentions-self.stderr +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-param-default-mentions-self.stderr @@ -1,5 +1,5 @@ error[E0393]: the const parameter `N` must be explicitly specified - --> $DIR/dyn-compat-const-param-default-mentions-self.rs:20:16 + --> $DIR/dyn-compat-const-param-default-mentions-self.rs:18:16 | LL | trait X::N }> {} | -------------------------------------------- const parameter `N` must be specified for this diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-projection-behind-trait-alias-mentions-self.rs b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-projection-behind-trait-alias-mentions-self.rs index 93036fbc01a8b..415d7bda347b3 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-projection-behind-trait-alias-mentions-self.rs +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-projection-behind-trait-alias-mentions-self.rs @@ -9,8 +9,7 @@ #![expect(incomplete_features)] trait Trait { - #[type_const] - const Y: i32; + type const Y: i32; } struct Hold(T); diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-projection-behind-trait-alias-mentions-self.stderr b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-projection-behind-trait-alias-mentions-self.stderr index 109cb7602dcd7..576d4c3230eeb 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-projection-behind-trait-alias-mentions-self.stderr +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-projection-behind-trait-alias-mentions-self.stderr @@ -1,5 +1,5 @@ error: associated constant binding in trait object type mentions `Self` - --> $DIR/dyn-compat-const-projection-behind-trait-alias-mentions-self.rs:21:12 + --> $DIR/dyn-compat-const-projection-behind-trait-alias-mentions-self.rs:20:12 | LL | trait Bound = Trait }>; | -------------------- this binding mentions `Self` diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-projection-from-supertrait-mentions-self.rs b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-projection-from-supertrait-mentions-self.rs index aa93edd025313..560a1b7f3f7a1 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-projection-from-supertrait-mentions-self.rs +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-projection-from-supertrait-mentions-self.rs @@ -5,13 +5,11 @@ #![expect(incomplete_features)] trait X: Y { - #[type_const] - const Q: usize; + type const Q: usize; } trait Y { - #[type_const] - const K: usize; + type const K: usize; } fn main() { diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-projection-from-supertrait-mentions-self.stderr b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-projection-from-supertrait-mentions-self.stderr index 373c4f0e66116..dae9e3d8c22bf 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-projection-from-supertrait-mentions-self.stderr +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-const-projection-from-supertrait-mentions-self.stderr @@ -1,8 +1,8 @@ error[E0191]: the value of the associated constant `K` in `Y` must be specified - --> $DIR/dyn-compat-const-projection-from-supertrait-mentions-self.rs:18:16 + --> $DIR/dyn-compat-const-projection-from-supertrait-mentions-self.rs:16:16 | -LL | const K: usize; - | -------------- `K` defined here +LL | type const K: usize; + | ------------------- `K` defined here ... LL | let _: dyn X; | ^^^^^^^^^ help: specify the associated constant: `X` diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-non-type-assoc-const.rs b/tests/ui/const-generics/associated-const-bindings/dyn-compat-non-type-assoc-const.rs index 67650bce8c896..38d593984724e 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-non-type-assoc-const.rs +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-non-type-assoc-const.rs @@ -7,7 +7,7 @@ trait Trait { const K: usize; - //~^ NOTE it contains associated const `K` that's not marked `#[type_const]` + //~^ NOTE it contains associated const `K` that's not defined as `type const` } fn main() { @@ -16,5 +16,5 @@ fn main() { // Check that specifying the non-type assoc const doesn't "magically make it work". let _: dyn Trait; //~^ ERROR the trait `Trait` is not dyn compatible - //~| ERROR use of trait associated const without `#[type_const]` + //~| ERROR use of trait associated const not defined as `type const` } diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-non-type-assoc-const.stderr b/tests/ui/const-generics/associated-const-bindings/dyn-compat-non-type-assoc-const.stderr index c579cd312f1fe..5bc072e98c0f8 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-non-type-assoc-const.stderr +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-non-type-assoc-const.stderr @@ -11,16 +11,16 @@ note: for a trait to be dyn compatible it needs to allow building a vtable LL | trait Trait { | ----- this trait is not dyn compatible... LL | const K: usize; - | ^ ...because it contains associated const `K` that's not marked `#[type_const]` + | ^ ...because it contains associated const `K` that's not defined as `type const` = help: consider moving `K` to another trait -error: use of trait associated const without `#[type_const]` +error: use of trait associated const not defined as `type const` --> $DIR/dyn-compat-non-type-assoc-const.rs:17:22 | LL | let _: dyn Trait; | ^^^^^ | - = note: the declaration in the trait must be marked with `#[type_const]` + = note: the declaration in the trait must begin with `type const` not just `const` alone error[E0038]: the trait `Trait` is not dyn compatible --> $DIR/dyn-compat-non-type-assoc-const.rs:17:16 @@ -35,7 +35,7 @@ note: for a trait to be dyn compatible it needs to allow building a vtable LL | trait Trait { | ----- this trait is not dyn compatible... LL | const K: usize; - | ^ ...because it contains associated const `K` that's not marked `#[type_const]` + | ^ ...because it contains associated const `K` that's not defined as `type const` = help: consider moving `K` to another trait error: aborting due to 3 previous errors diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs index 07ce629ab7be0..03f1a526b73ac 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs @@ -6,13 +6,11 @@ #![expect(incomplete_features)] trait Trait { - #[type_const] - const N: i32 where Self: Bound; + type const N: i32 where Self: Bound; } impl Trait for () { - #[type_const] - const N: i32 = 0; + type const N: i32 = 0; } trait Bound {} diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.stderr b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.stderr index 8eeb60d55c384..21e407f8a8618 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.stderr +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.stderr @@ -1,19 +1,19 @@ error[E0277]: the trait bound `(): Bound` is not satisfied - --> $DIR/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs:23:32 + --> $DIR/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs:21:32 | LL | let _: &dyn Trait = &(); | ^^^ the trait `Bound` is not implemented for `()` | help: this trait has no implementations, consider adding one - --> $DIR/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs:18:1 + --> $DIR/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs:16:1 | LL | trait Bound {} | ^^^^^^^^^^^ note: required by a bound in `Trait::N` - --> $DIR/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs:10:30 + --> $DIR/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs:9:35 | -LL | const N: i32 where Self: Bound; - | ^^^^^ required by this bound in `Trait::N` +LL | type const N: i32 where Self: Bound; + | ^^^^^ required by this bound in `Trait::N` error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-assoc-const-ty.rs b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-assoc-const-ty.rs index fc3bd1d2e753f..623769f5d12fe 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-assoc-const-ty.rs +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-assoc-const-ty.rs @@ -14,14 +14,12 @@ trait A { type Ty: std::marker::ConstParamTy_; - #[type_const] - const CT: Self::Ty; + type const CT: Self::Ty; } impl A for () { type Ty = i32; - #[type_const] - const CT: i32 = 0; + type const CT: i32 = 0; } fn main() { diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-assoc-const-ty.stderr b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-assoc-const-ty.stderr index 0b8dae1aac43a..cc08c25906b66 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-assoc-const-ty.stderr +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-assoc-const-ty.stderr @@ -1,23 +1,23 @@ error[E0277]: the trait bound `FreshTy(0): A` is not satisfied - --> $DIR/dyn-compat-self-const-projections-in-assoc-const-ty.rs:34:33 + --> $DIR/dyn-compat-self-const-projections-in-assoc-const-ty.rs:32:33 | LL | let _: dyn A; | ^ the trait `A` is not implemented for `FreshTy(0)` | help: the trait `A` is implemented for `()` - --> $DIR/dyn-compat-self-const-projections-in-assoc-const-ty.rs:21:1 + --> $DIR/dyn-compat-self-const-projections-in-assoc-const-ty.rs:20:1 | LL | impl A for () { | ^^^^^^^^^^^^^ error[E0277]: the trait bound `FreshTy(0): A` is not satisfied - --> $DIR/dyn-compat-self-const-projections-in-assoc-const-ty.rs:36:34 + --> $DIR/dyn-compat-self-const-projections-in-assoc-const-ty.rs:34:34 | LL | let _: &dyn A = &(); | ^ the trait `A` is not implemented for `FreshTy(0)` | help: the trait `A` is implemented for `()` - --> $DIR/dyn-compat-self-const-projections-in-assoc-const-ty.rs:21:1 + --> $DIR/dyn-compat-self-const-projections-in-assoc-const-ty.rs:20:1 | LL | impl A for () { | ^^^^^^^^^^^^^ diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-methods.rs b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-methods.rs index f5a5fbc8188ca..9886213743c8a 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-methods.rs +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-methods.rs @@ -15,15 +15,13 @@ #![expect(incomplete_features)] trait Trait { - #[type_const] - const N: usize; + type const N: usize; fn process(&self, _: [u8; Self::N]) -> [u8; Self::N]; } impl Trait for u8 { - #[type_const] - const N: usize = 2; + type const N: usize = 2; fn process(&self, [x, y]: [u8; Self::N]) -> [u8; Self::N] { [self * x, self + y] @@ -31,8 +29,7 @@ impl Trait for u8 { } impl Trait for [u8; N] { - #[type_const] - const N: usize = N; + type const N: usize = N; fn process(&self, other: [u8; Self::N]) -> [u8; Self::N] { let mut result = [0; _]; diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-supertrait-bounds.rs b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-supertrait-bounds.rs index c8929750f61c5..f2ae98accda57 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-supertrait-bounds.rs +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-supertrait-bounds.rs @@ -9,8 +9,7 @@ trait Trait: SuperTrait<{ Self::N }> { //~^ NOTE it uses `Self` as a type parameter - #[type_const] - const N: usize; + type const N: usize; } trait SuperTrait {} diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-supertrait-bounds.stderr b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-supertrait-bounds.stderr index 33edc96117d56..38c928fd58d73 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-supertrait-bounds.stderr +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-self-const-projections-in-supertrait-bounds.stderr @@ -1,5 +1,5 @@ error[E0038]: the trait `Trait` is not dyn compatible - --> $DIR/dyn-compat-self-const-projections-in-supertrait-bounds.rs:19:16 + --> $DIR/dyn-compat-self-const-projections-in-supertrait-bounds.rs:18:16 | LL | let _: dyn Trait; | ^^^^^ `Trait` is not dyn compatible diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-symbol-mangling.rs b/tests/ui/const-generics/associated-const-bindings/dyn-compat-symbol-mangling.rs index 18be0fccc0519..52ecd42b191df 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-symbol-mangling.rs +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-symbol-mangling.rs @@ -15,8 +15,7 @@ #![crate_name = "sym"] trait Trait { - #[type_const] - const N: usize; + type const N: usize; } #[rustc_symbol_name] diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-symbol-mangling.v0.stderr b/tests/ui/const-generics/associated-const-bindings/dyn-compat-symbol-mangling.v0.stderr index 424251acc3e97..8ca0f73494d38 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-symbol-mangling.v0.stderr +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-symbol-mangling.v0.stderr @@ -1,17 +1,17 @@ error: symbol-name(_RMCsCRATE_HASH_3symDNtB_5Traitp1NKj0_EL_) - --> $DIR/dyn-compat-symbol-mangling.rs:22:1 + --> $DIR/dyn-compat-symbol-mangling.rs:21:1 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ error: demangling(>) - --> $DIR/dyn-compat-symbol-mangling.rs:22:1 + --> $DIR/dyn-compat-symbol-mangling.rs:21:1 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ error: demangling-alt(>) - --> $DIR/dyn-compat-symbol-mangling.rs:22:1 + --> $DIR/dyn-compat-symbol-mangling.rs:21:1 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-unspecified-assoc-consts.rs b/tests/ui/const-generics/associated-const-bindings/dyn-compat-unspecified-assoc-consts.rs index 3525cbceb87bf..5bd8aa609420d 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-unspecified-assoc-consts.rs +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-unspecified-assoc-consts.rs @@ -6,8 +6,7 @@ #![expect(incomplete_features)] trait Trait { - #[type_const] - const K: usize; + type const K: usize; } // fn ctxt / body diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-compat-unspecified-assoc-consts.stderr b/tests/ui/const-generics/associated-const-bindings/dyn-compat-unspecified-assoc-consts.stderr index 68658a5711cb8..35fdd7f2751e5 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-compat-unspecified-assoc-consts.stderr +++ b/tests/ui/const-generics/associated-const-bindings/dyn-compat-unspecified-assoc-consts.stderr @@ -1,26 +1,26 @@ error[E0191]: the value of the associated constant `K` in `Trait` must be specified - --> $DIR/dyn-compat-unspecified-assoc-consts.rs:20:18 + --> $DIR/dyn-compat-unspecified-assoc-consts.rs:19:18 | -LL | const K: usize; - | -------------- `K` defined here +LL | type const K: usize; + | ------------------- `K` defined here ... LL | struct Store(dyn Trait); | ^^^^^ help: specify the associated constant: `Trait` error[E0191]: the value of the associated constant `K` in `Trait` must be specified - --> $DIR/dyn-compat-unspecified-assoc-consts.rs:24:21 + --> $DIR/dyn-compat-unspecified-assoc-consts.rs:23:21 | -LL | const K: usize; - | -------------- `K` defined here +LL | type const K: usize; + | ------------------- `K` defined here ... LL | type DynTrait = dyn Trait; | ^^^^^ help: specify the associated constant: `Trait` error[E0191]: the value of the associated constant `K` in `Trait` must be specified - --> $DIR/dyn-compat-unspecified-assoc-consts.rs:15:16 + --> $DIR/dyn-compat-unspecified-assoc-consts.rs:14:16 | -LL | const K: usize; - | -------------- `K` defined here +LL | type const K: usize; + | ------------------- `K` defined here ... LL | let _: dyn Trait; | ^^^^^ help: specify the associated constant: `Trait` diff --git a/tests/ui/const-generics/associated-const-bindings/equality-unused-issue-126729.rs b/tests/ui/const-generics/associated-const-bindings/equality-unused-issue-126729.rs index 614ed8c803d43..f42589f91d157 100644 --- a/tests/ui/const-generics/associated-const-bindings/equality-unused-issue-126729.rs +++ b/tests/ui/const-generics/associated-const-bindings/equality-unused-issue-126729.rs @@ -5,42 +5,34 @@ #![deny(dead_code)] trait Tr { - #[type_const] - const I: i32; + type const I: i32; } impl Tr for () { - #[type_const] - const I: i32 = 1; + type const I: i32 = 1; } fn foo() -> impl Tr {} trait Tr2 { - #[type_const] - const J: i32; - #[type_const] - const K: i32; + type const J: i32; + type const K: i32; } impl Tr2 for () { - #[type_const] - const J: i32 = 1; - #[type_const] - const K: i32 = 1; + type const J: i32 = 1; + type const K: i32 = 1; } fn foo2() -> impl Tr2 {} mod t { pub trait Tr3 { - #[type_const] - const L: i32; + type const L: i32; } impl Tr3 for () { - #[type_const] - const L: i32 = 1; + type const L: i32 = 1; } } diff --git a/tests/ui/const-generics/associated-const-bindings/equality_bound_with_infer.rs b/tests/ui/const-generics/associated-const-bindings/equality_bound_with_infer.rs index b7ed8ee39f87b..e50c13b5d3b5e 100644 --- a/tests/ui/const-generics/associated-const-bindings/equality_bound_with_infer.rs +++ b/tests/ui/const-generics/associated-const-bindings/equality_bound_with_infer.rs @@ -7,13 +7,11 @@ // though it contained inference variables, which would cause ICEs. trait Foo { - #[type_const] - const ASSOC: u32; + type const ASSOC: u32; } impl Foo for () { - #[type_const] - const ASSOC: u32 = N; + type const ASSOC: u32 = N; } fn bar = 10>>() {} diff --git a/tests/ui/const-generics/associated-const-bindings/esc-bound-var-in-ty.rs b/tests/ui/const-generics/associated-const-bindings/esc-bound-var-in-ty.rs index 4d06cdc7620f4..de888c5a79393 100644 --- a/tests/ui/const-generics/associated-const-bindings/esc-bound-var-in-ty.rs +++ b/tests/ui/const-generics/associated-const-bindings/esc-bound-var-in-ty.rs @@ -9,8 +9,7 @@ #![allow(incomplete_features)] trait Trait<'a> { - #[type_const] - const K: &'a (); + type const K: &'a (); } fn take(_: impl for<'r> Trait<'r, K = const { &() }>) {} diff --git a/tests/ui/const-generics/associated-const-bindings/esc-bound-var-in-ty.stderr b/tests/ui/const-generics/associated-const-bindings/esc-bound-var-in-ty.stderr index 3966483aa6002..122893662933d 100644 --- a/tests/ui/const-generics/associated-const-bindings/esc-bound-var-in-ty.stderr +++ b/tests/ui/const-generics/associated-const-bindings/esc-bound-var-in-ty.stderr @@ -1,5 +1,5 @@ error: the type of the associated constant `K` cannot capture late-bound generic parameters - --> $DIR/esc-bound-var-in-ty.rs:16:35 + --> $DIR/esc-bound-var-in-ty.rs:15:35 | LL | fn take(_: impl for<'r> Trait<'r, K = const { &() }>) {} | -- ^ its type cannot capture the late-bound lifetime parameter `'r` diff --git a/tests/ui/const-generics/associated-const-bindings/issue-102335-const.rs b/tests/ui/const-generics/associated-const-bindings/issue-102335-const.rs index a88a3abf0a12e..1663cad13c7cc 100644 --- a/tests/ui/const-generics/associated-const-bindings/issue-102335-const.rs +++ b/tests/ui/const-generics/associated-const-bindings/issue-102335-const.rs @@ -8,8 +8,7 @@ trait T { } trait S { - #[type_const] - const C: i32; + type const C: i32; } fn main() {} diff --git a/tests/ui/const-generics/associated-const-bindings/mismatched-types-with-generic-in-ace.rs b/tests/ui/const-generics/associated-const-bindings/mismatched-types-with-generic-in-ace.rs index 77f0f06f80401..1c6e873b98c3d 100644 --- a/tests/ui/const-generics/associated-const-bindings/mismatched-types-with-generic-in-ace.rs +++ b/tests/ui/const-generics/associated-const-bindings/mismatched-types-with-generic-in-ace.rs @@ -2,13 +2,11 @@ #![expect(incomplete_features)] trait Foo { - #[type_const] - const ASSOC: u32; + type const ASSOC: u32; } impl Foo for () { - #[type_const] - const ASSOC: u32 = N; + type const ASSOC: u32 = N; } fn bar = { N }>>() {} diff --git a/tests/ui/const-generics/associated-const-bindings/mismatched-types-with-generic-in-ace.stderr b/tests/ui/const-generics/associated-const-bindings/mismatched-types-with-generic-in-ace.stderr index c2fb7faa3a3a0..b447cd08a2143 100644 --- a/tests/ui/const-generics/associated-const-bindings/mismatched-types-with-generic-in-ace.stderr +++ b/tests/ui/const-generics/associated-const-bindings/mismatched-types-with-generic-in-ace.stderr @@ -1,26 +1,26 @@ error: the constant `N` is not of type `u32` - --> $DIR/mismatched-types-with-generic-in-ace.rs:14:29 + --> $DIR/mismatched-types-with-generic-in-ace.rs:12:29 | LL | fn bar = { N }>>() {} | ^^^^^^^^^^^^^^^^ expected `u32`, found `u64` | note: required by a const generic parameter in `Foo::ASSOC` - --> $DIR/mismatched-types-with-generic-in-ace.rs:6:17 + --> $DIR/mismatched-types-with-generic-in-ace.rs:5:22 | -LL | const ASSOC: u32; - | ^^^^^^^^^^^^ required by this const generic parameter in `Foo::ASSOC` +LL | type const ASSOC: u32; + | ^^^^^^^^^^^^ required by this const generic parameter in `Foo::ASSOC` error: the constant `10` is not of type `u32` - --> $DIR/mismatched-types-with-generic-in-ace.rs:18:5 + --> $DIR/mismatched-types-with-generic-in-ace.rs:16:5 | LL | bar::<10_u64, ()>(); | ^^^^^^^^^^^^^^^^^^^ expected `u32`, found `u64` | note: required by a const generic parameter in `Foo::ASSOC` - --> $DIR/mismatched-types-with-generic-in-ace.rs:6:17 + --> $DIR/mismatched-types-with-generic-in-ace.rs:5:22 | -LL | const ASSOC: u32; - | ^^^^^^^^^^^^ required by this const generic parameter in `Foo::ASSOC` +LL | type const ASSOC: u32; + | ^^^^^^^^^^^^ required by this const generic parameter in `Foo::ASSOC` error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/associated-const-bindings/normalization-via-param-env.rs b/tests/ui/const-generics/associated-const-bindings/normalization-via-param-env.rs index c7bb5bccedb3a..a1efa74090bb4 100644 --- a/tests/ui/const-generics/associated-const-bindings/normalization-via-param-env.rs +++ b/tests/ui/const-generics/associated-const-bindings/normalization-via-param-env.rs @@ -6,8 +6,7 @@ // with associated const equality bounds. trait Trait { - #[type_const] - const C: usize; + type const C: usize; } fn f>() { diff --git a/tests/ui/const-generics/associated-const-bindings/param-in-ty.rs b/tests/ui/const-generics/associated-const-bindings/param-in-ty.rs index 44e7e3f19ef2a..4d67186f71f9e 100644 --- a/tests/ui/const-generics/associated-const-bindings/param-in-ty.rs +++ b/tests/ui/const-generics/associated-const-bindings/param-in-ty.rs @@ -11,8 +11,7 @@ use std::marker::ConstParamTy_; trait Trait<'a, T: 'a + ConstParamTy_, const N: usize> { - #[type_const] - const K: &'a [T; N]; + type const K: &'a [T; N]; } fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>( @@ -32,8 +31,7 @@ fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>( ) {} trait Project: ConstParamTy_ { - #[type_const] - const SELF: Self; + type const SELF: Self; } fn take1(_: impl Project) {} diff --git a/tests/ui/const-generics/associated-const-bindings/param-in-ty.stderr b/tests/ui/const-generics/associated-const-bindings/param-in-ty.stderr index 719dad816a6f4..2ef3fab7e5ffa 100644 --- a/tests/ui/const-generics/associated-const-bindings/param-in-ty.stderr +++ b/tests/ui/const-generics/associated-const-bindings/param-in-ty.stderr @@ -1,5 +1,5 @@ error: the type of the associated constant `K` must not depend on generic parameters - --> $DIR/param-in-ty.rs:22:29 + --> $DIR/param-in-ty.rs:21:29 | LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>( | -- the lifetime parameter `'r` is defined here @@ -10,7 +10,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }> = note: `K` has type `&'r [A; Q]` error: the type of the associated constant `K` must not depend on generic parameters - --> $DIR/param-in-ty.rs:22:29 + --> $DIR/param-in-ty.rs:21:29 | LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>( | - the type parameter `A` is defined here @@ -21,7 +21,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }> = note: `K` has type `&'r [A; Q]` error: the type of the associated constant `K` must not depend on generic parameters - --> $DIR/param-in-ty.rs:22:29 + --> $DIR/param-in-ty.rs:21:29 | LL | fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>( | - the const parameter `Q` is defined here @@ -32,7 +32,7 @@ LL | _: impl Trait<'r, A, Q, K = const { loop {} }> = note: `K` has type `&'r [A; Q]` error: the type of the associated constant `SELF` must not depend on `impl Trait` - --> $DIR/param-in-ty.rs:39:26 + --> $DIR/param-in-ty.rs:37:26 | LL | fn take1(_: impl Project) {} | -------------^^^^------------ @@ -41,7 +41,7 @@ LL | fn take1(_: impl Project) {} | the `impl Trait` is specified here error: the type of the associated constant `SELF` must not depend on generic parameters - --> $DIR/param-in-ty.rs:44:21 + --> $DIR/param-in-ty.rs:42:21 | LL | fn take2>(_: P) {} | - ^^^^ its type must not depend on the type parameter `P` @@ -51,7 +51,7 @@ LL | fn take2>(_: P) {} = note: `SELF` has type `P` error: the type of the associated constant `K` must not depend on generic parameters - --> $DIR/param-in-ty.rs:53:52 + --> $DIR/param-in-ty.rs:51:52 | LL | trait Iface<'r>: ConstParamTy_ { | -- the lifetime parameter `'r` is defined here @@ -62,7 +62,7 @@ LL | type Assoc: Trait<'r, Self, Q, K = const { loop {} }> = note: `K` has type `&'r [Self; Q]` error: the type of the associated constant `K` must not depend on `Self` - --> $DIR/param-in-ty.rs:53:52 + --> $DIR/param-in-ty.rs:51:52 | LL | type Assoc: Trait<'r, Self, Q, K = const { loop {} }> | ^ its type must not depend on `Self` @@ -70,7 +70,7 @@ LL | type Assoc: Trait<'r, Self, Q, K = const { loop {} }> = note: `K` has type `&'r [Self; Q]` error: the type of the associated constant `K` must not depend on generic parameters - --> $DIR/param-in-ty.rs:53:52 + --> $DIR/param-in-ty.rs:51:52 | LL | type Assoc: Trait<'r, Self, Q, K = const { loop {} }> | - ^ its type must not depend on the const parameter `Q` @@ -80,7 +80,7 @@ LL | type Assoc: Trait<'r, Self, Q, K = const { loop {} }> = note: `K` has type `&'r [Self; Q]` error: the type of the associated constant `K` must not depend on generic parameters - --> $DIR/param-in-ty.rs:53:52 + --> $DIR/param-in-ty.rs:51:52 | LL | trait Iface<'r>: ConstParamTy_ { | -- the lifetime parameter `'r` is defined here @@ -92,7 +92,7 @@ LL | type Assoc: Trait<'r, Self, Q, K = const { loop {} }> = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: the type of the associated constant `K` must not depend on `Self` - --> $DIR/param-in-ty.rs:53:52 + --> $DIR/param-in-ty.rs:51:52 | LL | type Assoc: Trait<'r, Self, Q, K = const { loop {} }> | ^ its type must not depend on `Self` @@ -101,7 +101,7 @@ LL | type Assoc: Trait<'r, Self, Q, K = const { loop {} }> = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: the type of the associated constant `K` must not depend on generic parameters - --> $DIR/param-in-ty.rs:53:52 + --> $DIR/param-in-ty.rs:51:52 | LL | type Assoc: Trait<'r, Self, Q, K = const { loop {} }> | - ^ its type must not depend on the const parameter `Q` diff --git a/tests/ui/const-generics/associated-const-bindings/projection-unspecified-but-bounded.rs b/tests/ui/const-generics/associated-const-bindings/projection-unspecified-but-bounded.rs index 8a78b26dbc5dc..dbfbba9b7cbd1 100644 --- a/tests/ui/const-generics/associated-const-bindings/projection-unspecified-but-bounded.rs +++ b/tests/ui/const-generics/associated-const-bindings/projection-unspecified-but-bounded.rs @@ -4,8 +4,7 @@ // Issue 110549 pub trait TraitWAssocConst { - #[type_const] - const A: usize; + type const A: usize; } fn foo>() {} diff --git a/tests/ui/const-generics/associated-const-bindings/projection-unspecified-but-bounded.stderr b/tests/ui/const-generics/associated-const-bindings/projection-unspecified-but-bounded.stderr index 232b15b7e981a..11490a044091d 100644 --- a/tests/ui/const-generics/associated-const-bindings/projection-unspecified-but-bounded.stderr +++ b/tests/ui/const-generics/associated-const-bindings/projection-unspecified-but-bounded.stderr @@ -1,5 +1,5 @@ error[E0271]: type mismatch resolving `::A == 32` - --> $DIR/projection-unspecified-but-bounded.rs:14:11 + --> $DIR/projection-unspecified-but-bounded.rs:13:11 | LL | foo::(); | ^ expected `32`, found `::A` @@ -7,7 +7,7 @@ LL | foo::(); = note: expected constant `32` found constant `::A` note: required by a bound in `foo` - --> $DIR/projection-unspecified-but-bounded.rs:11:28 + --> $DIR/projection-unspecified-but-bounded.rs:10:28 | LL | fn foo>() {} | ^^^^^^ required by this bound in `foo` diff --git a/tests/ui/const-generics/associated-const-bindings/supertraits.rs b/tests/ui/const-generics/associated-const-bindings/supertraits.rs index a5f8859c92bd2..cdceb682a8543 100644 --- a/tests/ui/const-generics/associated-const-bindings/supertraits.rs +++ b/tests/ui/const-generics/associated-const-bindings/supertraits.rs @@ -16,8 +16,7 @@ use std::marker::ConstParamTy_; trait Trait: SuperTrait {} trait SuperTrait: SuperSuperTrait {} trait SuperSuperTrait { - #[type_const] - const K: T; + type const K: T; } fn take(_: impl Trait) {} diff --git a/tests/ui/const-generics/associated-const-bindings/using-fnptr-as-type_const.rs b/tests/ui/const-generics/associated-const-bindings/using-fnptr-as-type_const.rs index 5c494031d4fa5..95f81323acf46 100644 --- a/tests/ui/const-generics/associated-const-bindings/using-fnptr-as-type_const.rs +++ b/tests/ui/const-generics/associated-const-bindings/using-fnptr-as-type_const.rs @@ -4,8 +4,7 @@ #![feature(min_generic_const_args)] trait Trait { - #[type_const] - const F: fn(); + type const F: fn(); //~^ ERROR using function pointers as const generic parameters is forbidden } diff --git a/tests/ui/const-generics/associated-const-bindings/using-fnptr-as-type_const.stderr b/tests/ui/const-generics/associated-const-bindings/using-fnptr-as-type_const.stderr index 09d1063081fe1..333dd1b89e9bc 100644 --- a/tests/ui/const-generics/associated-const-bindings/using-fnptr-as-type_const.stderr +++ b/tests/ui/const-generics/associated-const-bindings/using-fnptr-as-type_const.stderr @@ -1,8 +1,8 @@ error[E0741]: using function pointers as const generic parameters is forbidden - --> $DIR/using-fnptr-as-type_const.rs:8:14 + --> $DIR/using-fnptr-as-type_const.rs:7:19 | -LL | const F: fn(); - | ^^^^ +LL | type const F: fn(); + | ^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/generic_const_exprs/auxiliary/non_local_type_const.rs b/tests/ui/const-generics/generic_const_exprs/auxiliary/non_local_type_const.rs index 6ec1071461c54..8cd46783d4fde 100644 --- a/tests/ui/const-generics/generic_const_exprs/auxiliary/non_local_type_const.rs +++ b/tests/ui/const-generics/generic_const_exprs/auxiliary/non_local_type_const.rs @@ -1,5 +1,4 @@ #![feature(min_generic_const_args)] #![allow(incomplete_features)] -#[type_const] -pub const NON_LOCAL_CONST: char = 'a'; +pub type const NON_LOCAL_CONST: char = 'a'; diff --git a/tests/ui/const-generics/mgca/adt_expr_arg_simple.rs b/tests/ui/const-generics/mgca/adt_expr_arg_simple.rs index 16479ba3f64f8..8470b933cadd2 100644 --- a/tests/ui/const-generics/mgca/adt_expr_arg_simple.rs +++ b/tests/ui/const-generics/mgca/adt_expr_arg_simple.rs @@ -10,9 +10,9 @@ use Option::Some; fn foo>() {} + trait Trait { - #[type_const] - const ASSOC: u32; + type const ASSOC: u32; } fn bar() { diff --git a/tests/ui/const-generics/mgca/adt_expr_arg_tuple_expr_fail.rs b/tests/ui/const-generics/mgca/adt_expr_arg_tuple_expr_fail.rs index 5f0d6c924bd12..68f999fb76fa6 100644 --- a/tests/ui/const-generics/mgca/adt_expr_arg_tuple_expr_fail.rs +++ b/tests/ui/const-generics/mgca/adt_expr_arg_tuple_expr_fail.rs @@ -1,9 +1,9 @@ #![feature(min_generic_const_args, adt_const_params, unsized_const_params)] #![expect(incomplete_features)] + trait Trait { - #[type_const] - const ASSOC: usize; + type const ASSOC: usize; } fn takes_tuple() {} diff --git a/tests/ui/const-generics/mgca/adt_expr_infers_from_value.rs b/tests/ui/const-generics/mgca/adt_expr_infers_from_value.rs index d3c9b655a9e5e..5def3cbb829b2 100644 --- a/tests/ui/const-generics/mgca/adt_expr_infers_from_value.rs +++ b/tests/ui/const-generics/mgca/adt_expr_infers_from_value.rs @@ -16,8 +16,7 @@ struct Foo { field: T, } -#[type_const] -const WRAP: Foo = { Foo:: { +type const WRAP: Foo = { Foo:: { field: N, } }; diff --git a/tests/ui/const-generics/mgca/array-expr-with-assoc-const.rs b/tests/ui/const-generics/mgca/array-expr-with-assoc-const.rs index 47ecbfa6b7e15..7401181962bb8 100644 --- a/tests/ui/const-generics/mgca/array-expr-with-assoc-const.rs +++ b/tests/ui/const-generics/mgca/array-expr-with-assoc-const.rs @@ -6,8 +6,7 @@ fn takes_array() {} trait Trait { - #[type_const] - const ASSOC: u32; + type const ASSOC: u32; } fn generic_caller() { diff --git a/tests/ui/const-generics/mgca/assoc-const-projection-in-bound.rs b/tests/ui/const-generics/mgca/assoc-const-projection-in-bound.rs index 460e143594832..13b2e031b118b 100644 --- a/tests/ui/const-generics/mgca/assoc-const-projection-in-bound.rs +++ b/tests/ui/const-generics/mgca/assoc-const-projection-in-bound.rs @@ -7,13 +7,11 @@ trait Abc {} trait A { - #[type_const] - const VALUE: usize; + type const VALUE: usize; } impl A for T { - #[type_const] - const VALUE: usize = 0; + type const VALUE: usize = 0; } trait S {} diff --git a/tests/ui/const-generics/mgca/assoc-const-without-type_const.rs b/tests/ui/const-generics/mgca/assoc-const-without-type_const.rs index a11314c11aaee..ca7299e7690b9 100644 --- a/tests/ui/const-generics/mgca/assoc-const-without-type_const.rs +++ b/tests/ui/const-generics/mgca/assoc-const-without-type_const.rs @@ -6,9 +6,9 @@ pub trait Tr { } fn mk_array(_x: T) -> [(); T::SIZE] { - //~^ ERROR type_const + //~^ ERROR: use of `const` in the type system not defined as `type const` [(); T::SIZE] - //~^ ERROR type_const + //~^ ERROR: use of `const` in the type system not defined as `type const` } fn main() {} diff --git a/tests/ui/const-generics/mgca/assoc-const-without-type_const.stderr b/tests/ui/const-generics/mgca/assoc-const-without-type_const.stderr index e06850747ff3a..759a40cc06759 100644 --- a/tests/ui/const-generics/mgca/assoc-const-without-type_const.stderr +++ b/tests/ui/const-generics/mgca/assoc-const-without-type_const.stderr @@ -1,26 +1,20 @@ -error: use of `const` in the type system without `#[type_const]` +error: use of `const` in the type system not defined as `type const` --> $DIR/assoc-const-without-type_const.rs:8:35 | +LL | const SIZE: usize; + | - help: add `type` before `const` for `Tr::SIZE`: `type` +... LL | fn mk_array(_x: T) -> [(); T::SIZE] { | ^^^^^^^ - | -help: add `#[type_const]` attribute to `Tr::SIZE` - | -LL + #[type_const] -LL | const SIZE: usize; - | -error: use of `const` in the type system without `#[type_const]` +error: use of `const` in the type system not defined as `type const` --> $DIR/assoc-const-without-type_const.rs:10:10 | +LL | const SIZE: usize; + | - help: add `type` before `const` for `Tr::SIZE`: `type` +... LL | [(); T::SIZE] | ^^^^^^^ - | -help: add `#[type_const]` attribute to `Tr::SIZE` - | -LL + #[type_const] -LL | const SIZE: usize; - | error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/assoc-const.rs b/tests/ui/const-generics/mgca/assoc-const.rs index fb5b4308a7f89..c49b84edba108 100644 --- a/tests/ui/const-generics/mgca/assoc-const.rs +++ b/tests/ui/const-generics/mgca/assoc-const.rs @@ -4,8 +4,7 @@ #![allow(incomplete_features)] pub trait Tr { - #[type_const] - const SIZE: usize; + type const SIZE: usize; } fn mk_array>(_x: T) -> [(); >::SIZE] { diff --git a/tests/ui/const-generics/mgca/bad-type_const-syntax.rs b/tests/ui/const-generics/mgca/bad-type_const-syntax.rs index bb5bdb8d7c4cf..81be1ca4eb882 100644 --- a/tests/ui/const-generics/mgca/bad-type_const-syntax.rs +++ b/tests/ui/const-generics/mgca/bad-type_const-syntax.rs @@ -1,16 +1,16 @@ trait Tr { - #[type_const()] - //~^ ERROR malformed - //~| ERROR experimental - const N: usize; + type const N: usize; + //~^ ERROR: `type const` syntax is experimental [E0658] + //~| ERROR: associated `type const` are unstable [E0658] } struct S; impl Tr for S { - #[type_const] - //~^ ERROR experimental - const N: usize = 0; + + type const N: usize = 0; + //~^ ERROR: `type const` syntax is experimental [E0658] + //~| ERROR: associated `type const` are unstable [E0658] } fn main() {} diff --git a/tests/ui/const-generics/mgca/bad-type_const-syntax.stderr b/tests/ui/const-generics/mgca/bad-type_const-syntax.stderr index df442c22241b9..7bb2adf27199c 100644 --- a/tests/ui/const-generics/mgca/bad-type_const-syntax.stderr +++ b/tests/ui/const-generics/mgca/bad-type_const-syntax.stderr @@ -1,33 +1,43 @@ -error[E0658]: the `#[type_const]` attribute is an experimental feature +error[E0658]: `type const` syntax is experimental --> $DIR/bad-type_const-syntax.rs:2:5 | -LL | #[type_const()] - | ^^^^^^^^^^^^^^^ +LL | type const N: usize; + | ^^^^^^^^^^ | = note: see issue #132980 for more information = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error[E0658]: the `#[type_const]` attribute is an experimental feature +error[E0658]: `type const` syntax is experimental --> $DIR/bad-type_const-syntax.rs:11:5 | -LL | #[type_const] - | ^^^^^^^^^^^^^ +LL | type const N: usize = 0; + | ^^^^^^^^^^ | = note: see issue #132980 for more information = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error[E0565]: malformed `type_const` attribute input +error[E0658]: associated `type const` are unstable --> $DIR/bad-type_const-syntax.rs:2:5 | -LL | #[type_const()] - | ^^^^^^^^^^^^--^ - | | | - | | didn't expect any arguments here - | help: must be of the form: `#[type_const]` +LL | type const N: usize; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #132980 for more information + = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: associated `type const` are unstable + --> $DIR/bad-type_const-syntax.rs:11:5 + | +LL | type const N: usize = 0; + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #132980 for more information + = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0565, E0658. -For more information about an error, try `rustc --explain E0565`. +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/const-generics/mgca/concrete-expr-with-generics-in-env.rs b/tests/ui/const-generics/mgca/concrete-expr-with-generics-in-env.rs index 37f9c31feaa55..69d16993a7e02 100644 --- a/tests/ui/const-generics/mgca/concrete-expr-with-generics-in-env.rs +++ b/tests/ui/const-generics/mgca/concrete-expr-with-generics-in-env.rs @@ -4,23 +4,17 @@ #![feature(min_generic_const_args, generic_const_items)] pub trait Tr { - #[type_const] - const N1: usize; - #[type_const] - const N2: usize; - #[type_const] - const N3: usize; + type const N1: usize; + type const N2: usize; + type const N3: usize; } pub struct S; impl Tr for S { - #[type_const] - const N1: usize = 0; - #[type_const] - const N2: usize = 1; - #[type_const] - const N3: usize = 2; + type const N1: usize = 0; + type const N2: usize = 1; + type const N3: usize = 2; } fn main() {} diff --git a/tests/ui/const-generics/mgca/const-arg-coherence-conflicting-methods.rs b/tests/ui/const-generics/mgca/const-arg-coherence-conflicting-methods.rs index efab014894044..9d475f8224fa5 100644 --- a/tests/ui/const-generics/mgca/const-arg-coherence-conflicting-methods.rs +++ b/tests/ui/const-generics/mgca/const-arg-coherence-conflicting-methods.rs @@ -3,8 +3,8 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] -#[type_const] -const C: usize = 0; + +type const C: usize = 0; pub struct A {} impl A { fn fun1() {} diff --git a/tests/ui/const-generics/mgca/cyclic-type-const-151251.rs b/tests/ui/const-generics/mgca/cyclic-type-const-151251.rs index 823a6d58bf471..a7e46ad877e72 100644 --- a/tests/ui/const-generics/mgca/cyclic-type-const-151251.rs +++ b/tests/ui/const-generics/mgca/cyclic-type-const-151251.rs @@ -4,8 +4,7 @@ #![feature(generic_const_exprs)] #![expect(incomplete_features)] -#[type_const] -const A: u8 = A; +type const A: u8 = A; //~^ ERROR overflow normalizing the unevaluated constant `A` fn main() {} diff --git a/tests/ui/const-generics/mgca/cyclic-type-const-151251.stderr b/tests/ui/const-generics/mgca/cyclic-type-const-151251.stderr index 1ce2af817277e..47653dd1896f7 100644 --- a/tests/ui/const-generics/mgca/cyclic-type-const-151251.stderr +++ b/tests/ui/const-generics/mgca/cyclic-type-const-151251.stderr @@ -1,8 +1,8 @@ error[E0275]: overflow normalizing the unevaluated constant `A` - --> $DIR/cyclic-type-const-151251.rs:8:1 + --> $DIR/cyclic-type-const-151251.rs:7:1 | -LL | const A: u8 = A; - | ^^^^^^^^^^^ +LL | type const A: u8 = A; + | ^^^^^^^^^^^^^^^^ | = note: in case this is a recursive type alias, consider using a struct, enum, or union instead diff --git a/tests/ui/const-generics/mgca/explicit_anon_consts.rs b/tests/ui/const-generics/mgca/explicit_anon_consts.rs index bf825a44b1c04..2b9909b43dfbb 100644 --- a/tests/ui/const-generics/mgca/explicit_anon_consts.rs +++ b/tests/ui/const-generics/mgca/explicit_anon_consts.rs @@ -34,22 +34,22 @@ fn repeats() -> [(); N] { //~^ ERROR: generic parameters may not be used in const operations } -#[type_const] -const ITEM1: usize = N; -#[type_const] -const ITEM2: usize = { N }; -#[type_const] -const ITEM3: usize = const { N }; + +type const ITEM1: usize = N; + +type const ITEM2: usize = { N }; + +type const ITEM3: usize = const { N }; //~^ ERROR: generic parameters may not be used in const operations -#[type_const] -const ITEM4: usize = { 1 + 1 }; + +type const ITEM4: usize = { 1 + 1 }; //~^ ERROR: complex const arguments must be placed inside of a `const` block -#[type_const] -const ITEM5: usize = const { 1 + 1}; + +type const ITEM5: usize = const { 1 + 1}; trait Trait { - #[type_const] - const ASSOC: usize; + + type const ASSOC: usize; } fn ace_bounds< diff --git a/tests/ui/const-generics/mgca/explicit_anon_consts.stderr b/tests/ui/const-generics/mgca/explicit_anon_consts.stderr index 1251f4415171d..714d7a804d111 100644 --- a/tests/ui/const-generics/mgca/explicit_anon_consts.stderr +++ b/tests/ui/const-generics/mgca/explicit_anon_consts.stderr @@ -17,10 +17,10 @@ LL | let _4 = [(); 1 + 1]; | ^^^^^ error: complex const arguments must be placed inside of a `const` block - --> $DIR/explicit_anon_consts.rs:45:38 + --> $DIR/explicit_anon_consts.rs:45:43 | -LL | const ITEM4: usize = { 1 + 1 }; - | ^^^^^^^^^ +LL | type const ITEM4: usize = { 1 + 1 }; + | ^^^^^^^^^ error: complex const arguments must be placed inside of a `const` block --> $DIR/explicit_anon_consts.rs:62:23 @@ -35,10 +35,10 @@ LL | struct Default4; | ^^^^^^^^^ error: generic parameters may not be used in const operations - --> $DIR/explicit_anon_consts.rs:42:46 + --> $DIR/explicit_anon_consts.rs:42:51 | -LL | const ITEM3: usize = const { N }; - | ^ +LL | type const ITEM3: usize = const { N }; + | ^ | = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items diff --git a/tests/ui/const-generics/mgca/explicit_anon_consts_literals_hack.rs b/tests/ui/const-generics/mgca/explicit_anon_consts_literals_hack.rs index 8131a5b723436..be853bb87a371 100644 --- a/tests/ui/const-generics/mgca/explicit_anon_consts_literals_hack.rs +++ b/tests/ui/const-generics/mgca/explicit_anon_consts_literals_hack.rs @@ -4,8 +4,7 @@ #![expect(incomplete_features)] trait Trait { - #[type_const] - const ASSOC: isize; + type const ASSOC: isize; } fn ace>() {} diff --git a/tests/ui/const-generics/mgca/multi_braced_direct_const_args.rs b/tests/ui/const-generics/mgca/multi_braced_direct_const_args.rs index 31f54abf31ef2..bbe624269672d 100644 --- a/tests/ui/const-generics/mgca/multi_braced_direct_const_args.rs +++ b/tests/ui/const-generics/mgca/multi_braced_direct_const_args.rs @@ -6,8 +6,7 @@ struct Foo; trait Trait { - #[type_const] - const ASSOC: usize; + type const ASSOC: usize; } type Arr = [(); {{{ N }}}]; diff --git a/tests/ui/const-generics/mgca/non-local-const-without-type_const.rs b/tests/ui/const-generics/mgca/non-local-const-without-type_const.rs index e98cbdf8e6175..6f1235269dfc8 100644 --- a/tests/ui/const-generics/mgca/non-local-const-without-type_const.rs +++ b/tests/ui/const-generics/mgca/non-local-const-without-type_const.rs @@ -5,5 +5,5 @@ extern crate non_local_const; fn main() { let x = [(); non_local_const::N]; - //~^ ERROR use of `const` in the type system without `#[type_const]` + //~^ ERROR: use of `const` in the type system not defined as `type const` } diff --git a/tests/ui/const-generics/mgca/non-local-const-without-type_const.stderr b/tests/ui/const-generics/mgca/non-local-const-without-type_const.stderr index 671dfa5fbb9eb..3c10b78eb3e17 100644 --- a/tests/ui/const-generics/mgca/non-local-const-without-type_const.stderr +++ b/tests/ui/const-generics/mgca/non-local-const-without-type_const.stderr @@ -1,10 +1,10 @@ -error: use of `const` in the type system without `#[type_const]` +error: use of `const` in the type system not defined as `type const` --> $DIR/non-local-const-without-type_const.rs:7:18 | LL | let x = [(); non_local_const::N]; | ^^^^^^^^^^^^^^^^^^ | - = note: only consts marked with `#[type_const]` may be used in types + = note: only consts marked defined as `type const` may be used in types error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/mgca/printing_valtrees_supports_non_values.rs b/tests/ui/const-generics/mgca/printing_valtrees_supports_non_values.rs index 819323d9cbec6..16ed24a7b2870 100644 --- a/tests/ui/const-generics/mgca/printing_valtrees_supports_non_values.rs +++ b/tests/ui/const-generics/mgca/printing_valtrees_supports_non_values.rs @@ -8,8 +8,8 @@ struct Foo; trait Trait { - #[type_const] - const ASSOC: u32; + + type const ASSOC: u32; } fn foo() {} diff --git a/tests/ui/const-generics/mgca/projection-error.rs b/tests/ui/const-generics/mgca/projection-error.rs index edb6db0980844..d3bd520297e1c 100644 --- a/tests/ui/const-generics/mgca/projection-error.rs +++ b/tests/ui/const-generics/mgca/projection-error.rs @@ -5,10 +5,8 @@ // containing erroneous types normalizes to a const error instead of // a type error. - pub trait Tr { - #[type_const] - const SIZE: usize; + type const SIZE: usize; } fn mk_array(_x: T) -> [(); >::SIZE] {} diff --git a/tests/ui/const-generics/mgca/projection-error.stderr b/tests/ui/const-generics/mgca/projection-error.stderr index 9357600a5e113..94e6bbcdd87f9 100644 --- a/tests/ui/const-generics/mgca/projection-error.stderr +++ b/tests/ui/const-generics/mgca/projection-error.stderr @@ -1,5 +1,5 @@ error[E0425]: cannot find type `T` in this scope - --> $DIR/projection-error.rs:14:17 + --> $DIR/projection-error.rs:12:17 | LL | pub trait Tr { | --------------- similarly named trait `Tr` defined here @@ -17,7 +17,7 @@ LL | fn mk_array(_x: T) -> [(); >::SIZE] {} | +++ error[E0425]: cannot find type `T` in this scope - --> $DIR/projection-error.rs:14:29 + --> $DIR/projection-error.rs:12:29 | LL | pub trait Tr { | --------------- similarly named trait `Tr` defined here diff --git a/tests/ui/const-generics/mgca/tuple_ctor_arg_simple.rs b/tests/ui/const-generics/mgca/tuple_ctor_arg_simple.rs index a5b3d3d0d5b6a..e946441453d82 100644 --- a/tests/ui/const-generics/mgca/tuple_ctor_arg_simple.rs +++ b/tests/ui/const-generics/mgca/tuple_ctor_arg_simple.rs @@ -15,8 +15,7 @@ enum MyEnum { } trait Trait { - #[type_const] - const ASSOC: u32; + type const ASSOC: u32; } fn with_point() -> Point { diff --git a/tests/ui/const-generics/mgca/tuple_ctor_erroneous.rs b/tests/ui/const-generics/mgca/tuple_ctor_erroneous.rs index ebbe097c226e8..95ee42d93d739 100644 --- a/tests/ui/const-generics/mgca/tuple_ctor_erroneous.rs +++ b/tests/ui/const-generics/mgca/tuple_ctor_erroneous.rs @@ -12,8 +12,8 @@ enum MyEnum { Unit, } -#[type_const] -const CONST_ITEM: u32 = 42; + +type const CONST_ITEM: u32 = 42; fn accepts_point() {} fn accepts_enum>() {} diff --git a/tests/ui/const-generics/mgca/tuple_expr_arg_complex.rs b/tests/ui/const-generics/mgca/tuple_expr_arg_complex.rs index e47052523fa39..5a40c1b14c2d6 100644 --- a/tests/ui/const-generics/mgca/tuple_expr_arg_complex.rs +++ b/tests/ui/const-generics/mgca/tuple_expr_arg_complex.rs @@ -2,8 +2,8 @@ #![expect(incomplete_features)] trait Trait { - #[type_const] - const ASSOC: usize; + + type const ASSOC: usize; } fn takes_tuple() {} diff --git a/tests/ui/const-generics/mgca/tuple_expr_arg_simple.rs b/tests/ui/const-generics/mgca/tuple_expr_arg_simple.rs index 3fde431e27e22..4c040bcaa9452 100644 --- a/tests/ui/const-generics/mgca/tuple_expr_arg_simple.rs +++ b/tests/ui/const-generics/mgca/tuple_expr_arg_simple.rs @@ -4,8 +4,7 @@ #![expect(incomplete_features)] trait Trait { - #[type_const] - const ASSOC: u32; + type const ASSOC: u32; } fn takes_tuple() {} diff --git a/tests/ui/const-generics/mgca/type-const-assoc-const-without-body.rs b/tests/ui/const-generics/mgca/type-const-assoc-const-without-body.rs index 158a7addd10da..e98b1ad4fe371 100644 --- a/tests/ui/const-generics/mgca/type-const-assoc-const-without-body.rs +++ b/tests/ui/const-generics/mgca/type-const-assoc-const-without-body.rs @@ -4,15 +4,13 @@ #![expect(incomplete_features)] trait Tr { - #[type_const] - const SIZE: usize; + type const SIZE: usize; } struct T; impl Tr for T { - #[type_const] - const SIZE: usize; + type const SIZE: usize; //~^ ERROR associated constant in `impl` without body } diff --git a/tests/ui/const-generics/mgca/type-const-assoc-const-without-body.stderr b/tests/ui/const-generics/mgca/type-const-assoc-const-without-body.stderr index 2db677aa0ca64..ba01456ee0404 100644 --- a/tests/ui/const-generics/mgca/type-const-assoc-const-without-body.stderr +++ b/tests/ui/const-generics/mgca/type-const-assoc-const-without-body.stderr @@ -1,10 +1,10 @@ error: associated constant in `impl` without body - --> $DIR/type-const-assoc-const-without-body.rs:15:5 + --> $DIR/type-const-assoc-const-without-body.rs:13:5 | -LL | const SIZE: usize; - | ^^^^^^^^^^^^^^^^^- - | | - | help: provide a definition for the constant: `= ;` +LL | type const SIZE: usize; + | ^^^^^^^^^^^^^^^^^^^^^^- + | | + | help: provide a definition for the constant: `= ;` error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/mgca/type-const-inherent-assoc-const-without-body.rs b/tests/ui/const-generics/mgca/type-const-inherent-assoc-const-without-body.rs index 85b2327d33515..9fa4176372951 100644 --- a/tests/ui/const-generics/mgca/type-const-inherent-assoc-const-without-body.rs +++ b/tests/ui/const-generics/mgca/type-const-inherent-assoc-const-without-body.rs @@ -4,8 +4,7 @@ #![expect(incomplete_features)] impl S { //~ ERROR cannot find type `S` in this scope - #[type_const] - const SIZE: usize; + type const SIZE: usize; //~^ ERROR associated constant in `impl` without body } diff --git a/tests/ui/const-generics/mgca/type-const-inherent-assoc-const-without-body.stderr b/tests/ui/const-generics/mgca/type-const-inherent-assoc-const-without-body.stderr index ac520a4e69469..b1e1edfa70d63 100644 --- a/tests/ui/const-generics/mgca/type-const-inherent-assoc-const-without-body.stderr +++ b/tests/ui/const-generics/mgca/type-const-inherent-assoc-const-without-body.stderr @@ -1,10 +1,10 @@ error: associated constant in `impl` without body - --> $DIR/type-const-inherent-assoc-const-without-body.rs:8:5 + --> $DIR/type-const-inherent-assoc-const-without-body.rs:7:5 | -LL | const SIZE: usize; - | ^^^^^^^^^^^^^^^^^- - | | - | help: provide a definition for the constant: `= ;` +LL | type const SIZE: usize; + | ^^^^^^^^^^^^^^^^^^^^^^- + | | + | help: provide a definition for the constant: `= ;` error[E0425]: cannot find type `S` in this scope --> $DIR/type-const-inherent-assoc-const-without-body.rs:6:6 diff --git a/tests/ui/const-generics/mgca/type-const-used-in-trait.rs b/tests/ui/const-generics/mgca/type-const-used-in-trait.rs index c98c14775a0fa..1efc65bd70183 100644 --- a/tests/ui/const-generics/mgca/type-const-used-in-trait.rs +++ b/tests/ui/const-generics/mgca/type-const-used-in-trait.rs @@ -3,8 +3,7 @@ #![feature(min_generic_const_args)] #![expect(incomplete_features)] -#[type_const] -const N: usize = 2; +type const N: usize = 2; trait CollectArray { fn inner_array(&mut self) -> [A; N]; diff --git a/tests/ui/const-generics/mgca/type_const-array-return.rs b/tests/ui/const-generics/mgca/type_const-array-return.rs index 5375e4fded6d7..43db35966a45a 100644 --- a/tests/ui/const-generics/mgca/type_const-array-return.rs +++ b/tests/ui/const-generics/mgca/type_const-array-return.rs @@ -6,14 +6,12 @@ pub struct A; pub trait Array { - #[type_const] - const LEN: usize; + type const LEN: usize; fn arr() -> [u8; Self::LEN]; } impl Array for A { - #[type_const] - const LEN: usize = 4; + type const LEN: usize = 4; #[allow(unused_braces)] fn arr() -> [u8; const { Self::LEN }] { diff --git a/tests/ui/const-generics/mgca/type_const-generic-param-in-type.gate.stderr b/tests/ui/const-generics/mgca/type_const-generic-param-in-type.gate.stderr index 8a64af285da55..095f42355c77a 100644 --- a/tests/ui/const-generics/mgca/type_const-generic-param-in-type.gate.stderr +++ b/tests/ui/const-generics/mgca/type_const-generic-param-in-type.gate.stderr @@ -1,38 +1,38 @@ error: anonymous constants referencing generics are not yet supported - --> $DIR/type_const-generic-param-in-type.rs:9:53 + --> $DIR/type_const-generic-param-in-type.rs:8:58 | -LL | const FOO: [T; 0] = const { [] }; - | ^^^^^^^^^^^^ +LL | type const FOO: [T; 0] = const { [] }; + | ^^^^^^^^^^^^ error: anonymous constants referencing generics are not yet supported - --> $DIR/type_const-generic-param-in-type.rs:14:38 + --> $DIR/type_const-generic-param-in-type.rs:12:43 | -LL | const BAR: [(); N] = const { [] }; - | ^^^^^^^^^^^^ +LL | type const BAR: [(); N] = const { [] }; + | ^^^^^^^^^^^^ error: anonymous constants with lifetimes in their type are not yet supported - --> $DIR/type_const-generic-param-in-type.rs:19:30 + --> $DIR/type_const-generic-param-in-type.rs:16:35 | -LL | const BAZ<'a>: [&'a (); 0] = const { [] }; - | ^^^^^^^^^^^^ +LL | type const BAZ<'a>: [&'a (); 0] = const { [] }; + | ^^^^^^^^^^^^ error: anonymous constants referencing generics are not yet supported - --> $DIR/type_const-generic-param-in-type.rs:39:59 + --> $DIR/type_const-generic-param-in-type.rs:32:64 | -LL | const ASSOC: [T; 0] = const { [] }; - | ^^^^^^^^^^^^ +LL | type const ASSOC: [T; 0] = const { [] }; + | ^^^^^^^^^^^^ error: anonymous constants referencing generics are not yet supported - --> $DIR/type_const-generic-param-in-type.rs:44:50 + --> $DIR/type_const-generic-param-in-type.rs:36:55 | -LL | const ASSOC_CONST: [(); N] = const { [] }; - | ^^^^^^^^^^^^ +LL | type const ASSOC_CONST: [(); N] = const { [] }; + | ^^^^^^^^^^^^ error: anonymous constants with lifetimes in their type are not yet supported - --> $DIR/type_const-generic-param-in-type.rs:49:39 + --> $DIR/type_const-generic-param-in-type.rs:40:44 | -LL | const ASSOC_LT<'a>: [&'a (); 0] = const { [] }; - | ^^^^^^^^^^^^ +LL | type const ASSOC_LT<'a>: [&'a (); 0] = const { [] }; + | ^^^^^^^^^^^^ error: aborting due to 6 previous errors diff --git a/tests/ui/const-generics/mgca/type_const-generic-param-in-type.nogate.stderr b/tests/ui/const-generics/mgca/type_const-generic-param-in-type.nogate.stderr index 14ae276324ade..b18bd678973a3 100644 --- a/tests/ui/const-generics/mgca/type_const-generic-param-in-type.nogate.stderr +++ b/tests/ui/const-generics/mgca/type_const-generic-param-in-type.nogate.stderr @@ -1,56 +1,56 @@ error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/type_const-generic-param-in-type.rs:9:45 + --> $DIR/type_const-generic-param-in-type.rs:8:50 | -LL | const FOO: [T; 0] = const { [] }; - | ^ the type must not depend on the parameter `T` +LL | type const FOO: [T; 0] = const { [] }; + | ^ the type must not depend on the parameter `T` error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/type_const-generic-param-in-type.rs:14:33 + --> $DIR/type_const-generic-param-in-type.rs:12:38 | -LL | const BAR: [(); N] = const { [] }; - | ^ the type must not depend on the parameter `N` +LL | type const BAR: [(); N] = const { [] }; + | ^ the type must not depend on the parameter `N` error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/type_const-generic-param-in-type.rs:19:18 + --> $DIR/type_const-generic-param-in-type.rs:16:23 | -LL | const BAZ<'a>: [&'a (); 0] = const { [] }; - | ^^ the type must not depend on the parameter `'a` +LL | type const BAZ<'a>: [&'a (); 0] = const { [] }; + | ^^ the type must not depend on the parameter `'a` error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/type_const-generic-param-in-type.rs:25:51 + --> $DIR/type_const-generic-param-in-type.rs:21:56 | -LL | const ASSOC: [T; 0]; - | ^ the type must not depend on the parameter `T` +LL | type const ASSOC: [T; 0]; + | ^ the type must not depend on the parameter `T` error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/type_const-generic-param-in-type.rs:29:45 + --> $DIR/type_const-generic-param-in-type.rs:24:50 | -LL | const ASSOC_CONST: [(); N]; - | ^ the type must not depend on the parameter `N` +LL | type const ASSOC_CONST: [(); N]; + | ^ the type must not depend on the parameter `N` error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/type_const-generic-param-in-type.rs:33:27 + --> $DIR/type_const-generic-param-in-type.rs:27:32 | -LL | const ASSOC_LT<'a>: [&'a (); 0]; - | ^^ the type must not depend on the parameter `'a` +LL | type const ASSOC_LT<'a>: [&'a (); 0]; + | ^^ the type must not depend on the parameter `'a` error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/type_const-generic-param-in-type.rs:39:51 + --> $DIR/type_const-generic-param-in-type.rs:32:56 | -LL | const ASSOC: [T; 0] = const { [] }; - | ^ the type must not depend on the parameter `T` +LL | type const ASSOC: [T; 0] = const { [] }; + | ^ the type must not depend on the parameter `T` error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/type_const-generic-param-in-type.rs:44:45 + --> $DIR/type_const-generic-param-in-type.rs:36:50 | -LL | const ASSOC_CONST: [(); N] = const { [] }; - | ^ the type must not depend on the parameter `N` +LL | type const ASSOC_CONST: [(); N] = const { [] }; + | ^ the type must not depend on the parameter `N` error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/type_const-generic-param-in-type.rs:49:27 + --> $DIR/type_const-generic-param-in-type.rs:40:32 | -LL | const ASSOC_LT<'a>: [&'a (); 0] = const { [] }; - | ^^ the type must not depend on the parameter `'a` +LL | type const ASSOC_LT<'a>: [&'a (); 0] = const { [] }; + | ^^ the type must not depend on the parameter `'a` error: aborting due to 9 previous errors diff --git a/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs b/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs index f1a4aba9bceed..72ae464822e4f 100644 --- a/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs +++ b/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs @@ -5,48 +5,39 @@ #![feature(adt_const_params, unsized_const_params, min_generic_const_args, generic_const_items)] #![cfg_attr(gate, feature(generic_const_parameter_types))] -#[type_const] -const FOO: [T; 0] = const { [] }; +type const FOO: [T; 0] = const { [] }; //[nogate]~^ ERROR the type of const parameters must not depend on other generic parameters //[gate]~^^ ERROR anonymous constants referencing generics are not yet supported -#[type_const] -const BAR: [(); N] = const { [] }; +type const BAR: [(); N] = const { [] }; //[nogate]~^ ERROR the type of const parameters must not depend on other generic parameters //[gate]~^^ ERROR anonymous constants referencing generics are not yet supported -#[type_const] -const BAZ<'a>: [&'a (); 0] = const { [] }; +type const BAZ<'a>: [&'a (); 0] = const { [] }; //[nogate]~^ ERROR the type of const parameters must not depend on other generic parameters //[gate]~^^ ERROR anonymous constants with lifetimes in their type are not yet supported trait Tr { - #[type_const] - const ASSOC: [T; 0]; + type const ASSOC: [T; 0]; //[nogate]~^ ERROR the type of const parameters must not depend on other generic parameters - #[type_const] - const ASSOC_CONST: [(); N]; + type const ASSOC_CONST: [(); N]; //[nogate]~^ ERROR the type of const parameters must not depend on other generic parameters - #[type_const] - const ASSOC_LT<'a>: [&'a (); 0]; + type const ASSOC_LT<'a>: [&'a (); 0]; //[nogate]~^ ERROR the type of const parameters must not depend on other generic parameters } impl Tr for () { - #[type_const] - const ASSOC: [T; 0] = const { [] }; + type const ASSOC: [T; 0] = const { [] }; //[nogate]~^ ERROR the type of const parameters must not depend on other generic parameters //[gate]~^^ ERROR anonymous constants referencing generics are not yet supported - #[type_const] - const ASSOC_CONST: [(); N] = const { [] }; + type const ASSOC_CONST: [(); N] = const { [] }; //[nogate]~^ ERROR the type of const parameters must not depend on other generic parameters //[gate]~^^ ERROR anonymous constants referencing generics are not yet supported - #[type_const] - const ASSOC_LT<'a>: [&'a (); 0] = const { [] }; + type const ASSOC_LT<'a>: [&'a (); 0] = const { [] }; //[nogate]~^ ERROR the type of const parameters must not depend on other generic parameters //[gate]~^^ ERROR anonymous constants with lifetimes in their type are not yet supported } diff --git a/tests/ui/const-generics/mgca/type_const-incemental-compile.rs b/tests/ui/const-generics/mgca/type_const-incemental-compile.rs index 60e6968363db3..7094d89d50622 100644 --- a/tests/ui/const-generics/mgca/type_const-incemental-compile.rs +++ b/tests/ui/const-generics/mgca/type_const-incemental-compile.rs @@ -6,6 +6,5 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] -#[type_const] -const TYPE_CONST: usize = 0; +type const TYPE_CONST: usize = 0; fn main() {} diff --git a/tests/ui/const-generics/mgca/type_const-inherent-const-omitted-type.rs b/tests/ui/const-generics/mgca/type_const-inherent-const-omitted-type.rs index b2c7340980091..3262e79478bdb 100644 --- a/tests/ui/const-generics/mgca/type_const-inherent-const-omitted-type.rs +++ b/tests/ui/const-generics/mgca/type_const-inherent-const-omitted-type.rs @@ -4,8 +4,7 @@ struct A; impl A { - #[type_const] - const B = 4; + type const B = 4; //~^ ERROR: missing type for `const` item } diff --git a/tests/ui/const-generics/mgca/type_const-inherent-const-omitted-type.stderr b/tests/ui/const-generics/mgca/type_const-inherent-const-omitted-type.stderr index b44e47cd7e611..77e54ab2f2e93 100644 --- a/tests/ui/const-generics/mgca/type_const-inherent-const-omitted-type.stderr +++ b/tests/ui/const-generics/mgca/type_const-inherent-const-omitted-type.stderr @@ -1,13 +1,13 @@ error: missing type for `const` item - --> $DIR/type_const-inherent-const-omitted-type.rs:8:12 + --> $DIR/type_const-inherent-const-omitted-type.rs:7:17 | -LL | const B = 4; - | ^ +LL | type const B = 4; + | ^ | help: provide a type for the item | -LL | const B: = 4; - | ++++++++ +LL | type const B: = 4; + | ++++++++ error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/mgca/type_const-mismatched-types.rs b/tests/ui/const-generics/mgca/type_const-mismatched-types.rs index 8d2eae71d330d..460c5d7b21998 100644 --- a/tests/ui/const-generics/mgca/type_const-mismatched-types.rs +++ b/tests/ui/const-generics/mgca/type_const-mismatched-types.rs @@ -1,22 +1,18 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] -#[type_const] -const FREE: u32 = 5_usize; +type const FREE: u32 = 5_usize; //~^ ERROR mismatched types -#[type_const] -const FREE2: isize = FREE; +type const FREE2: isize = FREE; //~^ ERROR the constant `5` is not of type `isize` trait Tr { - #[type_const] - const N: usize; + type const N: usize; } impl Tr for () { - #[type_const] - const N: usize = false; + type const N: usize = false; //~^ ERROR mismatched types } diff --git a/tests/ui/const-generics/mgca/type_const-mismatched-types.stderr b/tests/ui/const-generics/mgca/type_const-mismatched-types.stderr index 4029bb7b6bff2..152dd9ec0cca1 100644 --- a/tests/ui/const-generics/mgca/type_const-mismatched-types.stderr +++ b/tests/ui/const-generics/mgca/type_const-mismatched-types.stderr @@ -1,26 +1,26 @@ error: the constant `5` is not of type `isize` - --> $DIR/type_const-mismatched-types.rs:9:1 + --> $DIR/type_const-mismatched-types.rs:7:1 | -LL | const FREE2: isize = FREE; - | ^^^^^^^^^^^^^^^^^^ expected `isize`, found `u32` +LL | type const FREE2: isize = FREE; + | ^^^^^^^^^^^^^^^^^^^^^^^ expected `isize`, found `u32` error[E0308]: mismatched types - --> $DIR/type_const-mismatched-types.rs:5:19 + --> $DIR/type_const-mismatched-types.rs:4:24 | -LL | const FREE: u32 = 5_usize; - | ^^^^^^^ expected `u32`, found `usize` +LL | type const FREE: u32 = 5_usize; + | ^^^^^^^ expected `u32`, found `usize` | help: change the type of the numeric literal from `usize` to `u32` | -LL - const FREE: u32 = 5_usize; -LL + const FREE: u32 = 5_u32; +LL - type const FREE: u32 = 5_usize; +LL + type const FREE: u32 = 5_u32; | error[E0308]: mismatched types - --> $DIR/type_const-mismatched-types.rs:19:22 + --> $DIR/type_const-mismatched-types.rs:15:27 | -LL | const N: usize = false; - | ^^^^^ expected `usize`, found `bool` +LL | type const N: usize = false; + | ^^^^^ expected `usize`, found `bool` error: aborting due to 3 previous errors diff --git a/tests/ui/const-generics/mgca/type_const-not-constparamty.rs b/tests/ui/const-generics/mgca/type_const-not-constparamty.rs index 11db82187b847..b78bb4ca599d5 100644 --- a/tests/ui/const-generics/mgca/type_const-not-constparamty.rs +++ b/tests/ui/const-generics/mgca/type_const-not-constparamty.rs @@ -5,21 +5,18 @@ struct S; // FIXME(mgca): need support for ctors without anon const // (we use a const-block to trigger an anon const here) -#[type_const] -const FREE: S = const { S }; +type const FREE: S = const { S }; //~^ ERROR `S` must implement `ConstParamTy` to be used as the type of a const generic parameter trait Tr { - #[type_const] - const N: S; + type const N: S; //~^ ERROR `S` must implement `ConstParamTy` to be used as the type of a const generic parameter } impl Tr for S { // FIXME(mgca): need support for ctors without anon const // (we use a const-block to trigger an anon const here) - #[type_const] - const N: S = const { S }; + type const N: S = const { S }; //~^ ERROR `S` must implement `ConstParamTy` to be used as the type of a const generic parameter } diff --git a/tests/ui/const-generics/mgca/type_const-not-constparamty.stderr b/tests/ui/const-generics/mgca/type_const-not-constparamty.stderr index d07bbde1e62e7..2cbb644f2c711 100644 --- a/tests/ui/const-generics/mgca/type_const-not-constparamty.stderr +++ b/tests/ui/const-generics/mgca/type_const-not-constparamty.stderr @@ -1,8 +1,8 @@ error[E0741]: `S` must implement `ConstParamTy` to be used as the type of a const generic parameter - --> $DIR/type_const-not-constparamty.rs:9:13 + --> $DIR/type_const-not-constparamty.rs:8:18 | -LL | const FREE: S = const { S }; - | ^ +LL | type const FREE: S = const { S }; + | ^ | help: add `#[derive(ConstParamTy, PartialEq, Eq)]` to the struct | @@ -11,10 +11,10 @@ LL | struct S; | error[E0741]: `S` must implement `ConstParamTy` to be used as the type of a const generic parameter - --> $DIR/type_const-not-constparamty.rs:22:14 + --> $DIR/type_const-not-constparamty.rs:19:19 | -LL | const N: S = const { S }; - | ^ +LL | type const N: S = const { S }; + | ^ | help: add `#[derive(ConstParamTy, PartialEq, Eq)]` to the struct | @@ -23,10 +23,10 @@ LL | struct S; | error[E0741]: `S` must implement `ConstParamTy` to be used as the type of a const generic parameter - --> $DIR/type_const-not-constparamty.rs:14:14 + --> $DIR/type_const-not-constparamty.rs:12:19 | -LL | const N: S; - | ^ +LL | type const N: S; + | ^ | help: add `#[derive(ConstParamTy, PartialEq, Eq)]` to the struct | diff --git a/tests/ui/const-generics/mgca/type_const-on-generic-expr.rs b/tests/ui/const-generics/mgca/type_const-on-generic-expr.rs index ac4c4fb594193..f4cf3a4c5ce9f 100644 --- a/tests/ui/const-generics/mgca/type_const-on-generic-expr.rs +++ b/tests/ui/const-generics/mgca/type_const-on-generic-expr.rs @@ -1,11 +1,11 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args, generic_const_items)] -#[type_const] -const FREE1: usize = const { std::mem::size_of::() }; + +type const FREE1: usize = const { std::mem::size_of::() }; //~^ ERROR generic parameters may not be used in const operations -#[type_const] -const FREE2: usize = const { I + 1 }; + +type const FREE2: usize = const { I + 1 }; //~^ ERROR generic parameters may not be used in const operations fn main() {} diff --git a/tests/ui/const-generics/mgca/type_const-on-generic-expr.stderr b/tests/ui/const-generics/mgca/type_const-on-generic-expr.stderr index 8d43f2177562f..475d2cf312d64 100644 --- a/tests/ui/const-generics/mgca/type_const-on-generic-expr.stderr +++ b/tests/ui/const-generics/mgca/type_const-on-generic-expr.stderr @@ -1,16 +1,16 @@ error: generic parameters may not be used in const operations - --> $DIR/type_const-on-generic-expr.rs:5:53 + --> $DIR/type_const-on-generic-expr.rs:5:58 | -LL | const FREE1: usize = const { std::mem::size_of::() }; - | ^ +LL | type const FREE1: usize = const { std::mem::size_of::() }; + | ^ | = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items error: generic parameters may not be used in const operations - --> $DIR/type_const-on-generic-expr.rs:8:46 + --> $DIR/type_const-on-generic-expr.rs:8:51 | -LL | const FREE2: usize = const { I + 1 }; - | ^ +LL | type const FREE2: usize = const { I + 1 }; + | ^ | = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items diff --git a/tests/ui/const-generics/mgca/type_const-on-generic_expr-2.rs b/tests/ui/const-generics/mgca/type_const-on-generic_expr-2.rs index 37de4d4a4abba..2a26138d373f6 100644 --- a/tests/ui/const-generics/mgca/type_const-on-generic_expr-2.rs +++ b/tests/ui/const-generics/mgca/type_const-on-generic_expr-2.rs @@ -2,25 +2,19 @@ #![feature(min_generic_const_args, generic_const_items)] pub trait Tr { - #[type_const] - const N1: usize; - #[type_const] - const N2: usize; - #[type_const] - const N3: usize; + type const N1: usize; + type const N2: usize; + type const N3: usize; } pub struct S; impl Tr for S { - #[type_const] - const N1: usize = const { std::mem::size_of::() }; + type const N1: usize = const { std::mem::size_of::() }; //~^ ERROR generic parameters may not be used in const operations - #[type_const] - const N2: usize = const { I + 1 }; + type const N2: usize = const { I + 1 }; //~^ ERROR generic parameters may not be used in const operations - #[type_const] - const N3: usize = const { 2 & X }; + type const N3: usize = const { 2 & X }; //~^ ERROR generic parameters may not be used in const operations } diff --git a/tests/ui/const-generics/mgca/type_const-on-generic_expr-2.stderr b/tests/ui/const-generics/mgca/type_const-on-generic_expr-2.stderr index 1a6097752e335..e13d6fbcdd82f 100644 --- a/tests/ui/const-generics/mgca/type_const-on-generic_expr-2.stderr +++ b/tests/ui/const-generics/mgca/type_const-on-generic_expr-2.stderr @@ -1,24 +1,24 @@ error: generic parameters may not be used in const operations - --> $DIR/type_const-on-generic_expr-2.rs:17:54 + --> $DIR/type_const-on-generic_expr-2.rs:13:59 | -LL | const N1: usize = const { std::mem::size_of::() }; - | ^ +LL | type const N1: usize = const { std::mem::size_of::() }; + | ^ | = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items error: generic parameters may not be used in const operations - --> $DIR/type_const-on-generic_expr-2.rs:20:47 + --> $DIR/type_const-on-generic_expr-2.rs:15:52 | -LL | const N2: usize = const { I + 1 }; - | ^ +LL | type const N2: usize = const { I + 1 }; + | ^ | = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items error: generic parameters may not be used in const operations - --> $DIR/type_const-on-generic_expr-2.rs:23:35 + --> $DIR/type_const-on-generic_expr-2.rs:17:40 | -LL | const N3: usize = const { 2 & X }; - | ^ +LL | type const N3: usize = const { 2 & X }; + | ^ | = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items diff --git a/tests/ui/const-generics/mgca/type_const-only-in-impl-omitted-type.rs b/tests/ui/const-generics/mgca/type_const-only-in-impl-omitted-type.rs index ab613859aa5c6..a7ff9f0ce03f7 100644 --- a/tests/ui/const-generics/mgca/type_const-only-in-impl-omitted-type.rs +++ b/tests/ui/const-generics/mgca/type_const-only-in-impl-omitted-type.rs @@ -8,14 +8,13 @@ trait BadTr { struct GoodS; impl BadTr for GoodS { - #[type_const] - const NUM: = 84; + type const NUM: = 84; //~^ ERROR: missing type for `const` item } fn accept_bad_tr>(_x: &T) {} -//~^ ERROR use of trait associated const without `#[type_const]` +//~^ ERROR use of trait associated const not defined as `type const` fn main() { accept_bad_tr::<84, _>(&GoodS); diff --git a/tests/ui/const-generics/mgca/type_const-only-in-impl-omitted-type.stderr b/tests/ui/const-generics/mgca/type_const-only-in-impl-omitted-type.stderr index 16f312454ed28..11a60246f6a68 100644 --- a/tests/ui/const-generics/mgca/type_const-only-in-impl-omitted-type.stderr +++ b/tests/ui/const-generics/mgca/type_const-only-in-impl-omitted-type.stderr @@ -1,16 +1,16 @@ error: missing type for `const` item - --> $DIR/type_const-only-in-impl-omitted-type.rs:12:15 + --> $DIR/type_const-only-in-impl-omitted-type.rs:11:20 | -LL | const NUM: = 84; - | ^ help: provide a type for the associated constant: `usize` +LL | type const NUM: = 84; + | ^ help: provide a type for the associated constant: `usize` -error: use of trait associated const without `#[type_const]` - --> $DIR/type_const-only-in-impl-omitted-type.rs:17:43 +error: use of trait associated const not defined as `type const` + --> $DIR/type_const-only-in-impl-omitted-type.rs:16:43 | LL | fn accept_bad_tr>(_x: &T) {} | ^^^^^^^^^^^ | - = note: the declaration in the trait must be marked with `#[type_const]` + = note: the declaration in the trait must begin with `type const` not just `const` alone error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/type_const-only-in-impl.rs b/tests/ui/const-generics/mgca/type_const-only-in-impl.rs index 1887f511bd62c..e016908b3cc38 100644 --- a/tests/ui/const-generics/mgca/type_const-only-in-impl.rs +++ b/tests/ui/const-generics/mgca/type_const-only-in-impl.rs @@ -8,12 +8,11 @@ trait BadTr { struct GoodS; impl BadTr for GoodS { - #[type_const] - const NUM: usize = 84; + type const NUM: usize = 84; } fn accept_bad_tr>(_x: &T) {} -//~^ ERROR use of trait associated const without `#[type_const]` +//~^ ERROR use of trait associated const not defined as `type const` fn main() { accept_bad_tr::<84, _>(&GoodS); diff --git a/tests/ui/const-generics/mgca/type_const-only-in-impl.stderr b/tests/ui/const-generics/mgca/type_const-only-in-impl.stderr index 44632e46fb079..55d5cca6ba699 100644 --- a/tests/ui/const-generics/mgca/type_const-only-in-impl.stderr +++ b/tests/ui/const-generics/mgca/type_const-only-in-impl.stderr @@ -1,10 +1,10 @@ -error: use of trait associated const without `#[type_const]` - --> $DIR/type_const-only-in-impl.rs:15:43 +error: use of trait associated const not defined as `type const` + --> $DIR/type_const-only-in-impl.rs:14:43 | LL | fn accept_bad_tr>(_x: &T) {} | ^^^^^^^^^^^ | - = note: the declaration in the trait must be marked with `#[type_const]` + = note: the declaration in the trait must begin with `type const` not just `const` alone error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/mgca/type_const-only-in-trait.rs b/tests/ui/const-generics/mgca/type_const-only-in-trait.rs index 2ff38648206a0..1def66a1ba681 100644 --- a/tests/ui/const-generics/mgca/type_const-only-in-trait.rs +++ b/tests/ui/const-generics/mgca/type_const-only-in-trait.rs @@ -2,15 +2,14 @@ #![feature(min_generic_const_args)] trait GoodTr { - #[type_const] - const NUM: usize; + type const NUM: usize; } struct BadS; impl GoodTr for BadS { const NUM: usize = 42; - //~^ ERROR implementation of `#[type_const]` const must be marked with `#[type_const]` + //~^ ERROR implementation of a `type const` must also be marked as `type const` } fn accept_good_tr>(_x: &T) {} diff --git a/tests/ui/const-generics/mgca/type_const-only-in-trait.stderr b/tests/ui/const-generics/mgca/type_const-only-in-trait.stderr index 29f1b724960aa..f98b4d9cbbfdb 100644 --- a/tests/ui/const-generics/mgca/type_const-only-in-trait.stderr +++ b/tests/ui/const-generics/mgca/type_const-only-in-trait.stderr @@ -1,16 +1,14 @@ -error: implementation of `#[type_const]` const must be marked with `#[type_const]` - --> $DIR/type_const-only-in-trait.rs:12:5 +error: implementation of a `type const` must also be marked as `type const` + --> $DIR/type_const-only-in-trait.rs:11:5 | LL | const NUM: usize = 42; | ^^^^^^^^^^^^^^^^ | -note: trait declaration of const is marked with `#[type_const]` +note: trait declaration of const is marked as `type const` --> $DIR/type_const-only-in-trait.rs:5:5 | -LL | #[type_const] - | ^^^^^^^^^^^^^ -LL | const NUM: usize; - | ^^^^^^^^^^^^^^^^ +LL | type const NUM: usize; + | ^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/mgca/type_const-pub.rs b/tests/ui/const-generics/mgca/type_const-pub.rs index f443562394df3..70fab75901b96 100644 --- a/tests/ui/const-generics/mgca/type_const-pub.rs +++ b/tests/ui/const-generics/mgca/type_const-pub.rs @@ -5,8 +5,7 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] -#[type_const] -pub const TYPE_CONST : usize = 1; +pub type const TYPE_CONST : usize = 1; fn main() { print!("{}", TYPE_CONST) } diff --git a/tests/ui/const-generics/mgca/type_const-recursive.rs b/tests/ui/const-generics/mgca/type_const-recursive.rs index 15e49f747ed6b..ebaab51bbc3b6 100644 --- a/tests/ui/const-generics/mgca/type_const-recursive.rs +++ b/tests/ui/const-generics/mgca/type_const-recursive.rs @@ -1,8 +1,8 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] -#[type_const] -const A: u8 = A; + +type const A: u8 = A; //~^ ERROR: overflow normalizing the unevaluated constant `A` [E0275] fn main() {} diff --git a/tests/ui/const-generics/mgca/type_const-recursive.stderr b/tests/ui/const-generics/mgca/type_const-recursive.stderr index 947319ec7eda2..d21ccb22bc90b 100644 --- a/tests/ui/const-generics/mgca/type_const-recursive.stderr +++ b/tests/ui/const-generics/mgca/type_const-recursive.stderr @@ -1,8 +1,8 @@ error[E0275]: overflow normalizing the unevaluated constant `A` --> $DIR/type_const-recursive.rs:5:1 | -LL | const A: u8 = A; - | ^^^^^^^^^^^ +LL | type const A: u8 = A; + | ^^^^^^^^^^^^^^^^ | = note: in case this is a recursive type alias, consider using a struct, enum, or union instead diff --git a/tests/ui/const-generics/mgca/type_const-use.rs b/tests/ui/const-generics/mgca/type_const-use.rs index 04362cd285384..f295bf465e30c 100644 --- a/tests/ui/const-generics/mgca/type_const-use.rs +++ b/tests/ui/const-generics/mgca/type_const-use.rs @@ -3,8 +3,7 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] -#[type_const] -const CONST: usize = 1; +type const CONST: usize = 1; fn uses_const() { CONST; diff --git a/tests/ui/const-generics/mgca/unbraced_const_block_const_arg_gated.rs b/tests/ui/const-generics/mgca/unbraced_const_block_const_arg_gated.rs index c01fb47002b24..cf75b45b9ff03 100644 --- a/tests/ui/const-generics/mgca/unbraced_const_block_const_arg_gated.rs +++ b/tests/ui/const-generics/mgca/unbraced_const_block_const_arg_gated.rs @@ -32,9 +32,10 @@ fn generic() { const NON_TYPE_CONST: usize = const { 1 }; -#[type_const] -//~^ ERROR: the `#[type_const]` attribute is an experimental feature -const TYPE_CONST: usize = const { 1 }; + +type const TYPE_CONST: usize = const { 1 }; +//~^ ERROR: `type const` syntax is experimental [E0658] +//~| ERROR: top-level `type const` are unstable [E0658] static STATIC: usize = const { 1 }; diff --git a/tests/ui/const-generics/mgca/unbraced_const_block_const_arg_gated.stderr b/tests/ui/const-generics/mgca/unbraced_const_block_const_arg_gated.stderr index bbcd9f9897a63..dbcb8c56ac5b8 100644 --- a/tests/ui/const-generics/mgca/unbraced_const_block_const_arg_gated.stderr +++ b/tests/ui/const-generics/mgca/unbraced_const_block_const_arg_gated.stderr @@ -48,16 +48,26 @@ LL | generic::(); = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error[E0658]: the `#[type_const]` attribute is an experimental feature - --> $DIR/unbraced_const_block_const_arg_gated.rs:35:1 +error[E0658]: `type const` syntax is experimental + --> $DIR/unbraced_const_block_const_arg_gated.rs:36:1 | -LL | #[type_const] - | ^^^^^^^^^^^^^ +LL | type const TYPE_CONST: usize = const { 1 }; + | ^^^^^^^^^^ | = note: see issue #132980 for more information = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: aborting due to 6 previous errors +error[E0658]: top-level `type const` are unstable + --> $DIR/unbraced_const_block_const_arg_gated.rs:36:1 + | +LL | type const TYPE_CONST: usize = const { 1 }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #132980 for more information + = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 7 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/const-generics/mgca/unmarked-free-const.rs b/tests/ui/const-generics/mgca/unmarked-free-const.rs index a517231facb72..d6d9b936d95b3 100644 --- a/tests/ui/const-generics/mgca/unmarked-free-const.rs +++ b/tests/ui/const-generics/mgca/unmarked-free-const.rs @@ -7,5 +7,5 @@ const N: usize = 4; fn main() { let x = [(); N]; - //~^ ERROR use of `const` in the type system without `#[type_const]` + //~^ ERROR use of `const` in the type system not defined as `type const` } diff --git a/tests/ui/const-generics/mgca/unmarked-free-const.stderr b/tests/ui/const-generics/mgca/unmarked-free-const.stderr index 052ae39fdf67b..76875d8db0eff 100644 --- a/tests/ui/const-generics/mgca/unmarked-free-const.stderr +++ b/tests/ui/const-generics/mgca/unmarked-free-const.stderr @@ -1,14 +1,11 @@ -error: use of `const` in the type system without `#[type_const]` +error: use of `const` in the type system not defined as `type const` --> $DIR/unmarked-free-const.rs:9:18 | +LL | const N: usize = 4; + | - help: add `type` before `const` for `N`: `type` +... LL | let x = [(); N]; | ^ - | -help: add `#[type_const]` attribute to `N` - | -LL + #[type_const] -LL | const N: usize = 4; - | error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/mgca/wrong_type_const_arr_diag_trait.rs b/tests/ui/const-generics/mgca/wrong_type_const_arr_diag_trait.rs index d290619a04ff6..909189ae48752 100644 --- a/tests/ui/const-generics/mgca/wrong_type_const_arr_diag_trait.rs +++ b/tests/ui/const-generics/mgca/wrong_type_const_arr_diag_trait.rs @@ -4,8 +4,8 @@ #![allow(incomplete_features)] trait Trait { - #[type_const] - const ASSOC: u8; + + type const ASSOC: u8; } struct TakesArr; diff --git a/tests/ui/const-generics/ogca/basic-fail.rs b/tests/ui/const-generics/ogca/basic-fail.rs index 87176c7b067e6..e3db3dea3735e 100644 --- a/tests/ui/const-generics/ogca/basic-fail.rs +++ b/tests/ui/const-generics/ogca/basic-fail.rs @@ -3,17 +3,13 @@ #![feature(opaque_generic_const_args)] #![expect(incomplete_features)] -#[type_const] -const ADD1: usize = const { N + 1 }; +type const ADD1: usize = const { N + 1 }; -#[type_const] -const INC: usize = const { N + 1 }; +type const INC: usize = const { N + 1 }; -#[type_const] -const ONE: usize = ADD1::<0>; +type const ONE: usize = ADD1::<0>; -#[type_const] -const OTHER_ONE: usize = INC::<0>; +type const OTHER_ONE: usize = INC::<0>; // Not definitionally equal. const ARR: [(); ADD1::<0>] = [(); INC::<0>]; diff --git a/tests/ui/const-generics/ogca/basic-fail.stderr b/tests/ui/const-generics/ogca/basic-fail.stderr index 05de01b132c6f..ce4e8eb1471c3 100644 --- a/tests/ui/const-generics/ogca/basic-fail.stderr +++ b/tests/ui/const-generics/ogca/basic-fail.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/basic-fail.rs:19:30 + --> $DIR/basic-fail.rs:15:30 | LL | const ARR: [(); ADD1::<0>] = [(); INC::<0>]; | ^^^^^^^^^^^^^^ expected an array with a size of const { N + 1 }, found one with a size of const { N + 1 } diff --git a/tests/ui/const-generics/ogca/basic.rs b/tests/ui/const-generics/ogca/basic.rs index c8aec9ee24ce2..e736484b5c3c9 100644 --- a/tests/ui/const-generics/ogca/basic.rs +++ b/tests/ui/const-generics/ogca/basic.rs @@ -5,17 +5,13 @@ #![feature(opaque_generic_const_args)] #![expect(incomplete_features)] -#[type_const] -const ADD1: usize = const { N + 1 }; +type const ADD1: usize = const { N + 1 }; -#[type_const] -const INC: usize = ADD1::; +type const INC: usize = ADD1::; -#[type_const] -const ONE: usize = ADD1::<0>; +type const ONE: usize = ADD1::<0>; -#[type_const] -const OTHER_ONE: usize = INC::<0>; +type const OTHER_ONE: usize = INC::<0>; const ARR: [(); ADD1::<0>] = [(); INC::<0>]; diff --git a/tests/ui/const-generics/ogca/coherence-ambiguous.rs b/tests/ui/const-generics/ogca/coherence-ambiguous.rs index c8c088b1e8fc3..21efe4cfe9818 100644 --- a/tests/ui/const-generics/ogca/coherence-ambiguous.rs +++ b/tests/ui/const-generics/ogca/coherence-ambiguous.rs @@ -4,11 +4,9 @@ #![feature(generic_const_items, min_generic_const_args, opaque_generic_const_args)] #![expect(incomplete_features)] -#[type_const] -const FOO: usize = const { N + 1 }; +type const FOO: usize = const { N + 1 }; -#[type_const] -const BAR: usize = const { N + 1 }; +type const BAR: usize = const { N + 1 }; trait Trait {} diff --git a/tests/ui/const-generics/ogca/rhs-but-not-root.rs b/tests/ui/const-generics/ogca/rhs-but-not-root.rs index 4ed136f04ced3..2897b16d493f7 100644 --- a/tests/ui/const-generics/ogca/rhs-but-not-root.rs +++ b/tests/ui/const-generics/ogca/rhs-but-not-root.rs @@ -4,11 +4,9 @@ #![expect(incomplete_features)] // Anon consts must be the root of the RHS to be OGCA. -#[type_const] -const FOO: usize = ID::; +type const FOO: usize = ID::; //~^ ERROR generic parameters may not be used in const operations -#[type_const] -const ID: usize = N; +type const ID: usize = N; fn main() {} diff --git a/tests/ui/const-generics/ogca/rhs-but-not-root.stderr b/tests/ui/const-generics/ogca/rhs-but-not-root.stderr index f4fdf5fb981b7..c720b58b9bde9 100644 --- a/tests/ui/const-generics/ogca/rhs-but-not-root.stderr +++ b/tests/ui/const-generics/ogca/rhs-but-not-root.stderr @@ -1,8 +1,8 @@ error: generic parameters may not be used in const operations - --> $DIR/rhs-but-not-root.rs:8:49 + --> $DIR/rhs-but-not-root.rs:7:54 | -LL | const FOO: usize = ID::; - | ^ +LL | type const FOO: usize = ID::; + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/type-relative-path-144547.rs b/tests/ui/const-generics/type-relative-path-144547.rs index b268055e1f7d4..e3532fe635c2f 100644 --- a/tests/ui/const-generics/type-relative-path-144547.rs +++ b/tests/ui/const-generics/type-relative-path-144547.rs @@ -2,20 +2,21 @@ //@ revisions: min mgca //@[mgca] check-pass - +#![allow(incomplete_features)] +#![feature(mgca_type_const_syntax)] #![cfg_attr(mgca, feature(min_generic_const_args))] -#![cfg_attr(mgca, expect(incomplete_features))] +// FIXME(mgca) syntax is it's own feature flag before +// expansion and is also an incomplete feature. +//#![cfg_attr(mgca, expect(incomplete_features))] trait UnderlyingImpl { type InfoType: LevelInfo; type SupportedArray; } -// FIXME: cfg_attr(..., type_const) is broken (search for sym::type_const in compiler/) trait LevelInfo { #[cfg(mgca)] - #[type_const] - const SUPPORTED_SLOTS: usize; + type const SUPPORTED_SLOTS: usize; #[cfg(not(mgca))] const SUPPORTED_SLOTS: usize; @@ -25,8 +26,7 @@ struct Info; impl LevelInfo for Info { #[cfg(mgca)] - #[type_const] - const SUPPORTED_SLOTS: usize = 1; + type const SUPPORTED_SLOTS: usize = 1; #[cfg(not(mgca))] const SUPPORTED_SLOTS: usize = 1; diff --git a/tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.rs b/tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.rs new file mode 100644 index 0000000000000..eea1c798fd207 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.rs @@ -0,0 +1,17 @@ +type const FOO: u8 = 10; +//~^ ERROR `type const` syntax is experimental [E0658] +//~| ERROR top-level `type const` are unstable [E0658] + +trait Bar { + type const BAR: bool; + //~^ ERROR `type const` syntax is experimental [E0658] + //~| ERROR associated `type const` are unstable [E0658] +} + +impl Bar for bool { + type const BAR: bool = false; + //~^ ERROR `type const` syntax is experimental [E0658] + //~| ERROR associated `type const` are unstable [E0658] +} + +fn main() { } diff --git a/tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.stderr b/tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.stderr new file mode 100644 index 0000000000000..15db8b87d661e --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.stderr @@ -0,0 +1,63 @@ +error[E0658]: `type const` syntax is experimental + --> $DIR/feature-gate-mgca-type-const-syntax.rs:1:1 + | +LL | type const FOO: u8 = 10; + | ^^^^^^^^^^ + | + = note: see issue #132980 for more information + = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: `type const` syntax is experimental + --> $DIR/feature-gate-mgca-type-const-syntax.rs:6:5 + | +LL | type const BAR: bool; + | ^^^^^^^^^^ + | + = note: see issue #132980 for more information + = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: `type const` syntax is experimental + --> $DIR/feature-gate-mgca-type-const-syntax.rs:12:5 + | +LL | type const BAR: bool = false; + | ^^^^^^^^^^ + | + = note: see issue #132980 for more information + = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: top-level `type const` are unstable + --> $DIR/feature-gate-mgca-type-const-syntax.rs:1:1 + | +LL | type const FOO: u8 = 10; + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #132980 for more information + = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: associated `type const` are unstable + --> $DIR/feature-gate-mgca-type-const-syntax.rs:6:5 + | +LL | type const BAR: bool; + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #132980 for more information + = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: associated `type const` are unstable + --> $DIR/feature-gate-mgca-type-const-syntax.rs:12:5 + | +LL | type const BAR: bool = false; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #132980 for more information + = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/feature-gates/feature-gate-min-generic-const-args.rs b/tests/ui/feature-gates/feature-gate-min-generic-const-args.rs index 1cf755b2c565d..49916736d46e9 100644 --- a/tests/ui/feature-gates/feature-gate-min-generic-const-args.rs +++ b/tests/ui/feature-gates/feature-gate-min-generic-const-args.rs @@ -1,7 +1,7 @@ trait Trait { - #[type_const] - //~^ ERROR experimental - const ASSOC: usize; + type const ASSOC: usize; + //~^ ERROR: associated `type const` are unstable [E0658] + //~| ERROR: `type const` syntax is experimental [E0658] } // FIXME(mgca): add suggestion for mgca to this error diff --git a/tests/ui/feature-gates/feature-gate-min-generic-const-args.stderr b/tests/ui/feature-gates/feature-gate-min-generic-const-args.stderr index af528a3c1b790..05166b4857fb0 100644 --- a/tests/ui/feature-gates/feature-gate-min-generic-const-args.stderr +++ b/tests/ui/feature-gates/feature-gate-min-generic-const-args.stderr @@ -7,16 +7,26 @@ LL | fn foo() -> [u8; ::ASSOC] { = note: type parameters may not be used in const expressions = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions -error[E0658]: the `#[type_const]` attribute is an experimental feature +error[E0658]: `type const` syntax is experimental --> $DIR/feature-gate-min-generic-const-args.rs:2:5 | -LL | #[type_const] - | ^^^^^^^^^^^^^ +LL | type const ASSOC: usize; + | ^^^^^^^^^^ | = note: see issue #132980 for more information = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: aborting due to 2 previous errors +error[E0658]: associated `type const` are unstable + --> $DIR/feature-gate-min-generic-const-args.rs:2:5 + | +LL | type const ASSOC: usize; + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #132980 for more information + = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/feature-gates/feature-gate-opaque-generic-const-args.rs b/tests/ui/feature-gates/feature-gate-opaque-generic-const-args.rs index 0b78911158ba2..f18f59cf60bd1 100644 --- a/tests/ui/feature-gates/feature-gate-opaque-generic-const-args.rs +++ b/tests/ui/feature-gates/feature-gate-opaque-generic-const-args.rs @@ -1,8 +1,7 @@ #![feature(generic_const_items, min_generic_const_args)] #![expect(incomplete_features)] -#[type_const] -const INC: usize = const { N + 1 }; +type const INC: usize = const { N + 1 }; //~^ ERROR generic parameters may not be used in const operations //~| HELP add `#![feature(opaque_generic_const_args)]` diff --git a/tests/ui/feature-gates/feature-gate-opaque-generic-const-args.stderr b/tests/ui/feature-gates/feature-gate-opaque-generic-const-args.stderr index 1b87443aa3cba..ef771e77f6923 100644 --- a/tests/ui/feature-gates/feature-gate-opaque-generic-const-args.stderr +++ b/tests/ui/feature-gates/feature-gate-opaque-generic-const-args.stderr @@ -1,8 +1,8 @@ error: generic parameters may not be used in const operations - --> $DIR/feature-gate-opaque-generic-const-args.rs:5:44 + --> $DIR/feature-gate-opaque-generic-const-args.rs:4:49 | -LL | const INC: usize = const { N + 1 }; - | ^ +LL | type const INC: usize = const { N + 1 }; + | ^ | = help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items diff --git a/tests/ui/generic-const-items/assoc-const-bindings.rs b/tests/ui/generic-const-items/assoc-const-bindings.rs index d0301b920e272..2bf4bea16debb 100644 --- a/tests/ui/generic-const-items/assoc-const-bindings.rs +++ b/tests/ui/generic-const-items/assoc-const-bindings.rs @@ -5,19 +5,15 @@ #![allow(incomplete_features)] trait Owner { - #[type_const] - const C: u32; - #[type_const] - const K: u32; + type const C: u32; + type const K: u32; // #[type_const] // const Q: Maybe; } impl Owner for () { - #[type_const] - const C: u32 = N; - #[type_const] - const K: u32 = const { 99 + 1 }; + type const C: u32 = N; + type const K: u32 = const { 99 + 1 }; // FIXME(mgca): re-enable once we properly support ctors and generics on paths // #[type_const] // const Q: Maybe = Maybe::Nothing; diff --git a/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.rs b/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.rs index 518ed64523691..df680f30fed98 100644 --- a/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.rs +++ b/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.rs @@ -8,8 +8,7 @@ pub struct NoPin; impl Pins for NoPin {} pub trait PinA { - #[type_const] - const A: &'static () = const { &() }; + type const A: &'static () = const { &() }; } pub trait Pins {} diff --git a/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.stderr b/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.stderr index f57fd74ad99df..b719ebe0664f2 100644 --- a/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.stderr +++ b/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `Pins<_>` for type `NoPin` - --> $DIR/assoc-const-no-infer-ice-115806.rs:17:1 + --> $DIR/assoc-const-no-infer-ice-115806.rs:16:1 | LL | impl Pins for NoPin {} | --------------------------- first implementation here diff --git a/tests/ui/sanitizer/cfi/assoc-const-projection-issue-151878.rs b/tests/ui/sanitizer/cfi/assoc-const-projection-issue-151878.rs index 50530e4f0db01..6bd995449fc64 100644 --- a/tests/ui/sanitizer/cfi/assoc-const-projection-issue-151878.rs +++ b/tests/ui/sanitizer/cfi/assoc-const-projection-issue-151878.rs @@ -8,8 +8,7 @@ #![expect(incomplete_features)] trait Trait { - #[type_const] - const N: usize = 0; + type const N: usize = 0; fn process(&self, _: [u8; Self::N]) {} } diff --git a/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.rs b/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.rs index 538b0c2b1d46c..578a46c674006 100644 --- a/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.rs +++ b/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.rs @@ -5,12 +5,11 @@ //~| WARN the feature `min_generic_const_args` is incomplete pub trait IsVoid { - #[type_const] - const IS_VOID: bool; + + type const IS_VOID: bool; } impl IsVoid for T { - #[type_const] - default const IS_VOID: bool = false; + default type const IS_VOID: bool = false; } pub trait NotVoid {} diff --git a/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.stderr b/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.stderr index 6159c2ed331a9..9361f7d6222f5 100644 --- a/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.stderr +++ b/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.stderr @@ -17,7 +17,7 @@ LL | #![feature(min_generic_const_args, specialization)] = help: consider using `min_specialization` instead, which is more stable and complete error[E0119]: conflicting implementations of trait `Maybe<()>` for type `()` - --> $DIR/overlap-due-to-unsatisfied-const-bound.rs:21:1 + --> $DIR/overlap-due-to-unsatisfied-const-bound.rs:20:1 | LL | impl Maybe for T {} | ---------------------- first implementation here