diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index bc8753f4dcaa7..1d88b8ba26496 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -4035,17 +4035,9 @@ pub struct ConstItem { pub generics: Generics, pub ty: Box, pub body: Option>, - #[visitable(ignore)] - pub kind: ConstItemKind, pub define_opaque: Option>, } -#[derive(Clone, Copy, Encodable, Decodable, Debug, PartialEq, Eq)] -pub enum ConstItemKind { - Body, - TypeConst, -} - #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct ConstBlockItem { pub id: NodeId, diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index b5e28d21a2613..6b1b034058417 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -272,7 +272,6 @@ impl<'hir> LoweringContext<'_, 'hir> { generics, ty, body, - kind, define_opaque, }) => { let ident = self.lower_ident(*ident); @@ -284,7 +283,7 @@ impl<'hir> LoweringContext<'_, 'hir> { ty, ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy), ); - let rhs = this.lower_const_item_rhs(body, *kind, span); + let rhs = this.lower_const_item_rhs(body, span); (ty, rhs) }, ); @@ -924,13 +923,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let (ident, generics, kind, has_value) = match &i.kind { AssocItemKind::Const(ConstItem { - ident, - generics, - ty, - body, - kind, - define_opaque, - .. + ident, generics, ty, body, define_opaque, .. }) => { let (generics, kind) = self.lower_generics( generics, @@ -942,7 +935,7 @@ impl<'hir> LoweringContext<'_, 'hir> { ); // Trait associated consts don't need an expression/body. let rhs = if body.is_some() { - Some(this.lower_const_item_rhs(body, *kind, i.span)) + Some(this.lower_const_item_rhs(body, i.span)) } else { None }; @@ -1187,13 +1180,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let (ident, (generics, kind)) = match &i.kind { AssocItemKind::Const(ConstItem { - ident, - generics, - ty, - body, - kind, - define_opaque, - .. + ident, generics, ty, body, define_opaque, .. }) => ( *ident, self.lower_generics( @@ -1205,7 +1192,7 @@ impl<'hir> LoweringContext<'_, 'hir> { ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy), ); this.lower_define_opaque(hir_id, &define_opaque); - let rhs = this.lower_const_item_rhs(body, *kind, i.span); + let rhs = this.lower_const_item_rhs(body, 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 ef6995d9c11d6..5a173a79db888 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -2671,56 +2671,31 @@ impl<'hir> LoweringContext<'_, 'hir> { fn lower_const_item_rhs( &mut self, body: &Option>, - kind: ConstItemKind, span: Span, ) -> hir::ConstItemRhs<'hir> { - match (body, kind) { - (body, ConstItemKind::Body) => { - let is_direct = |body| { - if self.tcx.features().macroless_generic_const_args() { - self.can_lower_expr_to_const_arg_direct( - body, - DirectConstArgContext::MacrolessMinGenericConstArgs, - ) - .is_ok() - } else { - // do not check can_lower_expr_to_const_arg_direct, but rather just - // ExprKind::DirectConstArg, because we don't want e.g. - // `impl { const C: u8 = N; }` to be a direct-rhs const - matches!(body, Expr { kind: ExprKind::DirectConstArg(_), .. }) - } - }; - // N.B.: the feature gate for this is generic_const_args, not min_generic_const_args - if self.tcx.features().generic_const_args() - && let Some(body) = body - && is_direct(body) - { - hir::ConstItemRhs::Direct( - self.arena.alloc(self.lower_expr_to_const_arg_direct(&body, None)), - ) - } else { - hir::ConstItemRhs::Body(self.lower_const_body(span, body.as_deref())) - } - } - (Some(body), ConstItemKind::TypeConst) => hir::ConstItemRhs::Direct(self.arena.alloc( - match self.can_lower_expr_to_const_arg_direct( - &body, + let is_direct = |body| { + if self.tcx.features().macroless_generic_const_args() { + self.can_lower_expr_to_const_arg_direct( + body, DirectConstArgContext::MacrolessMinGenericConstArgs, - ) { - Ok(()) => self.lower_expr_to_const_arg_direct(&body, None), - Err(err) => err.emit(self), - }, - )), - (None, ConstItemKind::TypeConst) => { - let const_arg = ConstArg { - hir_id: self.next_id(), - kind: hir::ConstArgKind::Error( - self.dcx().span_delayed_bug(DUMMY_SP, "no block"), - ), - span: DUMMY_SP, - }; - hir::ConstItemRhs::Direct(self.arena.alloc(const_arg)) + ) + .is_ok() + } else { + // do not check can_lower_expr_to_const_arg_direct, but rather just + // ExprKind::DirectConstArg, because we don't want e.g. + // `impl { const C: u8 = N; }` to be a direct-rhs const + matches!(body, Expr { kind: ExprKind::DirectConstArg(_), .. }) } + }; + if self.tcx.features().min_generic_const_args() + && let Some(body) = body + && is_direct(body) + { + hir::ConstItemRhs::Direct( + self.arena.alloc(self.lower_expr_to_const_arg_direct(&body, None)), + ) + } else { + hir::ConstItemRhs::Body(self.lower_const_body(span, body.as_deref())) } } diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index 387aa7566b42a..822fd9e3c7a53 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -113,7 +113,7 @@ impl<'hir> LoweringContext<'_, 'hir> { } // `a::b::Trait(Args)::TraitItem` Res::Def(DefKind::AssocFn, _) - | Res::Def(DefKind::AssocConst { .. }, _) + | Res::Def(DefKind::AssocConst, _) | Res::Def(DefKind::AssocTy, _) if i + 2 == proj_start => { diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 003865e147aa2..3397bb4e41286 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -190,13 +190,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { ast::ItemKind::TyAlias(ast::TyAlias { ty: Some(ty), .. }) => { self.check_impl_trait(ty, false) } - ast::ItemKind::Const(ast::ConstItem { - kind: ast::ConstItemKind::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"); - } _ => {} } @@ -350,18 +343,9 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { } false } - ast::AssocItemKind::Const(ast::ConstItem { - body, - kind: ast::ConstItemKind::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"); - // Make sure associated `type const` defaults in traits are only allowed - // if the feature gate is enabled. - // #![feature(associated_type_defaults)] - if ctxt == AssocCtxt::Trait && body.is_some() { + ast::AssocItemKind::Const(ast::ConstItem { body: Some(_), .. }) => { + if ctxt == AssocCtxt::Trait && attr::contains_name(&i.attrs, sym::rustc_always_gca) + { gate!( self, associated_type_defaults, diff --git a/compiler/rustc_ast_pretty/src/pprust/state/item.rs b/compiler/rustc_ast_pretty/src/pprust/state/item.rs index 6dd98bd201f48..ae13f627fcbe5 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/item.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/item.rs @@ -229,7 +229,6 @@ impl<'a> State<'a> { generics, ty, body, - kind: _, define_opaque, }) => { self.print_item_const( @@ -621,7 +620,6 @@ impl<'a> State<'a> { generics, ty, body, - kind: _, define_opaque, }) => { self.print_item_const( diff --git a/compiler/rustc_attr_ir/src/data_structures.rs b/compiler/rustc_attr_ir/src/data_structures.rs index 54d083a094883..d722d515582dc 100644 --- a/compiler/rustc_attr_ir/src/data_structures.rs +++ b/compiler/rustc_attr_ir/src/data_structures.rs @@ -785,6 +785,9 @@ pub enum AttributeKind { /// Represents `#[allow_internal_unstable]`. AllowInternalUnstable(ThinVec<(Symbol, Span)>, Span), + /// Represents `#[rustc_always_gca]` + AlwaysGca, + /// Represents `#[automatically_derived]` AutomaticallyDerived, diff --git a/compiler/rustc_attr_ir/src/encode_cross_crate.rs b/compiler/rustc_attr_ir/src/encode_cross_crate.rs index 270ec0399799e..6f05f763f2ada 100644 --- a/compiler/rustc_attr_ir/src/encode_cross_crate.rs +++ b/compiler/rustc_attr_ir/src/encode_cross_crate.rs @@ -20,6 +20,7 @@ impl AttributeKind { // tidy-alphabetical-start AllowInternalUnsafe(..) => Yes, AllowInternalUnstable(..) => Yes, + AlwaysGca => Yes, AutomaticallyDerived => Yes, CfgAttrTrace(..) => Yes, CfgTrace(..) => Yes, diff --git a/compiler/rustc_attr_parsing/src/attributes/semantics.rs b/compiler/rustc_attr_parsing/src/attributes/semantics.rs index 7a8475c12eada..9c9916b013ddd 100644 --- a/compiler/rustc_attr_parsing/src/attributes/semantics.rs +++ b/compiler/rustc_attr_parsing/src/attributes/semantics.rs @@ -28,3 +28,12 @@ impl NoArgsAttributeParser for ComptimeParser { const STABILITY: AttributeStability = unstable!(rustc_attrs); const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcComptime; } + +pub(crate) struct AlwaysGcaParser; +impl NoArgsAttributeParser for AlwaysGcaParser { + const PATH: &[Symbol] = &[sym::rustc_always_gca]; + const ALLOWED_TARGETS: AllowedTargets<'_> = + AllowedTargets::AllowList(&[Allow(Target::AssocConst(AssocCtxt::Trait))]); + const STABILITY: AttributeStability = unstable!(min_generic_const_args); + const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::AlwaysGca; +} diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index cf99311cc0cfc..13cdc78f07c3d 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -259,6 +259,7 @@ attribute_parsers!( Single, Single, Single>, + Single>, Single>, Single>, Single>, diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 97931fc76f152..3bc84fa3eca23 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -1271,10 +1271,7 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> { let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = base.kind else { return }; let (hir::def::Res::Local(_) | hir::def::Res::Def( - DefKind::Const { .. } - | DefKind::ConstParam - | DefKind::Static { .. } - | DefKind::AssocConst { .. }, + DefKind::Const | DefKind::ConstParam | DefKind::Static { .. } | DefKind::AssocConst, _, )) = path.res else { diff --git a/compiler/rustc_borrowck/src/implied_bounds.rs b/compiler/rustc_borrowck/src/implied_bounds.rs index bb1d09698a074..d5f765edfdb5d 100644 --- a/compiler/rustc_borrowck/src/implied_bounds.rs +++ b/compiler/rustc_borrowck/src/implied_bounds.rs @@ -90,7 +90,7 @@ pub(super) fn mir_borrowck_implied_outlives_bounds<'tcx>( // - We must compute the normalized signature and then compute implied bounds from that // in order to connect any unconstrained region vars created during normalization to // the types of the locals corresponding to the inputs and outputs of the item. #136547 - if matches!(tcx.def_kind(body_def_id), DefKind::AssocFn | DefKind::AssocConst { .. }) { + if matches!(tcx.def_kind(body_def_id), DefKind::AssocFn | DefKind::AssocConst) { for &(ty, _) in tcx.assumed_wf_types(tcx.local_parent(body_def_id)) { let normalized_ty = ocx .deeply_normalize( diff --git a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs index 5309ea8cb81b5..e5d4b9295578b 100644 --- a/compiler/rustc_borrowck/src/type_check/free_region_relations.rs +++ b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs @@ -296,8 +296,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> { // - We must compute the normalized signature and then compute implied bounds from that // in order to connect any unconstrained region vars created during normalization to // the types of the locals corresponding to the inputs and outputs of the item. (#136547) - if matches!(tcx.def_kind(defining_ty_def_id), DefKind::AssocFn | DefKind::AssocConst { .. }) - { + if matches!(tcx.def_kind(defining_ty_def_id), DefKind::AssocFn | DefKind::AssocConst) { for &(ty, _) in tcx.assumed_wf_types(tcx.local_parent(defining_ty_def_id)) { let result: Result<_, ErrorGuaranteed> = self .infcx diff --git a/compiler/rustc_builtin_macros/src/alloc_error_handler.rs b/compiler/rustc_builtin_macros/src/alloc_error_handler.rs index 57e589ac5a1e8..1272970a81be9 100644 --- a/compiler/rustc_builtin_macros/src/alloc_error_handler.rs +++ b/compiler/rustc_builtin_macros/src/alloc_error_handler.rs @@ -44,13 +44,8 @@ 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 = ecx.expr_block(ecx.block(span, stmts)); - let const_item = ecx.item_const( - span, - Ident::new(kw::Underscore, span), - const_ty, - Some(const_body), - ast::ConstItemKind::Body, - ); + let const_item = + ecx.item_const(span, Ident::new(kw::Underscore, span), const_ty, Some(const_body)); let const_item = if is_stmt { Annotatable::Stmt(Box::new(ecx.stmt_item(span, const_item))) } else { diff --git a/compiler/rustc_builtin_macros/src/eii.rs b/compiler/rustc_builtin_macros/src/eii.rs index 1b250cf9e1363..8faa51ca0d880 100644 --- a/compiler/rustc_builtin_macros/src/eii.rs +++ b/compiler/rustc_builtin_macros/src/eii.rs @@ -341,13 +341,7 @@ fn generate_default_impl( let anon_mod = |span: Span, stmts: ThinVec| { let unit = ecx.ty(item_span, ast::TyKind::Tup(ThinVec::new())); let underscore = Ident::new(kw::Underscore, item_span); - ecx.item_const( - span, - underscore, - unit, - Some(ecx.expr_block(ecx.block(span, stmts))), - ast::ConstItemKind::Body, - ) + ecx.item_const(span, underscore, unit, Some(ecx.expr_block(ecx.block(span, stmts)))) }; // const _: () = { diff --git a/compiler/rustc_builtin_macros/src/global_allocator.rs b/compiler/rustc_builtin_macros/src/global_allocator.rs index 00ed0f52d6a6f..d6293f8b015d0 100644 --- a/compiler/rustc_builtin_macros/src/global_allocator.rs +++ b/compiler/rustc_builtin_macros/src/global_allocator.rs @@ -55,13 +55,8 @@ 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 = ecx.expr_block(ecx.block(span, stmts)); - let const_item = ecx.item_const( - span, - Ident::new(kw::Underscore, span), - const_ty, - Some(const_body), - ast::ConstItemKind::Body, - ); + let const_item = + ecx.item_const(span, Ident::new(kw::Underscore, span), const_ty, Some(const_body)); let const_item = if is_stmt { Annotatable::Stmt(Box::new(ecx.stmt_item(span, const_item))) } else { diff --git a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs index 2f939e226c292..c35e56a8e850b 100644 --- a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs +++ b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs @@ -371,7 +371,6 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> Box { Ident::new(kw::Underscore, span), cx.ty(span, ast::TyKind::Tup(ThinVec::new())), Some(block), - ast::ConstItemKind::Body, ); // Integrate the new item into existing module structures. diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index b27bf8c3f2a20..a8a426d759057 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -282,7 +282,6 @@ pub(crate) fn expand_test_or_bench( generics: ast::Generics::default(), ty: cx.ty(sp, ast::TyKind::Path(None, test_path("TestDescAndFn"))), define_opaque: None, - kind: ast::ConstItemKind::Body, // test::TestDescAndFn { body: Some( cx.expr_struct( 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 c823da68b65bd..dcd9b13ab081c 100644 --- a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs @@ -61,11 +61,11 @@ fn setup_for_eval<'tcx>( cid.promoted.is_some() || matches!( ecx.tcx.def_kind(cid.instance.def_id()), - DefKind::Const { .. } + DefKind::Const | DefKind::Static { .. } | DefKind::ConstParam | DefKind::AnonConst - | DefKind::AssocConst { .. } + | DefKind::AssocConst ), "Unexpected DefKind: {:?}", ecx.tcx.def_kind(cid.instance.def_id()) @@ -441,9 +441,7 @@ fn eval_in_interpreter<'tcx, R: InterpretationResult<'tcx>>( ) -> Result { let def = cid.instance.def.def_id(); // directly represented consts don't have bodies - if cfg!(debug_assertions) - && matches!(tcx.def_kind(def), DefKind::Const { .. } | DefKind::AssocConst { .. }) - { + if cfg!(debug_assertions) && matches!(tcx.def_kind(def), DefKind::Const | DefKind::AssocConst) { debug_assert!( tcx.const_of_item(def).is_none(), "CTFE tried to evaluate directly represented const item: {def:?}" diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs index 2240fe115fde3..6738a96d60c32 100644 --- a/compiler/rustc_expand/src/build.rs +++ b/compiler/rustc_expand/src/build.rs @@ -720,7 +720,6 @@ impl<'a> ExtCtxt<'a> { ident: Ident, ty: Box, body: Option>, - kind: ast::ConstItemKind, ) -> Box { let defaultness = ast::Defaultness::Implicit; self.item( @@ -734,7 +733,6 @@ impl<'a> ExtCtxt<'a> { generics: ast::Generics::default(), ty, body, - kind, define_opaque: None, } .into(), diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index f79a8e9ffc79c..bb35a3281ccdc 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -321,6 +321,7 @@ pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[ // Internal attributes, Const related: // ========================================================================== + sym::rustc_always_gca, sym::rustc_promotable, sym::rustc_legacy_const_generics, // Do not const-check this function's body. It will always get replaced during CTFE via `hook_special_const_fn`. diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index f1047e6c0bab4..6deab943b836a 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -119,9 +119,7 @@ pub enum DefKind { // Value namespace Fn, - Const { - is_type_const: bool, - }, + Const, /// Constant generic parameter: `struct Foo { ... }` ConstParam, Static { @@ -153,9 +151,7 @@ pub enum DefKind { /// or `trait Foo { fn associated() {} }` AssocFn, /// Associated constant: `trait MyTrait { const ASSOC: usize; }` - AssocConst { - is_type_const: bool, - }, + AssocConst, // Macro namespace Macro(MacroKinds), @@ -231,8 +227,8 @@ impl DefKind { DefKind::Trait => "trait", DefKind::ForeignTy => "foreign type", DefKind::AssocFn => "associated function", - DefKind::Const { .. } => "constant", - DefKind::AssocConst { .. } => "associated constant", + DefKind::Const => "constant", + DefKind::AssocConst => "associated constant", DefKind::TyParam => "type parameter", DefKind::ConstParam => "const parameter", DefKind::Macro(kinds) => kinds.descr(), @@ -258,7 +254,7 @@ impl DefKind { pub fn article(&self) -> &'static str { match *self { DefKind::AssocTy - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::AssocFn | DefKind::Enum | DefKind::OpaqueTy @@ -285,12 +281,12 @@ impl DefKind { | DefKind::TyParam => Some(Namespace::TypeNS), DefKind::Fn - | DefKind::Const { .. } + | DefKind::Const | DefKind::ConstParam | DefKind::Static { .. } | DefKind::Ctor(..) | DefKind::AssocFn - | DefKind::AssocConst { .. } => Some(Namespace::ValueNS), + | DefKind::AssocConst => Some(Namespace::ValueNS), DefKind::Macro(..) => Some(Namespace::MacroNS), @@ -331,11 +327,11 @@ impl DefKind { DefKind::AssocTy => DefPathData::TypeNs(name.unwrap()), DefKind::Fn - | DefKind::Const { .. } + | DefKind::Const | DefKind::ConstParam | DefKind::Static { .. } | DefKind::AssocFn - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::Field => DefPathData::ValueNs(name.unwrap()), DefKind::Macro(..) => DefPathData::MacroNs(name.unwrap()), DefKind::LifetimeParam => DefPathData::LifetimeNs(name.unwrap()), @@ -353,7 +349,7 @@ impl DefKind { } pub fn is_assoc(self) -> bool { - matches!(self, DefKind::AssocConst { .. } | DefKind::AssocFn | DefKind::AssocTy) + matches!(self, DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy) } /// This is a "module" in name resolution sense. @@ -379,11 +375,11 @@ impl DefKind { pub fn has_generics(self) -> bool { match self { DefKind::AnonConst - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy | DefKind::Closure - | DefKind::Const { .. } + | DefKind::Const | DefKind::Ctor(..) | DefKind::Enum | DefKind::Field @@ -431,8 +427,8 @@ impl DefKind { | DefKind::ForeignTy | DefKind::TraitAlias | DefKind::AssocTy - | DefKind::Const { .. } - | DefKind::AssocConst { .. } + | DefKind::Const + | DefKind::AssocConst | DefKind::Macro(..) | DefKind::Use | DefKind::ForeignMod diff --git a/compiler/rustc_hir/src/target_impls.rs b/compiler/rustc_hir/src/target_impls.rs index d2959cf46fda0..b71a046958b57 100644 --- a/compiler/rustc_hir/src/target_impls.rs +++ b/compiler/rustc_hir/src/target_impls.rs @@ -54,7 +54,7 @@ impl From for Target { DefKind::ExternCrate => Target::ExternCrate, DefKind::Use => Target::Use, DefKind::Static { .. } => Target::Static, - DefKind::Const { .. } => Target::Const, + DefKind::Const => Target::Const, DefKind::Fn => Target::Fn, DefKind::Macro(..) => Target::MacroDef, DefKind::Mod => Target::Mod, diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index d5bc834b831c7..377a12c1ca63a 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -864,6 +864,12 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ty::TraitRef::new_from_args(tcx, def_id.to_def_id(), trait_args), ); } + ty::AssocKind::Const { .. } if assoc_item.defaultness(tcx).has_value() => { + let _: Result<_, rustc_errors::ErrorGuaranteed> = + super::compare_impl_item::compare_const_directness( + tcx, assoc_item, assoc_item, + ); + } _ => {} } } @@ -932,7 +938,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), // avoids this query from having a direct dependency edge on the HIR return res; } - DefKind::Const { .. } => { + DefKind::Const => { tcx.ensure_ok().generics_of(def_id); tcx.ensure_ok().type_of(def_id); tcx.ensure_ok().clauses_of(def_id); @@ -1116,7 +1122,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), // avoids this query from having a direct dependency edge on the HIR return res; } - DefKind::AssocConst { .. } => { + DefKind::AssocConst => { tcx.ensure_ok().type_of(def_id); tcx.ensure_ok().clauses_of(def_id); res = res.and(check_associated_item(tcx, def_id)); 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 d49c3b2869bd3..a2c7c39c20baa 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -2145,35 +2145,53 @@ fn compare_impl_const<'tcx>( trait_const_item: ty::AssocItem, impl_trait_ref: ty::TraitRef<'tcx>, ) -> Result<(), ErrorGuaranteed> { - compare_type_const(tcx, impl_const_item, trait_const_item)?; + compare_const_directness(tcx, impl_const_item, trait_const_item)?; compare_number_of_generics(tcx, impl_const_item, trait_const_item, false)?; compare_generic_param_kinds(tcx, impl_const_item, trait_const_item, false)?; check_region_bounds_on_impl_item(tcx, impl_const_item, trait_const_item, false)?; compare_const_clause_entailment(tcx, impl_const_item, trait_const_item, impl_trait_ref) } -fn compare_type_const<'tcx>( +pub(super) fn compare_const_directness<'tcx>( tcx: TyCtxt<'tcx>, impl_const_item: ty::AssocItem, trait_const_item: ty::AssocItem, ) -> Result<(), ErrorGuaranteed> { - let impl_is_type_const = tcx.is_type_const_syntax(impl_const_item.def_id); - let trait_is_type_const = tcx.is_type_const_syntax(trait_const_item.def_id); + let trait_is_gca = tcx.is_always_gca(trait_const_item.def_id); + let impl_is_gca = tcx.const_of_item(impl_const_item.def_id).is_some(); - if trait_is_type_const && !impl_is_type_const { - return Err(tcx - .dcx() + if trait_is_gca == impl_is_gca { + return Ok(()); + } + // feature(generic_const_args) is allowed to impl non-GCA traits with a GCA const + if tcx.features().generic_const_args() && !trait_is_gca && impl_is_gca { + return Ok(()); + } + + let guar = if trait_is_gca { + tcx.dcx() .struct_span_err( tcx.def_span(impl_const_item.def_id), - "implementation of a `type const` must also be marked as `type const`", + "implementation of a `#[rustc_always_gca]` must have a `direct_const_arg!` RHS", ) .with_span_note( tcx.def_span(trait_const_item.def_id), - "trait declaration of const is marked as `type const`", + "trait declaration of const is marked as `#[rustc_always_gca]`", ) - .emit()); - } - Ok(()) + .emit() + } else { + tcx.dcx() + .struct_span_err( + tcx.def_span(impl_const_item.def_id), + "implementation of a regular const cannot have a `direct_const_arg!` RHS", + ) + .with_span_note( + tcx.def_span(trait_const_item.def_id), + "trait declaration of const is not marked as `#[rustc_always_gca]`", + ) + .emit() + }; + Err(guar) } /// The equivalent of [compare_method_clause_entailment], but for associated constants diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 0dee9690737df..7f0895d2de5a7 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -2564,12 +2564,12 @@ fn lint_redundant_lifetimes<'tcx>( | DefKind::Trait | DefKind::TraitAlias | DefKind::Fn - | DefKind::Const { .. } + | DefKind::Const | DefKind::Impl { of_trait: _ } | DefKind::TestBinderConstraints => { // Proceed } - DefKind::AssocFn | DefKind::AssocTy | DefKind::AssocConst { .. } => { + DefKind::AssocFn | DefKind::AssocTy | DefKind::AssocConst => { if tcx.trait_impl_of_assoc(owner_id.to_def_id()).is_some() { // Don't check for redundant lifetimes for associated items of trait // implementations, since the signature is required to be compatible 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 042b931750b71..648d56cca069f 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -2051,10 +2051,10 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { _ => None, }, DefKind::AnonConst - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::AssocFn | DefKind::Closure - | DefKind::Const { .. } + | DefKind::Const | DefKind::ConstParam | DefKind::Ctor(..) | DefKind::ExternCrate 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 219637ba4f16f..36e56dce89916 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs @@ -561,18 +561,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { && !tcx.features().generic_const_args() { if tcx.features().min_generic_const_args() { - let mut err = self.dcx().struct_span_err( + let err = self.dcx().struct_span_err( constraint.span, - "use of trait associated const not defined as `type const`", - ); - err.note( - "the declaration in the trait must begin with `type const` not just `const` alone", + "use of trait associated const not defined as `#[rustc_always_gca]`", ); return Err(err.emit()); } else { let err = self.dcx().span_delayed_bug( constraint.span, - "use of trait associated const defined as `type const`", + "use of trait associated const defined as `#[rustc_always_gca]`", ); 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 8965767be3ed6..5e081753cc821 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -282,7 +282,7 @@ impl LowerTypeRelativePathMode { fn def_kind_for_diagnostics(self) -> DefKind { match self { Self::Type(_) => DefKind::AssocTy, - Self::Const => DefKind::AssocConst { is_type_const: false }, + Self::Const => DefKind::AssocConst, } } @@ -1482,7 +1482,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { TypeRelativePath::AssocItem(alias_term) => { let alias_ct = alias_term.expect_ct(); if let Some(def_id) = alias_ct.kind.opt_def_id() { - self.require_type_const_attribute(def_id, span)?; + self.check_const_item_in_type_system(def_id, span)?; } let ct = Const::new_alias(tcx, ty::IsRigid::No, alias_ct); let ct = self.check_param_uses_if_mcg(ct, span, false); @@ -1945,7 +1945,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { item_segment, ty::AssocTag::Const, )?; - self.require_type_const_attribute(item_def_id, span)?; + self.check_const_item_in_type_system(item_def_id, span)?; let alias_const = ty::AliasConst::new( tcx, ty::AliasConstKind::new_from_def_id( @@ -2165,12 +2165,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { } // Case 3. Reference to a top-level value. - DefKind::Fn | DefKind::Const { .. } | DefKind::ConstParam | DefKind::Static { .. } => { + DefKind::Fn | DefKind::Const | DefKind::ConstParam | DefKind::Static { .. } => { generic_segments.push(GenericPathSegment(def_id, last)); } // Case 4. Reference to a method or associated const. - DefKind::AssocFn | DefKind::AssocConst { .. } => { + DefKind::AssocFn | DefKind::AssocConst => { if segments.len() >= 2 { let generics = tcx.generics_of(def_id); generic_segments.push(GenericPathSegment(generics.parent.unwrap(), last - 1)); @@ -2397,11 +2397,16 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { // we have the ability to intermix typeck of anon const const args with the parent // bodies typeck. + // FIXME(min_generic_const_args): This check should be removed for mGCA, it is due to + // the lack of ConstParamTy rib-checking in nameres for directly represented const + // items. + // We also error if the type contains any regions as effectively any region will wind // up as a region variable in mir borrowck. It would also be somewhat concerning if // hir typeck was using equality but mir borrowck wound up using subtyping as that could // result in a non-infer in hir typeck but a region variable in borrowck. - if tcx.features().generic_const_parameter_types() + if (tcx.features().generic_const_parameter_types() + || tcx.features().min_generic_const_args()) && (ty.has_free_regions() || ty.has_erased_regions()) { let e = self.dcx().span_err( @@ -2894,8 +2899,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { ); self.lower_const_param(def_id, hir_id) } - Res::Def(DefKind::Const { .. }, did) => { - if let Err(guar) = self.require_type_const_attribute(did, span) { + Res::Def(DefKind::Const, did) => { + if let Err(guar) = self.check_const_item_in_type_system(did, span) { return Const::new_error(self.tcx(), guar); } @@ -2975,7 +2980,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { ty::Const::zero_sized(tcx, tcx.type_of(did).instantiate(tcx, args).skip_norm_wip()) } - Res::Def(DefKind::AssocConst { .. }, did) => { + Res::Def(DefKind::AssocConst, did) => { let trait_segment = if let [modules @ .., trait_, _item] = path.segments { let _ = self.prohibit_generic_args(modules.iter(), GenericsArgsErrExtend::None); Some(trait_) @@ -3147,42 +3152,47 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { }) } - fn require_type_const_attribute( + /// `def_id` is a const item used in the type system. Checks if that's OK. + fn check_const_item_in_type_system( &self, def_id: DefId, span: Span, ) -> Result<(), ErrorGuaranteed> { let tcx = self.tcx(); - if tcx.is_type_const_syntax(def_id) || tcx.features().generic_const_args() { + if tcx.features().generic_const_args() || tcx.is_direct_const(def_id) { Ok(()) } else { - let mut err = self.dcx().struct_span_err( - span, - "use of `const` in the type system not defined as `type const`", - ); + let mut err = self + .dcx() + .struct_span_err(span, "use of `const` in the type system not marked as direct"); if let Some(local_def_id) = def_id.as_local() { - let name = tcx.def_path_str(def_id); - let (insertion_span, sugg) = match tcx.hir_node_by_def_id(local_def_id) { - hir::Node::Item(item) if !item.vis_span.is_empty() => { - (item.vis_span.shrink_to_hi(), " type") - } - hir::Node::ImplItem(impl_item) - if let Some(vis_span) = - impl_item.vis_span().filter(|span| !span.is_empty()) => - { - (vis_span.shrink_to_hi(), " type") - } - _ => (tcx.def_span(def_id).shrink_to_lo(), "type "), - }; - - err.span_suggestion_verbose( - insertion_span, - format!("add `type` before `const` for `{name}`"), - sugg, - Applicability::MaybeIncorrect, - ); + if let Some(body_id) = tcx.hir_node_by_def_id(local_def_id).body_id() { + let body_span = tcx.hir_body(body_id).value.span; + + err.multipart_suggestion( + "add direct_const_arg!() to the right-hand side of the constant", + vec![ + (body_span.shrink_to_lo(), String::from("core::direct_const_arg!(")), + (body_span.shrink_to_hi(), String::from(")")), + ], + Applicability::MaybeIncorrect, + ); + } else if let DefKind::AssocConst = tcx.def_kind(def_id) + && let DefKind::Trait = tcx.def_kind(tcx.parent(def_id)) + { + let node = tcx.hir_node_by_def_id(local_def_id).expect_trait_item(); + let sp = node.span.shrink_to_lo(); + err.span_suggestion_verbose( + sp, + "add `#[rustc_always_gca]` to the constant", + "#[rustc_always_gca] ", + Applicability::MaybeIncorrect, + ); + } } else { - err.note("only consts marked defined as `type const` may be used in types"); + err.note( + "only consts with a `direct_const_arg!` right-hand side 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 f2c25c8716783..d414f4dbcc240 100644 --- a/compiler/rustc_hir_analysis/src/hir_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/hir_wf_check.rs @@ -104,7 +104,7 @@ pub(super) fn diagnostic_hir_wf_check<'tcx>( if self.depth >= self.cause_depth { self.cause = Some(error.obligation.cause); if let hir::TyKind::TraitObject(..) = ty.kind - && let DefKind::AssocTy | DefKind::AssocConst { .. } | DefKind::AssocFn = + && let DefKind::AssocTy | DefKind::AssocConst | DefKind::AssocFn = self.tcx.def_kind(self.def_id) { self.cause = Some(ObligationCause::new( diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 20ef75244bb4e..c77a0af58e9ab 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -172,7 +172,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) { tcx.ensure_ok().eval_static_initializer(item_def_id); check::maybe_check_static_with_link_section(tcx, item_def_id); } - DefKind::Const { .. } + DefKind::Const if !tcx.generics_of(item_def_id).own_requires_monomorphization() && tcx.const_of_item(item_def_id).is_none() => { diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index 659bb844702aa..355664e2e0c65 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -755,8 +755,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { hir::Path { res: hir::def::Res::Def( - hir::def::DefKind::Static { .. } - | hir::def::DefKind::Const { .. }, + hir::def::DefKind::Static { .. } | hir::def::DefKind::Const, def_id, ), .. diff --git a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs index e8f912165a4c5..73bf03e19150d 100644 --- a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs @@ -905,8 +905,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx let res = self.cx.typeck_results().qpath_res(qpath, *hir_id); match res { - Res::Def(DefKind::Const { .. }, _) - | Res::Def(DefKind::AssocConst { .. }, _) => { + Res::Def(DefKind::Const, _) | Res::Def(DefKind::AssocConst, _) => { // Named constants have to be equated with the value // being matched, so that's a read of the value being matched. // @@ -1402,9 +1401,9 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx match res { Res::Def( DefKind::Ctor(..) - | DefKind::Const { .. } + | DefKind::Const | DefKind::ConstParam - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::Fn | DefKind::AssocFn, _, diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index b59dc21981ce6..ca4c03c853552 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -1039,7 +1039,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Res::Def(DefKind::Ctor(CtorOf::Variant, _), _) => { err_extend = GenericsArgsErrExtend::DefVariant(segments); } - Res::Def(DefKind::AssocFn | DefKind::AssocConst { .. }, def_id) => { + Res::Def(DefKind::AssocFn | DefKind::AssocConst, def_id) => { let assoc_item = tcx.associated_item(def_id); let container = assoc_item.container; let container_id = assoc_item.container_id(tcx); diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index ba44d1966d971..bf1d839fed953 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -102,8 +102,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { hir::ExprKind::ConstBlock(..) => return None, hir::ExprKind::Path(qpath) => { let res = self.typeck_results.borrow().qpath_res(qpath, element.hir_id); - if let Res::Def(DefKind::Const { .. } | DefKind::AssocConst { .. }, _) = res - { + if let Res::Def(DefKind::Const | DefKind::AssocConst, _) = res { return None; } } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 573c08895255b..4d3009bb7640c 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -1992,9 +1992,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } _ => return false, }; - if item.def_id == old_def_id - || !matches!(self.tcx.def_kind(item.def_id), DefKind::AssocConst { .. }) - { + if item.def_id == old_def_id || self.tcx.def_kind(item.def_id) != DefKind::AssocConst { // Same item return false; } @@ -2559,7 +2557,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { && match expr.kind { ExprKind::Path(QPath::Resolved( None, - Path { res: Res::Def(DefKind::Const { .. }, _), .. }, + Path { res: Res::Def(DefKind::Const, _), .. }, )) => true, ExprKind::Call( Expr { diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index 7413215b15ba1..917946006d1b1 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -312,7 +312,7 @@ enum ResolvedPatKind<'tcx> { impl<'tcx> ResolvedPat<'tcx> { fn adjust_mode(&self) -> AdjustMode { if let ResolvedPatKind::Path { res, .. } = self.kind - && matches!(res, Res::Def(DefKind::Const { .. } | DefKind::AssocConst { .. }, _)) + && matches!(res, Res::Def(DefKind::Const | DefKind::AssocConst, _)) { // These constants can be of a reference type, e.g. `const X: &u8 = &0;`. // Peeling the reference types too early will cause type checking failures. @@ -1613,8 +1613,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } Res::Def( DefKind::Ctor(_, CtorKind::Const) - | DefKind::Const { .. } - | DefKind::AssocConst { .. } + | DefKind::Const + | DefKind::AssocConst | DefKind::ConstParam, _, ) => {} // OK @@ -1715,9 +1715,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ => { let (type_def_id, item_def_id) = match resolved_pat.ty.kind() { ty::Adt(def, _) => match res { - Res::Def(DefKind::Const { .. }, def_id) => { - (Some(def.did()), Some(def_id)) - } + Res::Def(DefKind::Const, def_id) => (Some(def.did()), Some(def_id)), _ => (None, None), }, _ => (None, None), @@ -1795,7 +1793,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Res::Err => { self.dcx().span_bug(pat.span, "`Res::Err` but no error emitted"); } - Res::Def(DefKind::AssocConst { .. } | DefKind::AssocFn, _) => { + Res::Def(DefKind::AssocConst | DefKind::AssocFn, _) => { return report_unexpected_res(res); } Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) => tcx.expect_variant_res(res), diff --git a/compiler/rustc_lint/src/interior_mutable_consts.rs b/compiler/rustc_lint/src/interior_mutable_consts.rs index 0bcec3ced1a52..ff48749a2e6a9 100644 --- a/compiler/rustc_lint/src/interior_mutable_consts.rs +++ b/compiler/rustc_lint/src/interior_mutable_consts.rs @@ -77,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for InteriorMutableConsts { }; if let ExprKind::Path(qpath) = &receiver.kind - && let Res::Def(DefKind::Const { .. } | DefKind::AssocConst { .. }, const_did) = + && let Res::Def(DefKind::Const | DefKind::AssocConst , const_did) = typeck.qpath_res(qpath, receiver.hir_id) // Don't consider derefs as those can do arbitrary things // like using thread local (see rust-lang/rust#150157) diff --git a/compiler/rustc_lint/src/non_local_def.rs b/compiler/rustc_lint/src/non_local_def.rs index 4fb30651829fd..76db88ffa4c46 100644 --- a/compiler/rustc_lint/src/non_local_def.rs +++ b/compiler/rustc_lint/src/non_local_def.rs @@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { // Per RFC we (currently) ignore anon-const (`const _: Ty = ...`) in top-level module. if self.body_depth == 1 - && matches!(parent_def_kind, DefKind::Const { .. }) + && parent_def_kind == DefKind::Const && parent_opt_item_name == Some(kw::Underscore) { return; @@ -159,7 +159,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { // for impl, otherwise the item-def and impl-def won't have the same parent. let outermost_impl_parent = peel_parent_while(cx.tcx, parent, |tcx, did| { tcx.def_kind(did) == DefKind::Mod - || (matches!(tcx.def_kind(did), DefKind::Const { .. }) + || (tcx.def_kind(did) == DefKind::Const && tcx.opt_item_name(did) == Some(kw::Underscore)) }); @@ -179,22 +179,20 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { // Get the span of the parent const item ident (if it's a not a const anon). // // Used to suggest changing the const item to a const anon. - let span_for_const_anon_suggestion = - if matches!(parent_def_kind, DefKind::Const { .. }) - && parent_opt_item_name != Some(kw::Underscore) - && let Some(parent) = parent.as_local() - && let Node::Item(item) = cx.tcx.hir_node_by_def_id(parent) - && let ItemKind::Const(ident, _, ty, _) = item.kind - && let TyKind::Tup(&[]) = ty.kind - { - Some(ident.span) - } else { - None - }; + let span_for_const_anon_suggestion = if parent_def_kind == DefKind::Const + && parent_opt_item_name != Some(kw::Underscore) + && let Some(parent) = parent.as_local() + && let Node::Item(item) = cx.tcx.hir_node_by_def_id(parent) + && let ItemKind::Const(ident, _, ty, _) = item.kind + && let TyKind::Tup(&[]) = ty.kind + { + Some(ident.span) + } else { + None + }; - let const_anon = - matches!(parent_def_kind, DefKind::Const { .. } | DefKind::Static { .. }) - .then_some(span_for_const_anon_suggestion); + let const_anon = matches!(parent_def_kind, DefKind::Const | DefKind::Static { .. }) + .then_some(span_for_const_anon_suggestion); let impl_span = item.span.shrink_to_lo().to(impl_.self_ty.span); let mut ms = MultiSpan::from_span(impl_span); @@ -317,7 +315,7 @@ fn did_has_local_parent( peel_parent_while(tcx, parent_did, |tcx, did| { tcx.def_kind(did) == DefKind::Mod - || (matches!(tcx.def_kind(did), DefKind::Const { .. }) + || (tcx.def_kind(did) == DefKind::Const && tcx.opt_item_name(did) == Some(kw::Underscore)) }) .map(|parent_did| parent_did == impl_parent || Some(parent_did) == outermost_impl_parent) diff --git a/compiler/rustc_lint/src/nonstandard_style.rs b/compiler/rustc_lint/src/nonstandard_style.rs index 45f34e6a6e3c1..a0db07e187cba 100644 --- a/compiler/rustc_lint/src/nonstandard_style.rs +++ b/compiler/rustc_lint/src/nonstandard_style.rs @@ -626,7 +626,7 @@ impl<'tcx> LateLintPass<'tcx> for NonUpperCaseGlobals { .. }) = p.kind { - if let Res::Def(DefKind::Const { .. }, _) = path.res + if let Res::Def(DefKind::Const, _) = path.res && let [segment] = path.segments { NonUpperCaseGlobals::check_upper_case( diff --git a/compiler/rustc_lint/src/transmute.rs b/compiler/rustc_lint/src/transmute.rs index 28050690cbfc7..3a4092a46a6b6 100644 --- a/compiler/rustc_lint/src/transmute.rs +++ b/compiler/rustc_lint/src/transmute.rs @@ -216,7 +216,7 @@ fn check_ptr_transmute_in_const<'tcx>( dst: Ty<'tcx>, ) { if matches!(const_context, Some(hir::ConstContext::ConstFn)) - || matches!(cx.tcx.def_kind(body_owner_def_id), DefKind::AssocConst { .. }) + || cx.tcx.def_kind(body_owner_def_id) == DefKind::AssocConst { if src.is_raw_ptr() && dst.is_integral() { cx.tcx.emit_node_span_lint( diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 8a565369d7610..ef29bd026b583 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1399,9 +1399,7 @@ impl CrateMetadata { fn get_associated_item(&self, tcx: TyCtxt<'_>, id: DefIndex) -> ty::AssocItem { let kind = match self.def_kind(id) { - DefKind::AssocConst { is_type_const } => { - ty::AssocKind::Const { name: self.item_name(id), is_type_const } - } + DefKind::AssocConst => ty::AssocKind::Const { name: self.item_name(id) }, DefKind::AssocFn => ty::AssocKind::Fn { name: self.item_name(id), has_self: self.get_fn_has_self_parameter(tcx, id), diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 713671c3a5b47..304c06cd4d026 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -912,11 +912,11 @@ fn should_encode_span(def_kind: DefKind) -> bool { | DefKind::ConstParam | DefKind::LifetimeParam | DefKind::Fn - | DefKind::Const { .. } + | DefKind::Const | DefKind::Static { .. } | DefKind::Ctor(..) | DefKind::AssocFn - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::Macro(_) | DefKind::ExternCrate | DefKind::Use @@ -943,10 +943,10 @@ fn should_encode_attrs(def_kind: DefKind) -> bool { | DefKind::TraitAlias | DefKind::AssocTy | DefKind::Fn - | DefKind::Const { .. } + | DefKind::Const | DefKind::Static { nested: false, .. } | DefKind::AssocFn - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::Macro(_) | DefKind::Field | DefKind::ConstParam @@ -989,12 +989,12 @@ fn should_encode_expn_that_defined(def_kind: DefKind) -> bool { | DefKind::AssocTy | DefKind::TyParam | DefKind::Fn - | DefKind::Const { .. } + | DefKind::Const | DefKind::ConstParam | DefKind::Static { .. } | DefKind::Ctor(..) | DefKind::AssocFn - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::Macro(_) | DefKind::ExternCrate | DefKind::Use @@ -1023,11 +1023,11 @@ fn should_encode_visibility(def_kind: DefKind) -> bool { | DefKind::TraitAlias | DefKind::AssocTy | DefKind::Fn - | DefKind::Const { .. } + | DefKind::Const | DefKind::Static { nested: false, .. } | DefKind::Ctor(..) | DefKind::AssocFn - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::Macro(..) | DefKind::Field => true, DefKind::Use @@ -1056,11 +1056,11 @@ fn should_encode_stability(def_kind: DefKind) -> bool { | DefKind::Struct | DefKind::AssocTy | DefKind::AssocFn - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::TyParam | DefKind::ConstParam | DefKind::Static { .. } - | DefKind::Const { .. } + | DefKind::Const | DefKind::Fn | DefKind::ForeignMod | DefKind::TyAlias @@ -1112,7 +1112,7 @@ fn should_encode_mir( // instance_mir uses mir_for_ctfe rather than optimized_mir for constructors DefKind::Ctor(_, _) => (true, false), // Constants - DefKind::AnonConst | DefKind::AssocConst { .. } | DefKind::Const { .. } => (true, false), + DefKind::AnonConst | DefKind::AssocConst | DefKind::Const => (true, false), // Coroutines require optimized MIR to compute layout. DefKind::Closure if tcx.is_coroutine(def_id.to_def_id()) => (false, true), DefKind::SyntheticCoroutineBody => (false, true), @@ -1151,11 +1151,11 @@ fn should_encode_variances<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: Def DefKind::Mod | DefKind::Variant | DefKind::Field - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::TyParam | DefKind::ConstParam | DefKind::Static { .. } - | DefKind::Const { .. } + | DefKind::Const | DefKind::ForeignMod | DefKind::TyAlias | DefKind::Impl { .. } @@ -1186,11 +1186,11 @@ fn should_encode_generics(def_kind: DefKind) -> bool { | DefKind::TraitAlias | DefKind::AssocTy | DefKind::Fn - | DefKind::Const { .. } + | DefKind::Const | DefKind::Static { .. } | DefKind::Ctor(..) | DefKind::AssocFn - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::AnonConst | DefKind::OpaqueTy | DefKind::Impl { .. } @@ -1219,13 +1219,13 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) -> | DefKind::Ctor(..) | DefKind::Field | DefKind::Fn - | DefKind::Const { .. } + | DefKind::Const | DefKind::Static { nested: false, .. } | DefKind::TyAlias | DefKind::ForeignTy | DefKind::Impl { .. } | DefKind::AssocFn - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::Closure | DefKind::ConstParam | DefKind::AnonConst @@ -1280,14 +1280,14 @@ fn should_encode_fn_sig(def_kind: DefKind) -> bool { | DefKind::Enum | DefKind::Variant | DefKind::Field - | DefKind::Const { .. } + | DefKind::Const | DefKind::Static { .. } | DefKind::Ctor(..) | DefKind::TyAlias | DefKind::OpaqueTy | DefKind::ForeignTy | DefKind::Impl { .. } - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::Closure | DefKind::ConstParam | DefKind::AnonConst @@ -1319,8 +1319,8 @@ fn should_encode_constness(def_kind: DefKind) -> bool { | DefKind::Union | DefKind::Enum | DefKind::Field - | DefKind::Const { .. } - | DefKind::AssocConst { .. } + | DefKind::Const + | DefKind::AssocConst | DefKind::AnonConst | DefKind::Static { .. } | DefKind::TyAlias @@ -1349,7 +1349,7 @@ fn should_encode_constness(def_kind: DefKind) -> bool { fn should_encode_const(def_kind: DefKind) -> bool { match def_kind { // FIXME(mgca): should we remove Const and AssocConst here? - DefKind::Const { .. } | DefKind::AssocConst { .. } | DefKind::AnonConst => true, + DefKind::Const | DefKind::AssocConst | DefKind::AnonConst => true, DefKind::Struct | DefKind::Union @@ -1618,7 +1618,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { if let DefKind::AnonConst = def_kind { record!(self.tables.anon_const_kind[def_id] <- self.tcx.anon_const_kind(def_id)); } - if let DefKind::Const { .. } | DefKind::AssocConst { .. } = def_kind { + if let DefKind::Const | DefKind::AssocConst = def_kind { record!(self.tables.const_of_item[def_id] <- self.tcx.const_of_item(def_id)); } if tcx.impl_method_has_trait_impl_trait_tys(def_id) diff --git a/compiler/rustc_metadata/src/rmeta/table.rs b/compiler/rustc_metadata/src/rmeta/table.rs index c52b22c6f108e..811d370248dd9 100644 --- a/compiler/rustc_metadata/src/rmeta/table.rs +++ b/compiler/rustc_metadata/src/rmeta/table.rs @@ -165,12 +165,10 @@ fixed_size_enum! { ( AssocTy ) ( TyParam ) ( Fn ) - ( Const { is_type_const: true} ) - ( Const { is_type_const: false} ) + ( Const ) ( ConstParam ) ( AssocFn ) - ( AssocConst { is_type_const:true } ) - ( AssocConst { is_type_const:false } ) + ( AssocConst ) ( ExternCrate ) ( Use ) ( ForeignMod ) diff --git a/compiler/rustc_middle/src/hir/map.rs b/compiler/rustc_middle/src/hir/map.rs index 15188f68ccf52..02fa68efc2cc9 100644 --- a/compiler/rustc_middle/src/hir/map.rs +++ b/compiler/rustc_middle/src/hir/map.rs @@ -321,9 +321,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn hir_body_owner_kind(self, def_id: impl Into) -> BodyOwnerKind { let def_id = def_id.into(); match self.def_kind(def_id) { - DefKind::Const { .. } | DefKind::AssocConst { .. } => { - BodyOwnerKind::Const { inline: false } - } + DefKind::Const | DefKind::AssocConst => BodyOwnerKind::Const { inline: false }, DefKind::AnonConst => BodyOwnerKind::Const { inline: self.anon_const_kind(def_id) == ty::AnonConstKind::NonTypeSystemInline, }, diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 7bb9b4ff8c375..008742f96dd86 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -692,7 +692,7 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io: }; match (kind, body.source.promoted) { (_, Some(_)) => write!(w, "const ")?, // promoteds are the closest to consts - (DefKind::Const { .. } | DefKind::AssocConst { .. }, _) => write!(w, "const ")?, + (DefKind::Const | DefKind::AssocConst, _) => write!(w, "const ")?, (DefKind::Static { safety: _, mutability: hir::Mutability::Not, nested: false }, _) => { write!(w, "static ")? } diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 4dfc8d7c9705d..01614692c9ed2 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -837,10 +837,10 @@ impl DynCompatibilityViolation { Self::AssocConst(name, AssocConstViolation::FeatureNotEnabled, _) => { format!("it contains associated const `{name}`").into() } - Self::AssocConst(name, AssocConstViolation::NonType, _) => { - format!("it contains associated const `{name}` that's not defined as `type const`") - .into() - } + Self::AssocConst(name, AssocConstViolation::NonType, _) => format!( + "it contains associated const `{name}` that's not defined as `#[rustc_always_gca]`" + ) + .into(), Self::AssocConst(name, AssocConstViolation::Generic, _) => { format!("it contains generic associated const `{name}`").into() } diff --git a/compiler/rustc_middle/src/ty/assoc.rs b/compiler/rustc_middle/src/ty/assoc.rs index 8eee87bdd07ca..ac32a69a177df 100644 --- a/compiler/rustc_middle/src/ty/assoc.rs +++ b/compiler/rustc_middle/src/ty/assoc.rs @@ -181,7 +181,7 @@ pub enum AssocTypeData { #[derive(Copy, Clone, PartialEq, Debug, StableHash, Eq, Hash, Encodable, Decodable)] pub enum AssocKind { - Const { name: Symbol, is_type_const: bool }, + Const { name: Symbol }, Fn { name: Symbol, has_self: bool }, Type { data: AssocTypeData }, } @@ -204,7 +204,7 @@ impl AssocKind { pub fn as_def_kind(&self) -> DefKind { match self { - &Self::Const { is_type_const, .. } => DefKind::AssocConst { is_type_const }, + Self::Const { .. } => DefKind::AssocConst, Self::Fn { .. } => DefKind::AssocFn, Self::Type { .. } => DefKind::AssocTy, } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 5ff5c05de734a..3a7832aada3c0 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -858,10 +858,7 @@ impl<'tcx> TyCtxt<'tcx> { self.codegen_fn_attrs(def_id) } else if matches!( def_kind, - DefKind::AnonConst - | DefKind::AssocConst { .. } - | DefKind::Const { .. } - | DefKind::GlobalAsm + DefKind::AnonConst | DefKind::AssocConst | DefKind::Const | DefKind::GlobalAsm ) { CodegenFnAttrs::EMPTY } else { @@ -1036,25 +1033,13 @@ impl<'tcx> TyCtxt<'tcx> { /// declare a regular const, but an `impl` could implement it with a directly represented const /// (a la refinement). This method would return false in such a case. pub fn is_direct_const(self, def_id: DefId) -> bool { - debug_assert_matches!( - self.def_kind(def_id), - DefKind::Const { .. } | DefKind::AssocConst { .. } - ); - self.is_type_const_syntax(def_id) || self.const_of_item(def_id).is_some() + debug_assert_matches!(self.def_kind(def_id), DefKind::Const | DefKind::AssocConst); + self.is_always_gca(def_id) || self.const_of_item(def_id).is_some() } - /// Check if the given `def_id` is declared with `type const` syntax (mgca) - /// - /// This is NOT the same as whether the `def_id` can be represented in/used by the type system. - /// For that, you probably want to ask `is_direct_const()` or `const_of_item().is_some()`. - pub fn is_type_const_syntax(self, def_id: impl IntoQueryKey) -> bool { - let def_id = def_id.into_query_key(); - match self.def_kind(def_id) { - DefKind::Const { is_type_const } | DefKind::AssocConst { is_type_const } => { - is_type_const - } - _ => false, - } + /// Whether this is a projection const marked with `#[always_gca]` + pub fn is_always_gca(self, def_id: DefId) -> bool { + find_attr!(self, def_id, AlwaysGca) } /// Returns the movability of the coroutine of `def_id`, or panics @@ -2275,7 +2260,7 @@ impl<'tcx> TyCtxt<'tcx> { debug_assert_matches!(self.def_kind(def_id), DefKind::AnonConst); } ty::AliasTermKind::ProjectionConst { def_id } => { - debug_assert_matches!(self.def_kind(def_id), DefKind::AssocConst { .. }); + debug_assert_matches!(self.def_kind(def_id), DefKind::AssocConst); debug_assert_matches!( self.def_kind(self.parent(def_id)), DefKind::Trait | DefKind::Impl { of_trait: true } @@ -2283,14 +2268,14 @@ impl<'tcx> TyCtxt<'tcx> { } ty::AliasTermKind::InherentConstSelf { def_id } | ty::AliasTermKind::InherentConstImpl { def_id } => { - debug_assert_matches!(self.def_kind(def_id), DefKind::AssocConst { .. }); + debug_assert_matches!(self.def_kind(def_id), DefKind::AssocConst); debug_assert_matches!( self.def_kind(self.parent(def_id)), DefKind::Impl { of_trait: false } ); } ty::AliasTermKind::FreeConst { def_id } => { - debug_assert_matches!(self.def_kind(def_id), DefKind::Const { .. }); + debug_assert_matches!(self.def_kind(def_id), DefKind::Const); } } } diff --git a/compiler/rustc_middle/src/ty/context/impl_interner.rs b/compiler/rustc_middle/src/ty/context/impl_interner.rs index 202991d3f0ada..58fbbf8378a8a 100644 --- a/compiler/rustc_middle/src/ty/context/impl_interner.rs +++ b/compiler/rustc_middle/src/ty/context/impl_interner.rs @@ -226,7 +226,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { inherent_args: ty::AliasConstInherentArgsKind, ) -> ty::AliasConstKind<'tcx> { match self.def_kind(def_id) { - DefKind::AssocConst { .. } => { + DefKind::AssocConst => { if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id)) { match inherent_args { ty::AliasConstInherentArgsKind::WithSelf => { @@ -240,7 +240,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { ty::AliasConstKind::Projection { def_id } } } - DefKind::Const { .. } => ty::AliasConstKind::Free { def_id }, + DefKind::Const => ty::AliasConstKind::Free { def_id }, DefKind::AnonConst | DefKind::Ctor(_, CtorKind::Const) => { ty::AliasConstKind::Anon { def_id } } @@ -261,7 +261,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { ty::AliasTermKind::ProjectionTy { def_id } } } - DefKind::AssocConst { .. } => { + DefKind::AssocConst => { if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(def_id)) { match inherent_args { ty::AliasConstInherentArgsKind::WithSelf => { @@ -277,7 +277,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { } DefKind::OpaqueTy => ty::AliasTermKind::OpaqueTy { def_id }, DefKind::TyAlias => ty::AliasTermKind::FreeTy { def_id }, - DefKind::Const { .. } => ty::AliasTermKind::FreeConst { def_id }, + DefKind::Const => ty::AliasTermKind::FreeConst { def_id }, DefKind::AnonConst | DefKind::Ctor(_, CtorKind::Const) => { ty::AliasTermKind::AnonConst { def_id } } @@ -290,7 +290,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { def_id: DefId, args: ty::GenericArgsRef<'tcx>, ) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) { - debug_assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst { .. }); + debug_assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst); let trait_def_id = self.parent(def_id); debug_assert_matches!(self.def_kind(trait_def_id), DefKind::Trait); let trait_ref = ty::TraitRef::from_assoc(self, trait_def_id, args); diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 1863986682ec8..81da75b0a87f1 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -579,8 +579,8 @@ impl<'tcx> Instance<'tcx> { tcx.def_kind(def_id), DefKind::Fn | DefKind::AssocFn - | DefKind::Const { .. } - | DefKind::AssocConst { .. } + | DefKind::Const + | DefKind::AssocConst | DefKind::AnonConst | DefKind::Static { .. } | DefKind::Ctor(_, CtorKind::Fn) diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index cc6a8619e1e74..a7a64fe7cb964 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1736,9 +1736,7 @@ impl<'tcx> TyCtxt<'tcx> { } pub fn opt_associated_item(self, def_id: DefId) -> Option { - if let DefKind::AssocConst { .. } | DefKind::AssocFn | DefKind::AssocTy = - self.def_kind(def_id) - { + if let DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy = self.def_kind(def_id) { Some(self.associated_item(def_id)) } else { None @@ -1836,9 +1834,9 @@ impl<'tcx> TyCtxt<'tcx> { let def_kind = self.def_kind(def); debug!("returned from def_kind: {:?}", def_kind); match def_kind { - DefKind::Const { .. } + DefKind::Const | DefKind::Static { .. } - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::Ctor(..) | DefKind::AnonConst => self.mir_for_ctfe(def), DefKind::Fn | DefKind::AssocFn @@ -2278,10 +2276,10 @@ impl<'tcx> TyCtxt<'tcx> { | DefKind::TyAlias | DefKind::ForeignTy | DefKind::TyParam - | DefKind::Const { .. } + | DefKind::Const | DefKind::ConstParam | DefKind::Static { .. } - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::Macro(_) | DefKind::ExternCrate | DefKind::Use diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 07e935e265c8b..9df7bc38ce721 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -409,7 +409,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { return Ok(true); } if let Some(symbol) = key.get_opt_name() { - if let DefKind::AssocConst { .. } | DefKind::AssocFn | DefKind::AssocTy = kind + if let DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy = kind && let Some(parent) = self.tcx().opt_parent(def_id) && let parent_key = self.tcx().def_key(parent) && let Some(symbol) = parent_key.get_opt_name() @@ -434,7 +434,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { | DefKind::Trait | DefKind::TyAlias | DefKind::Fn - | DefKind::Const { .. } + | DefKind::Const | DefKind::Static { .. } = kind { } else { diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 8014a52c9b4e1..27b11e643af07 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -646,12 +646,12 @@ impl<'tcx> Ty<'tcx> { | DefKind::AssocTy | DefKind::TyParam | DefKind::Fn - | DefKind::Const { .. } + | DefKind::Const | DefKind::ConstParam | DefKind::Static { .. } | DefKind::Ctor(..) | DefKind::AssocFn - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::Macro(..) | DefKind::ExternCrate | DefKind::Use diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 622086b56c638..c93fc44399e1b 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -164,7 +164,7 @@ impl<'tcx> TyCtxt<'tcx> { | DefKind::AssocTy | DefKind::Fn | DefKind::AssocFn - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::Impl { .. }, def_id, ) => Some(def_id), @@ -613,12 +613,12 @@ impl<'tcx> TyCtxt<'tcx> { | DefKind::AssocTy | DefKind::TyParam | DefKind::Fn - | DefKind::Const { .. } + | DefKind::Const | DefKind::ConstParam | DefKind::Static { .. } | DefKind::Ctor(_, _) | DefKind::AssocFn - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::Macro(_) | DefKind::ExternCrate | DefKind::Use diff --git a/compiler/rustc_mir_build/src/builder/expr/as_constant.rs b/compiler/rustc_mir_build/src/builder/expr/as_constant.rs index 830fdc5d75573..9b1abb08b06c1 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_constant.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_constant.rs @@ -78,10 +78,8 @@ pub(crate) fn as_constant_inner<'tcx>( // FIXME(generic_const_args): there's a lot to consider here! `Const::Ty` uses valtrees // and `Const::Unevaluated` does not, we should revisit this before stabilization. if tcx.features().generic_const_args() - || matches!( - tcx.def_kind(def_id), - DefKind::Const { .. } | DefKind::AssocConst { .. } - ) && tcx.is_direct_const(def_id) + || matches!(tcx.def_kind(def_id), DefKind::Const | DefKind::AssocConst) + && tcx.is_direct_const(def_id) { let uneval = ty::AliasConst::new( tcx, diff --git a/compiler/rustc_mir_build/src/builder/mod.rs b/compiler/rustc_mir_build/src/builder/mod.rs index 00ef35173b4b9..e97819176c840 100644 --- a/compiler/rustc_mir_build/src/builder/mod.rs +++ b/compiler/rustc_mir_build/src/builder/mod.rs @@ -637,8 +637,8 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) - let hir_id = tcx.local_def_id_to_hir_id(def_id); let (inputs, output, coroutine) = match tcx.def_kind(def_id) { - DefKind::Const { .. } - | DefKind::AssocConst { .. } + DefKind::Const + | DefKind::AssocConst | DefKind::AnonConst | DefKind::Static { .. } | DefKind::GlobalAsm => { diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index edfa6d4e46233..070ce5a3d6e24 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -1207,8 +1207,8 @@ impl<'tcx> ThirBuildCx<'tcx> { Res::Def(DefKind::Fn, _) | Res::Def(DefKind::AssocFn, _) | Res::Def(DefKind::Ctor(_, CtorKind::Fn), _) - | Res::Def(DefKind::Const { .. }, _) - | Res::Def(DefKind::AssocConst { .. }, _) => { + | Res::Def(DefKind::Const, _) + | Res::Def(DefKind::AssocConst, _) => { self.typeck_results.user_provided_types().get(hir_id).copied().map(Box::new) } @@ -1448,8 +1448,7 @@ impl<'tcx> ThirBuildCx<'tcx> { ExprKind::ConstParam { param, def_id } } - Res::Def(DefKind::Const { .. }, def_id) - | Res::Def(DefKind::AssocConst { .. }, def_id) => { + Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => { let user_ty = self.user_args_applied_to_res(expr.hir_id, res); ExprKind::NamedConst { def_id, args, user_ty } } diff --git a/compiler/rustc_mir_build/src/thir/cx/mod.rs b/compiler/rustc_mir_build/src/thir/cx/mod.rs index 31a760cc59829..85c98f7b06779 100644 --- a/compiler/rustc_mir_build/src/thir/cx/mod.rs +++ b/compiler/rustc_mir_build/src/thir/cx/mod.rs @@ -18,7 +18,7 @@ pub(crate) fn thir_body<'tcx>( owner_def: LocalDefId, ) -> Result<(&'tcx Steal>, ExprId), ErrorGuaranteed> { if cfg!(debug_assertions) - && matches!(tcx.def_kind(owner_def), DefKind::Const { .. } | DefKind::AssocConst { .. }) + && matches!(tcx.def_kind(owner_def), DefKind::Const | DefKind::AssocConst) { debug_assert!( tcx.const_of_item(owner_def.to_def_id()).is_none(), diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index d11eef067c51a..5684162096e61 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -1074,7 +1074,7 @@ fn find_fallback_pattern_typo<'tcx>( continue; }; if let Some(value_ns) = path.res.value_ns - && let Res::Def(DefKind::Const { .. }, id) = value_ns + && let Res::Def(DefKind::Const, id) = value_ns && infcx.can_eq( param_env, ty, @@ -1095,7 +1095,7 @@ fn find_fallback_pattern_typo<'tcx>( } } } - if let DefKind::Const { .. } = cx.tcx.def_kind(item.owner_id) + if let DefKind::Const = cx.tcx.def_kind(item.owner_id) && infcx.can_eq( param_env, ty, @@ -1238,7 +1238,7 @@ fn is_const_pat_that_looks_like_binding<'tcx>(tcx: TyCtxt<'tcx>, pat: &Pat<'tcx> // the pattern's source text must resemble a plain identifier without any // `::` namespace separators or other non-identifier characters. if let Some(def_id) = try { pat.extra.as_deref()?.expanded_const? } - && matches!(tcx.def_kind(def_id), DefKind::Const { .. }) + && tcx.def_kind(def_id) == DefKind::Const && let Ok(snippet) = tcx.sess.source_map().span_to_snippet(pat.span) && snippet.chars().all(|c| c.is_alphanumeric() || c == '_') { diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index d64f98542b3a3..a4971fd0ba667 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -637,8 +637,7 @@ impl<'tcx, 'ptcx> PatCtxt<'tcx, 'ptcx> { let res = self.typeck_results.qpath_res(qpath, id); let (def_id, user_ty) = match res { - Res::Def(DefKind::Const { .. }, def_id) - | Res::Def(DefKind::AssocConst { .. }, def_id) => { + Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => { (def_id, self.typeck_results.user_provided_types().get(id)) } diff --git a/compiler/rustc_mir_transform/src/known_panics_lint.rs b/compiler/rustc_mir_transform/src/known_panics_lint.rs index 0d0b3f8c29c11..ccbbe410c70b9 100644 --- a/compiler/rustc_mir_transform/src/known_panics_lint.rs +++ b/compiler/rustc_mir_transform/src/known_panics_lint.rs @@ -37,7 +37,7 @@ impl<'tcx> crate::MirLint<'tcx> for KnownPanicsLint { let def_id = body.source.def_id().expect_local(); let def_kind = tcx.def_kind(def_id); let is_fn_like = def_kind.is_fn_like(); - let is_assoc_const = matches!(def_kind, DefKind::AssocConst { .. }); + let is_assoc_const = def_kind == DefKind::AssocConst; // Only run const prop on functions, methods, closures and associated constants if !is_fn_like && !is_assoc_const { diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 6fdccad1505a5..16c4570dd15be 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -446,10 +446,9 @@ fn mir_promoted( { tcx.mir_const_qualif(def) } - DefKind::AssocConst { .. } - | DefKind::Const { .. } - | DefKind::Static { .. } - | DefKind::AnonConst => tcx.mir_const_qualif(def), + DefKind::AssocConst | DefKind::Const | DefKind::Static { .. } | DefKind::AnonConst => { + tcx.mir_const_qualif(def) + } _ => ConstQualifs::default(), }; @@ -578,8 +577,8 @@ fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> & DefKind::Fn | DefKind::AssocFn | DefKind::Static { .. } - | DefKind::Const { .. } - | DefKind::AssocConst { .. } => { + | DefKind::Const + | DefKind::AssocConst => { if let Err(guar) = tcx.ensure_result().check_well_formed(root) { body.tainted_by_errors = Some(guar); } diff --git a/compiler/rustc_mir_transform/src/liveness.rs b/compiler/rustc_mir_transform/src/liveness.rs index 41435a0b58647..1a0d373f050a5 100644 --- a/compiler/rustc_mir_transform/src/liveness.rs +++ b/compiler/rustc_mir_transform/src/liveness.rs @@ -203,7 +203,7 @@ fn maybe_suggest_unit_pattern_typo<'tcx>( let constants = tcx .hir_body_owners() .filter(|&def_id| { - matches!(tcx.def_kind(def_id), DefKind::Const { .. }) + tcx.def_kind(def_id) == DefKind::Const && tcx.type_of(def_id).instantiate_identity().skip_norm_wip() == ty && tcx.visibility(def_id).is_accessible_from(body_def_id, tcx) }) diff --git a/compiler/rustc_mir_transform/src/trivial_const.rs b/compiler/rustc_mir_transform/src/trivial_const.rs index 9fb070750fd04..02465820aea2c 100644 --- a/compiler/rustc_mir_transform/src/trivial_const.rs +++ b/compiler/rustc_mir_transform/src/trivial_const.rs @@ -53,7 +53,7 @@ where B: Deref>, { match tcx.def_kind(def) { - DefKind::AssocConst { .. } | DefKind::Const { .. } => (), + DefKind::AssocConst | DefKind::Const => (), DefKind::AnonConst if tcx.anon_const_kind(def) != AnonConstKind::NonTypeSystemInline => (), _ => return None, } diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 4ee1abe4a1ff4..fd361c2cbeb67 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -1653,7 +1653,7 @@ impl<'v> RootCollector<'_, 'v> { debug!("RootCollector: ItemKind::Static({})", self.tcx.def_path_str(def_id)); self.output.push(dummy_spanned(MonoItem::Static(def_id))); } - DefKind::Const { .. } => { + DefKind::Const => { // Const items only generate mono items if they are actually used somewhere. // Just declaring them is insufficient. diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index b252a378722f3..d4717b88bbb14 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -328,7 +328,6 @@ impl<'a> Parser<'a> { generics, ty, body, - kind: ConstItemKind::Body, define_opaque: None, })) } else if let Some(kind) = self.is_reuse_item() { @@ -339,27 +338,8 @@ impl<'a> Parser<'a> { // MODULE ITEM self.parse_item_mod(attrs)? } else if self.eat_keyword_case(exp!(Type), case) { - 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, body) = self.parse_const_item(const_span)?; - // 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, - body, - kind: ConstItemKind::TypeConst, - define_opaque: None, - })) - } else { - // TYPE ITEM - self.parse_type_alias(def_())? - } + // TYPE ITEM + self.parse_type_alias(def_())? } else if self.eat_keyword_case(exp!(Enum), case) { // ENUM ITEM self.parse_item_enum()? @@ -1268,7 +1248,6 @@ impl<'a> Parser<'a> { generics: Generics::default(), ty, body: expr, - kind: ConstItemKind::Body, define_opaque, })) } diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index cd7f422fb72f3..ae8aeba5b7b91 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -244,6 +244,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { // tidy-alphabetical-start AttributeKind::AllowInternalUnsafe(..) => (), AttributeKind::AllowInternalUnstable(..) => (), + AttributeKind::AlwaysGca => (), AttributeKind::AutomaticallyDerived => (), AttributeKind::CfgAttrTrace(..) => (), AttributeKind::CfgTrace(..) => (), diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index d6a8b2c2f5eb6..b6be91d8b0999 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -47,10 +47,10 @@ fn should_explore(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { | DefKind::TraitAlias | DefKind::AssocTy | DefKind::Fn - | DefKind::Const { .. } + | DefKind::Const | DefKind::Static { .. } | DefKind::AssocFn - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::Macro(_) | DefKind::GlobalAsm | DefKind::Impl { .. } @@ -563,7 +563,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { ) -> ImplItemCheckResult { let (impl_block_id, trait_def_id) = match self.tcx.def_kind(local_def_id) { // assoc impl items of traits are live if the corresponding trait items are live - DefKind::AssocConst { .. } | DefKind::AssocTy | DefKind::AssocFn => { + DefKind::AssocConst | DefKind::AssocTy | DefKind::AssocFn => { let trait_def_id = self.tcx.trait_item_of(local_def_id).and_then(|def_id| def_id.as_local()); (self.tcx.local_parent(local_def_id), trait_def_id) @@ -956,7 +956,7 @@ fn maybe_record_as_seed<'tcx>( } } } - DefKind::AssocFn | DefKind::AssocConst { .. } | DefKind::AssocTy => { + DefKind::AssocFn | DefKind::AssocConst | DefKind::AssocTy => { if allow_dead_code.is_none() { let parent = tcx.local_parent(owner_id.def_id); match tcx.def_kind(parent) { @@ -984,7 +984,7 @@ fn maybe_record_as_seed<'tcx>( own: ComesFromAllowExpect::No, }); } - DefKind::Const { .. } => { + DefKind::Const => { if tcx.item_name(owner_id.def_id) == kw::Underscore { // `const _` is always live, as that syntax only exists for the side effects // of type checking and evaluating the constant expression, and marking them @@ -1292,7 +1292,7 @@ impl<'tcx> DeadVisitor<'tcx> { let enum_variants_with_same_name = dead_codes .iter() .filter_map(|dead_item| { - if let DefKind::AssocFn | DefKind::AssocConst { .. } = + if let DefKind::AssocFn | DefKind::AssocConst = tcx.def_kind(dead_item.def_id) && let impl_did = tcx.local_parent(dead_item.def_id) && let DefKind::Impl { of_trait: false } = tcx.def_kind(impl_did) @@ -1367,12 +1367,12 @@ impl<'tcx> DeadVisitor<'tcx> { return; } match self.tcx.def_kind(def_id) { - DefKind::AssocConst { .. } + DefKind::AssocConst | DefKind::AssocTy | DefKind::AssocFn | DefKind::Fn | DefKind::Static { .. } - | DefKind::Const { .. } + | DefKind::Const | DefKind::TyAlias | DefKind::Enum | DefKind::Union diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index de0d0a4f8a4f2..aa408784d44b8 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -368,7 +368,7 @@ impl<'tcx> ReachableContext<'tcx> { } // Reachable constants and reachable statics can have their contents inlined // into other crates. Mark them as reachable and recurse into their body. - DefKind::Const { .. } | DefKind::AssocConst { .. } | DefKind::Static { .. } => { + DefKind::Const | DefKind::AssocConst | DefKind::Static { .. } => { self.worklist.push(def_id); } _ => { diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 23cc86ae6ae61..6d99b31b9422c 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -53,7 +53,7 @@ fn inherit_deprecation(def_kind: DefKind) -> bool { fn inherit_const_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { let def_kind = tcx.def_kind(def_id); match def_kind { - DefKind::AssocFn | DefKind::AssocTy | DefKind::AssocConst { .. } => { + DefKind::AssocFn | DefKind::AssocTy | DefKind::AssocConst => { match tcx.def_kind(tcx.local_parent(def_id)) { DefKind::Trait | DefKind::Impl { .. } => true, _ => false, @@ -86,7 +86,7 @@ fn annotation_kind(tcx: TyCtxt<'_>, def_id: LocalDefId) -> AnnotationKind { } // Impl items in trait impls cannot have stability. - DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst { .. } => { + DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst => { match tcx.def_kind(tcx.local_parent(def_id)) { DefKind::Impl { of_trait: true } => AnnotationKind::Prohibited, _ => AnnotationKind::Required, diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 590cf99d1d272..d4347301f9e16 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -590,7 +590,7 @@ impl<'tcx> EmbargoVisitor<'tcx> { // Effective visibilities for macros are processed earlier. DefKind::Macro { .. } => {} DefKind::ForeignTy - | DefKind::Const { .. } + | DefKind::Const | DefKind::Static { .. } | DefKind::Fn | DefKind::TyAlias => { @@ -712,7 +712,7 @@ impl<'tcx> EmbargoVisitor<'tcx> { | DefKind::Variant | DefKind::AssocFn | DefKind::AssocTy - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::TyParam | DefKind::AnonConst | DefKind::OpaqueTy @@ -790,7 +790,7 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> { self.ev.queue.insert(def_id); } - DefKind::AssocConst { .. } | DefKind::AssocFn | DefKind::AssocTy => { + DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy => { // Traverse the whole impl/trait. self.ev.queue.insert(self.ev.tcx.local_parent(def_id)); } @@ -825,7 +825,7 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> { | DefKind::ExternCrate | DefKind::GlobalAsm | DefKind::ForeignMod - | DefKind::Const { .. } + | DefKind::Const | DefKind::TestBinderConstraints => { span_bug!( self.tcx().def_span(def_id), @@ -1293,10 +1293,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> { let def = def.filter(|(kind, _)| { matches!( kind, - DefKind::AssocFn - | DefKind::AssocConst { .. } - | DefKind::AssocTy - | DefKind::Static { .. } + DefKind::AssocFn | DefKind::AssocConst | DefKind::AssocTy | DefKind::Static { .. } ) }); if let Some((kind, def_id)) = def { @@ -1621,7 +1618,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> { let def_kind = tcx.def_kind(def_id); match def_kind { - DefKind::Const { .. } | DefKind::Static { .. } | DefKind::Fn | DefKind::TyAlias => { + DefKind::Const | DefKind::Static { .. } | DefKind::Fn | DefKind::TyAlias => { if let DefKind::TyAlias = def_kind { self.check_unnameable(def_id, effective_vis); } diff --git a/compiler/rustc_public/src/unstable/mod.rs b/compiler/rustc_public/src/unstable/mod.rs index 46e790becf1ae..c8eba987134f9 100644 --- a/compiler/rustc_public/src/unstable/mod.rs +++ b/compiler/rustc_public/src/unstable/mod.rs @@ -127,7 +127,7 @@ pub(crate) fn new_item_kind(kind: DefKind) -> ItemKind { DefKind::Closure | DefKind::AssocFn | DefKind::Fn | DefKind::SyntheticCoroutineBody => { ItemKind::Fn } - DefKind::Const { .. } | DefKind::AssocConst { .. } | DefKind::AnonConst => ItemKind::Const, + DefKind::Const | DefKind::AssocConst | DefKind::AnonConst => ItemKind::Const, DefKind::Static { .. } => ItemKind::Static, DefKind::Ctor(_, rustc_hir::def::CtorKind::Const) => ItemKind::Ctor(CtorKind::Const), DefKind::Ctor(_, rustc_hir::def::CtorKind::Fn) => ItemKind::Ctor(CtorKind::Fn), diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 88f057c3a6d6d..427861debb102 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -442,8 +442,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { DefKind::Fn | DefKind::AssocFn | DefKind::Static { .. } - | DefKind::Const { .. } - | DefKind::AssocConst { .. } + | DefKind::Const + | DefKind::AssocConst | DefKind::Ctor(..), _, ) => define_extern(ValueNS), diff --git a/compiler/rustc_resolve/src/def_collector.rs b/compiler/rustc_resolve/src/def_collector.rs index 4c8000c28f065..77d67b0cd53d3 100644 --- a/compiler/rustc_resolve/src/def_collector.rs +++ b/compiler/rustc_resolve/src/def_collector.rs @@ -166,11 +166,8 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> { mutability: s.mutability, nested: false, }, - ItemKind::Const(citem) => { - let is_type_const = citem.kind == ConstItemKind::TypeConst; - DefKind::Const { is_type_const } - } - ItemKind::ConstBlock(..) => DefKind::Const { is_type_const: false }, + ItemKind::Const(..) => DefKind::Const, + ItemKind::ConstBlock(..) => DefKind::Const, ItemKind::Fn(..) | ItemKind::Delegation(..) => DefKind::Fn, ItemKind::MacroDef(ident, def) => { let edition = i.span.edition(); @@ -393,11 +390,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> { | AssocItemKind::Delegation(Delegation { ident, .. }) => { (*ident, DefKind::AssocFn, ValueNS) } - AssocItemKind::Const(ConstItem { ident, kind, .. }) => ( - *ident, - DefKind::AssocConst { is_type_const: *kind == ConstItemKind::TypeConst }, - ValueNS, - ), + AssocItemKind::Const(ConstItem { ident, .. }) => (*ident, DefKind::AssocConst, ValueNS), AssocItemKind::Type(TyAlias { ident, .. }) => (*ident, DefKind::AssocTy, TypeNS), AssocItemKind::MacCall(..) => { self.visit_macro_invoc(i.id); diff --git a/compiler/rustc_resolve/src/diagnostics/impls.rs b/compiler/rustc_resolve/src/diagnostics/impls.rs index a005824e5dbfa..67666a3cbff26 100644 --- a/compiler/rustc_resolve/src/diagnostics/impls.rs +++ b/compiler/rustc_resolve/src/diagnostics/impls.rs @@ -809,7 +809,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { DefKind::Static { .. } => { Some(diagnostics::GenericParamsFromOuterItemStaticOrConst::Static) } - DefKind::Const { .. } => { + DefKind::Const => { Some(diagnostics::GenericParamsFromOuterItemStaticOrConst::Const) } _ => None, @@ -993,8 +993,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { Res::Def( DefKind::Ctor(CtorOf::Variant, CtorKind::Const) | DefKind::Ctor(CtorOf::Struct, CtorKind::Const) - | DefKind::Const { .. } - | DefKind::AssocConst { .. }, + | DefKind::Const + | DefKind::AssocConst, _, ) ) @@ -1005,8 +1005,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { let kind_matches: [fn(DefKind) -> bool; 4] = [ |kind| matches!(kind, DefKind::Ctor(CtorOf::Variant, CtorKind::Const)), |kind| matches!(kind, DefKind::Ctor(CtorOf::Struct, CtorKind::Const)), - |kind| matches!(kind, DefKind::Const { .. }), - |kind| matches!(kind, DefKind::AssocConst { .. }), + |kind| matches!(kind, DefKind::Const), + |kind| matches!(kind, DefKind::AssocConst), ]; let mut local_names = vec![]; self.add_module_candidates( diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 2966e3ad24a07..ce568ee69223d 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -602,11 +602,11 @@ impl PathSource<'_, '_, '_> { res, Res::Def( DefKind::Ctor(_, CtorKind::Const | CtorKind::Fn) - | DefKind::Const { .. } + | DefKind::Const | DefKind::Static { .. } | DefKind::Fn | DefKind::AssocFn - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::ConstParam, _, ) | Res::Local(..) @@ -614,10 +614,7 @@ impl PathSource<'_, '_, '_> { ), PathSource::Pat => { res.expected_in_unit_struct_pat() - || matches!( - res, - Res::Def(DefKind::Const { .. } | DefKind::AssocConst { .. }, _) - ) + || matches!(res, Res::Def(DefKind::Const | DefKind::AssocConst, _)) } PathSource::TupleStruct(..) => res.expected_in_tuple_struct_pat(), PathSource::Struct(_) => matches!( @@ -633,7 +630,7 @@ impl PathSource<'_, '_, '_> { | Res::SelfTyAlias { .. } ), PathSource::TraitItem(ns, _) => match res { - Res::Def(DefKind::AssocConst { .. } | DefKind::AssocFn, _) if ns == ValueNS => true, + Res::Def(DefKind::AssocConst | DefKind::AssocFn, _) if ns == ValueNS => true, Res::Def(DefKind::AssocTy, _) if ns == TypeNS => true, _ => false, }, @@ -2994,7 +2991,6 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { generics, ty, body, - kind, define_opaque, defaultness: _, }) => { @@ -3017,20 +3013,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { this.with_lifetime_rib( LifetimeRibKind::elided(LifetimeRes::Static), |this: &mut LateResolutionVisitor<'a, 'ast, 'ra, 'tcx>| { - if *kind == ast::ConstItemKind::TypeConst - && !this.r.features.generic_const_parameter_types() - { - this.with_rib(TypeNS, RibKind::ConstParamTy, |this| { - this.with_rib(ValueNS, RibKind::ConstParamTy, |this| { - this.with_lifetime_rib( - LifetimeRibKind::ConstParamTy, - |this| this.visit_ty(ty), - ) - }) - }); - } else { - this.visit_ty(ty); - } + this.visit_ty(ty) }, ); @@ -3412,14 +3395,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { self.resolve_doc_links(&item.attrs, MaybeExported::Ok(item.id)); match &item.kind { - AssocItemKind::Const(ast::ConstItem { - generics, - ty, - body, - kind, - define_opaque, - .. - }) => { + AssocItemKind::Const(ast::ConstItem { generics, ty, body, define_opaque, .. }) => { self.with_generic_param_rib( &generics.params, RibKind::AssocItem, @@ -3434,21 +3410,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { }, |this| { this.visit_generics(generics); - if *kind == ConstItemKind::TypeConst - && !this.r.features.generic_const_parameter_types() - { - this.with_rib(TypeNS, RibKind::ConstParamTy, |this| { - this.with_rib(ValueNS, RibKind::ConstParamTy, |this| { - this.with_lifetime_rib( - LifetimeRibKind::ConstParamTy, - |this| this.visit_ty(ty), - ) - }) - }); - } else { - this.visit_ty(ty); - } - + this.visit_ty(ty); // Only impose the restrictions of `ConstRibKind` for an // actual constant expression in a provided default. // @@ -3657,7 +3619,6 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { generics, ty, body, - kind, define_opaque, .. }) => { @@ -3689,20 +3650,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { ); this.visit_generics(generics); - if *kind == ConstItemKind::TypeConst - && !this.r.tcx.features().generic_const_parameter_types() - { - this.with_rib(TypeNS, RibKind::ConstParamTy, |this| { - this.with_rib(ValueNS, RibKind::ConstParamTy, |this| { - this.with_lifetime_rib( - LifetimeRibKind::ConstParamTy, - |this| this.visit_ty(ty), - ) - }) - }); - } else { - this.visit_ty(ty); - } + this.visit_ty(ty); // We allow arbitrary const expressions inside of associated consts, // even if they are potentially not const evaluatable. // @@ -3899,7 +3847,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { match (def_kind, kind) { (DefKind::AssocTy, AssocItemKind::Type(..)) | (DefKind::AssocFn, AssocItemKind::Fn(..)) - | (DefKind::AssocConst { .. }, AssocItemKind::Const(..)) + | (DefKind::AssocConst, AssocItemKind::Const(..)) | (DefKind::AssocFn, AssocItemKind::Delegation(..)) => { self.r.record_partial_res(id, PartialRes::new(res)); return; @@ -4504,7 +4452,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { match res { Res::SelfCtor(_) // See #70549. | Res::Def( - DefKind::Ctor(_, CtorKind::Const) | DefKind::Const { .. } | DefKind::AssocConst { .. } | DefKind::ConstParam, + DefKind::Ctor(_, CtorKind::Const) | DefKind::Const | DefKind::AssocConst | DefKind::ConstParam, _, ) if is_syntactic_ambiguity => { // Disambiguate in favor of a unit struct/variant or constant pattern. @@ -4515,8 +4463,8 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { } Res::Def( DefKind::Ctor(..) - | DefKind::Const { .. } - | DefKind::AssocConst { .. } + | DefKind::Const + | DefKind::AssocConst | DefKind::Static { .. }, _, ) => { @@ -4540,7 +4488,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { None } Res::Def(DefKind::ConstParam, def_id) => { - // Same as for DefKind::Const { .. } above, but here, `binding` is `None`, so we + // Same as for DefKind::Const above, but here, `binding` is `None`, so we // have to construct the error differently self.report_error( ident.span, diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index f5f40a641b66e..9bbfcbc60c42c 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -604,10 +604,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { .span_to_snippet(span) .is_ok_and(|snippet| snippet.ends_with(')')), Res::Def( - DefKind::Ctor(..) - | DefKind::AssocFn - | DefKind::Const { .. } - | DefKind::AssocConst { .. }, + DefKind::Ctor(..) | DefKind::AssocFn | DefKind::Const | DefKind::AssocConst, _, ) | Res::SelfCtor(_) @@ -2778,7 +2775,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { res.borrow(self.r).best_decl().map(|binding| (key, binding.res())) }) .filter(|(_, res)| match (kind, res) { - (AssocItemKind::Const(..), Res::Def(DefKind::AssocConst { .. }, _)) => true, + (AssocItemKind::Const(..), Res::Def(DefKind::AssocConst, _)) => true, (AssocItemKind::Fn(_), Res::Def(DefKind::AssocFn, _)) => true, (AssocItemKind::Type(..), Res::Def(DefKind::AssocTy, _)) => true, (AssocItemKind::Delegation(_), Res::Def(DefKind::AssocFn, _)) => true, @@ -2886,7 +2883,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { return Some(AssocSuggestion::AssocFn { called }); } } - Res::Def(DefKind::AssocConst { .. }, _) => { + Res::Def(DefKind::AssocConst, _) => { return Some(AssocSuggestion::AssocConst); } Res::Def(DefKind::AssocTy, _) => { diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index d5b1457865891..5743f1ffe928f 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -1221,10 +1221,7 @@ impl<'ra> DeclData<'ra> { } fn is_assoc_item(&self) -> bool { - matches!( - self.res(), - Res::Def(DefKind::AssocConst { .. } | DefKind::AssocFn | DefKind::AssocTy, _) - ) + matches!(self.res(), Res::Def(DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy, _)) } fn macro_kinds(&self) -> Option { diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 7665df4a4e5ae..ac05497f4cdbb 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1764,6 +1764,7 @@ symbols! { rustc_allow_incoherent_impl, rustc_allow_lifetime_dependent_specialization, rustc_allowed_through_unstable_modules, + rustc_always_gca, rustc_as_ptr, rustc_attrs, rustc_autodiff, diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs index 45ae86b39f35e..dbfc602066f8d 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs @@ -444,9 +444,9 @@ impl Trait for X { tcx.def_kind(body_owner_def_id), DefKind::Fn | DefKind::Static { .. } - | DefKind::Const { .. } + | DefKind::Const | DefKind::AssocFn - | DefKind::AssocConst { .. } + | DefKind::AssocConst ) && matches!( tcx.opaque_ty_origin(def_id), diff --git a/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs b/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs index 0ae50e02b1638..f2b221c59ee95 100644 --- a/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs +++ b/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs @@ -361,7 +361,7 @@ pub fn dyn_compatibility_violations_for_assoc_item( let span = || item.ident(tcx).span; match item.kind { - ty::AssocKind::Const { name, is_type_const } => { + ty::AssocKind::Const { name } => { // We will permit type associated consts if they are explicitly mentioned in the // trait object type. We can't check this here, as here we only check if it is // guaranteed to not be possible. @@ -371,7 +371,7 @@ pub fn dyn_compatibility_violations_for_assoc_item( if tcx.features().min_generic_const_args() { if !tcx.generics_of(item.def_id).is_own_empty() { errors.push(AssocConstViolation::Generic); - } else if !is_type_const && !tcx.features().generic_const_args() { + } else if !tcx.is_always_gca(item.def_id) && !tcx.features().generic_const_args() { errors.push(AssocConstViolation::NonType); } diff --git a/compiler/rustc_ty_utils/src/assoc.rs b/compiler/rustc_ty_utils/src/assoc.rs index ea58041a12b77..9305b8b2b2935 100644 --- a/compiler/rustc_ty_utils/src/assoc.rs +++ b/compiler/rustc_ty_utils/src/assoc.rs @@ -88,9 +88,7 @@ fn associated_item_from_trait_item( let owner_id = trait_item.owner_id; let name = trait_item.ident.name; let kind = match trait_item.kind { - hir::TraitItemKind::Const(_, _) => { - ty::AssocKind::Const { name, is_type_const: tcx.is_type_const_syntax(owner_id.def_id) } - } + hir::TraitItemKind::Const(_, _) => ty::AssocKind::Const { name }, hir::TraitItemKind::Fn { .. } => { ty::AssocKind::Fn { name, has_self: fn_has_self_parameter(tcx, owner_id) } } @@ -106,9 +104,7 @@ fn associated_item_from_impl_item(tcx: TyCtxt<'_>, impl_item: &hir::ImplItem<'_> let owner_id = impl_item.owner_id; let name = impl_item.ident.name; let kind = match impl_item.kind { - hir::ImplItemKind::Const(..) => { - ty::AssocKind::Const { name, is_type_const: tcx.is_type_const_syntax(owner_id.def_id) } - } + hir::ImplItemKind::Const(..) => ty::AssocKind::Const { name }, hir::ImplItemKind::Fn(..) => { ty::AssocKind::Fn { name, has_self: fn_has_self_parameter(tcx, owner_id) } } diff --git a/compiler/rustc_ty_utils/src/implied_bounds.rs b/compiler/rustc_ty_utils/src/implied_bounds.rs index 66ba76bcd6474..a905d707bcf54 100644 --- a/compiler/rustc_ty_utils/src/implied_bounds.rs +++ b/compiler/rustc_ty_utils/src/implied_bounds.rs @@ -124,11 +124,9 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<' } } } - DefKind::AssocConst { .. } | DefKind::AssocTy => { - tcx.assumed_wf_types(tcx.local_parent(def_id)) - } + DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.local_parent(def_id)), DefKind::Static { .. } - | DefKind::Const { .. } + | DefKind::Const | DefKind::AnonConst | DefKind::Struct | DefKind::Union diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index 92a104af7f85b..c1dd802d38340 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -42,7 +42,7 @@ enum CollectionMode { impl<'tcx> OpaqueTypeCollector<'tcx> { fn new(tcx: TyCtxt<'tcx>, item: LocalDefId) -> Self { let mode = match tcx.def_kind(item) { - DefKind::AssocConst { .. } | DefKind::AssocFn | DefKind::AssocTy => { + DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy => { CollectionMode::ImplTraitInAssocTypes } DefKind::TyAlias => CollectionMode::Taits, @@ -334,8 +334,8 @@ fn opaque_types_defined_by<'tcx>( DefKind::AssocFn | DefKind::Fn | DefKind::Static { .. } - | DefKind::Const { .. } - | DefKind::AssocConst { .. } + | DefKind::Const + | DefKind::AssocConst | DefKind::AnonConst => { // Non-type-system inline consts should be caught by `if tcx.is_typeck_child` above debug_assert!( diff --git a/compiler/rustc_ty_walk/src/lib.rs b/compiler/rustc_ty_walk/src/lib.rs index b1597eab2554b..1f80def6b0d4a 100644 --- a/compiler/rustc_ty_walk/src/lib.rs +++ b/compiler/rustc_ty_walk/src/lib.rs @@ -67,8 +67,8 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>( DefKind::TyAlias { .. } | DefKind::AssocTy | DefKind::Static { .. } - | DefKind::Const { .. } - | DefKind::AssocConst { .. } => return visit_alias(), + | DefKind::Const + | DefKind::AssocConst => return visit_alias(), DefKind::AnonConst if tcx.anon_const_kind(item) != ty::AnonConstKind::NonTypeSystemInline => { diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index e499955df9479..a3887c2bcac75 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -1076,8 +1076,8 @@ pub trait Tuple {} /// Creates a new style directly represented const argument. /// ```ignore (cannot test this from within core yet) -/// type const BAR: usize = N; -/// type const FOO: usize = direct!(BAR::); +/// const BAR: usize = direct_const_arg!(N); +/// const FOO: usize = direct_const_arg!(BAR::); /// ``` #[rustc_builtin_macro(direct_const_arg)] #[unstable(feature = "min_generic_const_args", issue = "132980")] diff --git a/src/doc/unstable-book/src/language-features/macroless-generic-const-args.md b/src/doc/unstable-book/src/language-features/macroless-generic-const-args.md index 18f4e5cd97a98..74baf8bb85c06 100644 --- a/src/doc/unstable-book/src/language-features/macroless-generic-const-args.md +++ b/src/doc/unstable-book/src/language-features/macroless-generic-const-args.md @@ -26,15 +26,17 @@ Here is an example from [min_generic_const_args]: #![feature(min_generic_const_args)] trait Bar { - type const VAL: usize; - type const VAL2: usize; + #[rustc_always_gca] + const VAL: usize; + #[rustc_always_gca] + const VAL2: usize; } struct Baz; impl Bar for Baz { - type const VAL: usize = 2; - type const VAL2: usize = const { Self::VAL * 2 }; + const VAL: usize = core::direct_const_arg!(2); + const VAL2: usize = core::direct_const_arg!(const { Self::VAL * 2 }); } struct Foo { @@ -50,15 +52,17 @@ Using `#![feature(macroless_generic_const_args)]` enables you to write the above #![feature(min_generic_const_args, macroless_generic_const_args)] trait Bar { - type const VAL: usize; - type const VAL2: usize; + #[rustc_always_gca] + const VAL: usize; + #[rustc_always_gca] + const VAL2: usize; } struct Baz; impl Bar for Baz { - type const VAL: usize = 2; - type const VAL2: usize = const { Self::VAL * 2 }; + const VAL: usize = 2; + const VAL2: usize = core::direct_const_arg!(const { Self::VAL * 2 }); } struct Foo { diff --git a/src/doc/unstable-book/src/language-features/min-generic-const-args.md b/src/doc/unstable-book/src/language-features/min-generic-const-args.md index c7815b176b6c3..0d33af9092cf6 100644 --- a/src/doc/unstable-book/src/language-features/min-generic-const-args.md +++ b/src/doc/unstable-book/src/language-features/min-generic-const-args.md @@ -1,6 +1,6 @@ # min_generic_const_args -Enables the generic const args MVP (paths to type const items and constructors for ADTs and primitives). +Enables the generic const args MVP (paths to direct const items and constructors for ADTs and primitives). The tracking issue for this feature is: [#132980] @@ -38,21 +38,21 @@ See [macroless_generic_const_args] as a feature to disable the requirement of wr [macroless_generic_const_args]: macroless-generic-const-args.md -## `type const` syntax +## direct const items -This feature introduces new syntax: `type const`. -Constants marked as `type const` are allowed to be used in type contexts, e.g.: +This feature introduces a new item kind: consts with a `direct_const_arg!` right-hand side. +Constants with a direct right-hand side are allowed to be used in type contexts, e.g.: ```compile_fail #![allow(incomplete_features)] #![feature(min_generic_const_args)] -type const X: usize = 1; +const X: usize = core::direct_const_arg!(1); const Y: usize = 1; struct Foo { good_arr: [(); core::direct_const_arg!(X)], // Allowed - bad_arr: [(); core::direct_const_arg!(Y)], // Will not compile, `Y` must be `type const`. + bad_arr: [(); core::direct_const_arg!(Y)], // Will not compile } ``` @@ -63,15 +63,17 @@ struct Foo { #![feature(min_generic_const_args)] trait Bar { - type const VAL: usize; - type const VAL2: usize; + #[rustc_always_gca] + const VAL: usize; + #[rustc_always_gca] + const VAL2: usize; } struct Baz; impl Bar for Baz { - type const VAL: usize = 2; - type const VAL2: usize = const { Self::VAL * 2 }; + const VAL: usize = core::direct_const_arg!(2); + const VAL2: usize = core::direct_const_arg!(const { Self::VAL * 2 }); } struct Foo { @@ -120,7 +122,7 @@ const fn inc(val: usize) -> usize { val + 1 } -type const INC: usize = const { inc(VAL) }; +const INC: usize = core::direct_const_arg!(const { inc(VAL) }); const ARR: [usize; INC] = [0; INC]; ``` diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index d7fbe64c30771..2fbfae88918a0 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -150,7 +150,7 @@ pub(crate) fn try_inline( clean::StaticItem(build_static(cx, did, cx.tcx.is_mutable_static(did))) }) } - Res::Def(DefKind::Const { .. }, did) => { + Res::Def(DefKind::Const, did) => { record_extern_fqn(cx, did, ItemType::Constant); cx.with_param_env(did, |cx| { let ct = build_const_item(cx, did); @@ -703,7 +703,7 @@ fn should_ignore_def_kind(kind: DefKind) -> bool { | DefKind::Variant | DefKind::Mod | DefKind::Static { .. } - | DefKind::Const { .. } + | DefKind::Const | DefKind::Macro(_) | DefKind::Use ) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 7a99ce8d39e9c..0dd397a2d8a40 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -256,11 +256,7 @@ impl ExternalCrate { tcx.module_children(root) .iter() .filter_map(|item| { - if let Res::Def(DefKind::Const { is_type_const: false }, did) = item.res { - Some(did) - } else { - None - } + if let Res::Def(DefKind::Const, did) = item.res { Some(did) } else { None } }) .filter_map(move |did| f(did, tcx)), ) diff --git a/src/librustdoc/formats/item_type.rs b/src/librustdoc/formats/item_type.rs index ed8804281334f..5d2638a33cb30 100644 --- a/src/librustdoc/formats/item_type.rs +++ b/src/librustdoc/formats/item_type.rs @@ -162,7 +162,7 @@ impl ItemType { DefKind::Enum => Self::Enum, DefKind::Fn => Self::Function, DefKind::Mod => Self::Module, - DefKind::Const { .. } => Self::Constant, + DefKind::Const => Self::Constant, DefKind::Static { .. } => Self::Static, DefKind::Struct => Self::Struct, DefKind::Union => Self::Union, @@ -185,7 +185,7 @@ impl ItemType { } DefKind::Ctor(CtorOf::Struct, _) => Self::Struct, DefKind::Ctor(CtorOf::Variant, _) => Self::Variant, - DefKind::AssocConst { .. } => Self::AssocConst, + DefKind::AssocConst => Self::AssocConst, DefKind::TyParam | DefKind::ConstParam | DefKind::ExternCrate diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 13fc6e3bc1bb8..a0cede949e98c 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -547,7 +547,7 @@ pub(crate) fn href_with_root_path( let tcx = cx.tcx(); let def_kind = tcx.def_kind(original_did); let did = match def_kind { - DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst { .. } | DefKind::Variant => { + DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst | DefKind::Variant => { // documented on their parent's page tcx.parent(original_did) } @@ -846,7 +846,7 @@ pub(crate) fn fragment(did: DefId, tcx: TyCtxt<'_>) -> impl Display { fmt::from_fn(move |f| { let def_kind = tcx.def_kind(did); match def_kind { - DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst { .. } | DefKind::Variant => { + DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst | DefKind::Variant => { let item_type = ItemType::from_def_id(did, tcx); write!(f, "#{}.{}", item_type.as_str(), tcx.item_name(did)) } diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 14a35795b275f..5241d5927a42e 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -123,10 +123,9 @@ impl Res { DefKind::Trait => "trait", DefKind::Union => "union", DefKind::Mod => "mod", - DefKind::Const { .. } - | DefKind::ConstParam - | DefKind::AssocConst { .. } - | DefKind::AnonConst => "const", + DefKind::Const | DefKind::ConstParam | DefKind::AssocConst | DefKind::AnonConst => { + "const" + } DefKind::Static { .. } => "static", DefKind::Field => "field", DefKind::Variant | DefKind::Ctor(..) => "variant", @@ -402,10 +401,7 @@ impl<'tcx> LinkCollector<'_, 'tcx> { if let Some(res) = self.resolve_path(path_str, ns, item_id, module_id) { return Ok(match res { Res::Def( - DefKind::AssocFn - | DefKind::AssocConst { .. } - | DefKind::AssocTy - | DefKind::Variant, + DefKind::AssocFn | DefKind::AssocConst | DefKind::AssocTy | DefKind::Variant, def_id, ) => { vec![(Res::from_def_id(self.cx.tcx, self.cx.tcx.parent(def_id)), Some(def_id))] @@ -502,7 +498,7 @@ fn resolve_self_ty<'tcx>( let self_id = match tcx.def_kind(item_id) { def_kind @ (DefKind::AssocFn - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::AssocTy | DefKind::Variant | DefKind::Field) => { @@ -1243,7 +1239,7 @@ impl LinkCollector<'_, '_> { let tcx = self.cx.tcx; let def_kind = tcx.def_kind(original_did); let did = match def_kind { - DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst { .. } | DefKind::Variant => { + DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst | DefKind::Variant => { // documented on their parent's page tcx.parent(original_did) } @@ -1432,11 +1428,11 @@ impl LinkCollector<'_, '_> { debug!("saw kind {kind:?} with disambiguator {disambiguator:?}"); match (kind, disambiguator) { | ( - DefKind::Const { .. } + DefKind::Const | DefKind::ConstParam - | DefKind::AssocConst { .. } + | DefKind::AssocConst | DefKind::AnonConst, - Some(Disambiguator::Kind(DefKind::Const { .. })), + Some(Disambiguator::Kind(DefKind::Const)), ) // NOTE: this allows 'method' to mean both normal functions and associated functions // This can't cause ambiguity because both are in the same namespace. @@ -1760,7 +1756,7 @@ impl Disambiguator { "trait" => Kind(DefKind::Trait), "union" => Kind(DefKind::Union), "module" | "mod" => Kind(DefKind::Mod), - "const" | "constant" => Kind(DefKind::Const { is_type_const: false }), + "const" | "constant" => Kind(DefKind::Const), "static" => Kind(DefKind::Static { mutability: Mutability::Not, nested: false, diff --git a/src/librustdoc/passes/lint/redundant_explicit_links.rs b/src/librustdoc/passes/lint/redundant_explicit_links.rs index c04438d69007b..d2f244e7bba0b 100644 --- a/src/librustdoc/passes/lint/redundant_explicit_links.rs +++ b/src/librustdoc/passes/lint/redundant_explicit_links.rs @@ -465,7 +465,7 @@ fn local_href_for_res(cx: &DocContext<'_>, module_id: DefId, res: Res) - if matches!( cx.tcx.def_kind(did), - DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst { .. } | DefKind::Variant + DefKind::AssocTy | DefKind::AssocFn | DefKind::AssocConst | DefKind::Variant ) || !did.is_local() { return None; diff --git a/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs b/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs index d5ada16a5c9a6..e72842d72f5cb 100644 --- a/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs +++ b/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs @@ -333,7 +333,7 @@ impl<'tcx> VarVisitor<'_, 'tcx> { } return false; // no need to walk further *on the variable* }, - Res::Def(DefKind::Static { .. } | DefKind::Const { .. }, ..) => { + Res::Def(DefKind::Static { .. } | DefKind::Const, ..) => { if index_used_directly { self.indexed_directly.insert( ( diff --git a/src/tools/clippy/clippy_lints/src/loops/same_item_push.rs b/src/tools/clippy/clippy_lints/src/loops/same_item_push.rs index 5e133cb79ce96..c31a857089fbd 100644 --- a/src/tools/clippy/clippy_lints/src/loops/same_item_push.rs +++ b/src/tools/clippy/clippy_lints/src/loops/same_item_push.rs @@ -82,7 +82,7 @@ pub(super) fn check<'tcx>( ExprKind::Lit(..) => emit_lint(cx, vec, pushed_item, ctxt, msrv), // immutable bindings that are initialized with constant ExprKind::Path(ref path) => { - if let Res::Def(DefKind::Const { .. }, ..) = cx.qpath_res(path, init.hir_id) { + if let Res::Def(DefKind::Const, ..) = cx.qpath_res(path, init.hir_id) { emit_lint(cx, vec, pushed_item, ctxt, msrv); } }, @@ -91,7 +91,7 @@ pub(super) fn check<'tcx>( } }, // constant - Res::Def(DefKind::Const { .. }, ..) => emit_lint(cx, vec, pushed_item, ctxt, msrv), + Res::Def(DefKind::Const, ..) => emit_lint(cx, vec, pushed_item, ctxt, msrv), _ => {}, } }, diff --git a/src/tools/clippy/clippy_lints/src/manual_float_methods.rs b/src/tools/clippy/clippy_lints/src/manual_float_methods.rs index 5e1d12179aacd..5eb9a8b855422 100644 --- a/src/tools/clippy/clippy_lints/src/manual_float_methods.rs +++ b/src/tools/clippy/clippy_lints/src/manual_float_methods.rs @@ -122,11 +122,11 @@ fn is_not_const(tcx: TyCtxt<'_>, def_id: DefId) -> bool { | DefKind::TestBinderConstraints => true, DefKind::AnonConst - | DefKind::Const { .. } + | DefKind::Const | DefKind::ConstParam | DefKind::Static { .. } | DefKind::Ctor(..) - | DefKind::AssocConst { .. } => false, + | DefKind::AssocConst => false, DefKind::Fn | DefKind::AssocFn | DefKind::Closure => tcx.constness(def_id) == Constness::NotConst, } diff --git a/src/tools/clippy/clippy_lints/src/manual_main_separator_str.rs b/src/tools/clippy/clippy_lints/src/manual_main_separator_str.rs index c209083a0b2a3..4cce5e1330fb9 100644 --- a/src/tools/clippy/clippy_lints/src/manual_main_separator_str.rs +++ b/src/tools/clippy/clippy_lints/src/manual_main_separator_str.rs @@ -50,7 +50,7 @@ impl LateLintPass<'_> for ManualMainSeparatorStr { if let ExprKind::MethodCall(path, receiver, &[], _) = target.kind && path.ident.name == sym::to_string && let ExprKind::Path(QPath::Resolved(None, path)) = receiver.kind - && let Res::Def(DefKind::Const { .. }, receiver_def_id) = path.res + && let Res::Def(DefKind::Const, receiver_def_id) = path.res && cx.ty_based_def(target).opt_parent(cx).is_diag_item(cx, sym::ToString) && cx.tcx.is_diagnostic_item(sym::path_main_separator, receiver_def_id) && let ty::Ref(_, ty, Mutability::Not) = cx.typeck_results().expr_ty_adjusted(expr).kind() diff --git a/src/tools/clippy/clippy_lints/src/matches/match_wild_enum.rs b/src/tools/clippy/clippy_lints/src/matches/match_wild_enum.rs index 7abcf7690e0b4..443e84f163824 100644 --- a/src/tools/clippy/clippy_lints/src/matches/match_wild_enum.rs +++ b/src/tools/clippy/clippy_lints/src/matches/match_wild_enum.rs @@ -67,7 +67,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) { }) => { // FIXME(clippy): don't you want to use the hir id of the peeled pat? let id = match cx.qpath_res(path, *hir_id) { - Res::Def(DefKind::Const { .. } | DefKind::ConstParam | DefKind::AnonConst, _) => return, + Res::Def(DefKind::Const | DefKind::ConstParam | DefKind::AnonConst, _) => return, Res::Def(_, id) => id, _ => return, }; 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 919b9b8ba8368..a9d747e2757f7 100644 --- a/src/tools/clippy/clippy_lints/src/non_copy_const.rs +++ b/src/tools/clippy/clippy_lints/src/non_copy_const.rs @@ -403,14 +403,14 @@ impl<'tcx> NonCopyConst<'tcx> { .instantiate(tcx, gen_args) .skip_norm_wip(); match res { - Res::Def(DefKind::Const { .. } | DefKind::AssocConst { .. }, did) + Res::Def(DefKind::Const | DefKind::AssocConst, did) if let Ok(val) = tcx.const_eval_resolve(typing_env, UnevaluatedConst::new(did, gen_args), DUMMY_SP) && let Ok(is_freeze) = self.is_value_freeze(tcx, typing_env, ty, val) => { is_freeze }, - Res::Def(DefKind::Const { .. } | DefKind::AssocConst { .. }, did) + Res::Def(DefKind::Const | DefKind::AssocConst, did) if let Some((typeck, init)) = get_const_hir_value(tcx, typing_env, did, gen_args) => { self.is_init_expr_freeze(tcx, typing_env, typeck, gen_args, init) @@ -602,7 +602,7 @@ impl<'tcx> NonCopyConst<'tcx> { .skip_norm_wip(); match init_typeck.qpath_res(init_path, init_expr.hir_id) { Res::Def(DefKind::Ctor(..), _) => return None, - Res::Def(DefKind::Const { .. } | DefKind::AssocConst { .. }, did) + Res::Def(DefKind::Const | DefKind::AssocConst, did) if let Ok(val) = tcx.const_eval_resolve( typing_env, UnevaluatedConst::new(did, next_init_args), @@ -612,7 +612,7 @@ impl<'tcx> NonCopyConst<'tcx> { { return res; }, - Res::Def(DefKind::Const { .. } | DefKind::AssocConst { .. }, did) + Res::Def(DefKind::Const | DefKind::AssocConst, did) if let Some((next_typeck, value)) = get_const_hir_value(tcx, typing_env, did, next_init_args) => { @@ -851,7 +851,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst<'tcx> { fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { if let ExprKind::Path(qpath) = &e.kind && let typeck = cx.typeck_results() - && let Res::Def(DefKind::Const { .. } | DefKind::AssocConst { .. }, did) = typeck.qpath_res(qpath, e.hir_id) + && let Res::Def(DefKind::Const | DefKind::AssocConst, did) = typeck.qpath_res(qpath, e.hir_id) // As of `1.80` constant contexts can't borrow any type with interior mutability && !is_in_const_context(cx) && !self.is_ty_freeze(cx.tcx, cx.typing_env(), typeck.expr_ty(e)).is_freeze() diff --git a/src/tools/clippy/clippy_lints/src/operators/float_equality_without_abs.rs b/src/tools/clippy/clippy_lints/src/operators/float_equality_without_abs.rs index 6c6221525b578..ba87cb9524164 100644 --- a/src/tools/clippy/clippy_lints/src/operators/float_equality_without_abs.rs +++ b/src/tools/clippy/clippy_lints/src/operators/float_equality_without_abs.rs @@ -35,7 +35,7 @@ pub(crate) fn check<'tcx>( // right hand side matches _::EPSILON && let ExprKind::Path(ref epsilon_path) = rhs.kind - && let Res::Def(DefKind::AssocConst { .. }, def_id) = cx.qpath_res(epsilon_path, rhs.hir_id) + && let Res::Def(DefKind::AssocConst, def_id) = cx.qpath_res(epsilon_path, rhs.hir_id) && let Some(sym) = cx.tcx.get_diagnostic_name(def_id) && matches!(sym, sym::f16_epsilon | sym::f32_epsilon | sym::f64_epsilon | sym::f128_epsilon) diff --git a/src/tools/clippy/clippy_lints_internal/src/symbols.rs b/src/tools/clippy/clippy_lints_internal/src/symbols.rs index d0a5b3590fbae..99be873863a17 100644 --- a/src/tools/clippy/clippy_lints_internal/src/symbols.rs +++ b/src/tools/clippy/clippy_lints_internal/src/symbols.rs @@ -112,7 +112,7 @@ impl<'tcx> LateLintPass<'tcx> for Symbols { } for item in cx.tcx.module_children(*def_id) { - if let Res::Def(DefKind::Const { .. }, item_def_id) = item.res + if let Res::Def(DefKind::Const, item_def_id) = item.res && let ty = cx.tcx.type_of(item_def_id).instantiate_identity().skip_norm_wip() && internal_paths::SYMBOL.matches_ty(cx, ty) && let Ok(ConstValue::Scalar(value)) = cx.tcx.const_eval_poly(item_def_id) 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 944dedb775729..c340c56781082 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs @@ -337,7 +337,6 @@ fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { generics: lg, ty: lt, body: lb, - kind: lk, define_opaque: _, }), Const(ConstItem { @@ -347,7 +346,6 @@ fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { ty: rt, body: rb, - kind: rk, define_opaque: _, }), ) => { @@ -355,7 +353,6 @@ fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { && eq_id(*li, *ri) && eq_generics(lg, rg) && eq_ty(lt, rt) - && lk == rk && both(lb.as_deref(), rb.as_deref(), eq_expr) }, ( @@ -606,7 +603,6 @@ fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { generics: lg, ty: lt, body: lb, - kind: lk, define_opaque: _, }), Const(ConstItem { @@ -615,7 +611,6 @@ fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { generics: rg, ty: rt, body: rb, - kind: rk, define_opaque: _, }), ) => { @@ -623,7 +618,6 @@ fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { && eq_id(*li, *ri) && eq_generics(lg, rg) && eq_ty(lt, rt) - && lk == rk && both(lb.as_deref(), rb.as_deref(), eq_expr) }, ( diff --git a/src/tools/clippy/clippy_utils/src/consts.rs b/src/tools/clippy/clippy_utils/src/consts.rs index 8ca6d08e325f7..14c987f39e86a 100644 --- a/src/tools/clippy/clippy_utils/src/consts.rs +++ b/src/tools/clippy/clippy_utils/src/consts.rs @@ -778,7 +778,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> { QPath::Resolved(None, path) if path.span.ctxt() == self.ctxt.get() && path.segments.iter().all(|s| self.ctxt.get() == s.ident.span.ctxt()) - && let Res::Def(DefKind::Const { .. }, did) = path.res + && let Res::Def(DefKind::Const, did) = path.res && (matches!( self.tcx.get_diagnostic_name(did), Some( @@ -866,7 +866,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> { && ty.span.ctxt() == self.ctxt.get() && ty_name.ident.span.ctxt() == self.ctxt.get() && matches!(ty_path.res, Res::PrimTy(_)) - && let Some((DefKind::AssocConst { .. }, did)) = self.typeck.type_dependent_def(id) + && let Some((DefKind::AssocConst, did)) = self.typeck.type_dependent_def(id) && self.tcx.inherent_impl_of_assoc(did).is_some() => { did @@ -874,10 +874,8 @@ impl<'tcx> ConstEvalCtxt<'tcx> { // TODO: revisit when feature `min_generic_const_args` is stabilized. In the meantime, // `TyCtxt::const_eval_resolve()` will trigger an ICE when evaluating the body of the // `type const` definition. - _ if let Res::Def( - DefKind::Const { is_type_const: false } | DefKind::AssocConst { is_type_const: false }, - did, - ) = self.typeck.qpath_res(qpath, id) => + _ if let Res::Def(DefKind::Const | DefKind::AssocConst, did) = self.typeck.qpath_res(qpath, id) + && !self.tcx.is_direct_const(did) => { self.source.set(ConstantSource::NonLocal); did diff --git a/src/tools/clippy/clippy_utils/src/hir_utils.rs b/src/tools/clippy/clippy_utils/src/hir_utils.rs index a229de847b92e..cf7777d037d9b 100644 --- a/src/tools/clippy/clippy_utils/src/hir_utils.rs +++ b/src/tools/clippy/clippy_utils/src/hir_utils.rs @@ -837,7 +837,7 @@ impl HirEqInterExpr<'_, '_, '_> { (Res::Local(_), _) | (_, Res::Local(_)) => false, (Res::Def(l_kind, l), Res::Def(r_kind, r)) if l_kind == r_kind - && let DefKind::Const { .. } + && let DefKind::Const | DefKind::Static { .. } | DefKind::Fn | DefKind::TyAlias @@ -1112,7 +1112,7 @@ pub fn eq_expr_value(cx: &LateContext<'_>, ctxt: SyntaxContext, left: &Expr<'_>, /// item, in which case it is the last two fn generic_path_segments<'tcx>(segments: &'tcx [PathSegment<'tcx>]) -> Option<&'tcx [PathSegment<'tcx>]> { match segments.last()?.res { - Res::Def(DefKind::AssocConst { .. } | DefKind::AssocFn | DefKind::AssocTy, _) => { + Res::Def(DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy, _) => { // >::assoc:: // ^^^^^^^^^^^^^^^^ ^^^^^^^^^^ segments: [module, Trait, assoc] Some(&segments[segments.len().checked_sub(2)?..]) diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index 5ba7c0496e906..6eeef786b9a1e 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -2361,7 +2361,7 @@ fn test_item_names(tcx: TyCtxt<'_>, module: LocalModId) -> Vec { Entry::Vacant(entry) => { let mut names = Vec::new(); for id in tcx.hir_module_free_items(module) { - if matches!(tcx.def_kind(id.owner_id), DefKind::Const { .. }) + if tcx.def_kind(id.owner_id) == DefKind::Const && let item = tcx.hir_item(id) && let ItemKind::Const(ident, _generics, ty, _body) = item.kind && let TyKind::Path(QPath::Resolved(_, path)) = ty.kind diff --git a/src/tools/clippy/clippy_utils/src/res.rs b/src/tools/clippy/clippy_utils/src/res.rs index 4d45677f4c8a5..3d0c4bb1a1188 100644 --- a/src/tools/clippy/clippy_utils/src/res.rs +++ b/src/tools/clippy/clippy_utils/src/res.rs @@ -576,7 +576,7 @@ pub trait MaybeDef: Copy { #[inline] fn assoc_parent<'tcx>(self, tcx: &impl HasTyCtxt<'tcx>) -> Option { match self.opt_def(tcx) { - Some((DefKind::AssocConst { .. } | DefKind::AssocFn | DefKind::AssocTy, id)) => tcx.tcx().opt_parent(id), + Some((DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy, id)) => tcx.tcx().opt_parent(id), _ => None, } } diff --git a/src/tools/clippy/clippy_utils/src/visitors.rs b/src/tools/clippy/clippy_utils/src/visitors.rs index 1192d7353d123..c5a101caebc21 100644 --- a/src/tools/clippy/clippy_utils/src/visitors.rs +++ b/src/tools/clippy/clippy_utils/src/visitors.rs @@ -364,8 +364,8 @@ fn is_const_evaluatable_helper<'tcx>(tcx: TyCtxt<'tcx>, typeck: &'tcx TypeckResu if matches!( typeck.qpath_res(p, e.hir_id), Res::Def( - DefKind::Const { .. } - | DefKind::AssocConst { .. } + DefKind::Const + | DefKind::AssocConst | DefKind::AnonConst | DefKind::ConstParam | DefKind::Ctor(..) diff --git a/src/tools/clippy/tests/ui/crashes/mgca-16691.rs b/src/tools/clippy/tests/ui/crashes/mgca-16691.rs index 37a8821c60ad4..7e45f96fa9a9a 100644 --- a/src/tools/clippy/tests/ui/crashes/mgca-16691.rs +++ b/src/tools/clippy/tests/ui/crashes/mgca-16691.rs @@ -3,12 +3,13 @@ #![feature(min_generic_const_args)] trait Trait { - type const N: usize; + #[rustc_always_gca] + const N: usize; fn process(); } impl Trait for () { - type const N: usize = 3; + const N: usize = core::direct_const_arg!(3); fn process() { const N: usize = <()>::N; _ = 0..Self::N; 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 96cc654fd090d..dc1d663a9393b 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,7 +3,8 @@ #![feature(min_generic_const_args)] trait AssocConstTrait { - type const ASSOC: usize; + #[rustc_always_gca] + 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 b81dd673bb694..669e0fbdd3809 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,7 +3,8 @@ #![feature(min_generic_const_args)] trait AssocConstTrait { - type const ASSOC: usize; + #[rustc_always_gca] + const ASSOC: usize; } fn assoc_const_args() where diff --git a/src/tools/clippy/tests/ui/trait_duplication_in_bounds_assoc_const_eq.stderr b/src/tools/clippy/tests/ui/trait_duplication_in_bounds_assoc_const_eq.stderr index 4053959aff61b..accc4d7b5bb8a 100644 --- a/src/tools/clippy/tests/ui/trait_duplication_in_bounds_assoc_const_eq.stderr +++ b/src/tools/clippy/tests/ui/trait_duplication_in_bounds_assoc_const_eq.stderr @@ -1,5 +1,5 @@ error: these where clauses contain repeated elements - --> tests/ui/trait_duplication_in_bounds_assoc_const_eq.rs:10:8 + --> tests/ui/trait_duplication_in_bounds_assoc_const_eq.rs:11:8 | LL | T: AssocConstTrait + AssocConstTrait, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `AssocConstTrait` diff --git a/src/tools/rustfmt/src/items.rs b/src/tools/rustfmt/src/items.rs index 37dc231c3c45a..d561ac6cd3b5c 100644 --- a/src/tools/rustfmt/src/items.rs +++ b/src/tools/rustfmt/src/items.rs @@ -2010,11 +2010,7 @@ impl<'a> StaticParts<'a> { ), ast::ItemKind::Const(c) => ( Some(c.defaultness), - if c.kind == ast::ConstItemKind::TypeConst { - "type const" - } else { - "const" - }, + "const", ast::Safety::Default, c.ident, &c.ty, @@ -2039,25 +2035,14 @@ impl<'a> StaticParts<'a> { } pub(crate) fn from_trait_item(ti: &'a ast::AssocItem, ident: Ident) -> Self { - let (defaultness, ty, expr_opt, generics, prefix) = match &ti.kind { + let (defaultness, ty, expr_opt, generics) = match &ti.kind { ast::AssocItemKind::Const(c) => { - let prefix = if c.kind == ast::ConstItemKind::TypeConst { - "type const" - } else { - "const" - }; - ( - c.defaultness, - &c.ty, - c.body.as_deref(), - Some(&c.generics), - prefix, - ) + (c.defaultness, &c.ty, c.body.as_deref(), Some(&c.generics)) } _ => unreachable!(), }; StaticParts { - prefix, + prefix: "const", safety: ast::Safety::Default, vis: &ti.vis, ident, @@ -2071,25 +2056,14 @@ impl<'a> StaticParts<'a> { } pub(crate) fn from_impl_item(ii: &'a ast::AssocItem, ident: Ident) -> Self { - let (defaultness, ty, expr_opt, generics, prefix) = match &ii.kind { + let (defaultness, ty, expr_opt, generics) = match &ii.kind { ast::AssocItemKind::Const(c) => { - let prefix = if c.kind == ast::ConstItemKind::TypeConst { - "type const" - } else { - "const" - }; - ( - c.defaultness, - &c.ty, - c.body.as_deref(), - Some(&c.generics), - prefix, - ) + (c.defaultness, &c.ty, c.body.as_deref(), Some(&c.generics)) } _ => unreachable!(), }; StaticParts { - prefix, + prefix: "const", safety: ast::Safety::Default, vis: &ii.vis, ident, diff --git a/src/tools/rustfmt/tests/source/direct_const_arg.rs b/src/tools/rustfmt/tests/source/direct_const_arg.rs index f6f9c25d9a0d8..6486d782cc1f5 100644 --- a/src/tools/rustfmt/tests/source/direct_const_arg.rs +++ b/src/tools/rustfmt/tests/source/direct_const_arg.rs @@ -5,7 +5,8 @@ #![feature(min_generic_const_args)] trait Trait { - type const TYPE_CONST: usize; + #[rustc_always_gca] + const TYPE_CONST: usize; } struct S; diff --git a/src/tools/rustfmt/tests/target/direct_const_arg.rs b/src/tools/rustfmt/tests/target/direct_const_arg.rs index 1ebadae00ff05..94a6c864b78ef 100644 --- a/src/tools/rustfmt/tests/target/direct_const_arg.rs +++ b/src/tools/rustfmt/tests/target/direct_const_arg.rs @@ -5,7 +5,8 @@ #![feature(min_generic_const_args)] trait Trait { - type const TYPE_CONST: usize; + #[rustc_always_gca] + const TYPE_CONST: usize; } struct S; diff --git a/tests/crashes/149809.rs b/tests/crashes/149809.rs index fafd1d5224e89..c2392a9c41eb2 100644 --- a/tests/crashes/149809.rs +++ b/tests/crashes/149809.rs @@ -5,7 +5,7 @@ struct Qux<'a> { x: &'a (), } impl<'a> Qux<'a> { - type const LEN: usize = 4; + const LEN: usize = core::direct_const_arg!(4); fn foo(_: [u8; core::direct_const_arg!(Qux::LEN)]) {} } diff --git a/tests/crashes/160553.rs b/tests/crashes/160553.rs index faf993e102756..dc5628cf598fb 100644 --- a/tests/crashes/160553.rs +++ b/tests/crashes/160553.rs @@ -5,12 +5,13 @@ #![feature(generic_const_parameter_types)] trait Trait { - type const LEN: usize; + #[rustc_always_gca] + const LEN: usize; } struct S; impl Trait for S { - type const LEN: usize = 2; + const LEN: usize = core::direct_const_arg!(2); } fn foo::LEN]>() -> [u8; ::LEN] { diff --git a/tests/debuginfo/associated-const-bindings.rs b/tests/debuginfo/associated-const-bindings.rs index 88c17cee8025c..1a7ca6a5b0a95 100644 --- a/tests/debuginfo/associated-const-bindings.rs +++ b/tests/debuginfo/associated-const-bindings.rs @@ -14,10 +14,11 @@ #![expect(unused_variables, incomplete_features)] trait Trait { - type const N: usize; + #[rustc_always_gca] + const N: usize; } impl Trait for () { - type const N: usize = 101; + const N: usize = core::direct_const_arg!(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 bdb82b91ec275..5c47382ef536d 100644 --- a/tests/rustdoc-html/constant/ice-associated-const-equality-105952.rs +++ b/tests/rustdoc-html/constant/ice-associated-const-equality-105952.rs @@ -10,7 +10,8 @@ pub enum ParseMode { Raw, } pub trait Parse { - type const PARSE_MODE: ParseMode; + #[rustc_always_gca] + 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 939740d8f918a..64cfc129d09ce 100644 --- a/tests/rustdoc-html/inline_cross/auxiliary/assoc-const-equality.rs +++ b/tests/rustdoc-html/inline_cross/auxiliary/assoc-const-equality.rs @@ -4,5 +4,6 @@ pub fn accept(_: impl Trait) {} pub trait Trait { - type const K: i32; + #[rustc_always_gca] + const K: i32; } diff --git a/tests/rustdoc-html/type-const-associated-const-no-body.rs b/tests/rustdoc-html/type-const-associated-const-no-body.rs index 1a5bb72f05fdd..101e4b48a9c9c 100644 --- a/tests/rustdoc-html/type-const-associated-const-no-body.rs +++ b/tests/rustdoc-html/type-const-associated-const-no-body.rs @@ -6,7 +6,8 @@ #![expect(incomplete_features)] pub trait Tr { - type const SIZE: usize; + #[rustc_always_gca] + const SIZE: usize; } //@ has 'foo/fn.mk_array.html' diff --git a/tests/rustdoc-html/type-const-free-in-array.rs b/tests/rustdoc-html/type-const-free-in-array.rs index fed209f16d1e0..4583e20fb8998 100644 --- a/tests/rustdoc-html/type-const-free-in-array.rs +++ b/tests/rustdoc-html/type-const-free-in-array.rs @@ -2,7 +2,7 @@ #![feature(min_generic_const_args, macroless_generic_const_args)] #![expect(incomplete_features)] -type const N: usize = 2; +const N: usize = core::direct_const_arg!(2); //@ has 'foo/trait.CollectArray.html' //@ has - '//pre[@class="rust item-decl"]/code' '[A; N]' diff --git a/tests/rustdoc-html/type-const-inherent-with-body.rs b/tests/rustdoc-html/type-const-inherent-with-body.rs index fae06a12f55f5..a209ac47dcb0d 100644 --- a/tests/rustdoc-html/type-const-inherent-with-body.rs +++ b/tests/rustdoc-html/type-const-inherent-with-body.rs @@ -5,7 +5,7 @@ pub struct Foo; impl Foo { - type const LEN: usize = 4; + const LEN: usize = core::direct_const_arg!(4); } //@ has 'foo/fn.mk_array.html' diff --git a/tests/rustdoc-ui/associated-constant-not-allowed-102467.rs b/tests/rustdoc-ui/associated-constant-not-allowed-102467.rs index 4168a5653dd5c..af6899571d631 100644 --- a/tests/rustdoc-ui/associated-constant-not-allowed-102467.rs +++ b/tests/rustdoc-ui/associated-constant-not-allowed-102467.rs @@ -11,7 +11,8 @@ trait T { } trait S { - type const C: i32; + #[rustc_always_gca] + const C: i32; } fn main() {} diff --git a/tests/ui-fulldeps/rustc_public/crate-info.rs b/tests/ui-fulldeps/rustc_public/crate-info.rs index 0a8facdcf716c..6d1f69d2a195c 100644 --- a/tests/ui-fulldeps/rustc_public/crate-info.rs +++ b/tests/ui-fulldeps/rustc_public/crate-info.rs @@ -16,14 +16,15 @@ extern crate rustc_interface; #[macro_use] extern crate rustc_public; +use std::assert_matches; +use std::io::Write; +use std::ops::ControlFlow; + use rustc_hir::def::DefKind; use rustc_public::ItemKind; use rustc_public::crate_def::CrateDef; use rustc_public::mir::mono::Instance; use rustc_public::ty::{RigidTy, TyKind}; -use std::assert_matches; -use std::io::Write; -use std::ops::ControlFlow; const CRATE_NAME: &str = "input"; @@ -139,8 +140,7 @@ fn test_stable_mir() -> ControlFlow<()> { } } - let foo_const = - get_item(&items, (DefKind::Const { is_type_const: false }, "input::FOO")).unwrap(); + let foo_const = get_item(&items, (DefKind::Const, "input::FOO")).unwrap(); // Ensure we don't panic trying to get the body of a constant. foo_const.expect_body(); @@ -182,8 +182,7 @@ fn get_item<'a>( items.iter().find(|crate_item| { matches!( (item.0, crate_item.kind()), - (DefKind::Fn, ItemKind::Fn) - | (DefKind::Const { is_type_const: false }, ItemKind::Const) + (DefKind::Fn, ItemKind::Fn) | (DefKind::Const, ItemKind::Const) ) && crate_item.name() == item.1 }) } diff --git a/tests/ui/associated-consts/issue-110933.rs b/tests/ui/associated-consts/issue-110933.rs index 0115fb7d6e655..8c3fc59af1bb1 100644 --- a/tests/ui/associated-consts/issue-110933.rs +++ b/tests/ui/associated-consts/issue-110933.rs @@ -4,7 +4,8 @@ #![allow(incomplete_features)] pub trait Trait { - type const ASSOC: usize; + #[rustc_always_gca] + 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 a61ca256baf91..919aba47aea28 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,7 +8,7 @@ struct OnDiskDirEntry<'a>(&'a ()); impl<'a> OnDiskDirEntry<'a> { - type const LFN_FRAGMENT_LEN: i64 = 2; + const LFN_FRAGMENT_LEN: i64 = core::direct_const_arg!(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.rs b/tests/ui/associated-consts/type-const-in-array-len.rs index 976d8c9ffd533..0f53aa9dd56fe 100644 --- a/tests/ui/associated-consts/type-const-in-array-len.rs +++ b/tests/ui/associated-consts/type-const-in-array-len.rs @@ -5,7 +5,7 @@ // Test case from #138226: generic impl with multiple type parameters struct Foo(A, B); impl Foo { - type const LEN: usize = 4; + const LEN: usize = core::direct_const_arg!(4); fn foo() { let _ = [5; Self::LEN]; @@ -15,7 +15,7 @@ impl Foo { // Test case from #138226: generic impl with const parameter struct Bar; impl Bar { - type const LEN: usize = 4; + const LEN: usize = core::direct_const_arg!(4); fn bar() { let _ = [0; Self::LEN]; @@ -25,7 +25,7 @@ impl Bar { // Test case from #150960: non-generic impl with const block struct Baz; impl Baz { - type const LEN: usize = 4; + const LEN: usize = core::direct_const_arg!(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 56403fdf6630c..0d1ab691c5c7f 100644 --- a/tests/ui/associated-type-bounds/duplicate-bound-err.rs +++ b/tests/ui/associated-type-bounds/duplicate-bound-err.rs @@ -1,10 +1,6 @@ //@ edition: 2024 -#![feature( - min_generic_const_args, - type_alias_impl_trait, - return_type_notation -)] +#![feature(min_generic_const_args, type_alias_impl_trait, return_type_notation)] #![expect(incomplete_features)] #![allow(refining_impl_trait_internal)] @@ -50,7 +46,8 @@ fn mismatch_2() -> impl Iterator { trait Trait { type Gat; - type const ASSOC: i32; + #[rustc_always_gca] + const ASSOC: i32; fn foo() -> impl Sized; } @@ -58,7 +55,7 @@ trait Trait { impl Trait for () { type Gat = (); - type const ASSOC: i32 = 3; + const ASSOC: i32 = core::direct_const_arg!(3); fn foo() {} } @@ -66,7 +63,7 @@ impl Trait for () { impl Trait for u32 { type Gat = (); - type const ASSOC: i32 = 4; + const ASSOC: i32 = core::direct_const_arg!(4); fn foo() -> u32 { 42 @@ -77,16 +74,15 @@ fn uncallable(_: impl Iterator) {} fn uncallable_const(_: impl Trait) {} -fn uncallable_rtn( - _: impl Trait, foo(..): Trait> -) {} +fn uncallable_rtn(_: impl Trait, foo(..): Trait>) {} type MustFail = dyn Iterator; //~^ ERROR [E0719] //~| ERROR conflicting associated type bindings trait Trait2 { - type const ASSOC: u32; + #[rustc_always_gca] + 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 f685b01cd8cc3..04c9f33c0889b 100644 --- a/tests/ui/associated-type-bounds/duplicate-bound-err.stderr +++ b/tests/ui/associated-type-bounds/duplicate-bound-err.stderr @@ -1,5 +1,5 @@ error[E0282]: type annotations needed - --> $DIR/duplicate-bound-err.rs:14:5 + --> $DIR/duplicate-bound-err.rs:10:5 | LL | iter::empty() | ^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `empty` @@ -10,7 +10,7 @@ LL | iter::empty::() | ++++++++++++++ error[E0282]: type annotations needed - --> $DIR/duplicate-bound-err.rs:18:5 + --> $DIR/duplicate-bound-err.rs:14:5 | LL | iter::empty() | ^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `empty` @@ -21,7 +21,7 @@ LL | iter::empty::() | ++++++++++++++ error[E0282]: type annotations needed - --> $DIR/duplicate-bound-err.rs:22:5 + --> $DIR/duplicate-bound-err.rs:18:5 | LL | iter::empty() | ^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `empty` @@ -32,7 +32,7 @@ LL | iter::empty::() | ++++++++++++++ error: unconstrained opaque type - --> $DIR/duplicate-bound-err.rs:26:51 + --> $DIR/duplicate-bound-err.rs:22:51 | LL | type Tait1> = impl Copy; | ^^^^^^^^^ @@ -40,7 +40,7 @@ LL | type Tait1> = impl Copy; = note: `Tait1` must be used in combination with a concrete type within the same crate error: unconstrained opaque type - --> $DIR/duplicate-bound-err.rs:28:51 + --> $DIR/duplicate-bound-err.rs:24:51 | LL | type Tait2> = impl Copy; | ^^^^^^^^^ @@ -48,7 +48,7 @@ LL | type Tait2> = impl Copy; = note: `Tait2` must be used in combination with a concrete type within the same crate error: unconstrained opaque type - --> $DIR/duplicate-bound-err.rs:30:57 + --> $DIR/duplicate-bound-err.rs:26:57 | LL | type Tait3> = impl Copy; | ^^^^^^^^^ @@ -56,7 +56,7 @@ LL | type Tait3> = impl Copy; = note: `Tait3` must be used in combination with a concrete type within the same crate error: unconstrained opaque type - --> $DIR/duplicate-bound-err.rs:33:14 + --> $DIR/duplicate-bound-err.rs:29:14 | LL | type Tait4 = impl Iterator; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -64,7 +64,7 @@ LL | type Tait4 = impl Iterator; = note: `Tait4` must be used in combination with a concrete type within the same crate error: unconstrained opaque type - --> $DIR/duplicate-bound-err.rs:35:14 + --> $DIR/duplicate-bound-err.rs:31:14 | LL | type Tait5 = impl Iterator; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -72,7 +72,7 @@ LL | type Tait5 = impl Iterator; = note: `Tait5` must be used in combination with a concrete type within the same crate error: unconstrained opaque type - --> $DIR/duplicate-bound-err.rs:37:14 + --> $DIR/duplicate-bound-err.rs:33:14 | LL | type Tait6 = impl Iterator; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -80,7 +80,7 @@ LL | type Tait6 = impl Iterator; = note: `Tait6` must be used in combination with a concrete type within the same crate error[E0277]: `*const ()` cannot be sent between threads safely - --> $DIR/duplicate-bound-err.rs:40:18 + --> $DIR/duplicate-bound-err.rs:36:18 | LL | fn mismatch() -> impl Iterator { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely @@ -91,7 +91,7 @@ LL | iter::empty::<*const ()>() = help: the trait `Send` is not implemented for `*const ()` error[E0277]: the trait bound `String: Copy` is not satisfied - --> $DIR/duplicate-bound-err.rs:45:20 + --> $DIR/duplicate-bound-err.rs:41:20 | LL | fn mismatch_2() -> impl Iterator { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` @@ -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:107:17 + --> $DIR/duplicate-bound-err.rs:103:17 | LL | fn foo() -> impl Iterator { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32` @@ -109,7 +109,7 @@ LL | [2u32].into_iter() | ------------------ return type was inferred to be `std::array::IntoIter` here | note: the method call chain might not have had the expected associated types - --> $DIR/duplicate-bound-err.rs:110:16 + --> $DIR/duplicate-bound-err.rs:106:16 | LL | [2u32].into_iter() | ------ ^^^^^^^^^^^ `Iterator::Item` is `u32` here @@ -117,19 +117,19 @@ LL | [2u32].into_iter() | this expression has type `[u32; 1]` error[E0271]: expected `impl Iterator` to be an iterator that yields `i32`, but it yields `u32` - --> $DIR/duplicate-bound-err.rs:107:17 + --> $DIR/duplicate-bound-err.rs:103: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:103:31 + --> $DIR/duplicate-bound-err.rs:99: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:84:42 + --> $DIR/duplicate-bound-err.rs:79:42 | LL | type MustFail = dyn Iterator; | ---------- ^^^^^^^^^^ re-bound here @@ -137,7 +137,7 @@ LL | type MustFail = dyn Iterator; | `Item` bound here first error: conflicting associated type bindings for `Item` - --> $DIR/duplicate-bound-err.rs:84:17 + --> $DIR/duplicate-bound-err.rs:79:17 | LL | type MustFail = dyn Iterator; | ^^^^^^^^^^^^^----------^^----------^ @@ -146,7 +146,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:92:43 + --> $DIR/duplicate-bound-err.rs:88:43 | LL | type MustFail2 = dyn Trait2; | ------------ ^^^^^^^^^^^^ re-bound here @@ -154,7 +154,7 @@ LL | type MustFail2 = dyn Trait2; | `ASSOC` bound here first error: conflicting associated constant bindings for `ASSOC` - --> $DIR/duplicate-bound-err.rs:92:18 + --> $DIR/duplicate-bound-err.rs:88:18 | LL | type MustFail2 = dyn Trait2; | ^^^^^^^^^^^------------^^------------^ @@ -163,7 +163,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:96:43 + --> $DIR/duplicate-bound-err.rs:92:43 | LL | type MustFail3 = dyn Iterator; | ---------- ^^^^^^^^^^ re-bound here @@ -171,7 +171,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:99:43 + --> $DIR/duplicate-bound-err.rs:95:43 | LL | type MustFail4 = dyn Trait2; | ------------ ^^^^^^^^^^^^ re-bound here @@ -179,7 +179,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:115:16 + --> $DIR/duplicate-bound-err.rs:111:16 | LL | uncallable(iter::empty::()); | ---------- ^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u32` @@ -187,13 +187,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:76:32 + --> $DIR/duplicate-bound-err.rs:73: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:116:16 + --> $DIR/duplicate-bound-err.rs:112:16 | LL | uncallable(iter::empty::()); | ---------- ^^^^^^^^^^^^^^^^^^^^ expected `u32`, found `i32` @@ -201,13 +201,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:76:44 + --> $DIR/duplicate-bound-err.rs:73: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:117:22 + --> $DIR/duplicate-bound-err.rs:113:22 | LL | uncallable_const(()); | ---------------- ^^ expected `4`, found `3` @@ -217,13 +217,13 @@ LL | uncallable_const(()); = note: expected constant `4` found constant `3` note: required by a bound in `uncallable_const` - --> $DIR/duplicate-bound-err.rs:78:46 + --> $DIR/duplicate-bound-err.rs:75: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:118:22 + --> $DIR/duplicate-bound-err.rs:114:22 | LL | uncallable_const(4u32); | ---------------- ^^^^ expected `3`, found `4` @@ -233,13 +233,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:78:35 + --> $DIR/duplicate-bound-err.rs:75: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:119:20 + --> $DIR/duplicate-bound-err.rs:115:20 | LL | uncallable_rtn(()); | -------------- ^^ expected `4`, found `3` @@ -249,15 +249,13 @@ LL | uncallable_rtn(()); = note: expected constant `4` found constant `3` note: required by a bound in `uncallable_rtn` - --> $DIR/duplicate-bound-err.rs:81:61 + --> $DIR/duplicate-bound-err.rs:77:75 | -LL | fn uncallable_rtn( - | -------------- required by a bound in this function -LL | _: impl Trait, foo(..): Trait> - | ^^^^^^^^^ required by this bound in `uncallable_rtn` +LL | fn uncallable_rtn(_: impl Trait, foo(..): Trait>) {} + | ^^^^^^^^^ required by this bound in `uncallable_rtn` error[E0271]: type mismatch resolving `::ASSOC == 3` - --> $DIR/duplicate-bound-err.rs:120:20 + --> $DIR/duplicate-bound-err.rs:116:20 | LL | uncallable_rtn(17u32); | -------------- ^^^^^ expected `3`, found `4` @@ -267,12 +265,10 @@ LL | uncallable_rtn(17u32); = note: expected constant `3` found constant `4` note: required by a bound in `uncallable_rtn` - --> $DIR/duplicate-bound-err.rs:81:34 + --> $DIR/duplicate-bound-err.rs:77:48 | -LL | fn uncallable_rtn( - | -------------- required by a bound in this function -LL | _: impl Trait, foo(..): Trait> - | ^^^^^^^^^ required by this bound in `uncallable_rtn` +LL | fn uncallable_rtn(_: impl Trait, foo(..): Trait>) {} + | ^^^^^^^^^ required by this bound in `uncallable_rtn` error: aborting due to 25 previous errors diff --git a/tests/ui/associated-type-bounds/duplicate-bound.rs b/tests/ui/associated-type-bounds/duplicate-bound.rs index 39cfa9db072c4..233b1ffb6ce76 100644 --- a/tests/ui/associated-type-bounds/duplicate-bound.rs +++ b/tests/ui/associated-type-bounds/duplicate-bound.rs @@ -189,7 +189,8 @@ trait Tra3 { trait Trait { type Gat; - type const ASSOC: i32; + #[rustc_always_gca] + const ASSOC: i32; fn foo() -> impl Sized; } @@ -197,7 +198,7 @@ trait Trait { impl Trait for () { type Gat = (); - type const ASSOC: i32 = 3; + const ASSOC: i32 = core::direct_const_arg!(3); fn foo() {} } @@ -222,9 +223,7 @@ fn uncallable_const(_: impl Trait) {} fn callable_const(_: impl Trait) {} -fn uncallable_rtn( - _: impl Trait, foo(..): Trait> -) {} +fn uncallable_rtn(_: impl Trait, foo(..): Trait>) {} fn callable_rtn(_: impl Trait) {} 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 a9c7373b4f448..63fa8eff1473b 100644 --- a/tests/ui/associated-types/type-const-inherent-impl-normalize.rs +++ b/tests/ui/associated-types/type-const-inherent-impl-normalize.rs @@ -1,15 +1,10 @@ struct S; impl S { - type const LEN: usize = 1; - //~^ ERROR: associated `type const` are unstable [E0658] - //~| ERROR: `type const` syntax is experimental [E0658] + const LEN: usize = core::direct_const_arg!(1); + //~^ ERROR: use of unstable library feature `min_generic_const_args` [E0658] + //~| ERROR: expected expression, found `direct_const_arg!()` fn arr() { [8; Self::LEN] - //~^ WARN: cannot use constants which depend on generic parameters in types - //~| WARN: this was previously accepted by the compiler but is being phased out - //~| WARN: cannot use constants which depend on generic parameters in types - //~| WARN: this was previously accepted by the compiler but is being phased out - //~| ERROR: mismatched 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 b86859f4a993f..421c2a83a19b9 100644 --- a/tests/ui/associated-types/type-const-inherent-impl-normalize.stderr +++ b/tests/ui/associated-types/type-const-inherent-impl-normalize.stderr @@ -1,52 +1,19 @@ -error[E0658]: `type const` syntax is experimental - --> $DIR/type-const-inherent-impl-normalize.rs:3:5 +error[E0658]: use of unstable library feature `min_generic_const_args` + --> $DIR/type-const-inherent-impl-normalize.rs:3:24 | -LL | type const LEN: usize = 1; - | ^^^^^^^^^^ +LL | const LEN: usize = core::direct_const_arg!(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 +error: expected expression, found `direct_const_arg!()` constant + --> $DIR/type-const-inherent-impl-normalize.rs:3:24 | -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 - -warning: cannot use constants which depend on generic parameters in types - --> $DIR/type-const-inherent-impl-normalize.rs:7:13 - | -LL | [8; Self::LEN] - | ^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #76200 - = note: `#[warn(const_evaluatable_unchecked)]` (part of `#[warn(future_incompatible)]`) on by default - -warning: cannot use constants which depend on generic parameters in types - --> $DIR/type-const-inherent-impl-normalize.rs:7:13 - | -LL | [8; Self::LEN] - | ^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #76200 - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error[E0308]: mismatched types - --> $DIR/type-const-inherent-impl-normalize.rs:7:9 - | -LL | fn arr() { - | - help: try adding a return type: `-> [i32; 1]` -LL | [8; Self::LEN] - | ^^^^^^^^^^^^^^ expected `()`, found `[{integer}; 1]` +LL | const LEN: usize = core::direct_const_arg!(1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 3 previous errors; 2 warnings emitted +error: aborting due to 2 previous errors -Some errors have detailed explanations: E0308, E0658. -For more information about an error, try `rustc --explain E0308`. +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/assumptions_on_binders/resolved-region-var-max-universe.rs b/tests/ui/assumptions_on_binders/resolved-region-var-max-universe.rs index 4668581cfc6e1..ffc605c0d51e0 100644 --- a/tests/ui/assumptions_on_binders/resolved-region-var-max-universe.rs +++ b/tests/ui/assumptions_on_binders/resolved-region-var-max-universe.rs @@ -15,7 +15,7 @@ struct Parent<'a> { } impl<'a> Parent<'a> { - type const CT: usize = 0; + const CT: usize = core::direct_const_arg!(0); } fn check() diff --git a/tests/ui/const-generics/associated-const-bindings/ambiguity.rs b/tests/ui/const-generics/associated-const-bindings/ambiguity.rs index 6871a028de5f3..88c1212fe2c93 100644 --- a/tests/ui/const-generics/associated-const-bindings/ambiguity.rs +++ b/tests/ui/const-generics/associated-const-bindings/ambiguity.rs @@ -6,21 +6,24 @@ trait Trait0: Parent0 + Parent0 {} trait Parent0 { - type const K: (); + #[rustc_always_gca] + const K: (); } -fn take0(_: impl Trait0) {} +fn take0(_: impl Trait0) {} //~^ ERROR ambiguous associated constant `K` in bounds of `Trait0` trait Trait1: Parent1 + Parent2 {} trait Parent1 { - type const C: i32; + #[rustc_always_gca] + const C: i32; } trait Parent2 { - type const C: &'static str; + #[rustc_always_gca] + const C: &'static str; } -fn take1(_: impl Trait1) {} +fn take1(_: impl Trait1) {} //~^ ERROR ambiguous associated constant `C` in bounds of `Trait1` fn main() {} diff --git a/tests/ui/const-generics/associated-const-bindings/ambiguity.stderr b/tests/ui/const-generics/associated-const-bindings/ambiguity.stderr index 9dcb30d6b737b..5ed843de96074 100644 --- a/tests/ui/const-generics/associated-const-bindings/ambiguity.stderr +++ b/tests/ui/const-generics/associated-const-bindings/ambiguity.stderr @@ -1,32 +1,32 @@ error[E0222]: ambiguous associated constant `K` in bounds of `Trait0` - --> $DIR/ambiguity.rs:12:25 + --> $DIR/ambiguity.rs:13:25 | -LL | type const K: (); - | ---------------- +LL | const K: (); + | ----------- | | | ambiguous `K` from `Parent0` | ambiguous `K` from `Parent0` ... -LL | fn take0(_: impl Trait0) {} - | ^^^^^^^^^^^^^ ambiguous associated constant `K` +LL | fn take0(_: impl Trait0) {} + | ^^^^^^^^^^^^ ambiguous associated constant `K` | = help: consider introducing a new type parameter `T` and adding `where` constraints: where T: Trait0, - T: Parent0::K = const { }, - T: Parent0::K = const { } + T: Parent0::K = const {}, + T: Parent0::K = const {} error[E0222]: ambiguous associated constant `C` in bounds of `Trait1` - --> $DIR/ambiguity.rs:23:25 + --> $DIR/ambiguity.rs:26:25 | -LL | type const C: i32; - | ----------------- ambiguous `C` from `Parent1` +LL | const C: i32; + | ------------ ambiguous `C` from `Parent1` ... -LL | type const C: &'static str; - | -------------------------- ambiguous `C` from `Parent2` +LL | const C: &'static str; + | --------------------- ambiguous `C` from `Parent2` ... -LL | fn take1(_: impl Trait1) {} - | ^^^^^^^ ambiguous associated constant `C` +LL | fn take1(_: impl Trait1) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ambiguous associated constant `C` | = help: consider introducing a new type parameter `T` and adding `where` constraints: where 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 3f8353b6914d0..598924316590c 100644 --- a/tests/ui/const-generics/associated-const-bindings/assoc-const.rs +++ b/tests/ui/const-generics/associated-const-bindings/assoc-const.rs @@ -3,20 +3,18 @@ #![allow(unused, incomplete_features)] pub trait Foo { - type const N: usize; + #[rustc_always_gca] + const N: usize; } pub struct Bar; impl Foo for Bar { - type const N: usize = 3; + const N: usize = core::direct_const_arg!(3); } -const TEST: usize = 3; - - fn foo>() {} fn main() { - foo::() + foo::() } 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 b66dff43a3d1d..a3dc049c144f2 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 @@ -4,14 +4,15 @@ min_generic_const_args, adt_const_params, const_param_ty_trait, - generic_const_parameter_types, + generic_const_parameter_types )] #![allow(incomplete_features)] use std::marker::ConstParamTy_; trait Trait { - type const K: T; + #[rustc_always_gca] + const K: T; } fn take( @@ -23,10 +24,18 @@ fn take( //~^^^ ERROR higher-ranked subtype error //~| ERROR higher-ranked subtype error -trait Project { type Out; } -impl Project for fn(T) -> T { type Out = T; } +trait Project { + type Out; +} +impl Project for fn(T) -> T { + type Out = T; +} -trait Discard { type Out; } -impl Discard for T { type Out = (); } +trait Discard { + type Out; +} +impl Discard for T { + type Out = (); +} fn main() {} 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 f2f69aad4ee65..a4f97525b5156 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:20:13 + --> $DIR/bound-var-in-ty-not-wf.rs:21:13 | LL | K = const { () } | ^^^^^^^^^^^^ error: higher-ranked subtype error - --> $DIR/bound-var-in-ty-not-wf.rs:20:13 + --> $DIR/bound-var-in-ty-not-wf.rs:21: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 e5757c8ef447f..729d4256d4baf 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 @@ -7,24 +7,24 @@ min_generic_const_args, adt_const_params, const_param_ty_trait, - generic_const_parameter_types, + generic_const_parameter_types )] #![allow(incomplete_features)] use std::marker::ConstParamTy_; trait Trait { - type const K: T; + #[rustc_always_gca] + const K: T; } -fn take( - _: impl Trait< - fn(&'a str) -> &'a str as Discard>::Out, - K = const { } - >, -) {} +fn take(_: impl Trait< fn(&'a str) -> &'a str as Discard>::Out, K = const {}>) {} -trait Discard { type Out; } -impl Discard for T { type Out = (); } +trait Discard { + type Out; +} +impl Discard for T { + type Out = (); +} fn main() {} 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 149755bad4ca3..a6c86ce4b867d 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,15 +12,17 @@ trait Trait: SuperTrait { type N; type Q; - type const N: usize; + #[rustc_always_gca] + const N: usize; } trait SuperTrait { - type const Q: &'static str; + #[rustc_always_gca] + const Q: &'static str; } fn take0(_: impl Trait) {} -fn take1(_: impl Trait) {} +fn take1(_: impl Trait) {} fn main() {} diff --git a/tests/ui/const-generics/associated-const-bindings/coherence.rs b/tests/ui/const-generics/associated-const-bindings/coherence.rs index e9296f3a8df0a..aa26c6f4cd18f 100644 --- a/tests/ui/const-generics/associated-const-bindings/coherence.rs +++ b/tests/ui/const-generics/associated-const-bindings/coherence.rs @@ -2,10 +2,11 @@ #![expect(incomplete_features)] pub trait IsVoid { - type const IS_VOID: bool; + #[rustc_always_gca] + const IS_VOID: bool; } impl IsVoid for () { - type const IS_VOID: bool = true; + const IS_VOID: bool = core::direct_const_arg!(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 df6781f2f9a27..ca1c968801243 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:13:1 + --> $DIR/coherence.rs:14: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 8e871ddf90ce5..8d876e2ca3582 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,7 +2,8 @@ #![allow(incomplete_features)] trait TraitWAssocConst { - type const A: usize; + #[rustc_always_gca] + 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 c533a7d65b90e..552b1579e6183 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:11:11 + --> $DIR/const-projection-err.rs:12: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:8:28 + --> $DIR/const-projection-err.rs:9: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 54ba1093325a3..a472118e51a82 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,13 +8,18 @@ #![allow(incomplete_features)] pub trait TraitA { - type const K: u8 = 0; + #[rustc_always_gca] + const K: u8 = core::direct_const_arg!(0); } pub trait TraitB {} impl TraitA for () {} impl TraitB for () where (): TraitA {} -fn check() where (): TraitB {} +fn check() +where + (): TraitB, +{ +} fn main() {} 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 454ce7b3875fa..f393a4910cd8d 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,12 +14,14 @@ 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 K: Self where Self: std::marker::ConstParamTy_; + #[rustc_always_gca] + 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 Q: ::Output; + #[rustc_always_gca] + 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 19cd8bf5af99b..dedbdd7f82bbb 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:36:16 + --> $DIR/dyn-compat-assoc-const-ty-mentions-self.rs:38: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:17:16 + --> $DIR/dyn-compat-assoc-const-ty-mentions-self.rs:18:11 | LL | trait Trait { | ----- this trait is not dyn compatible... ... -LL | type const K: Self where Self: std::marker::ConstParamTy_; - | ^ ...because it contains associated const `K` whose type references the `Self` type +LL | const K: Self where Self: std::marker::ConstParamTy_; + | ^ ...because it contains associated const `K` whose type references the `Self` type ... -LL | type const Q: ::Output; - | ^ ...because it contains associated const `Q` whose type references the `Self` type +LL | 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 8de8cb1a60db5..3a896b6b2e1fa 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,20 +7,24 @@ #![expect(incomplete_features)] trait Trait: SuperTrait { - type const K: usize; + #[rustc_always_gca] + const K: usize; } trait SuperTrait { - type const Q: usize; - type const C: usize; + #[rustc_always_gca] + const Q: usize; + #[rustc_always_gca] + const C: usize; } trait Bound { - type const N: usize; + #[rustc_always_gca] + const N: usize; } impl Bound for () { - type const N: usize = 10; + const N: usize = core::direct_const_arg!(10); } fn main() { @@ -29,5 +33,7 @@ fn main() { let obj: &dyn Bound = &(); _ = identity(obj); - fn identity(x: &(impl ?Sized + Bound)) -> &(impl ?Sized + Bound) { x } + fn identity(x: &(impl ?Sized + Bound)) -> &(impl ?Sized + Bound) { + x + } } 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 ad5c4b679117c..a28805f87b0f8 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,11 +4,12 @@ #![expect(incomplete_features)] trait Trait { - type const N: usize; + #[rustc_always_gca] + const N: usize; } impl Trait for () { - type const N: usize = 1; + const N: usize = core::direct_const_arg!(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 282504e3bc356..ea781f784a9b0 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:15:32 + --> $DIR/dyn-compat-const-mismatch.rs:16: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 6bfedab837714..f957a60a78b0b 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,11 +7,12 @@ trait X::N }> {} trait Y { - type const N: usize; + #[rustc_always_gca] + const N: usize; } impl Y for T { - type const N: usize = 1; + const N: usize = core::direct_const_arg!(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 a22545fcd8d21..365bae2188b00 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:18:16 + --> $DIR/dyn-compat-const-param-default-mentions-self.rs:19: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 ffc568a7b2c3f..1171744f8e774 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,7 +9,8 @@ #![expect(incomplete_features)] trait Trait { - type const Y: i32; + #[rustc_always_gca] + 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 699b9192cf937..9fd3c2138970e 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,17 +1,17 @@ error: the constant `Hold::` is not of type `i32` - --> $DIR/dyn-compat-const-projection-behind-trait-alias-mentions-self.rs:17:21 + --> $DIR/dyn-compat-const-projection-behind-trait-alias-mentions-self.rs:18:21 | LL | trait Bound = Trait }>; | ^^^^^^^^^^^^^^^^^^^^ expected `i32`, found struct constructor | note: required by a const generic parameter in `Bound` - --> $DIR/dyn-compat-const-projection-behind-trait-alias-mentions-self.rs:17:21 + --> $DIR/dyn-compat-const-projection-behind-trait-alias-mentions-self.rs:18:21 | LL | trait Bound = Trait }>; | ^^^^^^^^^^^^^^^^^^^^ required by this const generic parameter in `Bound` 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:22: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 3a36c0ccbc418..1a417be8ea451 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,11 +5,13 @@ #![expect(incomplete_features)] trait X: Y { - type const Q: usize; + #[rustc_always_gca] + const Q: usize; } trait Y { - type const K: usize; + #[rustc_always_gca] + 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 de4e9dc61aa4e..adfa522ecfa87 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:16:16 + --> $DIR/dyn-compat-const-projection-from-supertrait-mentions-self.rs:18:16 | -LL | type const K: usize; - | ------------------- `K` defined here +LL | const K: usize; + | -------------- `K` defined here ... LL | let _: dyn 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 302c4e4187349..9036de88bd355 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 defined as `type const` + //~^ NOTE it contains associated const `K` that's not defined as `#[rustc_always_gca]` } fn main() { @@ -16,5 +16,5 @@ fn main() { // Check that specifying the non-type assoc const doesn't work without full GCA. let _: dyn Trait; //~^ ERROR the trait `Trait` is not dyn compatible - //~| ERROR use of trait associated const not defined as `type const` + //~| ERROR use of trait associated const not defined as `#[rustc_always_gca]` } 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 5bc072e98c0f8..40a3c9c3d1128 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,14 @@ 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 defined as `type const` + | ^ ...because it contains associated const `K` that's not defined as `#[rustc_always_gca]` = help: consider moving `K` to another trait -error: use of trait associated const not defined as `type const` +error: use of trait associated const not defined as `#[rustc_always_gca]` --> $DIR/dyn-compat-non-type-assoc-const.rs:17:22 | LL | let _: dyn Trait; | ^^^^^ - | - = 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 +33,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 defined as `type const` + | ^ ...because it contains associated const `K` that's not defined as `#[rustc_always_gca]` = 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 03f1a526b73ac..16fb2af1c4b54 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,11 +6,12 @@ #![expect(incomplete_features)] trait Trait { - type const N: i32 where Self: Bound; + #[rustc_always_gca] + const N: i32 where Self: Bound; } impl Trait for () { - type const N: i32 = 0; + const N: i32 = core::direct_const_arg!(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 21e407f8a8618..25eeba203209d 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:21:32 + --> $DIR/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs:22: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:16:1 + --> $DIR/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs:17:1 | LL | trait Bound {} | ^^^^^^^^^^^ note: required by a bound in `Trait::N` - --> $DIR/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs:9:35 + --> $DIR/dyn-compat-self-bound-on-assoc-const-allowed-and-enforced.rs:10:30 | -LL | type const N: i32 where Self: Bound; - | ^^^^^ required by this bound in `Trait::N` +LL | 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 1ca24178ef2c2..b2f0b25041056 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 @@ -15,12 +15,13 @@ trait A { type Ty: std::marker::ConstParamTy_; - type const CT: Self::Ty; + #[rustc_always_gca] + const CT: Self::Ty; } impl A for () { type Ty = i32; - type const CT: i32 = 0; + const CT: i32 = core::direct_const_arg!(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 30b2b4776f93d..e3873eae6f04f 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,11 +1,11 @@ error: type annotations needed for the literal - --> $DIR/dyn-compat-self-const-projections-in-assoc-const-ty.rs:33:33 + --> $DIR/dyn-compat-self-const-projections-in-assoc-const-ty.rs:34:33 | LL | let _: dyn A; | ^ error: type annotations needed for the literal - --> $DIR/dyn-compat-self-const-projections-in-assoc-const-ty.rs:35:34 + --> $DIR/dyn-compat-self-const-projections-in-assoc-const-ty.rs:36:34 | LL | let _: &dyn A = &(); | ^ 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 193eedc02c0ca..148f5b8654af0 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,13 +15,14 @@ #![expect(incomplete_features)] trait Trait { - type const N: usize; + #[rustc_always_gca] + const N: usize; fn process(&self, _: [u8; Self::N]) -> [u8; Self::N]; } impl Trait for u8 { - type const N: usize = 2; + const N: usize = core::direct_const_arg!(2); fn process(&self, [x, y]: [u8; Self::N]) -> [u8; Self::N] { [self * x, self + y] @@ -29,7 +30,7 @@ impl Trait for u8 { } impl Trait for [u8; N] { - type const N: usize = N; + const N: usize = core::direct_const_arg!(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 375adb78513b6..256c9feeb6771 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 @@ -8,8 +8,9 @@ #![expect(incomplete_features)] trait Trait: SuperTrait<{ Self::N }> { -//~^ NOTE it uses `Self` as a type parameter - type const N: usize; + //~^ NOTE it uses `Self` as a type parameter + #[rustc_always_gca] + 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 38c928fd58d73..33edc96117d56 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:18:16 + --> $DIR/dyn-compat-self-const-projections-in-supertrait-bounds.rs:19: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 99ed73cf5986f..d467d5e0def02 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,7 +15,8 @@ #![crate_name = "sym"] trait Trait { - type const N: usize; + #[rustc_always_gca] + const N: usize; } #[rustc_dump_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 a1403c80f2722..d87ed6292608e 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:21:1 + --> $DIR/dyn-compat-symbol-mangling.rs:22:1 | LL | #[rustc_dump_symbol_name] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: demangling(>) - --> $DIR/dyn-compat-symbol-mangling.rs:21:1 + --> $DIR/dyn-compat-symbol-mangling.rs:22:1 | LL | #[rustc_dump_symbol_name] | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: demangling-alt(>) - --> $DIR/dyn-compat-symbol-mangling.rs:21:1 + --> $DIR/dyn-compat-symbol-mangling.rs:22:1 | LL | #[rustc_dump_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 5bd8aa609420d..6c4c8ccc35572 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,7 +6,8 @@ #![expect(incomplete_features)] trait Trait { - type const K: usize; + #[rustc_always_gca] + 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 d9ddea7a2524d..6276df3b33c25 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,8 +1,8 @@ error[E0191]: the value of the associated constant `K` in `Trait` must be specified - --> $DIR/dyn-compat-unspecified-assoc-consts.rs:19:18 + --> $DIR/dyn-compat-unspecified-assoc-consts.rs:20:18 | -LL | type const K: usize; - | ------------------- `K` defined here +LL | const K: usize; + | -------------- `K` defined here ... LL | struct Store(dyn Trait); | ^^^^^ @@ -13,10 +13,10 @@ LL | struct Store(dyn Trait); | +++++++++++++++++ error[E0191]: the value of the associated constant `K` in `Trait` must be specified - --> $DIR/dyn-compat-unspecified-assoc-consts.rs:23:21 + --> $DIR/dyn-compat-unspecified-assoc-consts.rs:24:21 | -LL | type const K: usize; - | ------------------- `K` defined here +LL | const K: usize; + | -------------- `K` defined here ... LL | type DynTrait = dyn Trait; | ^^^^^ @@ -27,10 +27,10 @@ LL | type DynTrait = dyn Trait; | +++++++++++++++++ error[E0191]: the value of the associated constant `K` in `Trait` must be specified - --> $DIR/dyn-compat-unspecified-assoc-consts.rs:14:16 + --> $DIR/dyn-compat-unspecified-assoc-consts.rs:15:16 | -LL | type const K: usize; - | ------------------- `K` defined here +LL | const K: usize; + | -------------- `K` defined here ... LL | let _: dyn Trait; | ^^^^^ diff --git a/tests/ui/const-generics/associated-const-bindings/dyn-const-projection-escaping-bound-vars.rs b/tests/ui/const-generics/associated-const-bindings/dyn-const-projection-escaping-bound-vars.rs index c2ae86232a02b..d498f52003b48 100644 --- a/tests/ui/const-generics/associated-const-bindings/dyn-const-projection-escaping-bound-vars.rs +++ b/tests/ui/const-generics/associated-const-bindings/dyn-const-projection-escaping-bound-vars.rs @@ -5,7 +5,10 @@ #![feature(min_generic_const_args)] #![expect(incomplete_features)] -trait Trait2<'a> { type const ASSOC: i32; } +trait Trait2<'a> { + #[rustc_always_gca] + const ASSOC: i32; +} fn g(_: for<'a> fn(Box>)) {} fn main() {} 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 f42589f91d157..7b05da5623b10 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,34 +5,38 @@ #![deny(dead_code)] trait Tr { - type const I: i32; + #[rustc_always_gca] + const I: i32; } impl Tr for () { - type const I: i32 = 1; + const I: i32 = core::direct_const_arg!(1); } fn foo() -> impl Tr {} trait Tr2 { - type const J: i32; - type const K: i32; + #[rustc_always_gca] + const J: i32; + #[rustc_always_gca] + const K: i32; } impl Tr2 for () { - type const J: i32 = 1; - type const K: i32 = 1; + const J: i32 = core::direct_const_arg!(1); + const K: i32 = core::direct_const_arg!(1); } fn foo2() -> impl Tr2 {} mod t { pub trait Tr3 { - type const L: i32; + #[rustc_always_gca] + const L: i32; } impl Tr3 for () { - type const L: i32 = 1; + const L: i32 = core::direct_const_arg!(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 e50c13b5d3b5e..01589ac645b05 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,11 +7,12 @@ // though it contained inference variables, which would cause ICEs. trait Foo { - type const ASSOC: u32; + #[rustc_always_gca] + const ASSOC: u32; } impl Foo for () { - type const ASSOC: u32 = N; + const ASSOC: u32 = core::direct_const_arg!(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 de888c5a79393..5a4ea95eae189 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 @@ -4,12 +4,13 @@ adt_const_params, min_generic_const_args, unsized_const_params, - generic_const_parameter_types, + generic_const_parameter_types )] #![allow(incomplete_features)] trait Trait<'a> { - type const K: &'a (); + #[rustc_always_gca] + 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 122893662933d..3966483aa6002 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:15:35 + --> $DIR/esc-bound-var-in-ty.rs:16: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 1663cad13c7cc..cfbca73dd531b 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,7 +8,8 @@ trait T { } trait S { - type const C: i32; + #[rustc_always_gca] + 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 1c6e873b98c3d..818609486d20c 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,11 +2,12 @@ #![expect(incomplete_features)] trait Foo { - type const ASSOC: u32; + #[rustc_always_gca] + const ASSOC: u32; } impl Foo for () { - type const ASSOC: u32 = N; + const ASSOC: u32 = core::direct_const_arg!(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 b447cd08a2143..72a783f8d06d4 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:12:29 + --> $DIR/mismatched-types-with-generic-in-ace.rs:13: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:5:22 + --> $DIR/mismatched-types-with-generic-in-ace.rs:6:17 | -LL | type const ASSOC: u32; - | ^^^^^^^^^^^^ required by this const generic parameter in `Foo::ASSOC` +LL | 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:16:5 + --> $DIR/mismatched-types-with-generic-in-ace.rs:17: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:5:22 + --> $DIR/mismatched-types-with-generic-in-ace.rs:6:17 | -LL | type const ASSOC: u32; - | ^^^^^^^^^^^^ required by this const generic parameter in `Foo::ASSOC` +LL | 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 4c57d8d14d039..d013eb164065f 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,7 +6,8 @@ // with associated const equality bounds. trait Trait { - type const C: usize; + #[rustc_always_gca] + 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 4d67186f71f9e..d7c6426d7bc38 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,7 +11,8 @@ use std::marker::ConstParamTy_; trait Trait<'a, T: 'a + ConstParamTy_, const N: usize> { - type const K: &'a [T; N]; + #[rustc_always_gca] + const K: &'a [T; N]; } fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>( @@ -31,7 +32,8 @@ fn take0<'r, A: 'r + ConstParamTy_, const Q: usize>( ) {} trait Project: ConstParamTy_ { - type const SELF: Self; + #[rustc_always_gca] + 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 2ef3fab7e5ffa..719dad816a6f4 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:21:29 + --> $DIR/param-in-ty.rs:22: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:21:29 + --> $DIR/param-in-ty.rs:22: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:21:29 + --> $DIR/param-in-ty.rs:22: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:37:26 + --> $DIR/param-in-ty.rs:39: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:42:21 + --> $DIR/param-in-ty.rs:44: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:51:52 + --> $DIR/param-in-ty.rs:53: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:51:52 + --> $DIR/param-in-ty.rs:53: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:51:52 + --> $DIR/param-in-ty.rs:53: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:51:52 + --> $DIR/param-in-ty.rs:53: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:51:52 + --> $DIR/param-in-ty.rs:53: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:51:52 + --> $DIR/param-in-ty.rs:53: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 dbfbba9b7cbd1..572e50862988b 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,7 +4,8 @@ // Issue 110549 pub trait TraitWAssocConst { - type const A: usize; + #[rustc_always_gca] + 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 11490a044091d..232b15b7e981a 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:13:11 + --> $DIR/projection-unspecified-but-bounded.rs:14: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:10:28 + --> $DIR/projection-unspecified-but-bounded.rs:11: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 6c8ae165a50db..d0647b62adb2e 100644 --- a/tests/ui/const-generics/associated-const-bindings/supertraits.rs +++ b/tests/ui/const-generics/associated-const-bindings/supertraits.rs @@ -7,7 +7,7 @@ min_generic_const_args, adt_const_params, const_param_ty_trait, - generic_const_parameter_types, + generic_const_parameter_types )] #![allow(incomplete_features)] @@ -16,7 +16,8 @@ use std::marker::ConstParamTy_; trait Trait: SuperTrait {} trait SuperTrait: SuperSuperTrait {} trait SuperSuperTrait { - type const K: T; + #[rustc_always_gca] + 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 95f81323acf46..b8eebfa3697e5 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,7 +4,8 @@ #![feature(min_generic_const_args)] trait Trait { - type const F: fn(); + #[rustc_always_gca] + 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 333dd1b89e9bc..09d1063081fe1 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:7:19 + --> $DIR/using-fnptr-as-type_const.rs:8:14 | -LL | type const F: fn(); - | ^^^^ +LL | const F: fn(); + | ^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/associated-const-bindings/wf-mismatch-1.rs b/tests/ui/const-generics/associated-const-bindings/wf-mismatch-1.rs index 1beeb07e995a0..d098350c34734 100644 --- a/tests/ui/const-generics/associated-const-bindings/wf-mismatch-1.rs +++ b/tests/ui/const-generics/associated-const-bindings/wf-mismatch-1.rs @@ -4,7 +4,10 @@ #![feature(min_generic_const_args)] #![expect(incomplete_features)] -trait Trait { type const CT: bool; } +trait Trait { + #[rustc_always_gca] + const CT: bool; +} fn f(_: impl Trait) {} //~^ ERROR the constant `N` is not of type `bool` diff --git a/tests/ui/const-generics/associated-const-bindings/wf-mismatch-1.stderr b/tests/ui/const-generics/associated-const-bindings/wf-mismatch-1.stderr index 56e01e6400783..f75f4a08969c8 100644 --- a/tests/ui/const-generics/associated-const-bindings/wf-mismatch-1.stderr +++ b/tests/ui/const-generics/associated-const-bindings/wf-mismatch-1.stderr @@ -1,11 +1,11 @@ error: the constant `N` is not of type `bool` - --> $DIR/wf-mismatch-1.rs:9:34 + --> $DIR/wf-mismatch-1.rs:12:34 | LL | fn f(_: impl Trait) {} | ^^^^^^^^^^ expected `bool`, found `i32` | note: required by a const generic parameter in `f` - --> $DIR/wf-mismatch-1.rs:9:34 + --> $DIR/wf-mismatch-1.rs:12:34 | LL | fn f(_: impl Trait) {} | ^^^^^^^^^^ required by this const generic parameter in `f` diff --git a/tests/ui/const-generics/associated-const-bindings/wf-mismatch-2.rs b/tests/ui/const-generics/associated-const-bindings/wf-mismatch-2.rs index 7a75b6da78c5c..67bfa9e6656ae 100644 --- a/tests/ui/const-generics/associated-const-bindings/wf-mismatch-2.rs +++ b/tests/ui/const-generics/associated-const-bindings/wf-mismatch-2.rs @@ -4,7 +4,10 @@ #![feature(min_generic_const_args)] #![expect(incomplete_features)] -trait Trait { type const CT: bool; } +trait Trait { + #[rustc_always_gca] + const CT: bool; +} fn f() { let _: dyn Trait; diff --git a/tests/ui/const-generics/associated-const-bindings/wf-mismatch-2.stderr b/tests/ui/const-generics/associated-const-bindings/wf-mismatch-2.stderr index 8169cc07fc5f5..c12b9fe78c049 100644 --- a/tests/ui/const-generics/associated-const-bindings/wf-mismatch-2.stderr +++ b/tests/ui/const-generics/associated-const-bindings/wf-mismatch-2.stderr @@ -1,5 +1,5 @@ error: the constant `N` is not of type `bool` - --> $DIR/wf-mismatch-2.rs:10:12 + --> $DIR/wf-mismatch-2.rs:13:12 | LL | let _: dyn Trait; | ^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `i32` diff --git a/tests/ui/const-generics/associated-const-bindings/wf-mismatch-3.rs b/tests/ui/const-generics/associated-const-bindings/wf-mismatch-3.rs index 92ae129c7310a..d5682e7de1294 100644 --- a/tests/ui/const-generics/associated-const-bindings/wf-mismatch-3.rs +++ b/tests/ui/const-generics/associated-const-bindings/wf-mismatch-3.rs @@ -4,13 +4,23 @@ #![feature(min_generic_const_args, macroless_generic_const_args)] #![expect(incomplete_features)] -trait Trait { type const CT: bool; } +trait Trait { + #[rustc_always_gca] + const CT: bool; +} -trait Bound { type const N: u32; } -impl Bound for () { type const N: u32 = 0; } +trait Bound { + #[rustc_always_gca] + const N: u32; +} +impl Bound for () { + const N: u32 = core::direct_const_arg!(0); +} -fn f() { let _: dyn Trait::N }>; } -//~^ ERROR the constant `0` is not of type `bool` +fn f() { + let _: dyn Trait::N }>; + //~^ ERROR the constant `0` is not of type `bool` +} fn g(_: impl Trait::N }>) {} //~^ ERROR the constant `0` is not of type `bool` diff --git a/tests/ui/const-generics/associated-const-bindings/wf-mismatch-3.stderr b/tests/ui/const-generics/associated-const-bindings/wf-mismatch-3.stderr index ac21527e04edd..f921e5893b51e 100644 --- a/tests/ui/const-generics/associated-const-bindings/wf-mismatch-3.stderr +++ b/tests/ui/const-generics/associated-const-bindings/wf-mismatch-3.stderr @@ -1,20 +1,20 @@ error: the constant `0` is not of type `bool` - --> $DIR/wf-mismatch-3.rs:14:20 + --> $DIR/wf-mismatch-3.rs:24:20 | LL | fn g(_: impl Trait::N }>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `u32` | note: required by a const generic parameter in `g` - --> $DIR/wf-mismatch-3.rs:14:20 + --> $DIR/wf-mismatch-3.rs:24:20 | LL | fn g(_: impl Trait::N }>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this const generic parameter in `g` error: the constant `0` is not of type `bool` - --> $DIR/wf-mismatch-3.rs:12:17 + --> $DIR/wf-mismatch-3.rs:21:12 | -LL | fn f() { let _: dyn Trait::N }>; } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `u32` +LL | let _: dyn Trait::N }>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `u32` error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/gca/basic-different-definitions.rs b/tests/ui/const-generics/gca/basic-different-definitions.rs index bd07cc2d5a26c..a80e50a6cb9e9 100644 --- a/tests/ui/const-generics/gca/basic-different-definitions.rs +++ b/tests/ui/const-generics/gca/basic-different-definitions.rs @@ -10,10 +10,6 @@ const ADD1: usize = N + 1; const INC: usize = N + 1; -type const ONE: usize = ADD1::<0>; - -type const OTHER_ONE: usize = INC::<0>; - -const ARR: [(); ADD1::<0>] = [(); INC::<0>]; +const ARR: [(); core::direct_const_arg!(ADD1::<0>)] = [(); core::direct_const_arg!(INC::<0>)]; fn main() {} diff --git a/tests/ui/const-generics/gca/basic.rs b/tests/ui/const-generics/gca/basic.rs index b4ff018dfa483..55712a80f2195 100644 --- a/tests/ui/const-generics/gca/basic.rs +++ b/tests/ui/const-generics/gca/basic.rs @@ -8,12 +8,8 @@ const ADD1: usize = N + 1; -type const INC: usize = ADD1::; +const INC: usize = core::direct_const_arg!(ADD1::); -type const ONE: usize = ADD1::<0>; - -type const OTHER_ONE: usize = INC::<0>; - -const ARR: [(); ADD1::<0>] = [(); INC::<0>]; +const ARR: [(); core::direct_const_arg!(ADD1::<0>)] = [(); core::direct_const_arg!(INC::<0>)]; fn main() {} diff --git a/tests/ui/const-generics/gca/coherence-ok.rs b/tests/ui/const-generics/gca/coherence-ok.rs index 1d55c08d3820f..5feebd2b2a6fb 100644 --- a/tests/ui/const-generics/gca/coherence-ok.rs +++ b/tests/ui/const-generics/gca/coherence-ok.rs @@ -3,13 +3,13 @@ #![feature(generic_const_items, min_generic_const_args, generic_const_args)] #![expect(incomplete_features)] -// computing different values with the same type const item should be fine +// computing different values with the same const item should be fine const ADD1: usize = N + 1; trait Trait {} -impl Trait for [(); ADD1::<1>] {} -impl Trait for [(); ADD1::<2>] {} +impl Trait for [(); core::direct_const_arg!(ADD1::<1>)] {} +impl Trait for [(); core::direct_const_arg!(ADD1::<2>)] {} fn main() {} diff --git a/tests/ui/const-generics/gca/gca-anon-const-rejected.rs b/tests/ui/const-generics/gca/gca-anon-const-rejected.rs index 297beba7eb539..72babbcfe0401 100644 --- a/tests/ui/const-generics/gca/gca-anon-const-rejected.rs +++ b/tests/ui/const-generics/gca/gca-anon-const-rejected.rs @@ -4,6 +4,6 @@ // `const FOO: usize = N + 1;` #![feature(generic_const_args, min_generic_const_args, generic_const_items)] -type const FOO: usize = const { N + 1 }; //~ ERROR generic parameters in const blocks are not allowed; use a named `const` item instead +const FOO: usize = core::direct_const_arg!(const { N + 1 }); //~ ERROR generic parameters in const blocks are not allowed; use a named `const` item instead fn main() {} diff --git a/tests/ui/const-generics/gca/gca-anon-const-rejected.stderr b/tests/ui/const-generics/gca/gca-anon-const-rejected.stderr index 45ba264b53a39..1b98cd734afd2 100644 --- a/tests/ui/const-generics/gca/gca-anon-const-rejected.stderr +++ b/tests/ui/const-generics/gca/gca-anon-const-rejected.stderr @@ -1,8 +1,8 @@ error: generic parameters in const blocks are not allowed; use a named `const` item instead - --> $DIR/gca-anon-const-rejected.rs:7:49 + --> $DIR/gca-anon-const-rejected.rs:7:68 | -LL | type const FOO: usize = const { N + 1 }; - | ^ +LL | const FOO: usize = core::direct_const_arg!(const { N + 1 }); + | ^ | = help: consider factoring the expression into a `type const` item and use it as the const argument instead diff --git a/tests/ui/const-generics/gca/rhs-but-not-root.rs b/tests/ui/const-generics/gca/rhs-but-not-root.rs index 9c068bf02b756..2c5f1e050a3fe 100644 --- a/tests/ui/const-generics/gca/rhs-but-not-root.rs +++ b/tests/ui/const-generics/gca/rhs-but-not-root.rs @@ -5,8 +5,8 @@ #![expect(incomplete_features)] // Anon consts must be the root of the RHS to be GCA. -type const FOO: usize = ID::; +const FOO: usize = core::direct_const_arg!(ID::); //~^ ERROR generic parameters in const blocks are not allowed; use a named `const` item instead -type const ID: usize = N; +const ID: usize = core::direct_const_arg!(N); fn main() {} diff --git a/tests/ui/const-generics/gca/rhs-but-not-root.stderr b/tests/ui/const-generics/gca/rhs-but-not-root.stderr index 7d6f9ae479547..6b2e5d61112d9 100644 --- a/tests/ui/const-generics/gca/rhs-but-not-root.stderr +++ b/tests/ui/const-generics/gca/rhs-but-not-root.stderr @@ -1,8 +1,8 @@ error: generic parameters in const blocks are not allowed; use a named `const` item instead - --> $DIR/rhs-but-not-root.rs:8:54 + --> $DIR/rhs-but-not-root.rs:8:73 | -LL | type const FOO: usize = ID::; - | ^ +LL | const FOO: usize = core::direct_const_arg!(ID::); + | ^ | = help: consider factoring the expression into a `type const` item and use it as the const argument instead diff --git a/tests/ui/const-generics/gca/suggest-const-item-for-generic-expr.rs b/tests/ui/const-generics/gca/suggest-const-item-for-generic-expr.rs index 63f1050861f54..f6415412e0df4 100644 --- a/tests/ui/const-generics/gca/suggest-const-item-for-generic-expr.rs +++ b/tests/ui/const-generics/gca/suggest-const-item-for-generic-expr.rs @@ -1,7 +1,7 @@ // Regression test for https://github.com/rust-lang/rust/issues/156729 // // When a generic parameter is used in a const operation, the diagnostic should -// suggest creating a `type const` item as an alternative to `generic_const_exprs`. +// suggest creating a `direct_const_arg!` item as an alternative to `generic_const_exprs`. use std::mem::size_of; 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 8cd46783d4fde..689a981e5469b 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,4 +1,4 @@ #![feature(min_generic_const_args)] #![allow(incomplete_features)] -pub type const NON_LOCAL_CONST: char = 'a'; +pub const NON_LOCAL_CONST: char = core::direct_const_arg!('a'); diff --git a/tests/ui/const-generics/generic_const_parameter_types/inherent-type-const.rs b/tests/ui/const-generics/generic_const_parameter_types/inherent-type-const.rs index 6a2d6eecbb743..be91b0a5933bd 100644 --- a/tests/ui/const-generics/generic_const_parameter_types/inherent-type-const.rs +++ b/tests/ui/const-generics/generic_const_parameter_types/inherent-type-const.rs @@ -13,7 +13,7 @@ struct ThreeTypes(T1, T2, T3); impl ThreeTypes { - type const INHERENT: [T3; 0] = []; + const INHERENT: [T3; 0] = core::direct_const_arg!([]); } struct Struct; 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 35ce7b7d9ead0..34fca58ff4e00 100644 --- a/tests/ui/const-generics/mgca/adt_expr_arg_simple.rs +++ b/tests/ui/const-generics/mgca/adt_expr_arg_simple.rs @@ -11,7 +11,8 @@ use Option::Some; fn foo>() {} trait Trait { - type const ASSOC: u32; + #[rustc_always_gca] + const ASSOC: u32; } fn bar() { diff --git a/tests/ui/const-generics/mgca/adt_expr_arg_simple.stderr b/tests/ui/const-generics/mgca/adt_expr_arg_simple.stderr index 2ce1e55e4f832..7b1249773f0cb 100644 --- a/tests/ui/const-generics/mgca/adt_expr_arg_simple.stderr +++ b/tests/ui/const-generics/mgca/adt_expr_arg_simple.stderr @@ -1,11 +1,11 @@ error: complex const arguments must be placed inside of a `const` block - --> $DIR/adt_expr_arg_simple.rs:28:54 + --> $DIR/adt_expr_arg_simple.rs:29:54 | LL | foo::<{ core::direct_const_arg!(Some:: { 0: N + 1 }) }>(); | ^^^^^ error: generic parameters may not be used in const operations - --> $DIR/adt_expr_arg_simple.rs:33:38 + --> $DIR/adt_expr_arg_simple.rs:34:38 | LL | foo::<{ Some:: { 0: const { N + 1 } } }>(); | ^ 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 8268a6b5689ae..6fbef3704991e 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 @@ -7,7 +7,8 @@ #![expect(incomplete_features)] trait Trait { - type const ASSOC: usize; + #[rustc_always_gca] + const ASSOC: usize; } fn takes_tuple() {} diff --git a/tests/ui/const-generics/mgca/adt_expr_arg_tuple_expr_fail.stderr b/tests/ui/const-generics/mgca/adt_expr_arg_tuple_expr_fail.stderr index 961aedbae66d6..2e06d4f2ce058 100644 --- a/tests/ui/const-generics/mgca/adt_expr_arg_tuple_expr_fail.stderr +++ b/tests/ui/const-generics/mgca/adt_expr_arg_tuple_expr_fail.stderr @@ -1,35 +1,35 @@ error: the constant `N` is not of type `u32` - --> $DIR/adt_expr_arg_tuple_expr_fail.rs:17:21 + --> $DIR/adt_expr_arg_tuple_expr_fail.rs:18:21 | LL | takes_tuple::<{ (N, N2) }>(); | ^^^^^^^ expected `u32`, found `usize` error: the constant `N` is not of type `u32` - --> $DIR/adt_expr_arg_tuple_expr_fail.rs:19:21 + --> $DIR/adt_expr_arg_tuple_expr_fail.rs:20:21 | LL | takes_tuple::<{ (N, T::ASSOC) }>(); | ^^^^^^^^^^^^^ expected `u32`, found `usize` error: the constant `::ASSOC` is not of type `u32` - --> $DIR/adt_expr_arg_tuple_expr_fail.rs:19:21 + --> $DIR/adt_expr_arg_tuple_expr_fail.rs:20:21 | LL | takes_tuple::<{ (N, T::ASSOC) }>(); | ^^^^^^^^^^^^^ expected `u32`, found `usize` error: the constant `N` is not of type `u32` - --> $DIR/adt_expr_arg_tuple_expr_fail.rs:23:28 + --> $DIR/adt_expr_arg_tuple_expr_fail.rs:24:28 | LL | takes_nested_tuple::<{ (N, (N, N2)) }>(); | ^^^^^^^^^^^^ expected `u32`, found `usize` error: the constant `N` is not of type `u32` - --> $DIR/adt_expr_arg_tuple_expr_fail.rs:25:28 + --> $DIR/adt_expr_arg_tuple_expr_fail.rs:26:28 | LL | takes_nested_tuple::<{ (N, (N, T::ASSOC)) }>(); | ^^^^^^^^^^^^^^^^^^ expected `u32`, found `usize` error: the constant `::ASSOC` is not of type `u32` - --> $DIR/adt_expr_arg_tuple_expr_fail.rs:25:28 + --> $DIR/adt_expr_arg_tuple_expr_fail.rs:26:28 | LL | takes_nested_tuple::<{ (N, (N, T::ASSOC)) }>(); | ^^^^^^^^^^^^^^^^^^ expected `u32`, found `usize` 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 4b66c563e5fda..bcd6660dc3533 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 @@ -17,9 +17,7 @@ struct Foo { field: T, } -type const WRAP: Foo = { Foo:: { - field: N, -} }; +const WRAP: Foo = core::direct_const_arg!(Foo:: { field: N }); fn main() { // What we're trying to accomplish here is winding up with an equality relation @@ -43,4 +41,5 @@ fn main() { struct PC { _0: PhantomData, } -const PC: PC = PC { _0: PhantomData:: }; +// FIXME(min_generic_const_args): this shouldn't have to do silly (expr,).0 hacks +const PC: PC = (PC { _0: PhantomData:: },).0; diff --git a/tests/ui/const-generics/mgca/array-const-arg-len-mismatch.rs b/tests/ui/const-generics/mgca/array-const-arg-len-mismatch.rs index 10b824fed4f36..5656d55d9f9c6 100644 --- a/tests/ui/const-generics/mgca/array-const-arg-len-mismatch.rs +++ b/tests/ui/const-generics/mgca/array-const-arg-len-mismatch.rs @@ -15,12 +15,13 @@ fn foo() -> [T; N] { fn bar() {} trait Trait { - type const LEN: usize; + #[rustc_always_gca] + const LEN: usize; } struct S; impl Trait for S { - type const LEN: usize = 3; + const LEN: usize = core::direct_const_arg!(3); } fn baz::LEN]>() {} diff --git a/tests/ui/const-generics/mgca/array-const-arg-len-mismatch.stderr b/tests/ui/const-generics/mgca/array-const-arg-len-mismatch.stderr index 42eea34bf6bc7..e83b0e98dfe6c 100644 --- a/tests/ui/const-generics/mgca/array-const-arg-len-mismatch.stderr +++ b/tests/ui/const-generics/mgca/array-const-arg-len-mismatch.stderr @@ -1,29 +1,29 @@ error: expected array with 2 elements, found 0 elements - --> $DIR/array-const-arg-len-mismatch.rs:29:20 + --> $DIR/array-const-arg-len-mismatch.rs:30:20 | LL | foo::(); | ^^ error: expected array with 2 elements, found 3 elements - --> $DIR/array-const-arg-len-mismatch.rs:31:20 + --> $DIR/array-const-arg-len-mismatch.rs:32:20 | LL | foo::(); | ^^^^^^^^^ error: expected array with 2 elements, found 0 elements - --> $DIR/array-const-arg-len-mismatch.rs:33:13 + --> $DIR/array-const-arg-len-mismatch.rs:34:13 | LL | bar::<{ [] }>(); | ^^ error: expected array with 2 elements, found 3 elements - --> $DIR/array-const-arg-len-mismatch.rs:35:13 + --> $DIR/array-const-arg-len-mismatch.rs:36:13 | LL | bar::<{ [1, 2, 3] }>(); | ^^^^^^^^^ error: expected array with 3 elements, found 1 elements - --> $DIR/array-const-arg-len-mismatch.rs:37:13 + --> $DIR/array-const-arg-len-mismatch.rs:38:13 | LL | baz::<{ [42] }>(); | ^^^^ 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 f4fb878fead35..356c48085adb0 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,7 +6,8 @@ fn takes_array() {} trait Trait { - type const ASSOC: u32; + #[rustc_always_gca] + const ASSOC: u32; } fn generic_caller() { diff --git a/tests/ui/const-generics/mgca/array_expr_arg_complex.rs b/tests/ui/const-generics/mgca/array_expr_arg_complex.rs index 4adb2bf6e429d..3d62adae09ada 100644 --- a/tests/ui/const-generics/mgca/array_expr_arg_complex.rs +++ b/tests/ui/const-generics/mgca/array_expr_arg_complex.rs @@ -2,7 +2,8 @@ #![expect(incomplete_features)] trait Trait { - type const ASSOC: usize; + #[rustc_always_gca] + const ASSOC: usize; } fn takes_array() {} diff --git a/tests/ui/const-generics/mgca/array_expr_arg_complex.stderr b/tests/ui/const-generics/mgca/array_expr_arg_complex.stderr index c7b13351d453c..c7db1e4753f8c 100644 --- a/tests/ui/const-generics/mgca/array_expr_arg_complex.stderr +++ b/tests/ui/const-generics/mgca/array_expr_arg_complex.stderr @@ -1,11 +1,11 @@ error: complex const arguments must be placed inside of a `const` block - --> $DIR/array_expr_arg_complex.rs:12:49 + --> $DIR/array_expr_arg_complex.rs:13:49 | LL | takes_array::<{ core::direct_const_arg!([N, N + 1]) }>(); | ^^^^^ error: complex const arguments must be placed inside of a `const` block - --> $DIR/array_expr_arg_complex.rs:13:61 + --> $DIR/array_expr_arg_complex.rs:14:61 | LL | takes_tuple_with_array::<{ core::direct_const_arg!(([N, N + 1], N)) }>(); | ^^^^^ 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 a278d5f69eb22..1b4c5b60edb72 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,11 +7,12 @@ trait Abc {} trait A { - type const VALUE: usize; + #[rustc_always_gca] + const VALUE: usize; } impl A for T { - type const VALUE: usize = 0; + const VALUE: usize = core::direct_const_arg!(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 f3f4779330b74..e3c37cac7a696 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: use of `const` in the type system not defined as `type const` + //~^ ERROR: use of `const` in the type system not marked as direct [(); T::SIZE] - //~^ ERROR: use of `const` in the type system not defined as `type const` + //~^ ERROR: use of `const` in the type system not marked as direct } 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 1a5f77ba33e15..122cb53124f8a 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,24 +1,24 @@ -error: use of `const` in the type system not defined as `type const` +error: use of `const` in the type system not marked as direct --> $DIR/assoc-const-without-type_const.rs:8:35 | LL | fn mk_array(_x: T) -> [(); T::SIZE] { | ^^^^^^^ | -help: add `type` before `const` for `Tr::SIZE` +help: add `#[rustc_always_gca]` to the constant | -LL | type const SIZE: usize; - | ++++ +LL | #[rustc_always_gca] const SIZE: usize; + | +++++++++++++++++++ -error: use of `const` in the type system not defined as `type const` +error: use of `const` in the type system not marked as direct --> $DIR/assoc-const-without-type_const.rs:10:10 | LL | [(); T::SIZE] | ^^^^^^^ | -help: add `type` before `const` for `Tr::SIZE` +help: add `#[rustc_always_gca]` to the constant | -LL | type const SIZE: usize; - | ++++ +LL | #[rustc_always_gca] 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 a618cfa7049b4..8a2a02ee096f6 100644 --- a/tests/ui/const-generics/mgca/assoc-const.rs +++ b/tests/ui/const-generics/mgca/assoc-const.rs @@ -4,7 +4,8 @@ #![allow(incomplete_features)] pub trait Tr { - type const SIZE: usize; + #[rustc_always_gca] + 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 81be1ca4eb882..9ffc2b70eecaf 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 N: usize; - //~^ ERROR: `type const` syntax is experimental [E0658] - //~| ERROR: associated `type const` are unstable [E0658] + #[rustc_always_gca] + //~^ ERROR: the `rustc_always_gca` attribute is an experimental feature [E0658] + const N: usize; } struct S; impl Tr for S { - - type const N: usize = 0; - //~^ ERROR: `type const` syntax is experimental [E0658] - //~| ERROR: associated `type const` are unstable [E0658] + const N: usize = core::direct_const_arg!(0); + //~^ ERROR: use of unstable library feature `min_generic_const_args` [E0658] + //~| ERROR: implementation of a `#[rustc_always_gca]` must have a `direct_const_arg!` RHS + //~| ERROR: expected expression, found `direct_const_arg!()` constant } 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 7bb2adf27199c..31be797b12590 100644 --- a/tests/ui/const-generics/mgca/bad-type_const-syntax.stderr +++ b/tests/ui/const-generics/mgca/bad-type_const-syntax.stderr @@ -1,42 +1,40 @@ -error[E0658]: `type const` syntax is experimental - --> $DIR/bad-type_const-syntax.rs:2:5 +error[E0658]: use of unstable library feature `min_generic_const_args` + --> $DIR/bad-type_const-syntax.rs:10:22 | -LL | type const N: usize; - | ^^^^^^^^^^ +LL | const N: usize = core::direct_const_arg!(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[E0658]: `type const` syntax is experimental - --> $DIR/bad-type_const-syntax.rs:11:5 +error[E0658]: the `rustc_always_gca` attribute is an experimental feature + --> $DIR/bad-type_const-syntax.rs:2:7 | -LL | type const N: usize = 0; - | ^^^^^^^^^^ +LL | #[rustc_always_gca] + | ^^^^^^^^^^^^^^^^ | = 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:2:5 +error: expected expression, found `direct_const_arg!()` constant + --> $DIR/bad-type_const-syntax.rs:10:22 | -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 +LL | const N: usize = core::direct_const_arg!(0); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0658]: associated `type const` are unstable - --> $DIR/bad-type_const-syntax.rs:11:5 +error: implementation of a `#[rustc_always_gca]` must have a `direct_const_arg!` RHS + --> $DIR/bad-type_const-syntax.rs:10:5 | -LL | type const N: usize = 0; - | ^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const N: usize = core::direct_const_arg!(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 +note: trait declaration of const is marked as `#[rustc_always_gca]` + --> $DIR/bad-type_const-syntax.rs:4:5 + | +LL | const N: usize; + | ^^^^^^^^^^^^^^ error: aborting due to 4 previous errors 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 69d16993a7e02..b365de395e80d 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 @@ -3,18 +3,24 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args, generic_const_items)] +extern crate core; +use core::direct_const_arg; + pub trait Tr { - type const N1: usize; - type const N2: usize; - type const N3: usize; + #[rustc_always_gca] + const N1: usize; + #[rustc_always_gca] + const N2: usize; + #[rustc_always_gca] + const N3: usize; } pub struct S; impl Tr for S { - type const N1: usize = 0; - type const N2: usize = 1; - type const N3: usize = 2; + const N1: usize = core::direct_const_arg!(0); + const N2: usize = core::direct_const_arg!(1); + const N3: usize = core::direct_const_arg!(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 9d475f8224fa5..c89c6a14a367a 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,7 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] - -type const C: usize = 0; +const C: usize = core::direct_const_arg!(0); pub struct A {} impl A { fn fun1() {} diff --git a/tests/ui/const-generics/mgca/const-arg-coherence-conflicting-methods.stderr b/tests/ui/const-generics/mgca/const-arg-coherence-conflicting-methods.stderr index 6b2b871ba4b98..3d74d1db206e1 100644 --- a/tests/ui/const-generics/mgca/const-arg-coherence-conflicting-methods.stderr +++ b/tests/ui/const-generics/mgca/const-arg-coherence-conflicting-methods.stderr @@ -1,11 +1,11 @@ error[E0107]: missing generics for struct `A` - --> $DIR/const-arg-coherence-conflicting-methods.rs:13:6 + --> $DIR/const-arg-coherence-conflicting-methods.rs:12:6 | LL | impl A { | ^ expected 1 generic argument | note: struct defined here, with 1 generic parameter: `M` - --> $DIR/const-arg-coherence-conflicting-methods.rs:8:12 + --> $DIR/const-arg-coherence-conflicting-methods.rs:7:12 | LL | pub struct A {} | ^ -------------- @@ -15,7 +15,7 @@ LL | impl A { | +++ error[E0592]: duplicate definitions with name `fun1` - --> $DIR/const-arg-coherence-conflicting-methods.rs:10:5 + --> $DIR/const-arg-coherence-conflicting-methods.rs:9:5 | LL | fn fun1() {} | ^^^^^^^^^ duplicate definitions for `fun1` diff --git a/tests/ui/const-generics/mgca/const-arg-mismatched-literal-suffix.rs b/tests/ui/const-generics/mgca/const-arg-mismatched-literal-suffix.rs index 0494871023e5c..df2dd048e6a43 100644 --- a/tests/ui/const-generics/mgca/const-arg-mismatched-literal-suffix.rs +++ b/tests/ui/const-generics/mgca/const-arg-mismatched-literal-suffix.rs @@ -1,7 +1,7 @@ #![feature(min_generic_const_args)] #![expect(incomplete_features)] -type const CONST: usize = 1_i32; +const CONST: usize = core::direct_const_arg!(1_i32); //~^ ERROR the constant `1` is not of type `usize` //~| NOTE expected `usize`, found `i32` diff --git a/tests/ui/const-generics/mgca/const-arg-mismatched-literal-suffix.stderr b/tests/ui/const-generics/mgca/const-arg-mismatched-literal-suffix.stderr index bd5de375e8545..49f9f76d6cb1b 100644 --- a/tests/ui/const-generics/mgca/const-arg-mismatched-literal-suffix.stderr +++ b/tests/ui/const-generics/mgca/const-arg-mismatched-literal-suffix.stderr @@ -1,8 +1,8 @@ error: the constant `1` is not of type `usize` --> $DIR/const-arg-mismatched-literal-suffix.rs:4:1 | -LL | type const CONST: usize = 1_i32; - | ^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `i32` +LL | const CONST: usize = core::direct_const_arg!(1_i32); + | ^^^^^^^^^^^^^^^^^^ expected `usize`, found `i32` error: aborting due to 1 previous error 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 b3dfef1cb26ca..89320472a3913 100644 --- a/tests/ui/const-generics/mgca/cyclic-type-const-151251.rs +++ b/tests/ui/const-generics/mgca/cyclic-type-const-151251.rs @@ -4,7 +4,7 @@ #![feature(generic_const_exprs)] #![expect(incomplete_features)] -type const A: u8 = A; -//~^ ERROR overflow normalizing the const alias `A` +const A: u8 = core::direct_const_arg!(A); +//~^ ERROR cycle detected when computing the type-level value for `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 07b4ca43eb77b..ac37da026f95f 100644 --- a/tests/ui/const-generics/mgca/cyclic-type-const-151251.stderr +++ b/tests/ui/const-generics/mgca/cyclic-type-const-151251.stderr @@ -1,11 +1,13 @@ -error[E0275]: overflow normalizing the const alias `A` +error[E0391]: cycle detected when computing the type-level value for `A` --> $DIR/cyclic-type-const-151251.rs:7:1 | -LL | type const A: u8 = A; - | ^^^^^^^^^^^^^^^^ +LL | const A: u8 = core::direct_const_arg!(A); + | ^^^^^^^^^^^ | - = note: in case this is a recursive type alias, consider using a struct, enum, or union instead + = note: ...which immediately requires computing the type-level value for `A` again + = note: cycle used when checking that `A` is well-formed + = note: for more information, see and error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0275`. +For more information about this error, try `rustc --explain E0391`. diff --git a/tests/ui/const-generics/mgca/explicit_anon_consts.rs b/tests/ui/const-generics/mgca/explicit_anon_consts.rs index 9b642b286fa3e..2fc1a0ea4b8ed 100644 --- a/tests/ui/const-generics/mgca/explicit_anon_consts.rs +++ b/tests/ui/const-generics/mgca/explicit_anon_consts.rs @@ -34,22 +34,21 @@ fn repeats() -> [(); N] { //~^ ERROR: generic parameters may not be used in const operations } +const ITEM1: usize = core::direct_const_arg!(N); -type const ITEM1: usize = N; +const ITEM2: usize = core::direct_const_arg!({ N }); -type const ITEM2: usize = { N }; - -type const ITEM3: usize = const { N }; +const ITEM3: usize = core::direct_const_arg!(const { N }); //~^ ERROR: generic parameters may not be used in const operations -type const ITEM4: usize = core::direct_const_arg!(1 + 1); +const ITEM4: usize = core::direct_const_arg!(1 + 1); //~^ ERROR: complex const arguments must be placed inside of a `const` block -type const ITEM5: usize = const { 1 + 1 }; +const ITEM5: usize = core::direct_const_arg!(const { 1 + 1 }); trait Trait { - - type const ASSOC: usize; + #[rustc_always_gca] + const ASSOC: usize; } fn ace_bounds< @@ -62,7 +61,8 @@ fn ace_bounds< T4: Trait, //~^ ERROR: complex const arguments must be placed inside of a `const` block T5: Trait, ->() {} +>() { +} struct Default1; struct Default2; diff --git a/tests/ui/const-generics/mgca/explicit_anon_consts.stderr b/tests/ui/const-generics/mgca/explicit_anon_consts.stderr index e9b32b6860c13..aa479bce84a7e 100644 --- a/tests/ui/const-generics/mgca/explicit_anon_consts.stderr +++ b/tests/ui/const-generics/mgca/explicit_anon_consts.stderr @@ -17,13 +17,13 @@ LL | let _4 = [(); core::direct_const_arg!(1 + 1)]; | ^^^^^ error: complex const arguments must be placed inside of a `const` block - --> $DIR/explicit_anon_consts.rs:45:67 + --> $DIR/explicit_anon_consts.rs:44:62 | -LL | type const ITEM4: usize = core::direct_const_arg!(1 + 1); - | ^^^^^ +LL | const ITEM4: usize = core::direct_const_arg!(1 + 1); + | ^^^^^ error: complex const arguments must be placed inside of a `const` block - --> $DIR/explicit_anon_consts.rs:62:49 + --> $DIR/explicit_anon_consts.rs:61:49 | LL | T4: Trait, | ^^^^^ @@ -35,15 +35,15 @@ LL | struct Default4 $DIR/explicit_anon_consts.rs:42:51 + --> $DIR/explicit_anon_consts.rs:41:70 | -LL | type const ITEM3: usize = const { N }; - | ^ +LL | const ITEM3: usize = core::direct_const_arg!(const { N }); + | ^ | = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item error: generic parameters may not be used in const operations - --> $DIR/explicit_anon_consts.rs:60:31 + --> $DIR/explicit_anon_consts.rs:59:31 | LL | T3: Trait, | ^ 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 be853bb87a371..f5e07d1891f40 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,7 +4,8 @@ #![expect(incomplete_features)] trait Trait { - type const ASSOC: isize; + #[rustc_always_gca] + const ASSOC: isize; } fn ace>() {} @@ -16,7 +17,9 @@ struct Foo; type NormalArg = (Foo<1>, Foo<-1>); #[derive(Eq, PartialEq, std::marker::ConstParamTy)] -struct ADT { field: u8 } +struct ADT { + field: u8, +} fn struct_expr() { fn takes_n() {} diff --git a/tests/ui/const-generics/mgca/free-const-recursive.stderr b/tests/ui/const-generics/mgca/free-const-recursive.gca.stderr similarity index 56% rename from tests/ui/const-generics/mgca/free-const-recursive.stderr rename to tests/ui/const-generics/mgca/free-const-recursive.gca.stderr index aeb2bd4b22ddf..62c2740c2967a 100644 --- a/tests/ui/const-generics/mgca/free-const-recursive.stderr +++ b/tests/ui/const-generics/mgca/free-const-recursive.gca.stderr @@ -1,14 +1,14 @@ error[E0275]: overflow evaluating the requirement `A == _` - --> $DIR/free-const-recursive.rs:7:1 + --> $DIR/free-const-recursive.rs:9:1 | -LL | type const A: () = A; - | ^^^^^^^^^^^^^^^^ +LL | const A: () = core::direct_const_arg!(A); + | ^^^^^^^^^^^ error[E0275]: overflow evaluating the requirement `the constant `A` has type `()`` - --> $DIR/free-const-recursive.rs:7:1 + --> $DIR/free-const-recursive.rs:9:1 | -LL | type const A: () = A; - | ^^^^^^^^^^^^^^^^ +LL | const A: () = core::direct_const_arg!(A); + | ^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/free-const-recursive.min_gca.stderr b/tests/ui/const-generics/mgca/free-const-recursive.min_gca.stderr new file mode 100644 index 0000000000000..1d7fc9a778478 --- /dev/null +++ b/tests/ui/const-generics/mgca/free-const-recursive.min_gca.stderr @@ -0,0 +1,13 @@ +error[E0391]: cycle detected when computing the type-level value for `A` + --> $DIR/free-const-recursive.rs:9:1 + | +LL | const A: () = core::direct_const_arg!(A); + | ^^^^^^^^^^^ + | + = note: ...which immediately requires computing the type-level value for `A` again + = note: cycle used when checking that `A` is well-formed + = note: for more information, see and + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0391`. diff --git a/tests/ui/const-generics/mgca/free-const-recursive.rs b/tests/ui/const-generics/mgca/free-const-recursive.rs index 1bbdc36e168b6..c55b52d42dd06 100644 --- a/tests/ui/const-generics/mgca/free-const-recursive.rs +++ b/tests/ui/const-generics/mgca/free-const-recursive.rs @@ -1,12 +1,15 @@ +//@ revisions: min_gca gca //! Regression test for //@ check-fail //@compile-flags: -Znext-solver=globally --emit=obj #![feature(min_generic_const_args)] #![expect(incomplete_features)] +#![cfg_attr(gca, feature(generic_const_args))] -type const A: () = A; -//~^ ERROR: overflow evaluating the requirement `A == _` -//~| ERROR: overflow evaluating the requirement `the constant `A` has type `()`` +const A: () = core::direct_const_arg!(A); +//[gca]~^ ERROR: overflow evaluating the requirement `A == _` +//[gca]~| ERROR: overflow evaluating the requirement `the constant `A` has type `()`` +//[min_gca]~^^^ ERROR: cycle detected when computing the type-level value for `A` fn main() { A; diff --git a/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments-fail.rs b/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments-fail.rs index 9e4443b1fc1c5..b435dcde6dc93 100644 --- a/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments-fail.rs +++ b/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments-fail.rs @@ -10,10 +10,10 @@ pub mod module { pub use super::Enum::Store; } fn main() { - type const _: Enum<()> = Enum::<()>::Unit::<()>; + const _: Enum<()> = core::direct_const_arg!(Enum::<()>::Unit::<()>); //~^ ERROR: type arguments are not allowed on unit variant `Unit` [E0109] - type const _: Enum<()> = Enum::<()>::Tuple::<()>(); + const _: Enum<()> = core::direct_const_arg!(Enum::<()>::Tuple::<()>()); //~^ ERROR: type arguments are not allowed on tuple variant `Tuple` [E0109] - type const _: Enum<()> = self::::Enum::<()>::Store; + const _: Enum<()> = core::direct_const_arg!(self::::Enum::<()>::Store); //~^ ERROR: type arguments are not allowed on module `generic_args_on_enum_variant_segments_fail` [E0109] } diff --git a/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments-fail.stderr b/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments-fail.stderr index ec129b3e33213..3a6c7a17544c8 100644 --- a/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments-fail.stderr +++ b/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments-fail.stderr @@ -1,40 +1,40 @@ error[E0109]: type arguments are not allowed on unit variant `Unit` - --> $DIR/generic-args-on-enum-variant-segments-fail.rs:13:49 + --> $DIR/generic-args-on-enum-variant-segments-fail.rs:13:68 | -LL | type const _: Enum<()> = Enum::<()>::Unit::<()>; - | ---- ^^ type argument not allowed - | | - | not allowed on unit variant `Unit` +LL | const _: Enum<()> = core::direct_const_arg!(Enum::<()>::Unit::<()>); + | ---- ^^ type argument not allowed + | | + | not allowed on unit variant `Unit` | = note: generic arguments are not allowed on both an enum and its variant's path segments simultaneously; they are only valid in one place or the other help: remove the generics arguments from one of the path segments | -LL - type const _: Enum<()> = Enum::<()>::Unit::<()>; -LL + type const _: Enum<()> = Enum::<()>::Unit; +LL - const _: Enum<()> = core::direct_const_arg!(Enum::<()>::Unit::<()>); +LL + const _: Enum<()> = core::direct_const_arg!(Enum::<()>::Unit); | error[E0109]: type arguments are not allowed on tuple variant `Tuple` - --> $DIR/generic-args-on-enum-variant-segments-fail.rs:15:50 + --> $DIR/generic-args-on-enum-variant-segments-fail.rs:15:69 | -LL | type const _: Enum<()> = Enum::<()>::Tuple::<()>(); - | ----- ^^ type argument not allowed - | | - | not allowed on tuple variant `Tuple` +LL | const _: Enum<()> = core::direct_const_arg!(Enum::<()>::Tuple::<()>()); + | ----- ^^ type argument not allowed + | | + | not allowed on tuple variant `Tuple` | = note: generic arguments are not allowed on both an enum and its variant's path segments simultaneously; they are only valid in one place or the other help: remove the generics arguments from one of the path segments | -LL - type const _: Enum<()> = Enum::<()>::Tuple::<()>(); -LL + type const _: Enum<()> = Enum::<()>::Tuple(); +LL - const _: Enum<()> = core::direct_const_arg!(Enum::<()>::Tuple::<()>()); +LL + const _: Enum<()> = core::direct_const_arg!(Enum::<()>::Tuple()); | error[E0109]: type arguments are not allowed on module `generic_args_on_enum_variant_segments_fail` - --> $DIR/generic-args-on-enum-variant-segments-fail.rs:17:37 + --> $DIR/generic-args-on-enum-variant-segments-fail.rs:17:56 | -LL | type const _: Enum<()> = self::::Enum::<()>::Store; - | ---- ^^^ type argument not allowed - | | - | not allowed on module `generic_args_on_enum_variant_segments_fail` +LL | const _: Enum<()> = core::direct_const_arg!(self::::Enum::<()>::Store); + | ---- ^^^ type argument not allowed + | | + | not allowed on module `generic_args_on_enum_variant_segments_fail` error: aborting due to 3 previous errors diff --git a/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments.rs b/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments.rs index caac7a3b23a50..234bca78d6cb3 100644 --- a/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments.rs +++ b/tests/ui/const-generics/mgca/generic-args-on-enum-variant-segments.rs @@ -10,7 +10,7 @@ enum Enum { Store(T), } -type const _: Enum<()> = Enum::<()>::Unit; -type const _: Enum<()> = Enum::<()>::Tuple(); +const _: Enum<()> = core::direct_const_arg!(Enum::<()>::Unit); +const _: Enum<()> = core::direct_const_arg!(Enum::<()>::Tuple()); fn main() {} diff --git a/tests/ui/const-generics/mgca/generic_const_type_mismatch.rs b/tests/ui/const-generics/mgca/generic_const_type_mismatch.rs index 0c975184dfbdc..928205d4bc4df 100644 --- a/tests/ui/const-generics/mgca/generic_const_type_mismatch.rs +++ b/tests/ui/const-generics/mgca/generic_const_type_mismatch.rs @@ -13,7 +13,7 @@ struct Foo { field: T, } -type const WRAP : T = Foo::{field : 1}; +const WRAP: T = core::direct_const_arg!(Foo:: { field: 1 }); //~^ ERROR: type annotations needed for the literal fn main() {} diff --git a/tests/ui/const-generics/mgca/generic_const_type_mismatch.stderr b/tests/ui/const-generics/mgca/generic_const_type_mismatch.stderr index fdb0995bff5d4..d7f89bede8d4d 100644 --- a/tests/ui/const-generics/mgca/generic_const_type_mismatch.stderr +++ b/tests/ui/const-generics/mgca/generic_const_type_mismatch.stderr @@ -1,8 +1,8 @@ error: type annotations needed for the literal - --> $DIR/generic_const_type_mismatch.rs:16:59 + --> $DIR/generic_const_type_mismatch.rs:16:77 | -LL | type const WRAP : T = Foo::{field : 1}; - | ^ +LL | const WRAP: T = core::direct_const_arg!(Foo:: { field: 1 }); + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/mgca/macro-const-arg-infer.rs b/tests/ui/const-generics/mgca/macro-const-arg-infer.rs index d96cd92aef628..a768228d94d28 100644 --- a/tests/ui/const-generics/mgca/macro-const-arg-infer.rs +++ b/tests/ui/const-generics/mgca/macro-const-arg-infer.rs @@ -1,5 +1,5 @@ //! Regression test for https://github.com/rust-lang/rust/issues/153198 -#![feature(min_generic_const_args, macroless_generic_const_args)] +#![feature(min_generic_const_args)] #![allow(incomplete_features)] macro_rules! y { ( $($matcher:tt)*) => { @@ -11,11 +11,9 @@ macro_rules! y { struct A; //~ ERROR: type parameter `T` is never used const y: A< - { - y! { - x - } - }, + core::direct_const_arg!(y! { + x + }), > = 1; fn main() {} diff --git a/tests/ui/const-generics/mgca/macro-const-arg-infer.stderr b/tests/ui/const-generics/mgca/macro-const-arg-infer.stderr index 68160da0595a1..0d745517e4406 100644 --- a/tests/ui/const-generics/mgca/macro-const-arg-infer.stderr +++ b/tests/ui/const-generics/mgca/macro-const-arg-infer.stderr @@ -13,10 +13,11 @@ error[E0747]: constant provided when a type was expected LL | _ | ^ ... -LL | / y! { -LL | | x -LL | | } - | |_________- in this macro invocation +LL | core::direct_const_arg!(y! { + | _____________________________- +LL | | x +LL | | }), + | |_____- in this macro invocation | = note: this error originates in the macro `y` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -26,10 +27,11 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures LL | _ | ^ not allowed in type signatures ... -LL | / y! { -LL | | x -LL | | } - | |_________- in this macro invocation +LL | core::direct_const_arg!(y! { + | _____________________________- +LL | | x +LL | | }), + | |_____- in this macro invocation | = note: this error originates in the macro `y` (in Nightly builds, run with -Z macro-backtrace for more info) 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 f328b5d0ba209..ecf6bba056a1a 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,19 +6,20 @@ struct Foo; trait Trait { - type const ASSOC: usize; + #[rustc_always_gca] + const ASSOC: usize; } -type Arr = [(); {{{ N }}}]; -type Arr2 = [(); {{{ ::ASSOC }}}]; -type Ty = Foo<{{{ N }}}>; -type Ty2 = Foo<{{{ ::ASSOC }}}>; -struct Default; -struct Default2::ASSOC }}}>(T); +type Arr = [(); { { { N } } }]; +type Arr2 = [(); { { { ::ASSOC } } }]; +type Ty = Foo<{ { { N } } }>; +type Ty2 = Foo<{ { { ::ASSOC } } }>; +struct Default; +struct Default2::ASSOC } } }>(T); fn repeat() { - let _1 = [(); {{{ N }}}]; - let _2 = [(); {{{ ::ASSOC }}}]; + let _1 = [(); { { { N } } }]; + let _2 = [(); { { { ::ASSOC } } }]; } fn main() {} 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 11974d034040a..d136668b9f90f 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 not defined as `type const` + //~^ ERROR: use of `const` in the type system not marked as direct } 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 3c10b78eb3e17..593eac88122c0 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 not defined as `type const` +error: use of `const` in the type system not marked as direct --> $DIR/non-local-const-without-type_const.rs:7:18 | LL | let x = [(); non_local_const::N]; | ^^^^^^^^^^^^^^^^^^ | - = note: only consts marked defined as `type const` may be used in types + = note: only consts with a `direct_const_arg!` right-hand side may be used in types error: aborting due to 1 previous error diff --git a/tests/ui/const-generics/mgca/opaque-ty-assoc-const-equality-117923.rs b/tests/ui/const-generics/mgca/opaque-ty-assoc-const-equality-117923.rs index 37f32038c55f4..ee336ea3f61e7 100644 --- a/tests/ui/const-generics/mgca/opaque-ty-assoc-const-equality-117923.rs +++ b/tests/ui/const-generics/mgca/opaque-ty-assoc-const-equality-117923.rs @@ -4,7 +4,8 @@ #![allow(incomplete_features, dead_code)] trait Trait { - type const CT: usize; + #[rustc_always_gca] + const CT: usize; } struct Type { @@ -12,7 +13,7 @@ struct Type { } impl Trait for Type { - type const CT: usize = N; + const CT: usize = core::direct_const_arg!(N); } fn func() -> impl Trait as Trait>::CT }> { diff --git a/tests/ui/const-generics/mgca/paren.rs b/tests/ui/const-generics/mgca/paren.rs index 3f4dd491da949..de9e726a756f0 100644 --- a/tests/ui/const-generics/mgca/paren.rs +++ b/tests/ui/const-generics/mgca/paren.rs @@ -4,7 +4,7 @@ struct Thing; -type const A: usize = N; +const A: usize = core::direct_const_arg!(N); fn f() { let _: [u32; core::direct_const_arg!(_)] = [5; 5]; 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 44f977d219d72..12a1feefeeac0 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 ASSOC: u32; + #[rustc_always_gca] + const ASSOC: u32; } fn foo() {} diff --git a/tests/ui/const-generics/mgca/projection-const-recursive.rs b/tests/ui/const-generics/mgca/projection-const-recursive.rs index a2f54fbfca0e3..90aceeb3b7c27 100644 --- a/tests/ui/const-generics/mgca/projection-const-recursive.rs +++ b/tests/ui/const-generics/mgca/projection-const-recursive.rs @@ -5,11 +5,12 @@ #![expect(incomplete_features)] trait Trait { - type const A: (); + #[rustc_always_gca] + const A: (); } impl Trait for () { - type const A: () = <() as Trait>::A; + const A: () = core::direct_const_arg!(<() as Trait>::A); //~^ ERROR: overflow evaluating the requirement `<() as Trait>::A == _` //~| ERROR: overflow evaluating the requirement `the constant `<() as Trait>::A` has type `()`` } diff --git a/tests/ui/const-generics/mgca/projection-const-recursive.stderr b/tests/ui/const-generics/mgca/projection-const-recursive.stderr index a102e82426fca..649e1213fcac2 100644 --- a/tests/ui/const-generics/mgca/projection-const-recursive.stderr +++ b/tests/ui/const-generics/mgca/projection-const-recursive.stderr @@ -1,14 +1,14 @@ error[E0275]: overflow evaluating the requirement `<() as Trait>::A == _` - --> $DIR/projection-const-recursive.rs:12:5 + --> $DIR/projection-const-recursive.rs:13:5 | -LL | type const A: () = <() as Trait>::A; - | ^^^^^^^^^^^^^^^^ +LL | const A: () = core::direct_const_arg!(<() as Trait>::A); + | ^^^^^^^^^^^ error[E0275]: overflow evaluating the requirement `the constant `<() as Trait>::A` has type `()`` - --> $DIR/projection-const-recursive.rs:12:5 + --> $DIR/projection-const-recursive.rs:13:5 | -LL | type const A: () = <() as Trait>::A; - | ^^^^^^^^^^^^^^^^ +LL | const A: () = core::direct_const_arg!(<() as Trait>::A); + | ^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/projection-error.rs b/tests/ui/const-generics/mgca/projection-error.rs index d3bd520297e1c..656416d31a3e1 100644 --- a/tests/ui/const-generics/mgca/projection-error.rs +++ b/tests/ui/const-generics/mgca/projection-error.rs @@ -6,7 +6,8 @@ // a type error. pub trait Tr { - type const SIZE: usize; + #[rustc_always_gca] + 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 360a9421f31bf..6fd45472c8c26 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:12:17 + --> $DIR/projection-error.rs:13:17 | LL | fn mk_array(_x: T) -> [(); >::SIZE] {} | ^ not found in this scope @@ -19,7 +19,7 @@ LL | fn mk_array(_x: T) -> [(); >::SIZE] {} | +++ error[E0425]: cannot find type `T` in this scope - --> $DIR/projection-error.rs:12:29 + --> $DIR/projection-error.rs:13:29 | LL | fn mk_array(_x: T) -> [(); >::SIZE] {} | ^ not found in this scope diff --git a/tests/ui/const-generics/mgca/static-const-arg.rs b/tests/ui/const-generics/mgca/static-const-arg.rs index 716c8bb6dc4de..8afc57c1c2785 100644 --- a/tests/ui/const-generics/mgca/static-const-arg.rs +++ b/tests/ui/const-generics/mgca/static-const-arg.rs @@ -2,17 +2,17 @@ // FIXME(min_generic_const_args): using statics as direct const arguments should error instead of // ICEing until const eval can evaluate statics to valtrees for const generics. -#![feature(min_generic_const_args, macroless_generic_const_args)] +#![feature(min_generic_const_args)] #![allow(incomplete_features)] static A: u32 = 0; struct Foo; -const _: Foo<{ A }> = Foo; +const _: Foo<{ core::direct_const_arg!(A) }> = Foo; //~^ ERROR static items cannot be used as const arguments -const _: Foo = Foo; +const _: Foo = Foo; //~^ ERROR static items cannot be used as const arguments fn main() {} diff --git a/tests/ui/const-generics/mgca/static-const-arg.stderr b/tests/ui/const-generics/mgca/static-const-arg.stderr index 9c5473f94d2cc..d2f878545971b 100644 --- a/tests/ui/const-generics/mgca/static-const-arg.stderr +++ b/tests/ui/const-generics/mgca/static-const-arg.stderr @@ -1,14 +1,14 @@ error: static items cannot be used as const arguments - --> $DIR/static-const-arg.rs:12:16 + --> $DIR/static-const-arg.rs:12:40 | -LL | const _: Foo<{ A }> = Foo; - | ^ +LL | const _: Foo<{ core::direct_const_arg!(A) }> = Foo; + | ^ error: static items cannot be used as const arguments - --> $DIR/static-const-arg.rs:15:14 + --> $DIR/static-const-arg.rs:15:38 | -LL | const _: Foo = Foo; - | ^ +LL | const _: Foo = Foo; + | ^ error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/suggest-direct-const.fixed b/tests/ui/const-generics/mgca/suggest-direct-const.fixed new file mode 100644 index 0000000000000..6a6af81570255 --- /dev/null +++ b/tests/ui/const-generics/mgca/suggest-direct-const.fixed @@ -0,0 +1,52 @@ +//! Regression test for +//@ run-rustfix +#![feature(min_generic_const_args, inherent_associated_types)] +#![allow(dead_code)] + +mod impl_item { + pub struct Bar; + impl Bar { + pub const PUBLIC: usize = core::direct_const_arg!(1); + pub(crate) const RESTRICTED: usize = core::direct_const_arg!(1); + const PRIVATE: usize = core::direct_const_arg!(1); + } + + pub struct Foo1([u8; core::direct_const_arg!(Bar::PUBLIC)]); + //~^ ERROR: use of `const` in the type system not marked as direct + pub struct Foo2([u8; core::direct_const_arg!(Bar::RESTRICTED)]); + //~^ ERROR: use of `const` in the type system not marked as direct + pub struct Foo3([u8; core::direct_const_arg!(Bar::PRIVATE)]); + //~^ ERROR: use of `const` in the type system not marked as direct +} + +mod top_level_item { + pub const PUBLIC: usize = core::direct_const_arg!(1); + pub(crate) const RESTRICTED: usize = core::direct_const_arg!(1); + const PRIVATE: usize = core::direct_const_arg!(1); + + pub struct Foo1([u8; core::direct_const_arg!(PUBLIC)]); + //~^ ERROR: use of `const` in the type system not marked as direct + pub struct Foo2([u8; core::direct_const_arg!(RESTRICTED)]); + //~^ ERROR: use of `const` in the type system not marked as direct + pub struct Foo3([u8; core::direct_const_arg!(PRIVATE)]); + //~^ ERROR: use of `const` in the type system not marked as direct +} + +mod trait_item { + pub trait Foo { + #[rustc_always_gca] const PUBLIC: usize; + //~^ ERROR: [E0449] + #[rustc_always_gca] const RESTRICTED: usize; + //~^ ERROR: [E0449] + #[rustc_always_gca] const PRIVATE: usize; + } + + pub struct Bar([u8; core::direct_const_arg!(T::PUBLIC)]); + //~^ ERROR: use of `const` in the type system not marked as direct + pub struct Bar2([u8; core::direct_const_arg!(T::RESTRICTED)]); + //~^ ERROR: use of `const` in the type system not marked as direct + pub struct Bar3([u8; core::direct_const_arg!(T::PRIVATE)]); + //~^ ERROR: use of `const` in the type system not marked as direct +} + +fn main() {} diff --git a/tests/ui/const-generics/mgca/suggest-direct-const.rs b/tests/ui/const-generics/mgca/suggest-direct-const.rs new file mode 100644 index 0000000000000..05b538a6cd1d9 --- /dev/null +++ b/tests/ui/const-generics/mgca/suggest-direct-const.rs @@ -0,0 +1,52 @@ +//! Regression test for +//@ run-rustfix +#![feature(min_generic_const_args, inherent_associated_types)] +#![allow(dead_code)] + +mod impl_item { + pub struct Bar; + impl Bar { + pub const PUBLIC: usize = 1; + pub(crate) const RESTRICTED: usize = 1; + const PRIVATE: usize = 1; + } + + pub struct Foo1([u8; core::direct_const_arg!(Bar::PUBLIC)]); + //~^ ERROR: use of `const` in the type system not marked as direct + pub struct Foo2([u8; core::direct_const_arg!(Bar::RESTRICTED)]); + //~^ ERROR: use of `const` in the type system not marked as direct + pub struct Foo3([u8; core::direct_const_arg!(Bar::PRIVATE)]); + //~^ ERROR: use of `const` in the type system not marked as direct +} + +mod top_level_item { + pub const PUBLIC: usize = 1; + pub(crate) const RESTRICTED: usize = 1; + const PRIVATE: usize = 1; + + pub struct Foo1([u8; core::direct_const_arg!(PUBLIC)]); + //~^ ERROR: use of `const` in the type system not marked as direct + pub struct Foo2([u8; core::direct_const_arg!(RESTRICTED)]); + //~^ ERROR: use of `const` in the type system not marked as direct + pub struct Foo3([u8; core::direct_const_arg!(PRIVATE)]); + //~^ ERROR: use of `const` in the type system not marked as direct +} + +mod trait_item { + pub trait Foo { + pub const PUBLIC: usize; + //~^ ERROR: [E0449] + pub(crate) const RESTRICTED: usize; + //~^ ERROR: [E0449] + const PRIVATE: usize; + } + + pub struct Bar([u8; core::direct_const_arg!(T::PUBLIC)]); + //~^ ERROR: use of `const` in the type system not marked as direct + pub struct Bar2([u8; core::direct_const_arg!(T::RESTRICTED)]); + //~^ ERROR: use of `const` in the type system not marked as direct + pub struct Bar3([u8; core::direct_const_arg!(T::PRIVATE)]); + //~^ ERROR: use of `const` in the type system not marked as direct +} + +fn main() {} diff --git a/tests/ui/const-generics/mgca/suggest-direct-const.stderr b/tests/ui/const-generics/mgca/suggest-direct-const.stderr new file mode 100644 index 0000000000000..69eeee156675d --- /dev/null +++ b/tests/ui/const-generics/mgca/suggest-direct-const.stderr @@ -0,0 +1,118 @@ +error[E0449]: visibility qualifiers are not permitted here + --> $DIR/suggest-direct-const.rs:37:9 + | +LL | pub const PUBLIC: usize; + | ^^^ help: remove the qualifier + | + = note: trait items always share the visibility of their trait + +error[E0449]: visibility qualifiers are not permitted here + --> $DIR/suggest-direct-const.rs:39:9 + | +LL | pub(crate) const RESTRICTED: usize; + | ^^^^^^^^^^ help: remove the qualifier + | + = note: trait items always share the visibility of their trait + +error: use of `const` in the type system not marked as direct + --> $DIR/suggest-direct-const.rs:14:50 + | +LL | pub struct Foo1([u8; core::direct_const_arg!(Bar::PUBLIC)]); + | ^^^^^^^^^^^ + | +help: add direct_const_arg!() to the right-hand side of the constant + | +LL | pub const PUBLIC: usize = core::direct_const_arg!(1); + | ++++++++++++++++++++++++ + + +error: use of `const` in the type system not marked as direct + --> $DIR/suggest-direct-const.rs:16:50 + | +LL | pub struct Foo2([u8; core::direct_const_arg!(Bar::RESTRICTED)]); + | ^^^^^^^^^^^^^^^ + | +help: add direct_const_arg!() to the right-hand side of the constant + | +LL | pub(crate) const RESTRICTED: usize = core::direct_const_arg!(1); + | ++++++++++++++++++++++++ + + +error: use of `const` in the type system not marked as direct + --> $DIR/suggest-direct-const.rs:18:50 + | +LL | pub struct Foo3([u8; core::direct_const_arg!(Bar::PRIVATE)]); + | ^^^^^^^^^^^^ + | +help: add direct_const_arg!() to the right-hand side of the constant + | +LL | const PRIVATE: usize = core::direct_const_arg!(1); + | ++++++++++++++++++++++++ + + +error: use of `const` in the type system not marked as direct + --> $DIR/suggest-direct-const.rs:27:50 + | +LL | pub struct Foo1([u8; core::direct_const_arg!(PUBLIC)]); + | ^^^^^^ + | +help: add direct_const_arg!() to the right-hand side of the constant + | +LL | pub const PUBLIC: usize = core::direct_const_arg!(1); + | ++++++++++++++++++++++++ + + +error: use of `const` in the type system not marked as direct + --> $DIR/suggest-direct-const.rs:29:50 + | +LL | pub struct Foo2([u8; core::direct_const_arg!(RESTRICTED)]); + | ^^^^^^^^^^ + | +help: add direct_const_arg!() to the right-hand side of the constant + | +LL | pub(crate) const RESTRICTED: usize = core::direct_const_arg!(1); + | ++++++++++++++++++++++++ + + +error: use of `const` in the type system not marked as direct + --> $DIR/suggest-direct-const.rs:31:50 + | +LL | pub struct Foo3([u8; core::direct_const_arg!(PRIVATE)]); + | ^^^^^^^ + | +help: add direct_const_arg!() to the right-hand side of the constant + | +LL | const PRIVATE: usize = core::direct_const_arg!(1); + | ++++++++++++++++++++++++ + + +error: use of `const` in the type system not marked as direct + --> $DIR/suggest-direct-const.rs:44:57 + | +LL | pub struct Bar([u8; core::direct_const_arg!(T::PUBLIC)]); + | ^^^^^^^^^ + | +help: add `#[rustc_always_gca]` to the constant + | +LL | #[rustc_always_gca] pub const PUBLIC: usize; + | +++++++++++++++++++ + +error: use of `const` in the type system not marked as direct + --> $DIR/suggest-direct-const.rs:46:58 + | +LL | pub struct Bar2([u8; core::direct_const_arg!(T::RESTRICTED)]); + | ^^^^^^^^^^^^^ + | +help: add `#[rustc_always_gca]` to the constant + | +LL | #[rustc_always_gca] pub(crate) const RESTRICTED: usize; + | +++++++++++++++++++ + +error: use of `const` in the type system not marked as direct + --> $DIR/suggest-direct-const.rs:48:58 + | +LL | pub struct Bar3([u8; core::direct_const_arg!(T::PRIVATE)]); + | ^^^^^^^^^^ + | +help: add `#[rustc_always_gca]` to the constant + | +LL | #[rustc_always_gca] const PRIVATE: usize; + | +++++++++++++++++++ + +error: aborting due to 11 previous errors + +For more information about this error, try `rustc --explain E0449`. diff --git a/tests/ui/const-generics/mgca/suggest-pub-type_const.fixed b/tests/ui/const-generics/mgca/suggest-pub-type_const.fixed deleted file mode 100644 index 501452b4846af..0000000000000 --- a/tests/ui/const-generics/mgca/suggest-pub-type_const.fixed +++ /dev/null @@ -1,53 +0,0 @@ -//! Regression test for -//! Tests suggesting `pub type const` instead of `type pub const`. -//@ run-rustfix -#![feature(min_generic_const_args, macroless_generic_const_args, inherent_associated_types)] -#![allow(dead_code)] - -mod impl_item { - pub struct Bar; - impl Bar { - pub type const PUBLIC: usize = 1; - pub(crate) type const RESTRICTED: usize = 1; - type const PRIVATE: usize = 1; - } - - pub struct Foo1([u8; Bar::PUBLIC]); - //~^ ERROR: use of `const` in the type system not defined as `type const` - pub struct Foo2([u8; Bar::RESTRICTED]); - //~^ ERROR: use of `const` in the type system not defined as `type const` - pub struct Foo3([u8; Bar::PRIVATE]); - //~^ ERROR: use of `const` in the type system not defined as `type const` -} - -mod top_level_item { - pub type const PUBLIC: usize = 1; - pub(crate) type const RESTRICTED: usize = 1; - type const PRIVATE: usize = 1; - - pub struct Foo1([u8; PUBLIC]); - //~^ ERROR: use of `const` in the type system not defined as `type const` - pub struct Foo2([u8; RESTRICTED]); - //~^ ERROR: use of `const` in the type system not defined as `type const` - pub struct Foo3([u8; PRIVATE]); - //~^ ERROR: use of `const` in the type system not defined as `type const` -} - -mod trait_item { - pub trait Foo { - type const PUBLIC: usize; - //~^ ERROR: [E0449] - type const RESTRICTED: usize; - //~^ ERROR: [E0449] - type const PRIVATE: usize; - } - - pub struct Bar([u8; T::PUBLIC]); - //~^ ERROR: use of `const` in the type system not defined as `type const` - pub struct Bar2([u8; T::RESTRICTED]); - //~^ ERROR: use of `const` in the type system not defined as `type const` - pub struct Bar3([u8; T::PRIVATE]); - //~^ ERROR: use of `const` in the type system not defined as `type const` -} - -fn main() {} diff --git a/tests/ui/const-generics/mgca/suggest-pub-type_const.rs b/tests/ui/const-generics/mgca/suggest-pub-type_const.rs deleted file mode 100644 index ae6efa8f85960..0000000000000 --- a/tests/ui/const-generics/mgca/suggest-pub-type_const.rs +++ /dev/null @@ -1,53 +0,0 @@ -//! Regression test for -//! Tests suggesting `pub type const` instead of `type pub const`. -//@ run-rustfix -#![feature(min_generic_const_args, macroless_generic_const_args, inherent_associated_types)] -#![allow(dead_code)] - -mod impl_item { - pub struct Bar; - impl Bar { - pub const PUBLIC: usize = 1; - pub(crate) const RESTRICTED: usize = 1; - const PRIVATE: usize = 1; - } - - pub struct Foo1([u8; Bar::PUBLIC]); - //~^ ERROR: use of `const` in the type system not defined as `type const` - pub struct Foo2([u8; Bar::RESTRICTED]); - //~^ ERROR: use of `const` in the type system not defined as `type const` - pub struct Foo3([u8; Bar::PRIVATE]); - //~^ ERROR: use of `const` in the type system not defined as `type const` -} - -mod top_level_item { - pub const PUBLIC: usize = 1; - pub(crate) const RESTRICTED: usize = 1; - const PRIVATE: usize = 1; - - pub struct Foo1([u8; PUBLIC]); - //~^ ERROR: use of `const` in the type system not defined as `type const` - pub struct Foo2([u8; RESTRICTED]); - //~^ ERROR: use of `const` in the type system not defined as `type const` - pub struct Foo3([u8; PRIVATE]); - //~^ ERROR: use of `const` in the type system not defined as `type const` -} - -mod trait_item { - pub trait Foo { - pub const PUBLIC: usize; - //~^ ERROR: [E0449] - pub(crate) const RESTRICTED: usize; - //~^ ERROR: [E0449] - const PRIVATE: usize; - } - - pub struct Bar([u8; T::PUBLIC]); - //~^ ERROR: use of `const` in the type system not defined as `type const` - pub struct Bar2([u8; T::RESTRICTED]); - //~^ ERROR: use of `const` in the type system not defined as `type const` - pub struct Bar3([u8; T::PRIVATE]); - //~^ ERROR: use of `const` in the type system not defined as `type const` -} - -fn main() {} diff --git a/tests/ui/const-generics/mgca/suggest-pub-type_const.stderr b/tests/ui/const-generics/mgca/suggest-pub-type_const.stderr deleted file mode 100644 index 17d71000cc515..0000000000000 --- a/tests/ui/const-generics/mgca/suggest-pub-type_const.stderr +++ /dev/null @@ -1,118 +0,0 @@ -error[E0449]: visibility qualifiers are not permitted here - --> $DIR/suggest-pub-type_const.rs:38:9 - | -LL | pub const PUBLIC: usize; - | ^^^ help: remove the qualifier - | - = note: trait items always share the visibility of their trait - -error[E0449]: visibility qualifiers are not permitted here - --> $DIR/suggest-pub-type_const.rs:40:9 - | -LL | pub(crate) const RESTRICTED: usize; - | ^^^^^^^^^^ help: remove the qualifier - | - = note: trait items always share the visibility of their trait - -error: use of `const` in the type system not defined as `type const` - --> $DIR/suggest-pub-type_const.rs:15:26 - | -LL | pub struct Foo1([u8; Bar::PUBLIC]); - | ^^^^^^^^^^^ - | -help: add `type` before `const` for `impl_item::Bar::PUBLIC` - | -LL | pub type const PUBLIC: usize = 1; - | ++++ - -error: use of `const` in the type system not defined as `type const` - --> $DIR/suggest-pub-type_const.rs:17:26 - | -LL | pub struct Foo2([u8; Bar::RESTRICTED]); - | ^^^^^^^^^^^^^^^ - | -help: add `type` before `const` for `impl_item::Bar::RESTRICTED` - | -LL | pub(crate) type const RESTRICTED: usize = 1; - | ++++ - -error: use of `const` in the type system not defined as `type const` - --> $DIR/suggest-pub-type_const.rs:19:26 - | -LL | pub struct Foo3([u8; Bar::PRIVATE]); - | ^^^^^^^^^^^^ - | -help: add `type` before `const` for `impl_item::Bar::PRIVATE` - | -LL | type const PRIVATE: usize = 1; - | ++++ - -error: use of `const` in the type system not defined as `type const` - --> $DIR/suggest-pub-type_const.rs:28:26 - | -LL | pub struct Foo1([u8; PUBLIC]); - | ^^^^^^ - | -help: add `type` before `const` for `PUBLIC` - | -LL | pub type const PUBLIC: usize = 1; - | ++++ - -error: use of `const` in the type system not defined as `type const` - --> $DIR/suggest-pub-type_const.rs:30:26 - | -LL | pub struct Foo2([u8; RESTRICTED]); - | ^^^^^^^^^^ - | -help: add `type` before `const` for `RESTRICTED` - | -LL | pub(crate) type const RESTRICTED: usize = 1; - | ++++ - -error: use of `const` in the type system not defined as `type const` - --> $DIR/suggest-pub-type_const.rs:32:26 - | -LL | pub struct Foo3([u8; PRIVATE]); - | ^^^^^^^ - | -help: add `type` before `const` for `PRIVATE` - | -LL | type const PRIVATE: usize = 1; - | ++++ - -error: use of `const` in the type system not defined as `type const` - --> $DIR/suggest-pub-type_const.rs:45:33 - | -LL | pub struct Bar([u8; T::PUBLIC]); - | ^^^^^^^^^ - | -help: add `type` before `const` for `Foo::PUBLIC` - | -LL | type pub const PUBLIC: usize; - | ++++ - -error: use of `const` in the type system not defined as `type const` - --> $DIR/suggest-pub-type_const.rs:47:34 - | -LL | pub struct Bar2([u8; T::RESTRICTED]); - | ^^^^^^^^^^^^^ - | -help: add `type` before `const` for `Foo::RESTRICTED` - | -LL | type pub(crate) const RESTRICTED: usize; - | ++++ - -error: use of `const` in the type system not defined as `type const` - --> $DIR/suggest-pub-type_const.rs:49:34 - | -LL | pub struct Bar3([u8; T::PRIVATE]); - | ^^^^^^^^^^ - | -help: add `type` before `const` for `Foo::PRIVATE` - | -LL | type const PRIVATE: usize; - | ++++ - -error: aborting due to 11 previous errors - -For more information about this error, try `rustc --explain E0449`. diff --git a/tests/ui/const-generics/mgca/syntactic-type-mismatch.rs b/tests/ui/const-generics/mgca/syntactic-type-mismatch.rs index 18898069c1452..2fd3dea527370 100644 --- a/tests/ui/const-generics/mgca/syntactic-type-mismatch.rs +++ b/tests/ui/const-generics/mgca/syntactic-type-mismatch.rs @@ -4,10 +4,10 @@ #![feature(min_generic_const_args)] #![expect(incomplete_features)] -type const T0: _ = (); +const T0: _ = core::direct_const_arg!(()); //~^ ERROR: the placeholder `_` is not allowed within types on item signatures for constants [E0121] -type const T1 = [0]; +const T1 = core::direct_const_arg!([0]); //~^ ERROR: missing type for `const` item fn main() {} diff --git a/tests/ui/const-generics/mgca/syntactic-type-mismatch.stderr b/tests/ui/const-generics/mgca/syntactic-type-mismatch.stderr index ede7b1b3e0a5b..6f0544c80a480 100644 --- a/tests/ui/const-generics/mgca/syntactic-type-mismatch.stderr +++ b/tests/ui/const-generics/mgca/syntactic-type-mismatch.stderr @@ -1,19 +1,19 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants - --> $DIR/syntactic-type-mismatch.rs:7:16 + --> $DIR/syntactic-type-mismatch.rs:7:11 | -LL | type const T0: _ = (); - | ^ not allowed in type signatures +LL | const T0: _ = core::direct_const_arg!(()); + | ^ not allowed in type signatures error: missing type for `const` item - --> $DIR/syntactic-type-mismatch.rs:10:14 + --> $DIR/syntactic-type-mismatch.rs:10:9 | -LL | type const T1 = [0]; - | ^ +LL | const T1 = core::direct_const_arg!([0]); + | ^ | help: provide a type for the item | -LL | type const T1: = [0]; - | ++++++++ +LL | const T1: = core::direct_const_arg!([0]); + | ++++++++ error: aborting due to 2 previous errors 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 f2edaf184914e..c769ea0dc4d01 100644 --- a/tests/ui/const-generics/mgca/tuple_ctor_arg_simple.rs +++ b/tests/ui/const-generics/mgca/tuple_ctor_arg_simple.rs @@ -15,7 +15,8 @@ enum MyEnum { } trait Trait { - type const ASSOC: u32; + #[rustc_always_gca] + 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 deefa8077f43f..d121566868a95 100644 --- a/tests/ui/const-generics/mgca/tuple_ctor_erroneous.rs +++ b/tests/ui/const-generics/mgca/tuple_ctor_erroneous.rs @@ -12,8 +12,7 @@ enum MyEnum { Unit, } - -type const CONST_ITEM: u32 = 42; +const CONST_ITEM: u32 = core::direct_const_arg!(42); fn accepts_point() {} fn accepts_enum>() {} diff --git a/tests/ui/const-generics/mgca/tuple_ctor_erroneous.stderr b/tests/ui/const-generics/mgca/tuple_ctor_erroneous.stderr index 56b11b2894aa2..b9bbfcc37469d 100644 --- a/tests/ui/const-generics/mgca/tuple_ctor_erroneous.stderr +++ b/tests/ui/const-generics/mgca/tuple_ctor_erroneous.stderr @@ -1,5 +1,5 @@ error[E0425]: cannot find function, tuple struct or tuple variant `UnresolvedIdent` in this scope - --> $DIR/tuple_ctor_erroneous.rs:30:23 + --> $DIR/tuple_ctor_erroneous.rs:29:23 | LL | accepts_point::<{ UnresolvedIdent(N, N) }>(); | ^^^^^^^^^^^^^^^ not found in this scope @@ -10,61 +10,61 @@ LL | fn test_errors() { | +++++++++++++++++++++++++++++++++++ error: tuple constructor has 2 arguments but 1 were provided - --> $DIR/tuple_ctor_erroneous.rs:24:23 + --> $DIR/tuple_ctor_erroneous.rs:23:23 | LL | accepts_point::<{ Point(N) }>(); | ^^^^^^^^ error: tuple constructor has 2 arguments but 3 were provided - --> $DIR/tuple_ctor_erroneous.rs:27:23 + --> $DIR/tuple_ctor_erroneous.rs:26:23 | LL | accepts_point::<{ Point(N, N, N) }>(); | ^^^^^^^^^^^^^^ error: tuple constructor with invalid base path - --> $DIR/tuple_ctor_erroneous.rs:30:23 + --> $DIR/tuple_ctor_erroneous.rs:29:23 | LL | accepts_point::<{ UnresolvedIdent(N, N) }>(); | ^^^^^^^^^^^^^^^^^^^^^ error: function items cannot be used as const args - --> $DIR/tuple_ctor_erroneous.rs:34:23 + --> $DIR/tuple_ctor_erroneous.rs:33:23 | LL | accepts_point::<{ non_ctor(N, N) }>(); | ^^^^^^^^ error: tuple constructor with invalid base path - --> $DIR/tuple_ctor_erroneous.rs:34:23 + --> $DIR/tuple_ctor_erroneous.rs:33:23 | LL | accepts_point::<{ non_ctor(N, N) }>(); | ^^^^^^^^^^^^^^ error: tuple constructor with invalid base path - --> $DIR/tuple_ctor_erroneous.rs:38:23 + --> $DIR/tuple_ctor_erroneous.rs:37:23 | LL | accepts_point::<{ CONST_ITEM(N, N) }>(); | ^^^^^^^^^^^^^^^^ error: the constant `Point` is not of type `Point` - --> $DIR/tuple_ctor_erroneous.rs:41:23 + --> $DIR/tuple_ctor_erroneous.rs:40:23 | LL | accepts_point::<{ Point }>(); | ^^^^^ expected `Point`, found struct constructor | note: required by a const generic parameter in `accepts_point` - --> $DIR/tuple_ctor_erroneous.rs:18:18 + --> $DIR/tuple_ctor_erroneous.rs:17:18 | LL | fn accepts_point() {} | ^^^^^^^^^^^^^^ required by this const generic parameter in `accepts_point` error: the constant `MyEnum::::Variant` is not of type `MyEnum` - --> $DIR/tuple_ctor_erroneous.rs:44:22 + --> $DIR/tuple_ctor_erroneous.rs:43:22 | LL | accepts_enum::<{ MyEnum::Variant:: }>(); | ^^^^^^^^^^^^^^^^^^^^^^ expected `MyEnum`, found enum constructor | note: required by a const generic parameter in `accepts_enum` - --> $DIR/tuple_ctor_erroneous.rs:19:17 + --> $DIR/tuple_ctor_erroneous.rs:18:17 | LL | fn accepts_enum>() {} | ^^^^^^^^^^^^^^^^^^^^ required by this const generic parameter in `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 0d99b8ae345d6..c932fdd248dae 100644 --- a/tests/ui/const-generics/mgca/tuple_expr_arg_complex.rs +++ b/tests/ui/const-generics/mgca/tuple_expr_arg_complex.rs @@ -2,7 +2,8 @@ #![expect(incomplete_features)] trait Trait { - type const ASSOC: usize; + #[rustc_always_gca] + const ASSOC: usize; } fn takes_tuple() {} diff --git a/tests/ui/const-generics/mgca/tuple_expr_arg_complex.stderr b/tests/ui/const-generics/mgca/tuple_expr_arg_complex.stderr index e4dad6f03e511..1ab93b1995749 100644 --- a/tests/ui/const-generics/mgca/tuple_expr_arg_complex.stderr +++ b/tests/ui/const-generics/mgca/tuple_expr_arg_complex.stderr @@ -1,23 +1,23 @@ error: complex const arguments must be placed inside of a `const` block - --> $DIR/tuple_expr_arg_complex.rs:12:49 + --> $DIR/tuple_expr_arg_complex.rs:13:49 | LL | takes_tuple::<{ core::direct_const_arg!((N, N + 1)) }>(); | ^^^^^ error: complex const arguments must be placed inside of a `const` block - --> $DIR/tuple_expr_arg_complex.rs:13:49 + --> $DIR/tuple_expr_arg_complex.rs:14:49 | LL | takes_tuple::<{ core::direct_const_arg!((N, T::ASSOC + 1)) }>(); | ^^^^^^^^^^^^ error: complex const arguments must be placed inside of a `const` block - --> $DIR/tuple_expr_arg_complex.rs:15:60 + --> $DIR/tuple_expr_arg_complex.rs:16:60 | LL | takes_nested_tuple::<{ core::direct_const_arg!((N, (N, N + 1))) }>(); | ^^^^^ error: generic parameters may not be used in const operations - --> $DIR/tuple_expr_arg_complex.rs:16:68 + --> $DIR/tuple_expr_arg_complex.rs:17:68 | LL | takes_nested_tuple::<{ core::direct_const_arg!((N, (N, const { N + 1 }))) }>(); | ^ diff --git a/tests/ui/const-generics/mgca/tuple_expr_arg_macroless.rs b/tests/ui/const-generics/mgca/tuple_expr_arg_macroless.rs index cf0effe884e63..e684e34792070 100644 --- a/tests/ui/const-generics/mgca/tuple_expr_arg_macroless.rs +++ b/tests/ui/const-generics/mgca/tuple_expr_arg_macroless.rs @@ -9,7 +9,8 @@ #![expect(incomplete_features)] trait Trait { - type const ASSOC: u32; + #[rustc_always_gca] + const ASSOC: u32; } 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 776c1e3208feb..70ca61c63c538 100644 --- a/tests/ui/const-generics/mgca/tuple_expr_arg_simple.rs +++ b/tests/ui/const-generics/mgca/tuple_expr_arg_simple.rs @@ -4,7 +4,8 @@ #![expect(incomplete_features)] trait Trait { - type const ASSOC: u32; + #[rustc_always_gca] + 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 e98b1ad4fe371..7b9923994b0ac 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,14 +4,16 @@ #![expect(incomplete_features)] trait Tr { - type const SIZE: usize; + #[rustc_always_gca] + const SIZE: usize; } struct T; impl Tr for T { - type const SIZE: usize; + const SIZE: usize; //~^ ERROR associated constant in `impl` without body + //~| ERROR implementation of a `#[rustc_always_gca]` must have a `direct_const_arg!` RHS } fn main() {} 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 ba01456ee0404..7425c09bb8a6a 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,22 @@ error: associated constant in `impl` without body - --> $DIR/type-const-assoc-const-without-body.rs:13:5 + --> $DIR/type-const-assoc-const-without-body.rs:14:5 | -LL | type const SIZE: usize; - | ^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: provide a definition for the constant: `= ;` +LL | const SIZE: usize; + | ^^^^^^^^^^^^^^^^^- + | | + | help: provide a definition for the constant: `= ;` -error: aborting due to 1 previous error +error: implementation of a `#[rustc_always_gca]` must have a `direct_const_arg!` RHS + --> $DIR/type-const-assoc-const-without-body.rs:14:5 + | +LL | const SIZE: usize; + | ^^^^^^^^^^^^^^^^^ + | +note: trait declaration of const is marked as `#[rustc_always_gca]` + --> $DIR/type-const-assoc-const-without-body.rs:8:5 + | +LL | const SIZE: usize; + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/type-const-associated-default.rs b/tests/ui/const-generics/mgca/type-const-associated-default.rs index 7492ccbc60af5..a6d7869261b24 100644 --- a/tests/ui/const-generics/mgca/type-const-associated-default.rs +++ b/tests/ui/const-generics/mgca/type-const-associated-default.rs @@ -1,9 +1,9 @@ #![feature(min_generic_const_args)] #![expect(incomplete_features)] trait Trait { - type const N: usize = 10; + #[rustc_always_gca] + const N: usize = core::direct_const_arg!(10); //~^ ERROR associated type defaults are unstable } -fn main(){ -} +fn main() {} diff --git a/tests/ui/const-generics/mgca/type-const-associated-default.stderr b/tests/ui/const-generics/mgca/type-const-associated-default.stderr index a1d635801513e..e2443d4e288e0 100644 --- a/tests/ui/const-generics/mgca/type-const-associated-default.stderr +++ b/tests/ui/const-generics/mgca/type-const-associated-default.stderr @@ -1,8 +1,8 @@ error[E0658]: associated type defaults are unstable - --> $DIR/type-const-associated-default.rs:4:5 + --> $DIR/type-const-associated-default.rs:5:5 | -LL | type const N: usize = 10; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const N: usize = core::direct_const_arg!(10); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #29661 for more information = help: add `#![feature(associated_type_defaults)]` to the crate attributes to enable diff --git a/tests/ui/const-generics/mgca/type-const-ctor-148953.rs b/tests/ui/const-generics/mgca/type-const-ctor-148953.rs index bdd3dcf8618fc..2c5ce1a3f260d 100644 --- a/tests/ui/const-generics/mgca/type-const-ctor-148953.rs +++ b/tests/ui/const-generics/mgca/type-const-ctor-148953.rs @@ -16,7 +16,7 @@ use std::marker::ConstParamTy; struct S; impl S { - type const N: S = S; + const N: S = core::direct_const_arg!(S); } #[derive(ConstParamTy, PartialEq, Eq)] @@ -25,7 +25,7 @@ enum E { } impl E { - type const M: E = { E::V }; + const M: E = core::direct_const_arg!({ E::V }); } fn main() {} diff --git a/tests/ui/const-generics/mgca/type-const-free-anon-const-mismatch.rs b/tests/ui/const-generics/mgca/type-const-free-anon-const-mismatch.rs index 2332c97a70ee8..31f5ce56f3979 100644 --- a/tests/ui/const-generics/mgca/type-const-free-anon-const-mismatch.rs +++ b/tests/ui/const-generics/mgca/type-const-free-anon-const-mismatch.rs @@ -2,10 +2,10 @@ #![feature(min_generic_const_args)] -type const X: usize = const { N }; +const X: usize = core::direct_const_arg!(const { N }); //~^ ERROR type annotations needed -type const N: usize = "this isn't a usize"; +const N: usize = core::direct_const_arg!("this isn't a usize"); //~^ ERROR the constant `"this isn't a usize"` is not of type `usize` fn main() {} diff --git a/tests/ui/const-generics/mgca/type-const-free-anon-const-mismatch.stderr b/tests/ui/const-generics/mgca/type-const-free-anon-const-mismatch.stderr index d0339d09cdc7a..f8655132e9574 100644 --- a/tests/ui/const-generics/mgca/type-const-free-anon-const-mismatch.stderr +++ b/tests/ui/const-generics/mgca/type-const-free-anon-const-mismatch.stderr @@ -1,16 +1,16 @@ error[E0284]: type annotations needed --> $DIR/type-const-free-anon-const-mismatch.rs:5:1 | -LL | type const X: usize = const { N }; - | ^^^^^^^^^^^^^^^^^^^ cannot infer the value of the constant `_` +LL | const X: usize = core::direct_const_arg!(const { N }); + | ^^^^^^^^^^^^^^ cannot infer the value of the constant `_` | = note: cannot satisfy `X::{constant#0} == _` error: the constant `"this isn't a usize"` is not of type `usize` --> $DIR/type-const-free-anon-const-mismatch.rs:8:1 | -LL | type const N: usize = "this isn't a usize"; - | ^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&'static str` +LL | const N: usize = core::direct_const_arg!("this isn't a usize"); + | ^^^^^^^^^^^^^^ expected `usize`, found `&'static str` error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.current.stderr b/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.current.stderr index 28f7064d99325..425de1e1b1d4b 100644 --- a/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.current.stderr +++ b/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.current.stderr @@ -1,8 +1,8 @@ error: the constant `"this isn't a usize"` is not of type `usize` --> $DIR/type-const-free-value-type-mismatch.rs:8:1 | -LL | type const N: usize = "this isn't a usize"; - | ^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&'static str` +LL | const N: usize = core::direct_const_arg!("this isn't a usize"); + | ^^^^^^^^^^^^^^ expected `usize`, found `&'static str` error[E0308]: mismatched types --> $DIR/type-const-free-value-type-mismatch.rs:11:11 diff --git a/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.next.stderr b/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.next.stderr index d96726829ee0b..74fb8ab8999d9 100644 --- a/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.next.stderr +++ b/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.next.stderr @@ -1,8 +1,8 @@ error: the constant `"this isn't a usize"` is not of type `usize` --> $DIR/type-const-free-value-type-mismatch.rs:8:1 | -LL | type const N: usize = "this isn't a usize"; - | ^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&'static str` +LL | const N: usize = core::direct_const_arg!("this isn't a usize"); + | ^^^^^^^^^^^^^^ expected `usize`, found `&'static str` error[E0284]: type annotations needed --> $DIR/type-const-free-value-type-mismatch.rs:11:11 diff --git a/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.rs b/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.rs index 50661eb6f7e10..7cb465d114935 100644 --- a/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.rs +++ b/tests/ui/const-generics/mgca/type-const-free-value-type-mismatch.rs @@ -5,7 +5,7 @@ //@[next] compile-flags: -Znext-solver //@ compile-flags: -Zvalidate-mir -type const N: usize = "this isn't a usize"; +const N: usize = core::direct_const_arg!("this isn't a usize"); //~^ ERROR the constant `"this isn't a usize"` is not of type `usize` fn f() -> [u8; const { N }] {} diff --git a/tests/ui/const-generics/mgca/type-const-free-value-used-in-body.rs b/tests/ui/const-generics/mgca/type-const-free-value-used-in-body.rs index 90740e191807d..c1e0044b0947c 100644 --- a/tests/ui/const-generics/mgca/type-const-free-value-used-in-body.rs +++ b/tests/ui/const-generics/mgca/type-const-free-value-used-in-body.rs @@ -4,10 +4,10 @@ //@ compile-flags: --emit=mir -type const CONST: usize = 1u32; +const CONST: usize = core::direct_const_arg!(1u32); //~^ ERROR the constant `1` is not of type `usize` -type const S: bool = 1i32; +const S: bool = core::direct_const_arg!(1i32); //~^ ERROR the constant `1` is not of type `bool` fn main() { diff --git a/tests/ui/const-generics/mgca/type-const-free-value-used-in-body.stderr b/tests/ui/const-generics/mgca/type-const-free-value-used-in-body.stderr index 759efca661303..1e20f48b7515c 100644 --- a/tests/ui/const-generics/mgca/type-const-free-value-used-in-body.stderr +++ b/tests/ui/const-generics/mgca/type-const-free-value-used-in-body.stderr @@ -1,14 +1,14 @@ error: the constant `1` is not of type `usize` --> $DIR/type-const-free-value-used-in-body.rs:7:1 | -LL | type const CONST: usize = 1u32; - | ^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `u32` +LL | const CONST: usize = core::direct_const_arg!(1u32); + | ^^^^^^^^^^^^^^^^^^ expected `usize`, found `u32` error: the constant `1` is not of type `bool` --> $DIR/type-const-free-value-used-in-body.rs:10:1 | -LL | type const S: bool = 1i32; - | ^^^^^^^^^^^^^^^^^^ expected `bool`, found `i32` +LL | const S: bool = core::direct_const_arg!(1i32); + | ^^^^^^^^^^^^^ expected `bool`, found `i32` error: aborting due to 2 previous errors 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 9fa4176372951..0b83889ec764d 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,7 +4,7 @@ #![expect(incomplete_features)] impl S { //~ ERROR cannot find type `S` in this scope - type const SIZE: usize; + 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 b1e1edfa70d63..65b61a919c523 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:7:5 | -LL | type const SIZE: usize; - | ^^^^^^^^^^^^^^^^^^^^^^- - | | - | help: provide a definition for the constant: `= ;` +LL | 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-inherent-value-type-mismatch.current.stderr b/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.current.stderr index bfcc9a8fef63c..017bc22d7fe0f 100644 --- a/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.current.stderr +++ b/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.current.stderr @@ -1,8 +1,8 @@ error: the constant `"this isn't a usize"` is not of type `usize` --> $DIR/type-const-inherent-value-type-mismatch.rs:13:5 | -LL | type const N: usize = "this isn't a usize"; - | ^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&'static str` +LL | const N: usize = core::direct_const_arg!("this isn't a usize"); + | ^^^^^^^^^^^^^^ expected `usize`, found `&'static str` error[E0308]: mismatched types --> $DIR/type-const-inherent-value-type-mismatch.rs:17:11 diff --git a/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.next.stderr b/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.next.stderr index eeabde2d06320..111a1801d7adb 100644 --- a/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.next.stderr +++ b/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.next.stderr @@ -9,8 +9,8 @@ LL | fn f() -> [u8; const { Struct::N }] {} error: the constant `"this isn't a usize"` is not of type `usize` --> $DIR/type-const-inherent-value-type-mismatch.rs:13:5 | -LL | type const N: usize = "this isn't a usize"; - | ^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&'static str` +LL | const N: usize = core::direct_const_arg!("this isn't a usize"); + | ^^^^^^^^^^^^^^ expected `usize`, found `&'static str` error[E0308]: mismatched types --> $DIR/type-const-inherent-value-type-mismatch.rs:17:11 diff --git a/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.rs b/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.rs index ad6d551968b03..a08f31e686f2f 100644 --- a/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.rs +++ b/tests/ui/const-generics/mgca/type-const-inherent-value-type-mismatch.rs @@ -10,7 +10,7 @@ struct Struct; impl Struct { - type const N: usize = "this isn't a usize"; + const N: usize = core::direct_const_arg!("this isn't a usize"); //~^ ERROR the constant `"this isn't a usize"` is not of type `usize` } diff --git a/tests/ui/const-generics/mgca/type-const-suggestion.rs b/tests/ui/const-generics/mgca/type-const-suggestion.rs index 8b01f17d41d9e..036d16b0e529d 100644 --- a/tests/ui/const-generics/mgca/type-const-suggestion.rs +++ b/tests/ui/const-generics/mgca/type-const-suggestion.rs @@ -3,7 +3,8 @@ #![feature(min_generic_const_args)] trait Trait { - type const K: i32; + #[rustc_always_gca] + const K: i32; } fn take(_: impl Trait<0>) {} //~^ ERROR: trait takes 0 generic arguments but 1 generic argument was supplied [E0107] diff --git a/tests/ui/const-generics/mgca/type-const-suggestion.stderr b/tests/ui/const-generics/mgca/type-const-suggestion.stderr index d59dc60ebca1c..8d729bf1842e0 100644 --- a/tests/ui/const-generics/mgca/type-const-suggestion.stderr +++ b/tests/ui/const-generics/mgca/type-const-suggestion.stderr @@ -1,5 +1,5 @@ error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied - --> $DIR/type-const-suggestion.rs:8:17 + --> $DIR/type-const-suggestion.rs:9:17 | LL | fn take(_: impl Trait<0>) {} | ^^^^^ expected 0 generic arguments 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 1efc65bd70183..71bdc472e2e22 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,7 +3,7 @@ #![feature(min_generic_const_args)] #![expect(incomplete_features)] -type const N: usize = 2; +const N: usize = core::direct_const_arg!(2); trait CollectArray { fn inner_array(&mut self) -> [A; N]; diff --git a/tests/ui/const-generics/mgca/type-const-value-type-mismatch.current.stderr b/tests/ui/const-generics/mgca/type-const-value-type-mismatch.current.stderr index 7c4b0f58fb98b..614946eb7dc0f 100644 --- a/tests/ui/const-generics/mgca/type-const-value-type-mismatch.current.stderr +++ b/tests/ui/const-generics/mgca/type-const-value-type-mismatch.current.stderr @@ -1,11 +1,11 @@ error[E0053]: method `arr` has an incompatible type for trait - --> $DIR/type-const-value-type-mismatch.rs:21:5 + --> $DIR/type-const-value-type-mismatch.rs:22:5 | LL | fn arr() -> [u8; const { Self::LEN }] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an array with a size of 0, found one with a size of const { Self::LEN } | note: type in trait - --> $DIR/type-const-value-type-mismatch.rs:14:5 + --> $DIR/type-const-value-type-mismatch.rs:15:5 | LL | fn arr() -> [u8; Self::LEN]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,13 +13,13 @@ LL | fn arr() -> [u8; Self::LEN]; found signature `fn() -> [u8; const { Self::LEN }]` error: the constant `0` is not of type `usize` - --> $DIR/type-const-value-type-mismatch.rs:18:5 + --> $DIR/type-const-value-type-mismatch.rs:19:5 | -LL | type const LEN: usize = 0u8; - | ^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `u8` +LL | const LEN: usize = core::direct_const_arg!(0u8); + | ^^^^^^^^^^^^^^^^ expected `usize`, found `u8` error[E0308]: mismatched types - --> $DIR/type-const-value-type-mismatch.rs:21:17 + --> $DIR/type-const-value-type-mismatch.rs:22:17 | LL | fn arr() -> [u8; const { Self::LEN }] {} | --- ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `[u8; const { Self::LEN }]`, found `()` diff --git a/tests/ui/const-generics/mgca/type-const-value-type-mismatch.next.stderr b/tests/ui/const-generics/mgca/type-const-value-type-mismatch.next.stderr index 748ffe1294e0a..9180bf19727cf 100644 --- a/tests/ui/const-generics/mgca/type-const-value-type-mismatch.next.stderr +++ b/tests/ui/const-generics/mgca/type-const-value-type-mismatch.next.stderr @@ -1,17 +1,17 @@ error[E0271]: type mismatch resolving `::LEN == _` - --> $DIR/type-const-value-type-mismatch.rs:21:5 + --> $DIR/type-const-value-type-mismatch.rs:22:5 | LL | fn arr() -> [u8; const { Self::LEN }] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ error: the constant `0` is not of type `usize` - --> $DIR/type-const-value-type-mismatch.rs:18:5 + --> $DIR/type-const-value-type-mismatch.rs:19:5 | -LL | type const LEN: usize = 0u8; - | ^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `u8` +LL | const LEN: usize = core::direct_const_arg!(0u8); + | ^^^^^^^^^^^^^^^^ expected `usize`, found `u8` error[E0284]: type annotations needed - --> $DIR/type-const-value-type-mismatch.rs:21:17 + --> $DIR/type-const-value-type-mismatch.rs:22:17 | LL | fn arr() -> [u8; const { Self::LEN }] {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer the value of the constant `_` @@ -19,7 +19,7 @@ LL | fn arr() -> [u8; const { Self::LEN }] {} = note: cannot satisfy `::arr::{constant#0}::{constant#0} == _` error[E0308]: mismatched types - --> $DIR/type-const-value-type-mismatch.rs:21:17 + --> $DIR/type-const-value-type-mismatch.rs:22:17 | LL | fn arr() -> [u8; const { Self::LEN }] {} | --- ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `[u8; _]`, found `()` diff --git a/tests/ui/const-generics/mgca/type-const-value-type-mismatch.rs b/tests/ui/const-generics/mgca/type-const-value-type-mismatch.rs index 73507f6e5d7ec..5609924575693 100644 --- a/tests/ui/const-generics/mgca/type-const-value-type-mismatch.rs +++ b/tests/ui/const-generics/mgca/type-const-value-type-mismatch.rs @@ -10,12 +10,13 @@ pub struct A; pub trait Array { - type const LEN: usize; + #[rustc_always_gca] + const LEN: usize; fn arr() -> [u8; Self::LEN]; } impl Array for A { - type const LEN: usize = 0u8; + const LEN: usize = core::direct_const_arg!(0u8); //~^ ERROR the constant `0` is not of type `usize` fn arr() -> [u8; const { Self::LEN }] {} diff --git a/tests/ui/const-generics/mgca/type_const-adt-expr-missing-field.rs b/tests/ui/const-generics/mgca/type_const-adt-expr-missing-field.rs index 05be2097e124f..4d4fcdb03164b 100644 --- a/tests/ui/const-generics/mgca/type_const-adt-expr-missing-field.rs +++ b/tests/ui/const-generics/mgca/type_const-adt-expr-missing-field.rs @@ -5,9 +5,9 @@ #![feature(macroless_generic_const_args)] #![feature(generic_const_items)] -type const ADD1: usize = const { N + 1 }; +const ADD1: usize = core::direct_const_arg!(const { N + 1 }); //~^ ERROR: unconstrained generic constant -type const AliasFnUnused: ADD1 = ADD1::<{ Some:: {} }>; +const AliasFnUnused: ADD1 = core::direct_const_arg!(ADD1::<{ Some:: {} }>); //~^ ERROR: cannot find type `ADD1` in this scope [E0573] //~| ERROR: struct expression with missing field initialiser for `0` diff --git a/tests/ui/const-generics/mgca/type_const-adt-expr-missing-field.stderr b/tests/ui/const-generics/mgca/type_const-adt-expr-missing-field.stderr index bc4821f20cf24..7a5a299320459 100644 --- a/tests/ui/const-generics/mgca/type_const-adt-expr-missing-field.stderr +++ b/tests/ui/const-generics/mgca/type_const-adt-expr-missing-field.stderr @@ -1,27 +1,27 @@ error[E0573]: cannot find type `ADD1` in this scope - --> $DIR/type_const-adt-expr-missing-field.rs:10:27 + --> $DIR/type_const-adt-expr-missing-field.rs:10:22 | -LL | type const AliasFnUnused: ADD1 = ADD1::<{ Some:: {} }>; - | ^^^^ not found in this scope +LL | const AliasFnUnused: ADD1 = core::direct_const_arg!(ADD1::<{ Some:: {} }>); + | ^^^^ not found in this scope | = note: a constant named `ADD1` exists in another namespace error: unconstrained generic constant --> $DIR/type_const-adt-expr-missing-field.rs:8:1 | -LL | type const ADD1: usize = const { N + 1 }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const ADD1: usize = core::direct_const_arg!(const { N + 1 }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: try adding a `where` bound | -LL | type const ADD1: usize where [(); const { N + 1 }]: = const { N + 1 }; - | ++++++++++++++++++++++++++++ +LL | const ADD1: usize where [(); const { N + 1 }]: = core::direct_const_arg!(const { N + 1 }); + | ++++++++++++++++++++++++++++ error: struct expression with missing field initialiser for `0` - --> $DIR/type_const-adt-expr-missing-field.rs:10:43 + --> $DIR/type_const-adt-expr-missing-field.rs:10:62 | -LL | type const AliasFnUnused: ADD1 = ADD1::<{ Some:: {} }>; - | ^^^^^^^^^^^^^^^^ +LL | const AliasFnUnused: ADD1 = core::direct_const_arg!(ADD1::<{ Some:: {} }>); + | ^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors 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 be01590c99bdd..5b8f50925529d 100644 --- a/tests/ui/const-generics/mgca/type_const-array-return.rs +++ b/tests/ui/const-generics/mgca/type_const-array-return.rs @@ -6,12 +6,13 @@ pub struct A; pub trait Array { - type const LEN: usize; + #[rustc_always_gca] + const LEN: usize; fn arr() -> [u8; Self::LEN]; } impl Array for A { - type const LEN: usize = 4; + const LEN: usize = core::direct_const_arg!(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 095f42355c77a..a236198f4abc9 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:8:58 + --> $DIR/type_const-generic-param-in-type.rs:8:77 | -LL | type const FOO: [T; 0] = const { [] }; - | ^^^^^^^^^^^^ +LL | const FOO: [T; 0] = core::direct_const_arg!(const { [] }); + | ^^^^^^^^^^^^ error: anonymous constants referencing generics are not yet supported - --> $DIR/type_const-generic-param-in-type.rs:12:43 + --> $DIR/type_const-generic-param-in-type.rs:11:62 | -LL | type const BAR: [(); N] = const { [] }; - | ^^^^^^^^^^^^ +LL | const BAR: [(); N] = core::direct_const_arg!(const { [] }); + | ^^^^^^^^^^^^ error: anonymous constants with lifetimes in their type are not yet supported - --> $DIR/type_const-generic-param-in-type.rs:16:35 + --> $DIR/type_const-generic-param-in-type.rs:14:54 | -LL | type const BAZ<'a>: [&'a (); 0] = const { [] }; - | ^^^^^^^^^^^^ +LL | const BAZ<'a>: [&'a (); 0] = core::direct_const_arg!(const { [] }); + | ^^^^^^^^^^^^ error: anonymous constants referencing generics are not yet supported - --> $DIR/type_const-generic-param-in-type.rs:32:64 + --> $DIR/type_const-generic-param-in-type.rs:30:83 | -LL | type const ASSOC: [T; 0] = const { [] }; - | ^^^^^^^^^^^^ +LL | const ASSOC: [T; 0] = core::direct_const_arg!(const { [] }); + | ^^^^^^^^^^^^ error: anonymous constants referencing generics are not yet supported - --> $DIR/type_const-generic-param-in-type.rs:36:55 + --> $DIR/type_const-generic-param-in-type.rs:33:74 | -LL | type const ASSOC_CONST: [(); N] = const { [] }; - | ^^^^^^^^^^^^ +LL | const ASSOC_CONST: [(); N] = core::direct_const_arg!(const { [] }); + | ^^^^^^^^^^^^ error: anonymous constants with lifetimes in their type are not yet supported - --> $DIR/type_const-generic-param-in-type.rs:40:44 + --> $DIR/type_const-generic-param-in-type.rs:36:63 | -LL | type const ASSOC_LT<'a>: [&'a (); 0] = const { [] }; - | ^^^^^^^^^^^^ +LL | const ASSOC_LT<'a>: [&'a (); 0] = core::direct_const_arg!(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 b18bd678973a3..a236198f4abc9 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,57 +1,38 @@ -error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/type_const-generic-param-in-type.rs:8:50 +error: anonymous constants referencing generics are not yet supported + --> $DIR/type_const-generic-param-in-type.rs:8:77 | -LL | type const FOO: [T; 0] = const { [] }; - | ^ the type must not depend on the parameter `T` +LL | const FOO: [T; 0] = core::direct_const_arg!(const { [] }); + | ^^^^^^^^^^^^ -error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/type_const-generic-param-in-type.rs:12:38 +error: anonymous constants referencing generics are not yet supported + --> $DIR/type_const-generic-param-in-type.rs:11:62 | -LL | type const BAR: [(); N] = const { [] }; - | ^ the type must not depend on the parameter `N` +LL | const BAR: [(); N] = core::direct_const_arg!(const { [] }); + | ^^^^^^^^^^^^ -error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/type_const-generic-param-in-type.rs:16:23 +error: anonymous constants with lifetimes in their type are not yet supported + --> $DIR/type_const-generic-param-in-type.rs:14:54 | -LL | type const BAZ<'a>: [&'a (); 0] = const { [] }; - | ^^ the type must not depend on the parameter `'a` +LL | const BAZ<'a>: [&'a (); 0] = core::direct_const_arg!(const { [] }); + | ^^^^^^^^^^^^ -error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/type_const-generic-param-in-type.rs:21:56 +error: anonymous constants referencing generics are not yet supported + --> $DIR/type_const-generic-param-in-type.rs:30:83 | -LL | type const ASSOC: [T; 0]; - | ^ the type must not depend on the parameter `T` +LL | const ASSOC: [T; 0] = core::direct_const_arg!(const { [] }); + | ^^^^^^^^^^^^ -error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/type_const-generic-param-in-type.rs:24:50 +error: anonymous constants referencing generics are not yet supported + --> $DIR/type_const-generic-param-in-type.rs:33:74 | -LL | type const ASSOC_CONST: [(); N]; - | ^ the type must not depend on the parameter `N` +LL | const ASSOC_CONST: [(); N] = core::direct_const_arg!(const { [] }); + | ^^^^^^^^^^^^ -error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/type_const-generic-param-in-type.rs:27:32 +error: anonymous constants with lifetimes in their type are not yet supported + --> $DIR/type_const-generic-param-in-type.rs:36:63 | -LL | type const ASSOC_LT<'a>: [&'a (); 0]; - | ^^ the type must not depend on the parameter `'a` +LL | const ASSOC_LT<'a>: [&'a (); 0] = core::direct_const_arg!(const { [] }); + | ^^^^^^^^^^^^ -error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/type_const-generic-param-in-type.rs:32:56 - | -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:36:50 - | -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:40:32 - | -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 +error: aborting due to 6 previous errors -For more information about this error, try `rustc --explain E0770`. 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 72ae464822e4f..e6cf2fd60eb0a 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,41 +5,36 @@ #![feature(adt_const_params, unsized_const_params, min_generic_const_args, generic_const_items)] #![cfg_attr(gate, feature(generic_const_parameter_types))] -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 +const FOO: [T; 0] = core::direct_const_arg!(const { [] }); +//~^ ERROR anonymous constants referencing generics are not yet supported -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 +const BAR: [(); N] = core::direct_const_arg!(const { [] }); +//~^ ERROR anonymous constants referencing generics are not yet supported -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 +const BAZ<'a>: [&'a (); 0] = core::direct_const_arg!(const { [] }); +//~^ ERROR anonymous constants with lifetimes in their type are not yet supported trait Tr { - type const ASSOC: [T; 0]; - //[nogate]~^ ERROR the type of const parameters must not depend on other generic parameters + // FIXME(min_generic_const_args): These should error under [nogate] + #[rustc_always_gca] + const ASSOC: [T; 0]; - type const ASSOC_CONST: [(); N]; - //[nogate]~^ ERROR the type of const parameters must not depend on other generic parameters + #[rustc_always_gca] + const ASSOC_CONST: [(); N]; - type const ASSOC_LT<'a>: [&'a (); 0]; - //[nogate]~^ ERROR the type of const parameters must not depend on other generic parameters + #[rustc_always_gca] + const ASSOC_LT<'a>: [&'a (); 0]; } impl Tr for () { - 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 + const ASSOC: [T; 0] = core::direct_const_arg!(const { [] }); + //~^ ERROR anonymous constants referencing generics are not yet supported - 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 + const ASSOC_CONST: [(); N] = core::direct_const_arg!(const { [] }); + //~^ ERROR anonymous constants referencing generics are not yet supported - 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 + const ASSOC_LT<'a>: [&'a (); 0] = core::direct_const_arg!(const { [] }); + //~^ ERROR anonymous constants with lifetimes in their type are not yet supported } fn main() {} 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 7094d89d50622..59581327cbb2d 100644 --- a/tests/ui/const-generics/mgca/type_const-incemental-compile.rs +++ b/tests/ui/const-generics/mgca/type_const-incemental-compile.rs @@ -6,5 +6,5 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] -type const TYPE_CONST: usize = 0; +const TYPE_CONST: usize = core::direct_const_arg!(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 c57121a4a26a0..81c567f034e1e 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,7 +4,7 @@ struct A; impl A { - type const B = 4; + const B = core::direct_const_arg!(4); //~^ ERROR: missing type for `const` item //~| ERROR: type annotations needed for the literal } 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 7fbb7461a4911..742e5aff86285 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,19 +1,19 @@ error: missing type for `const` item - --> $DIR/type_const-inherent-const-omitted-type.rs:7:17 + --> $DIR/type_const-inherent-const-omitted-type.rs:7:12 | -LL | type const B = 4; - | ^ +LL | const B = core::direct_const_arg!(4); + | ^ | help: provide a type for the item | -LL | type const B: = 4; - | ++++++++ +LL | const B: = core::direct_const_arg!(4); + | ++++++++ error: type annotations needed for the literal - --> $DIR/type_const-inherent-const-omitted-type.rs:7:20 + --> $DIR/type_const-inherent-const-omitted-type.rs:7:39 | -LL | type const B = 4; - | ^ +LL | const B = core::direct_const_arg!(4); + | ^ error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.rs b/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.rs index 74c945b0881a4..af59430e5b6ef 100644 --- a/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.rs +++ b/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.rs @@ -2,10 +2,10 @@ //! //@ incremental #![feature(min_generic_const_args)] -type const R: usize = 1_i32; //~ ERROR: the constant `1` is not of type `usize` -type const U: usize = -1_i32; //~ ERROR: the constant `-1` is not of type `usize` -type const S: bool = 1i32; //~ ERROR: the constant `1` is not of type `bool` -type const T: bool = -1i32; //~ ERROR: the constant `-1` is not of type `bool` +const R: usize = core::direct_const_arg!(1_i32); //~ ERROR: the constant `1` is not of type `usize` +const U: usize = core::direct_const_arg!(-1_i32); //~ ERROR: the constant `-1` is not of type `usize` +const S: bool = core::direct_const_arg!(1i32); //~ ERROR: the constant `1` is not of type `bool` +const T: bool = core::direct_const_arg!(-1i32); //~ ERROR: the constant `-1` is not of type `bool` fn main() { R; diff --git a/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.stderr b/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.stderr index b09ac22240325..86c807d9df356 100644 --- a/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.stderr +++ b/tests/ui/const-generics/mgca/type_const-mismatched-type-incremental.stderr @@ -1,26 +1,26 @@ error: the constant `1` is not of type `usize` --> $DIR/type_const-mismatched-type-incremental.rs:5:1 | -LL | type const R: usize = 1_i32; - | ^^^^^^^^^^^^^^^^^^^ expected `usize`, found `i32` +LL | const R: usize = core::direct_const_arg!(1_i32); + | ^^^^^^^^^^^^^^ expected `usize`, found `i32` error: the constant `-1` is not of type `usize` --> $DIR/type_const-mismatched-type-incremental.rs:6:1 | -LL | type const U: usize = -1_i32; - | ^^^^^^^^^^^^^^^^^^^ expected `usize`, found `i32` +LL | const U: usize = core::direct_const_arg!(-1_i32); + | ^^^^^^^^^^^^^^ expected `usize`, found `i32` error: the constant `1` is not of type `bool` --> $DIR/type_const-mismatched-type-incremental.rs:7:1 | -LL | type const S: bool = 1i32; - | ^^^^^^^^^^^^^^^^^^ expected `bool`, found `i32` +LL | const S: bool = core::direct_const_arg!(1i32); + | ^^^^^^^^^^^^^ expected `bool`, found `i32` error: the constant `-1` is not of type `bool` --> $DIR/type_const-mismatched-type-incremental.rs:8:1 | -LL | type const T: bool = -1i32; - | ^^^^^^^^^^^^^^^^^^ expected `bool`, found `i32` +LL | const T: bool = core::direct_const_arg!(-1i32); + | ^^^^^^^^^^^^^ expected `bool`, found `i32` error: aborting due to 4 previous errors 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 74f6aa5a2ddf2..9dbba436520c6 100644 --- a/tests/ui/const-generics/mgca/type_const-mismatched-types.rs +++ b/tests/ui/const-generics/mgca/type_const-mismatched-types.rs @@ -1,19 +1,20 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] -type const FREE: u32 = 5_usize; +const FREE: u32 = core::direct_const_arg!(5_usize); //~^ ERROR the constant `5` is not of type `u32` -type const FREE2: isize = FREE; +const FREE2: isize = core::direct_const_arg!(FREE); //~^ ERROR the constant `5` is not of type `u32` //~| ERROR the constant `5` is not of type `isize` trait Tr { - type const N: usize; + #[rustc_always_gca] + const N: usize; } impl Tr for () { - type const N: usize = false; + const N: usize = core::direct_const_arg!(false); //~^ ERROR the constant `false` is not of type `usize` } 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 df728d8065923..e4b3e39180361 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 `u32` --> $DIR/type_const-mismatched-types.rs:4:1 | -LL | type const FREE: u32 = 5_usize; - | ^^^^^^^^^^^^^^^^^^^^ expected `u32`, found `usize` +LL | const FREE: u32 = core::direct_const_arg!(5_usize); + | ^^^^^^^^^^^^^^^ expected `u32`, found `usize` error: the constant `5` is not of type `u32` --> $DIR/type_const-mismatched-types.rs:7:1 | -LL | type const FREE2: isize = FREE; - | ^^^^^^^^^^^^^^^^^^^^^^^ expected `u32`, found `usize` +LL | const FREE2: isize = core::direct_const_arg!(FREE); + | ^^^^^^^^^^^^^^^^^^ expected `u32`, found `usize` error: the constant `5` is not of type `isize` --> $DIR/type_const-mismatched-types.rs:7:1 | -LL | type const FREE2: isize = FREE; - | ^^^^^^^^^^^^^^^^^^^^^^^ expected `isize`, found `usize` +LL | const FREE2: isize = core::direct_const_arg!(FREE); + | ^^^^^^^^^^^^^^^^^^ expected `isize`, found `usize` error: the constant `false` is not of type `usize` - --> $DIR/type_const-mismatched-types.rs:16:5 + --> $DIR/type_const-mismatched-types.rs:17:5 | -LL | type const N: usize = false; - | ^^^^^^^^^^^^^^^^^^^ expected `usize`, found `bool` +LL | const N: usize = core::direct_const_arg!(false); + | ^^^^^^^^^^^^^^ expected `usize`, found `bool` error: aborting due to 4 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 b78bb4ca599d5..27debb924ffd6 100644 --- a/tests/ui/const-generics/mgca/type_const-not-constparamty.rs +++ b/tests/ui/const-generics/mgca/type_const-not-constparamty.rs @@ -5,18 +5,19 @@ struct S; // FIXME(mgca): need support for ctors without anon const // (we use a const-block to trigger an anon const here) -type const FREE: S = const { S }; +const FREE: S = core::direct_const_arg!(const { S }); //~^ ERROR `S` must implement `ConstParamTy` to be used as the type of a const generic parameter trait Tr { - type const N: S; + #[rustc_always_gca] + 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 N: S = const { S }; + const N: S = core::direct_const_arg!(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 2cbb644f2c711..7492432119943 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:8:18 + --> $DIR/type_const-not-constparamty.rs:8:13 | -LL | type const FREE: S = const { S }; - | ^ +LL | const FREE: S = core::direct_const_arg!(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:19:19 + --> $DIR/type_const-not-constparamty.rs:20:14 | -LL | type const N: S = const { S }; - | ^ +LL | const N: S = core::direct_const_arg!(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:12:19 + --> $DIR/type_const-not-constparamty.rs:13:14 | -LL | type const N: S; - | ^ +LL | 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 f4cf3a4c5ce9f..574a5febadaac 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,10 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args, generic_const_items)] - -type const FREE1: usize = const { std::mem::size_of::() }; +const FREE1: usize = core::direct_const_arg!(const { std::mem::size_of::() }); //~^ ERROR generic parameters may not be used in const operations -type const FREE2: usize = const { I + 1 }; +const FREE2: usize = core::direct_const_arg!(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 b6737d31ef012..1e11af4de9571 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:58 + --> $DIR/type_const-on-generic-expr.rs:4:77 | -LL | type const FREE1: usize = const { std::mem::size_of::() }; - | ^ +LL | const FREE1: usize = core::direct_const_arg!(const { std::mem::size_of::() }); + | ^ | = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item error: generic parameters may not be used in const operations - --> $DIR/type_const-on-generic-expr.rs:8:51 + --> $DIR/type_const-on-generic-expr.rs:7:70 | -LL | type const FREE2: usize = const { I + 1 }; - | ^ +LL | const FREE2: usize = core::direct_const_arg!(const { I + 1 }); + | ^ | = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item 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 2a26138d373f6..b82eb2f046485 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,19 +2,22 @@ #![feature(min_generic_const_args, generic_const_items)] pub trait Tr { - type const N1: usize; - type const N2: usize; - type const N3: usize; + #[rustc_always_gca] + const N1: usize; + #[rustc_always_gca] + const N2: usize; + #[rustc_always_gca] + const N3: usize; } pub struct S; impl Tr for S { - type const N1: usize = const { std::mem::size_of::() }; + const N1: usize = core::direct_const_arg!(const { std::mem::size_of::() }); //~^ ERROR generic parameters may not be used in const operations - type const N2: usize = const { I + 1 }; + const N2: usize = core::direct_const_arg!(const { I + 1 }); //~^ ERROR generic parameters may not be used in const operations - type const N3: usize = const { 2 & X }; + const N3: usize = core::direct_const_arg!(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 56d94d5d928b9..cac6858b937c0 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:13:59 + --> $DIR/type_const-on-generic_expr-2.rs:16:78 | -LL | type const N1: usize = const { std::mem::size_of::() }; - | ^ +LL | const N1: usize = core::direct_const_arg!(const { std::mem::size_of::() }); + | ^ | = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item error: generic parameters may not be used in const operations - --> $DIR/type_const-on-generic_expr-2.rs:15:52 + --> $DIR/type_const-on-generic_expr-2.rs:18:71 | -LL | type const N2: usize = const { I + 1 }; - | ^ +LL | const N2: usize = core::direct_const_arg!(const { I + 1 }); + | ^ | = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item error: generic parameters may not be used in const operations - --> $DIR/type_const-on-generic_expr-2.rs:17:40 + --> $DIR/type_const-on-generic_expr-2.rs:20:59 | -LL | type const N3: usize = const { 2 & X }; - | ^ +LL | const N3: usize = core::direct_const_arg!(const { 2 & X }); + | ^ | = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item 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 c8c7788eb135a..853eb37aae3f0 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,14 @@ trait BadTr { struct GoodS; impl BadTr for GoodS { - type const NUM: = 84; + const NUM: = core::direct_const_arg!(84); //~^ ERROR: missing type for `const` item //~| ERROR: type annotations needed for the literal - + //~| ERROR: implementation of a regular const cannot have a `direct_const_arg!` RHS } fn accept_bad_tr>(_x: &T) {} -//~^ ERROR use of trait associated const not defined as `type const` +//~^ ERROR use of trait associated const not defined as `#[rustc_always_gca]` 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 99dc6398170db..445d5d4a2efd9 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,22 +1,32 @@ error: missing type for `const` item - --> $DIR/type_const-only-in-impl-omitted-type.rs:11:20 + --> $DIR/type_const-only-in-impl-omitted-type.rs:11:15 | -LL | type const NUM: = 84; - | ^ help: provide a type for the associated constant: `usize` +LL | const NUM: = core::direct_const_arg!(84); + | ^ help: provide a type for the associated constant: `usize` -error: use of trait associated const not defined as `type const` - --> $DIR/type_const-only-in-impl-omitted-type.rs:17:43 +error: type annotations needed for the literal + --> $DIR/type_const-only-in-impl-omitted-type.rs:11:42 | -LL | fn accept_bad_tr>(_x: &T) {} - | ^^^^^^^^^^^ +LL | const NUM: = core::direct_const_arg!(84); + | ^^ + +error: implementation of a regular const cannot have a `direct_const_arg!` RHS + --> $DIR/type_const-only-in-impl-omitted-type.rs:11:5 + | +LL | const NUM: = core::direct_const_arg!(84); + | ^^^^^^^^^^ | - = note: the declaration in the trait must begin with `type const` not just `const` alone +note: trait declaration of const is not marked as `#[rustc_always_gca]` + --> $DIR/type_const-only-in-impl-omitted-type.rs:5:5 + | +LL | const NUM: usize; + | ^^^^^^^^^^^^^^^^ -error: type annotations needed for the literal - --> $DIR/type_const-only-in-impl-omitted-type.rs:11:23 +error: use of trait associated const not defined as `#[rustc_always_gca]` + --> $DIR/type_const-only-in-impl-omitted-type.rs:17:43 | -LL | type const NUM: = 84; - | ^^ +LL | fn accept_bad_tr>(_x: &T) {} + | ^^^^^^^^^^^ -error: aborting due to 3 previous errors +error: aborting due to 4 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 e016908b3cc38..3f8b924af0799 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,11 +8,12 @@ trait BadTr { struct GoodS; impl BadTr for GoodS { - type const NUM: usize = 84; + const NUM: usize = core::direct_const_arg!(84); + //~^ ERROR implementation of a regular const cannot have a `direct_const_arg!` RHS } fn accept_bad_tr>(_x: &T) {} -//~^ ERROR use of trait associated const not defined as `type const` +//~^ ERROR use of trait associated const not defined as `#[rustc_always_gca]` 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 55d5cca6ba699..cc32eafad40fc 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,20 @@ -error: use of trait associated const not defined as `type const` - --> $DIR/type_const-only-in-impl.rs:14:43 +error: implementation of a regular const cannot have a `direct_const_arg!` RHS + --> $DIR/type_const-only-in-impl.rs:11:5 + | +LL | const NUM: usize = core::direct_const_arg!(84); + | ^^^^^^^^^^^^^^^^ + | +note: trait declaration of const is not marked as `#[rustc_always_gca]` + --> $DIR/type_const-only-in-impl.rs:5:5 + | +LL | const NUM: usize; + | ^^^^^^^^^^^^^^^^ + +error: use of trait associated const not defined as `#[rustc_always_gca]` + --> $DIR/type_const-only-in-impl.rs:15:43 | LL | fn accept_bad_tr>(_x: &T) {} | ^^^^^^^^^^^ - | - = note: the declaration in the trait must begin with `type const` not just `const` alone -error: aborting due to 1 previous error +error: aborting due to 2 previous errors 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 1def66a1ba681..82c5a6f8417a5 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,14 +2,15 @@ #![feature(min_generic_const_args)] trait GoodTr { - type const NUM: usize; + #[rustc_always_gca] + const NUM: usize; } struct BadS; impl GoodTr for BadS { const NUM: usize = 42; - //~^ ERROR implementation of a `type const` must also be marked as `type const` + //~^ ERROR implementation of a `#[rustc_always_gca]` must have a `direct_const_arg!` RHS } 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 f98b4d9cbbfdb..e2ba59133925f 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,14 +1,14 @@ -error: implementation of a `type const` must also be marked as `type const` - --> $DIR/type_const-only-in-trait.rs:11:5 +error: implementation of a `#[rustc_always_gca]` must have a `direct_const_arg!` RHS + --> $DIR/type_const-only-in-trait.rs:12:5 | LL | const NUM: usize = 42; | ^^^^^^^^^^^^^^^^ | -note: trait declaration of const is marked as `type const` - --> $DIR/type_const-only-in-trait.rs:5:5 +note: trait declaration of const is marked as `#[rustc_always_gca]` + --> $DIR/type_const-only-in-trait.rs:6:5 | -LL | type const NUM: usize; - | ^^^^^^^^^^^^^^^^^^^^^ +LL | 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 70fab75901b96..36936e22726d4 100644 --- a/tests/ui/const-generics/mgca/type_const-pub.rs +++ b/tests/ui/const-generics/mgca/type_const-pub.rs @@ -5,7 +5,7 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] -pub type const TYPE_CONST : usize = 1; +pub const TYPE_CONST: usize = core::direct_const_arg!(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 0791325d603be..1963cdce9fe4c 100644 --- a/tests/ui/const-generics/mgca/type_const-recursive.rs +++ b/tests/ui/const-generics/mgca/type_const-recursive.rs @@ -1,8 +1,7 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] - -type const A: u8 = A; -//~^ ERROR: overflow normalizing the const alias `A` [E0275] +const A: u8 = core::direct_const_arg!(A); +//~^ ERROR: cycle detected when computing the type-level value for `A` [E0391] 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 f9e0965dc5412..2dd4102b472bc 100644 --- a/tests/ui/const-generics/mgca/type_const-recursive.stderr +++ b/tests/ui/const-generics/mgca/type_const-recursive.stderr @@ -1,11 +1,13 @@ -error[E0275]: overflow normalizing the const alias `A` - --> $DIR/type_const-recursive.rs:5:1 +error[E0391]: cycle detected when computing the type-level value for `A` + --> $DIR/type_const-recursive.rs:4:1 | -LL | type const A: u8 = A; - | ^^^^^^^^^^^^^^^^ +LL | const A: u8 = core::direct_const_arg!(A); + | ^^^^^^^^^^^ | - = note: in case this is a recursive type alias, consider using a struct, enum, or union instead + = note: ...which immediately requires computing the type-level value for `A` again + = note: cycle used when checking that `A` is well-formed + = note: for more information, see and error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0275`. +For more information about this error, try `rustc --explain E0391`. diff --git a/tests/ui/const-generics/mgca/type_const-use.rs b/tests/ui/const-generics/mgca/type_const-use.rs index f295bf465e30c..cef0d10f0c4ed 100644 --- a/tests/ui/const-generics/mgca/type_const-use.rs +++ b/tests/ui/const-generics/mgca/type_const-use.rs @@ -3,7 +3,7 @@ #![expect(incomplete_features)] #![feature(min_generic_const_args)] -type const CONST: usize = 1; +const CONST: usize = core::direct_const_arg!(1); fn uses_const() { CONST; diff --git a/tests/ui/const-generics/mgca/type_const_in_pattern.rs b/tests/ui/const-generics/mgca/type_const_in_pattern.rs index 18062cd4cb1c7..01fae246f9293 100644 --- a/tests/ui/const-generics/mgca/type_const_in_pattern.rs +++ b/tests/ui/const-generics/mgca/type_const_in_pattern.rs @@ -3,22 +3,23 @@ #![expect(incomplete_features)] #![allow(irrefutable_let_patterns)] -type const CONST: usize = 1_usize; +const CONST: usize = core::direct_const_arg!(1_usize); struct Inherent; impl Inherent { - type const BAR: usize = 1_usize; + const BAR: usize = core::direct_const_arg!(1_usize); } trait Trait { - type const BAZ: usize; + #[rustc_always_gca] + const BAZ: usize; } struct Assoc; impl Trait for Assoc { - type const BAZ: usize = 1_usize; + const BAZ: usize = core::direct_const_arg!(1_usize); } fn main() { diff --git a/tests/ui/const-generics/mgca/type_const_in_pattern_too_generic.rs b/tests/ui/const-generics/mgca/type_const_in_pattern_too_generic.rs index 31284298044d0..891e627780d4e 100644 --- a/tests/ui/const-generics/mgca/type_const_in_pattern_too_generic.rs +++ b/tests/ui/const-generics/mgca/type_const_in_pattern_too_generic.rs @@ -2,7 +2,8 @@ #![expect(incomplete_features)] trait Trait { - type const ASSOC: usize; + #[rustc_always_gca] + const ASSOC: usize; } fn test() { diff --git a/tests/ui/const-generics/mgca/type_const_in_pattern_too_generic.stderr b/tests/ui/const-generics/mgca/type_const_in_pattern_too_generic.stderr index 419e03cfadc30..73187fdefe38d 100644 --- a/tests/ui/const-generics/mgca/type_const_in_pattern_too_generic.stderr +++ b/tests/ui/const-generics/mgca/type_const_in_pattern_too_generic.stderr @@ -1,10 +1,11 @@ error: could not evaluate constant pattern - --> $DIR/type_const_in_pattern_too_generic.rs:9:12 + --> $DIR/type_const_in_pattern_too_generic.rs:10:12 | LL | trait Trait { | ----------- -LL | type const ASSOC: usize; - | ----------------------- constant defined here +LL | #[rustc_always_gca] +LL | const ASSOC: usize; + | ------------------ constant defined here ... LL | if let ::ASSOC = 1 {} | ^^^^^^^^^^^^^^^^^^^ could not evaluate constant 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 cf75b45b9ff03..e341727407143 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 @@ -12,7 +12,7 @@ struct Foo< type Array = [(); const { 1 }]; type NormalTy = Inner; - //~^ ERROR: unbraced const blocks as const args are experimental +//~^ ERROR: unbraced const blocks as const args are experimental fn repeat() { [1_u8; const { 1 }]; @@ -32,10 +32,9 @@ fn generic() { const NON_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] +const TYPE_CONST: usize = core::direct_const_arg!(const { 1 }); +//~^ ERROR: use of unstable library feature `min_generic_const_args` [E0658] +//~| ERROR: expected expression, found `direct_const_arg!()` constant 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 dbcb8c56ac5b8..bd2b5238a9356 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 @@ -1,3 +1,13 @@ +error[E0658]: use of unstable library feature `min_generic_const_args` + --> $DIR/unbraced_const_block_const_arg_gated.rs:35:27 + | +LL | const TYPE_CONST: usize = core::direct_const_arg!(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[E0658]: unbraced const blocks as const args are experimental --> $DIR/unbraced_const_block_const_arg_gated.rs:7:27 | @@ -48,25 +58,11 @@ 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]: `type const` syntax is experimental - --> $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[E0658]: top-level `type const` are unstable - --> $DIR/unbraced_const_block_const_arg_gated.rs:36:1 +error: expected expression, found `direct_const_arg!()` constant + --> $DIR/unbraced_const_block_const_arg_gated.rs:35:27 | -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 +LL | const TYPE_CONST: usize = core::direct_const_arg!(const { 1 }); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 7 previous errors diff --git a/tests/ui/const-generics/mgca/unmarked-free-const.rs b/tests/ui/const-generics/mgca/unmarked-free-const.rs index c06b3b399c669..e118b486f2c77 100644 --- a/tests/ui/const-generics/mgca/unmarked-free-const.rs +++ b/tests/ui/const-generics/mgca/unmarked-free-const.rs @@ -1,11 +1,11 @@ // regression test, used to ICE -#![feature(min_generic_const_args, macroless_generic_const_args)] +#![feature(min_generic_const_args)] #![allow(incomplete_features)] const N: usize = 4; fn main() { - let x = [(); N]; - //~^ ERROR use of `const` in the type system not defined as `type const` + let x = [(); core::direct_const_arg!(N)]; + //~^ ERROR use of `const` in the type system not marked as direct } diff --git a/tests/ui/const-generics/mgca/unmarked-free-const.stderr b/tests/ui/const-generics/mgca/unmarked-free-const.stderr index dd33de4ce0223..246a8200247c1 100644 --- a/tests/ui/const-generics/mgca/unmarked-free-const.stderr +++ b/tests/ui/const-generics/mgca/unmarked-free-const.stderr @@ -1,13 +1,13 @@ -error: use of `const` in the type system not defined as `type const` - --> $DIR/unmarked-free-const.rs:9:18 +error: use of `const` in the type system not marked as direct + --> $DIR/unmarked-free-const.rs:9:42 | -LL | let x = [(); N]; - | ^ +LL | let x = [(); core::direct_const_arg!(N)]; + | ^ | -help: add `type` before `const` for `N` +help: add direct_const_arg!() to the right-hand side of the constant | -LL | type const N: usize = 4; - | ++++ +LL | const N: usize = core::direct_const_arg!(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 81ec01eeffbab..02268c4e37d7e 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,15 +4,15 @@ #![allow(incomplete_features)] trait Trait { - - type const ASSOC: u8; + #[rustc_always_gca] + const ASSOC: u8; } struct TakesArr; fn foo() where - u8: Trait + u8: Trait, { let _: TakesArr<{ [::ASSOC] }> = TakesArr::<{ [1] }>; //~^ ERROR: mismatched types [E0308] diff --git a/tests/ui/const-generics/type-const-ice-issue-151631.rs b/tests/ui/const-generics/type-const-ice-issue-151631.rs index c20adda1c6366..8112d21a923f0 100644 --- a/tests/ui/const-generics/type-const-ice-issue-151631.rs +++ b/tests/ui/const-generics/type-const-ice-issue-151631.rs @@ -5,10 +5,12 @@ trait SuperTrait {} trait Trait: SuperTrait { - type const K: u32; + #[rustc_always_gca] + const K: u32; } -impl Trait for () { //~ ERROR: the trait bound `(): SuperTrait` is not satisfied - type const K: u32 = const { 1 }; +impl Trait for () { + //~^ ERROR: the trait bound `(): SuperTrait` is not satisfied + const K: u32 = core::direct_const_arg!(const { 1 }); } fn check(_: impl Trait) {} diff --git a/tests/ui/const-generics/type-const-ice-issue-151631.stderr b/tests/ui/const-generics/type-const-ice-issue-151631.stderr index 1c4f7448c8580..aa934b91fb5a4 100644 --- a/tests/ui/const-generics/type-const-ice-issue-151631.stderr +++ b/tests/ui/const-generics/type-const-ice-issue-151631.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `(): SuperTrait` is not satisfied - --> $DIR/type-const-ice-issue-151631.rs:10:16 + --> $DIR/type-const-ice-issue-151631.rs:11:16 | LL | impl Trait for () { | ^^ the trait `SuperTrait` is not implemented for `()` @@ -16,7 +16,7 @@ LL | trait Trait: SuperTrait { | ^^^^^^^^^^ required by this bound in `Trait` error[E0271]: type mismatch resolving `<() as Trait>::K == 0` - --> $DIR/type-const-ice-issue-151631.rs:17:11 + --> $DIR/type-const-ice-issue-151631.rs:19:11 | LL | check(()); | ----- ^^ expected `0`, found `1` @@ -26,7 +26,7 @@ LL | check(()); = note: expected constant `0` found constant `1` note: required by a bound in `check` - --> $DIR/type-const-ice-issue-151631.rs:14:24 + --> $DIR/type-const-ice-issue-151631.rs:16:24 | LL | fn check(_: impl Trait) {} | ^^^^^ required by this bound in `check` diff --git a/tests/ui/const-generics/type-relative-path-144547.min.stderr b/tests/ui/const-generics/type-relative-path-144547.min.stderr index 76f48afe60f42..dae6e7098ad05 100644 --- a/tests/ui/const-generics/type-relative-path-144547.min.stderr +++ b/tests/ui/const-generics/type-relative-path-144547.min.stderr @@ -1,5 +1,5 @@ error: generic parameters may not be used in const operations - --> $DIR/type-relative-path-144547.rs:39:35 + --> $DIR/type-relative-path-144547.rs:40:35 | LL | type SupportedArray = [T; ::SUPPORTED_SLOTS]; | ^^^^^^^^^^^^^^ diff --git a/tests/ui/const-generics/type-relative-path-144547.rs b/tests/ui/const-generics/type-relative-path-144547.rs index fe79fa2897856..37e86413ed4de 100644 --- a/tests/ui/const-generics/type-relative-path-144547.rs +++ b/tests/ui/const-generics/type-relative-path-144547.rs @@ -16,7 +16,8 @@ trait UnderlyingImpl { trait LevelInfo { #[cfg(mgca)] - type const SUPPORTED_SLOTS: usize; + #[rustc_always_gca] + const SUPPORTED_SLOTS: usize; #[cfg(not(mgca))] const SUPPORTED_SLOTS: usize; @@ -26,7 +27,7 @@ struct Info; impl LevelInfo for Info { #[cfg(mgca)] - type const SUPPORTED_SLOTS: usize = 1; + const SUPPORTED_SLOTS: usize = core::direct_const_arg!(1); #[cfg(not(mgca))] const SUPPORTED_SLOTS: usize = 1; diff --git a/tests/ui/feature-gates/feature-gate-generic-const-args.rs b/tests/ui/feature-gates/feature-gate-generic-const-args.rs index b62e7fb08099a..c9403a269a8bc 100644 --- a/tests/ui/feature-gates/feature-gate-generic-const-args.rs +++ b/tests/ui/feature-gates/feature-gate-generic-const-args.rs @@ -1,7 +1,7 @@ #![feature(generic_const_items, min_generic_const_args)] #![expect(incomplete_features)] -type const INC: usize = const { N + 1 }; +const INC: usize = core::direct_const_arg!(const { N + 1 }); //~^ ERROR generic parameters may not be used in const operations //~| HELP add `#![feature(generic_const_args)]` diff --git a/tests/ui/feature-gates/feature-gate-generic-const-args.stderr b/tests/ui/feature-gates/feature-gate-generic-const-args.stderr index 1e4628a8c4f0a..6094430968f51 100644 --- a/tests/ui/feature-gates/feature-gate-generic-const-args.stderr +++ b/tests/ui/feature-gates/feature-gate-generic-const-args.stderr @@ -1,8 +1,8 @@ error: generic parameters may not be used in const operations - --> $DIR/feature-gate-generic-const-args.rs:4:49 + --> $DIR/feature-gate-generic-const-args.rs:4:68 | -LL | type const INC: usize = const { N + 1 }; - | ^ +LL | const INC: usize = core::direct_const_arg!(const { N + 1 }); + | ^ | = help: add `#![feature(generic_const_args)]` and extract the expression into a `type const` item diff --git a/tests/ui/feature-gates/feature-gate-macroless-generic-const-args.rs b/tests/ui/feature-gates/feature-gate-macroless-generic-const-args.rs index 49916736d46e9..9c720d53a5d7a 100644 --- a/tests/ui/feature-gates/feature-gate-macroless-generic-const-args.rs +++ b/tests/ui/feature-gates/feature-gate-macroless-generic-const-args.rs @@ -1,7 +1,7 @@ trait Trait { - type const ASSOC: usize; - //~^ ERROR: associated `type const` are unstable [E0658] - //~| ERROR: `type const` syntax is experimental [E0658] + #[rustc_always_gca] + //~^ ERROR: the `rustc_always_gca` attribute is an experimental feature [E0658] + const ASSOC: usize; } // FIXME(mgca): add suggestion for mgca to this error diff --git a/tests/ui/feature-gates/feature-gate-macroless-generic-const-args.stderr b/tests/ui/feature-gates/feature-gate-macroless-generic-const-args.stderr index e50042fb431d9..956c983894518 100644 --- a/tests/ui/feature-gates/feature-gate-macroless-generic-const-args.stderr +++ b/tests/ui/feature-gates/feature-gate-macroless-generic-const-args.stderr @@ -8,26 +8,16 @@ LL | fn foo() -> [u8; ::ASSOC] { = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item -error[E0658]: `type const` syntax is experimental - --> $DIR/feature-gate-macroless-generic-const-args.rs:2:5 +error[E0658]: the `rustc_always_gca` attribute is an experimental feature + --> $DIR/feature-gate-macroless-generic-const-args.rs:2:7 | -LL | type const ASSOC: usize; - | ^^^^^^^^^^ +LL | #[rustc_always_gca] + | ^^^^^^^^^^^^^^^^ | = 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-macroless-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 +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0658`. 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 index eea1c798fd207..9737d9c521ac7 100644 --- a/tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.rs +++ b/tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.rs @@ -1,17 +1,18 @@ -type const FOO: u8 = 10; -//~^ ERROR `type const` syntax is experimental [E0658] -//~| ERROR top-level `type const` are unstable [E0658] +const FOO: u8 = core::direct_const_arg!(10); +//~^ ERROR use of unstable library feature `min_generic_const_args` [E0658] +//~| ERROR expected expression, found `direct_const_arg!()` constant trait Bar { - type const BAR: bool; - //~^ ERROR `type const` syntax is experimental [E0658] - //~| ERROR associated `type const` are unstable [E0658] + #[rustc_always_gca] + //~^ ERROR the `rustc_always_gca` attribute is an experimental feature [E0658] + const BAR: bool; } impl Bar for bool { - type const BAR: bool = false; - //~^ ERROR `type const` syntax is experimental [E0658] - //~| ERROR associated `type const` are unstable [E0658] + const BAR: bool = core::direct_const_arg!(false); + //~^ ERROR use of unstable library feature `min_generic_const_args` [E0658] + //~| ERROR expected expression, found `direct_const_arg!()` constant + //~| ERROR implementation of a `#[rustc_always_gca]` must have a `direct_const_arg!` RHS } -fn main() { } +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 index 15db8b87d661e..2daf2e1056b95 100644 --- a/tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.stderr +++ b/tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.stderr @@ -1,62 +1,56 @@ -error[E0658]: `type const` syntax is experimental - --> $DIR/feature-gate-mgca-type-const-syntax.rs:1:1 +error[E0658]: use of unstable library feature `min_generic_const_args` + --> $DIR/feature-gate-mgca-type-const-syntax.rs:1:17 | -LL | type const FOO: u8 = 10; - | ^^^^^^^^^^ +LL | const FOO: u8 = core::direct_const_arg!(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 +error[E0658]: use of unstable library feature `min_generic_const_args` + --> $DIR/feature-gate-mgca-type-const-syntax.rs:12:23 | -LL | type const BAR: bool; - | ^^^^^^^^^^ +LL | const BAR: bool = core::direct_const_arg!(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]: `type const` syntax is experimental - --> $DIR/feature-gate-mgca-type-const-syntax.rs:12:5 - | -LL | type const BAR: bool = false; - | ^^^^^^^^^^ +error: expected expression, found `direct_const_arg!()` constant + --> $DIR/feature-gate-mgca-type-const-syntax.rs:1:17 | - = 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 +LL | const FOO: u8 = core::direct_const_arg!(10); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0658]: top-level `type const` are unstable - --> $DIR/feature-gate-mgca-type-const-syntax.rs:1:1 +error[E0658]: the `rustc_always_gca` attribute is an experimental feature + --> $DIR/feature-gate-mgca-type-const-syntax.rs:6:7 | -LL | type const FOO: u8 = 10; - | ^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_always_gca] + | ^^^^^^^^^^^^^^^^ | = 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; - | ^^^^^^^^^^^^^^^^^^^^^ +error: expected expression, found `direct_const_arg!()` constant + --> $DIR/feature-gate-mgca-type-const-syntax.rs:12:23 | - = 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 +LL | const BAR: bool = core::direct_const_arg!(false); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error[E0658]: associated `type const` are unstable +error: implementation of a `#[rustc_always_gca]` must have a `direct_const_arg!` RHS --> $DIR/feature-gate-mgca-type-const-syntax.rs:12:5 | -LL | type const BAR: bool = false; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const BAR: bool = core::direct_const_arg!(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 +note: trait declaration of const is marked as `#[rustc_always_gca]` + --> $DIR/feature-gate-mgca-type-const-syntax.rs:8:5 + | +LL | const BAR: bool; + | ^^^^^^^^^^^^^^^ error: aborting due to 6 previous errors 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 6ac8ef8fa4181..a39d07eca0ee7 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,14 +1,14 @@ trait Trait { - type const ASSOC: usize; - //~^ ERROR: associated `type const` are unstable [E0658] - //~| ERROR: `type const` syntax is experimental [E0658] + #[rustc_always_gca] + //~^ ERROR: the `rustc_always_gca` attribute is an experimental feature [E0658] + const ASSOC: usize; } // FIXME(mgca): add suggestion for mgca to this error fn foo() -> [u8; core::direct_const_arg!(::ASSOC)] { //~^ ERROR generic parameters may not be used in const operations - //~| ERROR use of unstable library feature `min_generic_const_args` [E0658] - //~| ERROR expected expression, found `direct_const_arg!()` constant + //~| ERROR: use of unstable library feature `min_generic_const_args` [E0658] + //~| ERROR: expected expression, found `direct_const_arg!()` loop {} } 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 f896d0de99ec6..eac9545d29681 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 @@ -18,21 +18,11 @@ LL | fn foo() -> [u8; core::direct_const_arg!(::ASSOC)] { = help: add `#![feature(generic_const_exprs)]` to allow generic const expressions = help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item -error[E0658]: `type const` syntax is experimental - --> $DIR/feature-gate-min-generic-const-args.rs:2:5 +error[E0658]: the `rustc_always_gca` attribute is an experimental feature + --> $DIR/feature-gate-min-generic-const-args.rs:2:7 | -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[E0658]: associated `type const` are unstable - --> $DIR/feature-gate-min-generic-const-args.rs:2:5 - | -LL | type const ASSOC: usize; - | ^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[rustc_always_gca] + | ^^^^^^^^^^^^^^^^ | = note: see issue #132980 for more information = help: add `#![feature(min_generic_const_args)]` to the crate attributes to enable @@ -44,6 +34,6 @@ error: expected expression, found `direct_const_arg!()` constant LL | fn foo() -> [u8; core::direct_const_arg!(::ASSOC)] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/generic-const-items/assoc-const-bindings.rs b/tests/ui/generic-const-items/assoc-const-bindings.rs index 2ebdda28a69fd..596c47de98f86 100644 --- a/tests/ui/generic-const-items/assoc-const-bindings.rs +++ b/tests/ui/generic-const-items/assoc-const-bindings.rs @@ -7,15 +7,18 @@ use std::marker::{ConstParamTy, ConstParamTy_}; trait Owner { - type const C: u32; - type const K: u32; - type const Q: Maybe; + #[rustc_always_gca] + const C: u32; + #[rustc_always_gca] + const K: u32; + #[rustc_always_gca] + const Q: Maybe; } impl Owner for () { - type const C: u32 = N; - type const K: u32 = const { 99 + 1 }; - type const Q: Maybe = Maybe::Nothing::; + const C: u32 = core::direct_const_arg!(N); + const K: u32 = core::direct_const_arg!(const { 99 + 1 }); + const Q: Maybe = core::direct_const_arg!(Maybe::Nothing::); } fn take0(_: impl Owner = { N }>) {} 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 354880e6d573e..d321f8ce802c0 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 @@ -9,12 +9,19 @@ pub struct NoPin; impl Pins for NoPin {} pub trait PinA { - type const A: &'static () = const { &() }; + #[rustc_always_gca] + const A: &'static () = core::direct_const_arg!(const { &() }); + //~^ ERROR anonymous constants with lifetimes in their type are not yet supported } pub trait Pins {} -impl Pins for T where T: PinA {} +impl Pins for T //~^ ERROR conflicting implementations of trait `Pins<_>` for type `NoPin` +where + T: PinA, + //~^ ERROR anonymous constants with lifetimes in their type are not yet supported +{ +} pub fn main() {} 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..5ccca6bb0c677 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,14 +1,29 @@ +error: anonymous constants with lifetimes in their type are not yet supported + --> $DIR/assoc-const-no-infer-ice-115806.rs:22:50 + | +LL | T: PinA, + | ^^^^^^^^^^^^^ + 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:19:1 | -LL | impl Pins for NoPin {} - | --------------------------- first implementation here +LL | impl Pins for NoPin {} + | --------------------------- first implementation here ... -LL | impl Pins for T where T: PinA {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `NoPin` +LL | / impl Pins for T +LL | | +LL | | where +LL | | T: PinA, + | |___________________________________________________________________^ conflicting implementation for `NoPin` | = note: downstream crates may implement trait `PinA<_>` for type `NoPin` -error: aborting due to 1 previous error +error: anonymous constants with lifetimes in their type are not yet supported + --> $DIR/assoc-const-no-infer-ice-115806.rs:13:52 + | +LL | const A: &'static () = core::direct_const_arg!(const { &() }); + | ^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0119`. diff --git a/tests/ui/generic-const-items/type-const-nested-assoc-const.rs b/tests/ui/generic-const-items/type-const-nested-assoc-const.rs index 72a3098b76cfe..64df0183f101e 100644 --- a/tests/ui/generic-const-items/type-const-nested-assoc-const.rs +++ b/tests/ui/generic-const-items/type-const-nested-assoc-const.rs @@ -3,14 +3,15 @@ #![feature(generic_const_items, min_generic_const_args)] #![allow(incomplete_features)] -type const CT: usize = { ::N }; +const CT: usize = core::direct_const_arg!(::N); trait Trait { - type const N: usize; + #[rustc_always_gca] + const N: usize; } impl Trait for T { - type const N:usize = 0; + const N: usize = core::direct_const_arg!(0); } fn f(_x: [(); CT::<()>]) {} diff --git a/tests/ui/object-lifetime/object-lifetime-default-inherent-gac.rs b/tests/ui/object-lifetime/object-lifetime-default-inherent-gac.rs index 51ad438ec9bfb..4b415a230cbd4 100644 --- a/tests/ui/object-lifetime/object-lifetime-default-inherent-gac.rs +++ b/tests/ui/object-lifetime/object-lifetime-default-inherent-gac.rs @@ -12,30 +12,40 @@ )] #![expect(incomplete_features)] -mod own { // the lifetime comes from the own generics +mod own { + // the lifetime comes from the own generics struct Parent; impl Parent { - type const CT<'a, T: 'a + super::AbideBy<'a> + ?Sized>: usize = 0; + const CT<'a, T: 'a + super::AbideBy<'a> + ?Sized>: usize = core::direct_const_arg!(0); } // FIXME: Ideally, we would deduce `dyn Trait + 'r` from the bound `'a` on ty param `T` of // type-level inherent assoc const `CT` but for that we'd need to somehow obtain the // resolution of the type-relative path `Parent::CT` from HIR ty lowering in RBV. - fn check<'r>() where [(); Parent::CT::<'r, dyn super::Trait>]: {} - //~^ ERROR cannot deduce the lifetime bound for this trait object type from context + fn check<'r>() + where + [(); Parent::CT::<'r, dyn super::Trait>]:, + //~^ ERROR cannot deduce the lifetime bound for this trait object type from context + { + } } -mod parent { // the lifetime comes from the parent generics +mod parent { + // the lifetime comes from the parent generics struct Parent<'a>(&'a ()); impl<'a> Parent<'a> { - type const CT + ?Sized>: usize = 0; + const CT + ?Sized>: usize = core::direct_const_arg!(0); } //FIXME: Ideally, we would deduce `dyn Trait + 'r` from the bound `'a` on ty param `T` of // type-level inherent assoc const `CT` but for that we'd need to somehow obtain the // resolution of the type-relative path `Parent::<'r>::CT` from HIR ty lowering in RBV. - fn check<'r>() where [(); Parent::<'r>::CT::]: {} - //~^ ERROR cannot deduce the lifetime bound for this trait object type from context + fn check<'r>() + where + [(); Parent::<'r>::CT::]:, + //~^ ERROR cannot deduce the lifetime bound for this trait object type from context + { + } } trait Trait {} diff --git a/tests/ui/object-lifetime/object-lifetime-default-inherent-gac.stderr b/tests/ui/object-lifetime/object-lifetime-default-inherent-gac.stderr index 2762f69719099..1461caea1bbed 100644 --- a/tests/ui/object-lifetime/object-lifetime-default-inherent-gac.stderr +++ b/tests/ui/object-lifetime/object-lifetime-default-inherent-gac.stderr @@ -1,24 +1,24 @@ error[E0228]: cannot deduce the lifetime bound for this trait object type from context - --> $DIR/object-lifetime-default-inherent-gac.rs:24:48 + --> $DIR/object-lifetime-default-inherent-gac.rs:27:31 | -LL | fn check<'r>() where [(); Parent::CT::<'r, dyn super::Trait>]: {} - | ^^^^^^^^^^^^^^^^ +LL | [(); Parent::CT::<'r, dyn super::Trait>]:, + | ^^^^^^^^^^^^^^^^ | help: please supply an explicit bound | -LL | fn check<'r>() where [(); Parent::CT::<'r, dyn super::Trait + /* 'a */>]: {} - | ++++++++++ +LL | [(); Parent::CT::<'r, dyn super::Trait + /* 'a */>]:, + | ++++++++++ error[E0228]: cannot deduce the lifetime bound for this trait object type from context - --> $DIR/object-lifetime-default-inherent-gac.rs:37:50 + --> $DIR/object-lifetime-default-inherent-gac.rs:45:33 | -LL | fn check<'r>() where [(); Parent::<'r>::CT::]: {} - | ^^^^^^^^^^^^^^^^ +LL | [(); Parent::<'r>::CT::]:, + | ^^^^^^^^^^^^^^^^ | help: please supply an explicit bound | -LL | fn check<'r>() where [(); Parent::<'r>::CT::]: {} - | ++++++++++ +LL | [(); Parent::<'r>::CT::]:, + | ++++++++++ error: aborting due to 2 previous errors 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 3fd33c7c1bb67..113ef41f532f0 100644 --- a/tests/ui/sanitizer/cfi/assoc-const-projection-issue-151878.rs +++ b/tests/ui/sanitizer/cfi/assoc-const-projection-issue-151878.rs @@ -8,7 +8,8 @@ #![expect(incomplete_features)] trait Trait { - type const N: usize = 0; + #[rustc_always_gca] + const N: usize = core::direct_const_arg!(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 0cf6092891272..a57e86127da7b 100644 --- a/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.rs +++ b/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.rs @@ -3,11 +3,11 @@ #![feature(min_generic_const_args, specialization)] pub trait IsVoid { - - type const IS_VOID: bool; + #[rustc_always_gca] + const IS_VOID: bool; } impl IsVoid for T { - default type const IS_VOID: bool = false; + default const IS_VOID: bool = core::direct_const_arg!(false); } pub trait NotVoid {} diff --git a/tests/ui/supertrait-shadowing/assoc-const.rs b/tests/ui/supertrait-shadowing/assoc-const.rs index be0d990284b0c..0fd798217d77a 100644 --- a/tests/ui/supertrait-shadowing/assoc-const.rs +++ b/tests/ui/supertrait-shadowing/assoc-const.rs @@ -12,10 +12,11 @@ impl A for T { } trait B: A { - type const CONST: i32; + #[rustc_always_gca] + const CONST: i32; } impl B for T { - type const CONST: i32 = 2; + const CONST: i32 = core::direct_const_arg!(2); } trait C: B {} diff --git a/tests/ui/supertrait-shadowing/common-ancestor-2.rs b/tests/ui/supertrait-shadowing/common-ancestor-2.rs index 908c5d2bf2199..b1ff2e895eb48 100644 --- a/tests/ui/supertrait-shadowing/common-ancestor-2.rs +++ b/tests/ui/supertrait-shadowing/common-ancestor-2.rs @@ -39,12 +39,13 @@ trait C: A + B { } type Assoc; //~^ WARN trait item `Assoc` from `C` shadows identically named item - type const CONST: i32; + #[rustc_always_gca] + const CONST: i32; //~^ WARN trait item `CONST` from `C` shadows identically named item } impl C for T { type Assoc = i32; - type const CONST: i32 = 3; + const CONST: i32 = core::direct_const_arg!(3); } fn main() { diff --git a/tests/ui/supertrait-shadowing/common-ancestor-2.stderr b/tests/ui/supertrait-shadowing/common-ancestor-2.stderr index 646726b835041..3e47a33991007 100644 --- a/tests/ui/supertrait-shadowing/common-ancestor-2.stderr +++ b/tests/ui/supertrait-shadowing/common-ancestor-2.stderr @@ -34,10 +34,10 @@ LL | type Assoc; | ^^^^^^^^^^ warning: trait item `CONST` from `C` shadows identically named item from supertrait - --> $DIR/common-ancestor-2.rs:42:5 + --> $DIR/common-ancestor-2.rs:43:5 | -LL | type const CONST: i32; - | ^^^^^^^^^^^^^^^^^^^^^ +LL | const CONST: i32; + | ^^^^^^^^^^^^^^^^ | note: items from several supertraits are shadowed: `B` and `A` --> $DIR/common-ancestor-2.rs:16:5 @@ -49,7 +49,7 @@ LL | const CONST: i32; | ^^^^^^^^^^^^^^^^ warning: trait item `hello` from `C` shadows identically named item from supertrait - --> $DIR/common-ancestor-2.rs:51:19 + --> $DIR/common-ancestor-2.rs:52:19 | LL | assert_eq!(().hello(), "C"); | ^^^^^ diff --git a/tests/ui/supertrait-shadowing/common-ancestor-3.rs b/tests/ui/supertrait-shadowing/common-ancestor-3.rs index ade23ca88aec2..ba8689d3a43f2 100644 --- a/tests/ui/supertrait-shadowing/common-ancestor-3.rs +++ b/tests/ui/supertrait-shadowing/common-ancestor-3.rs @@ -39,12 +39,13 @@ trait C: A + B { } type Assoc; //~^ WARN trait item `Assoc` from `C` shadows identically named item - type const CONST: i32; + #[rustc_always_gca] + const CONST: i32; //~^ WARN trait item `CONST` from `C` shadows identically named item } impl C for T { type Assoc = i32; - type const CONST: i32 = 3; + const CONST: i32 = core::direct_const_arg!(3); } // `D` extends `C` which extends `B` and `A` @@ -56,12 +57,13 @@ trait D: C { } type Assoc; //~^ WARN trait item `Assoc` from `D` shadows identically named item - type const CONST: i32; + #[rustc_always_gca] + const CONST: i32; //~^ WARN trait item `CONST` from `D` shadows identically named item } impl D for T { type Assoc = i64; - type const CONST: i32 = 4; + const CONST: i32 = core::direct_const_arg!(4); } fn main() { diff --git a/tests/ui/supertrait-shadowing/common-ancestor-3.stderr b/tests/ui/supertrait-shadowing/common-ancestor-3.stderr index 62132832da4ba..2fd7ff0003c74 100644 --- a/tests/ui/supertrait-shadowing/common-ancestor-3.stderr +++ b/tests/ui/supertrait-shadowing/common-ancestor-3.stderr @@ -34,10 +34,10 @@ LL | type Assoc; | ^^^^^^^^^^ warning: trait item `CONST` from `C` shadows identically named item from supertrait - --> $DIR/common-ancestor-3.rs:42:5 + --> $DIR/common-ancestor-3.rs:43:5 | -LL | type const CONST: i32; - | ^^^^^^^^^^^^^^^^^^^^^ +LL | const CONST: i32; + | ^^^^^^^^^^^^^^^^ | note: items from several supertraits are shadowed: `B` and `A` --> $DIR/common-ancestor-3.rs:16:5 @@ -49,7 +49,7 @@ LL | const CONST: i32; | ^^^^^^^^^^^^^^^^ warning: trait item `hello` from `D` shadows identically named item from supertrait - --> $DIR/common-ancestor-3.rs:53:5 + --> $DIR/common-ancestor-3.rs:54:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -67,7 +67,7 @@ LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: trait item `Assoc` from `D` shadows identically named item from supertrait - --> $DIR/common-ancestor-3.rs:57:5 + --> $DIR/common-ancestor-3.rs:58:5 | LL | type Assoc; | ^^^^^^^^^^ @@ -85,10 +85,10 @@ LL | type Assoc; | ^^^^^^^^^^ warning: trait item `CONST` from `D` shadows identically named item from supertrait - --> $DIR/common-ancestor-3.rs:59:5 + --> $DIR/common-ancestor-3.rs:61:5 | -LL | type const CONST: i32; - | ^^^^^^^^^^^^^^^^^^^^^ +LL | const CONST: i32; + | ^^^^^^^^^^^^^^^^ | note: items from several supertraits are shadowed: `C`, `B`, and `A` --> $DIR/common-ancestor-3.rs:16:5 @@ -99,17 +99,17 @@ LL | const CONST: i32; LL | const CONST: i32; | ^^^^^^^^^^^^^^^^ ... -LL | type const CONST: i32; - | ^^^^^^^^^^^^^^^^^^^^^ +LL | const CONST: i32; + | ^^^^^^^^^^^^^^^^ warning: trait item `hello` from `D` shadows identically named item from supertrait - --> $DIR/common-ancestor-3.rs:68:19 + --> $DIR/common-ancestor-3.rs:70:19 | LL | assert_eq!(().hello(), "D"); | ^^^^^ | note: item from `D` shadows a supertrait item - --> $DIR/common-ancestor-3.rs:53:5 + --> $DIR/common-ancestor-3.rs:54:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/supertrait-shadowing/common-ancestor.rs b/tests/ui/supertrait-shadowing/common-ancestor.rs index 903f85957870b..7acc4bcad56ca 100644 --- a/tests/ui/supertrait-shadowing/common-ancestor.rs +++ b/tests/ui/supertrait-shadowing/common-ancestor.rs @@ -27,12 +27,13 @@ trait B: A { } type Assoc; //~^ WARN trait item `Assoc` from `B` shadows identically named item - type const CONST: i32; + #[rustc_always_gca] + const CONST: i32; //~^ WARN trait item `CONST` from `B` shadows identically named item } impl B for T { type Assoc = i16; - type const CONST: i32 = 2; + const CONST: i32 = core::direct_const_arg!(2); } fn main() { diff --git a/tests/ui/supertrait-shadowing/common-ancestor.stderr b/tests/ui/supertrait-shadowing/common-ancestor.stderr index 9b13537cf800c..a0b885b58eb5f 100644 --- a/tests/ui/supertrait-shadowing/common-ancestor.stderr +++ b/tests/ui/supertrait-shadowing/common-ancestor.stderr @@ -28,10 +28,10 @@ LL | type Assoc; | ^^^^^^^^^^ warning: trait item `CONST` from `B` shadows identically named item from supertrait - --> $DIR/common-ancestor.rs:30:5 + --> $DIR/common-ancestor.rs:31:5 | -LL | type const CONST: i32; - | ^^^^^^^^^^^^^^^^^^^^^ +LL | const CONST: i32; + | ^^^^^^^^^^^^^^^^ | note: item from `A` is shadowed by a subtrait item --> $DIR/common-ancestor.rs:16:5 @@ -40,7 +40,7 @@ LL | const CONST: i32; | ^^^^^^^^^^^^^^^^ warning: trait item `hello` from `B` shadows identically named item from supertrait - --> $DIR/common-ancestor.rs:39:19 + --> $DIR/common-ancestor.rs:40:19 | LL | assert_eq!(().hello(), "B"); | ^^^^^ diff --git a/tests/ui/supertrait-shadowing/no-common-ancestor-2.rs b/tests/ui/supertrait-shadowing/no-common-ancestor-2.rs index 957aabf5a51f8..64d34ccb8c9ae 100644 --- a/tests/ui/supertrait-shadowing/no-common-ancestor-2.rs +++ b/tests/ui/supertrait-shadowing/no-common-ancestor-2.rs @@ -32,11 +32,12 @@ trait C: A + B { "C" } type Assoc; - type const CONST: i32; + #[rustc_always_gca] + const CONST: i32; } impl C for T { type Assoc = i32; - type const CONST: i32 = 3; + const CONST: i32 = core::direct_const_arg!(3); } // Since `D` is not a subtrait of `C`, @@ -47,11 +48,12 @@ trait D: B { "D" } type Assoc; - type const CONST: i32; + #[rustc_always_gca] + const CONST: i32; } impl D for T { type Assoc = i64; - type const CONST: i32 = 4; + const CONST: i32 = core::direct_const_arg!(4); } fn main() { diff --git a/tests/ui/supertrait-shadowing/no-common-ancestor-2.stderr b/tests/ui/supertrait-shadowing/no-common-ancestor-2.stderr index 987adcfbbe959..85c0937c03d9c 100644 --- a/tests/ui/supertrait-shadowing/no-common-ancestor-2.stderr +++ b/tests/ui/supertrait-shadowing/no-common-ancestor-2.stderr @@ -1,5 +1,5 @@ error[E0034]: multiple applicable items in scope - --> $DIR/no-common-ancestor-2.rs:58:8 + --> $DIR/no-common-ancestor-2.rs:60:8 | LL | ().hello(); | ^^^^^ multiple `hello` found @@ -20,7 +20,7 @@ note: candidate #3 is defined in an impl of the trait `C` for the type `T` LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: candidate #4 is defined in an impl of the trait `D` for the type `T` - --> $DIR/no-common-ancestor-2.rs:46:5 + --> $DIR/no-common-ancestor-2.rs:47:5 | LL | fn hello(&self) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -46,7 +46,7 @@ LL + D::hello(&()); | error[E0221]: ambiguous associated type `Assoc` in bounds of `T` - --> $DIR/no-common-ancestor-2.rs:64:23 + --> $DIR/no-common-ancestor-2.rs:66:23 | LL | type Assoc; | ---------- ambiguous `Assoc` from `A` @@ -85,7 +85,7 @@ LL + let _ = size_of::<::Assoc>(); | error[E0034]: multiple applicable items in scope - --> $DIR/no-common-ancestor-2.rs:66:16 + --> $DIR/no-common-ancestor-2.rs:68:16 | LL | let _ = T::CONST; | ^^^^^ multiple `CONST` found @@ -101,15 +101,15 @@ note: candidate #2 is defined in the trait `B` LL | const CONST: i32; | ^^^^^^^^^^^^^^^^ note: candidate #3 is defined in the trait `C` - --> $DIR/no-common-ancestor-2.rs:35:5 + --> $DIR/no-common-ancestor-2.rs:36:5 | -LL | type const CONST: i32; - | ^^^^^^^^^^^^^^^^^^^^^ +LL | const CONST: i32; + | ^^^^^^^^^^^^^^^^ note: candidate #4 is defined in the trait `D` - --> $DIR/no-common-ancestor-2.rs:50:5 + --> $DIR/no-common-ancestor-2.rs:52:5 | -LL | type const CONST: i32; - | ^^^^^^^^^^^^^^^^^^^^^ +LL | const CONST: i32; + | ^^^^^^^^^^^^^^^^ help: use fully-qualified syntax to disambiguate | LL - let _ = T::CONST; diff --git a/tests/ui/supertrait-shadowing/out-of-scope.rs b/tests/ui/supertrait-shadowing/out-of-scope.rs index 7b2322843f1c3..11c7477cc3f8a 100644 --- a/tests/ui/supertrait-shadowing/out-of-scope.rs +++ b/tests/ui/supertrait-shadowing/out-of-scope.rs @@ -11,11 +11,12 @@ mod out_of_scope { "subtrait" } type Assoc; - type const CONST: i32; + #[rustc_always_gca] + const CONST: i32; } impl Subtrait for T { type Assoc = i16; - type const CONST: i32 = 2; + const CONST: i32 = core::direct_const_arg!(2); } } diff --git a/tests/ui/supertrait-shadowing/type-dependent.rs b/tests/ui/supertrait-shadowing/type-dependent.rs index 75272d101dd29..0287bb7ad43a8 100644 --- a/tests/ui/supertrait-shadowing/type-dependent.rs +++ b/tests/ui/supertrait-shadowing/type-dependent.rs @@ -25,11 +25,12 @@ trait B: A { "B" } type Assoc; - type const CONST: i32; + #[rustc_always_gca] + const CONST: i32; } impl B for T { type Assoc = i16; - type const CONST: i32 = 2; + const CONST: i32 = core::direct_const_arg!(2); } fn foo() -> &'static str { diff --git a/tests/ui/traits/final/final-on-assoc-type-const.rs b/tests/ui/traits/final/final-on-assoc-type-const.rs index 9d20c0515476c..5c248fa57a8c2 100644 --- a/tests/ui/traits/final/final-on-assoc-type-const.rs +++ b/tests/ui/traits/final/final-on-assoc-type-const.rs @@ -5,7 +5,8 @@ trait Uwu { final type Ovo; //~^ error: `final` is only allowed on associated functions in traits - final type const QwQ: (); + #[rustc_always_gca] + final const QwQ: (); //~^ error: `final` is only allowed on associated functions in traits } diff --git a/tests/ui/traits/final/final-on-assoc-type-const.stderr b/tests/ui/traits/final/final-on-assoc-type-const.stderr index ac2ab123e1d17..ebbaa311c008d 100644 --- a/tests/ui/traits/final/final-on-assoc-type-const.stderr +++ b/tests/ui/traits/final/final-on-assoc-type-const.stderr @@ -7,10 +7,10 @@ LL | final type Ovo; | `final` because of this error: `final` is only allowed on associated functions in traits - --> $DIR/final-on-assoc-type-const.rs:8:5 + --> $DIR/final-on-assoc-type-const.rs:9:5 | -LL | final type const QwQ: (); - | -----^^^^^^^^^^^^^^^^^^^^ +LL | final const QwQ: (); + | -----^^^^^^^^^^^^^^^ | | | `final` because of this diff --git a/tests/ui/type-alias/recursive-lazy-type-alias-ice-152633.rs b/tests/ui/type-alias/recursive-lazy-type-alias-ice-152633.rs index 9180623a6c66c..285dda667792d 100644 --- a/tests/ui/type-alias/recursive-lazy-type-alias-ice-152633.rs +++ b/tests/ui/type-alias/recursive-lazy-type-alias-ice-152633.rs @@ -6,7 +6,8 @@ #![feature(checked_type_aliases, min_generic_const_args, macroless_generic_const_args)] trait Trait { - type const ASSOC: (); + #[rustc_always_gca] + const ASSOC: (); } type Arr2 = [usize; ::ASSOC]; //~ ERROR E0275 diff --git a/tests/ui/type-alias/recursive-lazy-type-alias-ice-152633.stderr b/tests/ui/type-alias/recursive-lazy-type-alias-ice-152633.stderr index f432026449e12..a8e68a05253b9 100644 --- a/tests/ui/type-alias/recursive-lazy-type-alias-ice-152633.stderr +++ b/tests/ui/type-alias/recursive-lazy-type-alias-ice-152633.stderr @@ -1,5 +1,5 @@ error[E0275]: overflow normalizing the type alias `Arr2` - --> $DIR/recursive-lazy-type-alias-ice-152633.rs:11:1 + --> $DIR/recursive-lazy-type-alias-ice-152633.rs:12:1 | LL | type Arr2 = [usize; ::ASSOC]; | ^^^^^^^^^