From 0a355170c0ad0b057b072f76fdb35245d3bba009 Mon Sep 17 00:00:00 2001 From: Boxy Uwu Date: Mon, 13 Oct 2025 21:58:36 +0100 Subject: [PATCH] fix associated_const_equality tests --- .../src/hir_ty_lowering/bounds.rs | 30 +++++++++++++++++-- .../src/hir_ty_lowering/mod.rs | 14 +++++++-- compiler/rustc_middle/src/ty/assoc.rs | 20 ------------- compiler/rustc_passes/src/check_attr.rs | 13 ++------ .../assoc-const-eq-ambiguity.rs | 18 ++++++++--- .../assoc-const-eq-ambiguity.stderr | 27 +++++++++-------- .../assoc-const-eq-bound-var-in-ty-not-wf.rs | 4 ++- ...soc-const-eq-bound-var-in-ty-not-wf.stderr | 6 ++-- .../assoc-const-eq-bound-var-in-ty.rs | 4 ++- ...oc-const-eq-const_evaluatable_unchecked.rs | 8 +++-- .../assoc-const-eq-esc-bound-var-in-ty.rs | 4 ++- .../assoc-const-eq-esc-bound-var-in-ty.stderr | 2 +- .../assoc-const-eq-param-in-ty.rs | 5 +++- .../assoc-const-eq-param-in-ty.stderr | 22 +++++++------- .../assoc-const-eq-supertraits.rs | 4 ++- .../assoc-const-eq-ty-alias-noninteracting.rs | 5 +++- tests/ui/associated-consts/assoc-const.rs | 6 ++-- .../equality-unused-issue-126729.rs | 11 ++++++- .../associated-consts/issue-102335-const.rs | 4 ++- .../issue-102335-const.stderr | 4 +-- tests/ui/associated-consts/issue-110933.rs | 4 ++- .../projection-unspecified-but-bounded.rs | 4 ++- .../projection-unspecified-but-bounded.stderr | 4 +-- .../const-projection-err.gce.stderr | 15 ++-------- .../const-projection-err.rs | 6 ++-- .../const-projection-err.stock.stderr | 8 ++--- .../equality_bound_with_infer.rs | 11 ++++--- .../equality_bound_with_infer.stderr | 17 ----------- .../unconstrained_impl_param.rs | 2 +- .../unconstrained_impl_param.stderr | 19 ++---------- .../mgca/bad-type_const-syntax.rs | 3 +- .../mgca/bad-type_const-syntax.stderr | 8 +---- .../const-generics/mgca/projection-error.rs | 1 + .../mgca/projection-error.stderr | 4 +-- .../assoc-const-no-infer-ice-115806.rs | 3 +- .../assoc-const-no-infer-ice-115806.stderr | 2 +- .../associated-const-equality.rs | 11 +++++-- .../overlap-due-to-unsatisfied-const-bound.rs | 5 +++- ...rlap-due-to-unsatisfied-const-bound.stderr | 20 +++++++++---- 39 files changed, 194 insertions(+), 164 deletions(-) delete mode 100644 tests/ui/const-generics/associated_const_equality/equality_bound_with_infer.stderr 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 1832e6e890b9..555ef5c45e12 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs @@ -4,9 +4,10 @@ use rustc_errors::codes::*; use rustc_errors::struct_span_code_err; use rustc_hir as hir; -use rustc_hir::PolyTraitRef; +use rustc_hir::attrs::AttributeKind; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{CRATE_DEF_ID, DefId}; +use rustc_hir::{PolyTraitRef, find_attr}; use rustc_middle::bug; use rustc_middle::ty::{ self as ty, IsSuggestable, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, @@ -602,7 +603,32 @@ pub(super) fn lower_assoc_item_constraint( term, }) }); - bounds.push((bound.upcast(tcx), constraint.span)); + + if let ty::AssocTag::Const = assoc_tag + && !find_attr!( + self.tcx().get_all_attrs(assoc_item.def_id), + AttributeKind::TypeConst(_) + ) + { + if tcx.features().min_generic_const_args() + || tcx.features().associated_const_equality() + { + let mut err = self.dcx().struct_span_err( + constraint.span, + "use of trait associated const without `#[type_const]`", + ); + err.note("the declaration in the trait must be marked with `#[type_const]`"); + return Err(err.emit()); + } else { + let err = self.dcx().span_delayed_bug( + constraint.span, + "use of trait associated const without `#[type_const]`", + ); + return Err(err); + } + } else { + bounds.push((bound.upcast(tcx), constraint.span)); + } } // SelfTraitThatDefines is only interested in trait predicates. PredicateFilter::SelfTraitThatDefines(_) => {} 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 8ea4af9e1761..de65e4c6addf 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -27,9 +27,10 @@ use rustc_errors::{ Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, FatalError, struct_span_code_err, }; +use rustc_hir::attrs::AttributeKind; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId}; -use rustc_hir::{self as hir, AnonConst, GenericArg, GenericArgs, HirId}; +use rustc_hir::{self as hir, AnonConst, GenericArg, GenericArgs, HirId, find_attr}; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_infer::traits::DynCompatibilityViolation; use rustc_macros::{TypeFoldable, TypeVisitable}; @@ -1278,7 +1279,7 @@ fn lower_type_relative_const_path( LowerTypeRelativePathMode::Const, )? { TypeRelativePath::AssocItem(def_id, args) => { - if !tcx.associated_item(def_id).is_type_const_capable(tcx) { + if !find_attr!(self.tcx().get_all_attrs(def_id), AttributeKind::TypeConst(_)) { let mut err = self.dcx().struct_span_err( span, "use of trait associated const without `#[type_const]`", @@ -1716,6 +1717,15 @@ fn lower_resolved_assoc_const_path( ty::AssocTag::Const, ) { Ok((item_def_id, item_args)) => { + if !find_attr!(self.tcx().get_all_attrs(item_def_id), AttributeKind::TypeConst(_)) { + let mut err = self.dcx().struct_span_err( + span, + "use of `const` in the type system without `#[type_const]`", + ); + err.note("the declaration must be marked with `#[type_const]`"); + return Const::new_error(self.tcx(), err.emit()); + } + let uv = ty::UnevaluatedConst::new(item_def_id, item_args); Const::new_unevaluated(self.tcx(), uv) } diff --git a/compiler/rustc_middle/src/ty/assoc.rs b/compiler/rustc_middle/src/ty/assoc.rs index 768646c76302..5e20bc142ffe 100644 --- a/compiler/rustc_middle/src/ty/assoc.rs +++ b/compiler/rustc_middle/src/ty/assoc.rs @@ -1,9 +1,7 @@ use rustc_data_structures::sorted_map::SortedIndexMultiMap; use rustc_hir as hir; -use rustc_hir::attrs::AttributeKind; use rustc_hir::def::{DefKind, Namespace}; use rustc_hir::def_id::DefId; -use rustc_hir::find_attr; use rustc_macros::{Decodable, Encodable, HashStable}; use rustc_span::{ErrorGuaranteed, Ident, Symbol}; @@ -173,24 +171,6 @@ pub fn as_tag(&self) -> AssocTag { pub fn is_impl_trait_in_trait(&self) -> bool { matches!(self.kind, AssocKind::Type { data: AssocTypeData::Rpitit(_) }) } - - /// Returns true if: - /// - This trait associated item has the `#[type_const]` attribute, - /// - If it is in a trait impl, the item from the original trait has this attribute, or - /// - It is an inherent assoc const. - pub fn is_type_const_capable(&self, tcx: TyCtxt<'_>) -> bool { - if !matches!(self.kind, ty::AssocKind::Const { .. }) { - return false; - } - - let def_id = match self.container { - AssocContainer::Trait => self.def_id, - AssocContainer::TraitImpl(Ok(trait_item_did)) => trait_item_did, - AssocContainer::TraitImpl(Err(_)) => return false, - AssocContainer::InherentImpl => return true, - }; - find_attr!(tcx.get_all_attrs(def_id), AttributeKind::TypeConst(_)) - } } #[derive(Copy, Clone, PartialEq, Debug, HashStable, Eq, Hash, Encodable, Decodable)] diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index ef42c42f68b3..91453e0c1d42 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -2102,19 +2102,12 @@ fn check_proc_macro(&self, hir_id: HirId, target: Target, kind: ProcMacroKind) { } } - fn check_type_const(&self, hir_id: HirId, attr_span: Span, target: Target) { - let tcx = self.tcx; - if target == Target::AssocConst - && let parent = tcx.parent(hir_id.expect_owner().to_def_id()) - && self.tcx.def_kind(parent) == DefKind::Trait - { + fn check_type_const(&self, _hir_id: HirId, attr_span: Span, target: Target) { + if matches!(target, Target::AssocConst | Target::Const) { return; } else { self.dcx() - .struct_span_err( - attr_span, - "`#[type_const]` must only be applied to trait associated constants", - ) + .struct_span_err(attr_span, "`#[type_const]` must only be applied to const items") .emit(); } } diff --git a/tests/ui/associated-consts/assoc-const-eq-ambiguity.rs b/tests/ui/associated-consts/assoc-const-eq-ambiguity.rs index ac085864ff09..d433af6bdd57 100644 --- a/tests/ui/associated-consts/assoc-const-eq-ambiguity.rs +++ b/tests/ui/associated-consts/assoc-const-eq-ambiguity.rs @@ -1,17 +1,27 @@ // We used to say "ambiguous associated type" on ambiguous associated consts. // Ensure that we now use the correct label. -#![feature(associated_const_equality)] +#![feature(associated_const_equality, min_generic_const_args)] +#![allow(incomplete_features)] trait Trait0: Parent0 + Parent0 {} -trait Parent0 { const K: (); } +trait Parent0 { + #[type_const] + const K: (); +} fn take0(_: impl Trait0) {} //~^ ERROR ambiguous associated constant `K` in bounds of `Trait0` trait Trait1: Parent1 + Parent2 {} -trait Parent1 { const C: i32; } -trait Parent2 { const C: &'static str; } +trait Parent1 { + #[type_const] + const C: i32; +} +trait Parent2 { + #[type_const] + const C: &'static str; +} fn take1(_: impl Trait1) {} //~^ ERROR ambiguous associated constant `C` in bounds of `Trait1` diff --git a/tests/ui/associated-consts/assoc-const-eq-ambiguity.stderr b/tests/ui/associated-consts/assoc-const-eq-ambiguity.stderr index aa1db4cb032e..3541664d1c6a 100644 --- a/tests/ui/associated-consts/assoc-const-eq-ambiguity.stderr +++ b/tests/ui/associated-consts/assoc-const-eq-ambiguity.stderr @@ -1,12 +1,12 @@ error[E0222]: ambiguous associated constant `K` in bounds of `Trait0` - --> $DIR/assoc-const-eq-ambiguity.rs:9:25 + --> $DIR/assoc-const-eq-ambiguity.rs:13:25 | -LL | trait Parent0 { const K: (); } - | ----------- - | | - | ambiguous `K` from `Parent0` - | ambiguous `K` from `Parent0` -LL | +LL | const K: (); + | ----------- + | | + | ambiguous `K` from `Parent0` + | ambiguous `K` from `Parent0` +... LL | fn take0(_: impl Trait0) {} | ^^^^^^^^^^ ambiguous associated constant `K` | @@ -17,13 +17,14 @@ LL | fn take0(_: impl Trait0) {} T: Parent0::K = { () } error[E0222]: ambiguous associated constant `C` in bounds of `Trait1` - --> $DIR/assoc-const-eq-ambiguity.rs:16:25 + --> $DIR/assoc-const-eq-ambiguity.rs:26:25 | -LL | trait Parent1 { const C: i32; } - | ------------ ambiguous `C` from `Parent1` -LL | trait Parent2 { const C: &'static str; } - | --------------------- ambiguous `C` from `Parent2` -LL | +LL | const C: i32; + | ------------ ambiguous `C` from `Parent1` +... +LL | const C: &'static str; + | --------------------- ambiguous `C` from `Parent2` +... LL | fn take1(_: impl Trait1) {} | ^^^^^^^ ambiguous associated constant `C` diff --git a/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.rs b/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.rs index e583b12b1d70..f6240ead0b9b 100644 --- a/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.rs +++ b/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.rs @@ -1,8 +1,10 @@ // Check that we eventually catch types of assoc const bounds // (containing late-bound vars) that are ill-formed. -#![feature(associated_const_equality)] +#![feature(associated_const_equality, min_generic_const_args)] +#![allow(incomplete_features)] trait Trait { + #[type_const] const K: T; } diff --git a/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.stderr b/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.stderr index 42e084f39c01..b629bb4d3f8c 100644 --- a/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.stderr +++ b/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.stderr @@ -1,11 +1,11 @@ error: higher-ranked subtype error - --> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:12:13 + --> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:14:13 | LL | K = { () } | ^^^^^^ error: higher-ranked subtype error - --> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:12:13 + --> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:14:13 | LL | K = { () } | ^^^^^^ @@ -13,7 +13,7 @@ LL | K = { () } = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: implementation of `Project` is not general enough - --> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:10:13 + --> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:12:13 | LL | _: impl Trait< | _____________^ diff --git a/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty.rs b/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty.rs index 7fc6d564ca44..36b3d8a648fd 100644 --- a/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty.rs +++ b/tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty.rs @@ -3,9 +3,11 @@ // //@ check-pass -#![feature(associated_const_equality)] +#![feature(associated_const_equality, min_generic_const_args)] +#![allow(incomplete_features)] trait Trait { + #[type_const] const K: T; } diff --git a/tests/ui/associated-consts/assoc-const-eq-const_evaluatable_unchecked.rs b/tests/ui/associated-consts/assoc-const-eq-const_evaluatable_unchecked.rs index 4b6de6f56d55..22a03e47b2f7 100644 --- a/tests/ui/associated-consts/assoc-const-eq-const_evaluatable_unchecked.rs +++ b/tests/ui/associated-consts/assoc-const-eq-const_evaluatable_unchecked.rs @@ -4,9 +4,13 @@ // // issue: //@ check-pass -#![feature(associated_const_equality)] +#![feature(associated_const_equality, min_generic_const_args)] +#![allow(incomplete_features)] -pub trait TraitA { const K: u8 = 0; } +pub trait TraitA { + #[type_const] + const K: u8 = 0; +} pub trait TraitB {} impl TraitA for () {} diff --git a/tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.rs b/tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.rs index 6db1e85ccfa6..3f48b3bfbb6d 100644 --- a/tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.rs +++ b/tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.rs @@ -1,8 +1,10 @@ // Detect and reject escaping late-bound generic params in // the type of assoc consts used in an equality bound. -#![feature(associated_const_equality)] +#![feature(associated_const_equality, min_generic_const_args)] +#![allow(incomplete_features)] trait Trait<'a> { + #[type_const] const K: &'a (); } diff --git a/tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.stderr b/tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.stderr index 349fddcafe8b..d6a7eb6cfc7d 100644 --- a/tests/ui/associated-consts/assoc-const-eq-esc-bound-var-in-ty.stderr +++ b/tests/ui/associated-consts/assoc-const-eq-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/assoc-const-eq-esc-bound-var-in-ty.rs:9:35 + --> $DIR/assoc-const-eq-esc-bound-var-in-ty.rs:11:35 | LL | fn take(_: impl for<'r> Trait<'r, K = { &() }>) {} | -- ^ its type cannot capture the late-bound lifetime parameter `'r` diff --git a/tests/ui/associated-consts/assoc-const-eq-param-in-ty.rs b/tests/ui/associated-consts/assoc-const-eq-param-in-ty.rs index 06fd0a024f00..5b0438e95695 100644 --- a/tests/ui/associated-consts/assoc-const-eq-param-in-ty.rs +++ b/tests/ui/associated-consts/assoc-const-eq-param-in-ty.rs @@ -1,8 +1,10 @@ // Regression test for issue #108271. // Detect and reject generic params in the type of assoc consts used in an equality bound. -#![feature(associated_const_equality)] +#![feature(associated_const_equality, min_generic_const_args)] +#![allow(incomplete_features)] trait Trait<'a, T: 'a, const N: usize> { + #[type_const] const K: &'a [T; N]; } @@ -21,6 +23,7 @@ fn take0<'r, A: 'r, const Q: usize>(_: impl Trait<'r, A, Q, K = { loop {} }>) {} //~| NOTE `K` has type `&'r [A; Q]` trait Project { + #[type_const] const SELF: Self; } diff --git a/tests/ui/associated-consts/assoc-const-eq-param-in-ty.stderr b/tests/ui/associated-consts/assoc-const-eq-param-in-ty.stderr index 6b7b714fff10..7ba1d638baa8 100644 --- a/tests/ui/associated-consts/assoc-const-eq-param-in-ty.stderr +++ b/tests/ui/associated-consts/assoc-const-eq-param-in-ty.stderr @@ -1,5 +1,5 @@ error: the type of the associated constant `K` must not depend on generic parameters - --> $DIR/assoc-const-eq-param-in-ty.rs:9:61 + --> $DIR/assoc-const-eq-param-in-ty.rs:11:61 | LL | fn take0<'r, A: 'r, const Q: usize>(_: impl Trait<'r, A, Q, K = { loop {} }>) {} | -- the lifetime parameter `'r` is defined here ^ its type must not depend on the lifetime parameter `'r` @@ -7,7 +7,7 @@ LL | fn take0<'r, A: 'r, const Q: usize>(_: impl Trait<'r, A, Q, K = { loop {} } = note: `K` has type `&'r [A; Q]` error: the type of the associated constant `K` must not depend on generic parameters - --> $DIR/assoc-const-eq-param-in-ty.rs:9:61 + --> $DIR/assoc-const-eq-param-in-ty.rs:11:61 | LL | fn take0<'r, A: 'r, const Q: usize>(_: impl Trait<'r, A, Q, K = { loop {} }>) {} | - the type parameter `A` is defined here ^ its type must not depend on the type parameter `A` @@ -15,7 +15,7 @@ LL | fn take0<'r, A: 'r, const Q: usize>(_: impl Trait<'r, A, Q, K = { loop {} } = note: `K` has type `&'r [A; Q]` error: the type of the associated constant `K` must not depend on generic parameters - --> $DIR/assoc-const-eq-param-in-ty.rs:9:61 + --> $DIR/assoc-const-eq-param-in-ty.rs:11:61 | LL | fn take0<'r, A: 'r, const Q: usize>(_: impl Trait<'r, A, Q, K = { loop {} }>) {} | - ^ its type must not depend on the const parameter `Q` @@ -25,7 +25,7 @@ LL | fn take0<'r, A: 'r, const Q: usize>(_: impl Trait<'r, A, Q, K = { loop {} } = note: `K` has type `&'r [A; Q]` error: the type of the associated constant `SELF` must not depend on `impl Trait` - --> $DIR/assoc-const-eq-param-in-ty.rs:27:26 + --> $DIR/assoc-const-eq-param-in-ty.rs:30:26 | LL | fn take1(_: impl Project) {} | -------------^^^^------ @@ -34,7 +34,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/assoc-const-eq-param-in-ty.rs:32:21 + --> $DIR/assoc-const-eq-param-in-ty.rs:35:21 | LL | fn take2>(_: P) {} | - ^^^^ its type must not depend on the type parameter `P` @@ -44,7 +44,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/assoc-const-eq-param-in-ty.rs:41:52 + --> $DIR/assoc-const-eq-param-in-ty.rs:44:52 | LL | trait Iface<'r> { | -- the lifetime parameter `'r` is defined here @@ -55,7 +55,7 @@ LL | type Assoc: Trait<'r, Self, Q, K = { loop {} }> = note: `K` has type `&'r [Self; Q]` error: the type of the associated constant `K` must not depend on `Self` - --> $DIR/assoc-const-eq-param-in-ty.rs:41:52 + --> $DIR/assoc-const-eq-param-in-ty.rs:44:52 | LL | type Assoc: Trait<'r, Self, Q, K = { loop {} }> | ^ its type must not depend on `Self` @@ -63,7 +63,7 @@ LL | type Assoc: Trait<'r, Self, Q, K = { loop {} }> = note: `K` has type `&'r [Self; Q]` error: the type of the associated constant `K` must not depend on generic parameters - --> $DIR/assoc-const-eq-param-in-ty.rs:41:52 + --> $DIR/assoc-const-eq-param-in-ty.rs:44:52 | LL | type Assoc: Trait<'r, Self, Q, K = { loop {} }> | - ^ its type must not depend on the const parameter `Q` @@ -73,7 +73,7 @@ LL | type Assoc: Trait<'r, Self, Q, K = { loop {} }> = note: `K` has type `&'r [Self; Q]` error: the type of the associated constant `K` must not depend on generic parameters - --> $DIR/assoc-const-eq-param-in-ty.rs:41:52 + --> $DIR/assoc-const-eq-param-in-ty.rs:44:52 | LL | trait Iface<'r> { | -- the lifetime parameter `'r` is defined here @@ -85,7 +85,7 @@ LL | type Assoc: Trait<'r, Self, Q, K = { 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/assoc-const-eq-param-in-ty.rs:41:52 + --> $DIR/assoc-const-eq-param-in-ty.rs:44:52 | LL | type Assoc: Trait<'r, Self, Q, K = { loop {} }> | ^ its type must not depend on `Self` @@ -94,7 +94,7 @@ LL | type Assoc: Trait<'r, Self, Q, K = { 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/assoc-const-eq-param-in-ty.rs:41:52 + --> $DIR/assoc-const-eq-param-in-ty.rs:44:52 | LL | type Assoc: Trait<'r, Self, Q, K = { loop {} }> | - ^ its type must not depend on the const parameter `Q` diff --git a/tests/ui/associated-consts/assoc-const-eq-supertraits.rs b/tests/ui/associated-consts/assoc-const-eq-supertraits.rs index d5d724c9b153..301ddf2d0104 100644 --- a/tests/ui/associated-consts/assoc-const-eq-supertraits.rs +++ b/tests/ui/associated-consts/assoc-const-eq-supertraits.rs @@ -3,11 +3,13 @@ //@ check-pass -#![feature(associated_const_equality)] +#![feature(associated_const_equality, min_generic_const_args)] +#![allow(incomplete_features)] trait Trait: SuperTrait {} trait SuperTrait: SuperSuperTrait {} trait SuperSuperTrait { + #[type_const] const K: T; } diff --git a/tests/ui/associated-consts/assoc-const-eq-ty-alias-noninteracting.rs b/tests/ui/associated-consts/assoc-const-eq-ty-alias-noninteracting.rs index 76df014ccd9b..febd838e2c2e 100644 --- a/tests/ui/associated-consts/assoc-const-eq-ty-alias-noninteracting.rs +++ b/tests/ui/associated-consts/assoc-const-eq-ty-alias-noninteracting.rs @@ -5,16 +5,19 @@ //@ check-pass -#![feature(associated_const_equality)] +#![feature(associated_const_equality, min_generic_const_args)] +#![allow(incomplete_features)] trait Trait: SuperTrait { type N; type Q; + #[type_const] const N: usize; } trait SuperTrait { + #[type_const] const Q: &'static str; } diff --git a/tests/ui/associated-consts/assoc-const.rs b/tests/ui/associated-consts/assoc-const.rs index 5b272cfeb0c2..4eed8bba53b1 100644 --- a/tests/ui/associated-consts/assoc-const.rs +++ b/tests/ui/associated-consts/assoc-const.rs @@ -1,14 +1,16 @@ //@ run-pass -#![feature(associated_const_equality)] -#![allow(unused)] +#![feature(associated_const_equality, min_generic_const_args)] +#![allow(unused, incomplete_features)] pub trait Foo { + #[type_const] const N: usize; } pub struct Bar; impl Foo for Bar { + #[type_const] const N: usize = 3; } diff --git a/tests/ui/associated-consts/equality-unused-issue-126729.rs b/tests/ui/associated-consts/equality-unused-issue-126729.rs index 1482b874b9d6..35b49314b5f5 100644 --- a/tests/ui/associated-consts/equality-unused-issue-126729.rs +++ b/tests/ui/associated-consts/equality-unused-issue-126729.rs @@ -1,25 +1,32 @@ //@ check-pass -#![feature(associated_const_equality)] +#![feature(associated_const_equality, min_generic_const_args)] +#![allow(incomplete_features)] #![deny(dead_code)] trait Tr { + #[type_const] const I: i32; } impl Tr for () { + #[type_const] const I: i32 = 1; } fn foo() -> impl Tr {} trait Tr2 { + #[type_const] const J: i32; + #[type_const] const K: i32; } impl Tr2 for () { + #[type_const] const J: i32 = 1; + #[type_const] const K: i32 = 1; } @@ -27,10 +34,12 @@ fn foo2() -> impl Tr2 {} mod t { pub trait Tr3 { + #[type_const] const L: i32; } impl Tr3 for () { + #[type_const] const L: i32 = 1; } } diff --git a/tests/ui/associated-consts/issue-102335-const.rs b/tests/ui/associated-consts/issue-102335-const.rs index fd922cd0f1d8..f9b816fd3bc9 100644 --- a/tests/ui/associated-consts/issue-102335-const.rs +++ b/tests/ui/associated-consts/issue-102335-const.rs @@ -1,4 +1,5 @@ -#![feature(associated_const_equality)] +#![feature(associated_const_equality, min_generic_const_args)] +#![allow(incomplete_features)] trait T { type A: S = 34>; @@ -7,6 +8,7 @@ trait T { } trait S { + #[type_const] const C: i32; } diff --git a/tests/ui/associated-consts/issue-102335-const.stderr b/tests/ui/associated-consts/issue-102335-const.stderr index cf96c8cf8eb9..536e39e5522d 100644 --- a/tests/ui/associated-consts/issue-102335-const.stderr +++ b/tests/ui/associated-consts/issue-102335-const.stderr @@ -1,5 +1,5 @@ error[E0229]: associated item constraints are not allowed here - --> $DIR/issue-102335-const.rs:4:17 + --> $DIR/issue-102335-const.rs:5:17 | LL | type A: S = 34>; | ^^^^^^^^ associated item constraint not allowed here @@ -11,7 +11,7 @@ LL + type A: S; | error[E0229]: associated item constraints are not allowed here - --> $DIR/issue-102335-const.rs:4:17 + --> $DIR/issue-102335-const.rs:5:17 | LL | type A: S = 34>; | ^^^^^^^^ associated item constraint not allowed here diff --git a/tests/ui/associated-consts/issue-110933.rs b/tests/ui/associated-consts/issue-110933.rs index efd7e13e4bcd..0284369f4d65 100644 --- a/tests/ui/associated-consts/issue-110933.rs +++ b/tests/ui/associated-consts/issue-110933.rs @@ -1,8 +1,10 @@ //@ check-pass -#![feature(associated_const_equality)] +#![feature(associated_const_equality, min_generic_const_args)] +#![allow(incomplete_features)] pub trait Trait { + #[type_const] const ASSOC: usize; } diff --git a/tests/ui/associated-consts/projection-unspecified-but-bounded.rs b/tests/ui/associated-consts/projection-unspecified-but-bounded.rs index b1a0f39962b6..7f3304f07656 100644 --- a/tests/ui/associated-consts/projection-unspecified-but-bounded.rs +++ b/tests/ui/associated-consts/projection-unspecified-but-bounded.rs @@ -1,8 +1,10 @@ -#![feature(associated_const_equality)] +#![feature(associated_const_equality, min_generic_const_args)] +#![allow(incomplete_features)] // Issue 110549 pub trait TraitWAssocConst { + #[type_const] const A: usize; } diff --git a/tests/ui/associated-consts/projection-unspecified-but-bounded.stderr b/tests/ui/associated-consts/projection-unspecified-but-bounded.stderr index 91bfcf29cb37..232b15b7e981 100644 --- a/tests/ui/associated-consts/projection-unspecified-but-bounded.stderr +++ b/tests/ui/associated-consts/projection-unspecified-but-bounded.stderr @@ -1,5 +1,5 @@ error[E0271]: type mismatch resolving `::A == 32` - --> $DIR/projection-unspecified-but-bounded.rs:12: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:9:28 + --> $DIR/projection-unspecified-but-bounded.rs:11:28 | LL | fn foo>() {} | ^^^^^^ required by this bound in `foo` diff --git a/tests/ui/associated-type-bounds/const-projection-err.gce.stderr b/tests/ui/associated-type-bounds/const-projection-err.gce.stderr index 0b6207074979..9ad851d188d3 100644 --- a/tests/ui/associated-type-bounds/const-projection-err.gce.stderr +++ b/tests/ui/associated-type-bounds/const-projection-err.gce.stderr @@ -1,24 +1,15 @@ -warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/const-projection-err.rs:4:26 - | -LL | #![cfg_attr(gce, feature(generic_const_exprs))] - | ^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #76560 for more information - = note: `#[warn(incomplete_features)]` on by default - error[E0271]: type mismatch resolving `::A == 1` - --> $DIR/const-projection-err.rs:14:11 + --> $DIR/const-projection-err.rs:16:11 | LL | foo::(); | ^ expected `0`, found `1` | note: required by a bound in `foo` - --> $DIR/const-projection-err.rs:11:28 + --> $DIR/const-projection-err.rs:13:28 | LL | fn foo>() {} | ^^^^^ required by this bound in `foo` -error: aborting due to 1 previous error; 1 warning emitted +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0271`. diff --git a/tests/ui/associated-type-bounds/const-projection-err.rs b/tests/ui/associated-type-bounds/const-projection-err.rs index 22f1897c07f1..80845ec3ee86 100644 --- a/tests/ui/associated-type-bounds/const-projection-err.rs +++ b/tests/ui/associated-type-bounds/const-projection-err.rs @@ -1,10 +1,12 @@ //@ revisions: stock gce -#![feature(associated_const_equality)] +#![feature(associated_const_equality, min_generic_const_args)] +#![allow(incomplete_features)] + #![cfg_attr(gce, feature(generic_const_exprs))] -//[gce]~^ WARN the feature `generic_const_exprs` is incomplete trait TraitWAssocConst { + #[type_const] const A: usize; } diff --git a/tests/ui/associated-type-bounds/const-projection-err.stock.stderr b/tests/ui/associated-type-bounds/const-projection-err.stock.stderr index e782571c7dea..0cacec26aaee 100644 --- a/tests/ui/associated-type-bounds/const-projection-err.stock.stderr +++ b/tests/ui/associated-type-bounds/const-projection-err.stock.stderr @@ -1,13 +1,13 @@ error[E0271]: type mismatch resolving `::A == 1` - --> $DIR/const-projection-err.rs:14:11 + --> $DIR/const-projection-err.rs:16:11 | LL | foo::(); - | ^ expected `1`, found `::A` + | ^ expected `1`, found `0` | = note: expected constant `1` - found constant `::A` + found constant `0` note: required by a bound in `foo` - --> $DIR/const-projection-err.rs:11:28 + --> $DIR/const-projection-err.rs:13:28 | LL | fn foo>() {} | ^^^^^ required by this bound in `foo` diff --git a/tests/ui/const-generics/associated_const_equality/equality_bound_with_infer.rs b/tests/ui/const-generics/associated_const_equality/equality_bound_with_infer.rs index dc42e00c2e83..3973c7af15b4 100644 --- a/tests/ui/const-generics/associated_const_equality/equality_bound_with_infer.rs +++ b/tests/ui/const-generics/associated_const_equality/equality_bound_with_infer.rs @@ -1,14 +1,18 @@ -#![feature(associated_const_equality, generic_const_items)] +//@ check-pass + +#![feature(associated_const_equality, min_generic_const_args, generic_const_items)] #![expect(incomplete_features)] // Regression test for #133066 where we would try to evaluate `<() as Foo>::ASSOC<_>` even // though it contained inference variables, which would cause ICEs. trait Foo { + #[type_const] const ASSOC: u32; } impl Foo for () { + #[type_const] const ASSOC: u32 = N; } @@ -16,9 +20,4 @@ fn bar = 10>>() {} fn main() { bar::<_, ()>(); - //~^ ERROR: type mismatch resolving `<() as Foo>::ASSOC<_> == 10` - - // FIXME(mgca): - // FIXME(associated_const_equality): - // This ought to start compiling once const items are aliases rather than bodies } diff --git a/tests/ui/const-generics/associated_const_equality/equality_bound_with_infer.stderr b/tests/ui/const-generics/associated_const_equality/equality_bound_with_infer.stderr deleted file mode 100644 index 00741c901e4c..000000000000 --- a/tests/ui/const-generics/associated_const_equality/equality_bound_with_infer.stderr +++ /dev/null @@ -1,17 +0,0 @@ -error[E0271]: type mismatch resolving `<() as Foo>::ASSOC<_> == 10` - --> $DIR/equality_bound_with_infer.rs:18:14 - | -LL | bar::<_, ()>(); - | ^^ expected `10`, found `<() as Foo>::ASSOC::<_>` - | - = note: expected constant `10` - found constant `<() as Foo>::ASSOC::<_>` -note: required by a bound in `bar` - --> $DIR/equality_bound_with_infer.rs:15:29 - | -LL | fn bar = 10>>() {} - | ^^^^^^^^^^^^^ required by this bound in `bar` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0271`. diff --git a/tests/ui/const-generics/associated_const_equality/unconstrained_impl_param.rs b/tests/ui/const-generics/associated_const_equality/unconstrained_impl_param.rs index 99318ef75984..edadcd7c80ed 100644 --- a/tests/ui/const-generics/associated_const_equality/unconstrained_impl_param.rs +++ b/tests/ui/const-generics/associated_const_equality/unconstrained_impl_param.rs @@ -19,7 +19,7 @@ impl Trait for () where (U,): AssocConst {} fn foo() where (): Trait, - //~^ ERROR type mismatch resolving + //~^ ERROR type annotations needed { } diff --git a/tests/ui/const-generics/associated_const_equality/unconstrained_impl_param.stderr b/tests/ui/const-generics/associated_const_equality/unconstrained_impl_param.stderr index e6799ec5c3aa..4106c500215b 100644 --- a/tests/ui/const-generics/associated_const_equality/unconstrained_impl_param.stderr +++ b/tests/ui/const-generics/associated_const_equality/unconstrained_impl_param.stderr @@ -14,26 +14,13 @@ error[E0207]: the type parameter `U` is not constrained by the impl trait, self LL | impl Trait for () where (U,): AssocConst {} | ^ unconstrained type parameter -error[E0271]: type mismatch resolving `<(_,) as AssocConst>::A == 0` +error[E0282]: type annotations needed --> $DIR/unconstrained_impl_param.rs:21:5 | LL | (): Trait, - | ^^^^^^^^^ expected `0`, found `<(_,) as AssocConst>::A` - | - = note: expected constant `0` - found constant `<(_,) as AssocConst>::A` -note: required for `()` to implement `Trait` - --> $DIR/unconstrained_impl_param.rs:15:9 - | -LL | impl Trait for () where (U,): AssocConst {} - | ^^^^^ ^^ --------- unsatisfied trait bound introduced here - = help: see issue #48214 -help: add `#![feature(trivial_bounds)]` to the crate attributes to enable - | -LL + #![feature(trivial_bounds)] - | + | ^^^^^^^^^ cannot infer type for type parameter `U` error: aborting due to 3 previous errors -Some errors have detailed explanations: E0207, E0271, E0658. +Some errors have detailed explanations: E0207, E0282, E0658. For more information about an error, try `rustc --explain E0207`. 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 1e9673a56b56..bb5bdb8d7c4c 100644 --- a/tests/ui/const-generics/mgca/bad-type_const-syntax.rs +++ b/tests/ui/const-generics/mgca/bad-type_const-syntax.rs @@ -9,8 +9,7 @@ trait Tr { impl Tr for S { #[type_const] - //~^ ERROR must only be applied to trait associated constants - //~| ERROR experimental + //~^ ERROR experimental const N: usize = 0; } 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 125c778ef1cd..df442c22241b 100644 --- a/tests/ui/const-generics/mgca/bad-type_const-syntax.stderr +++ b/tests/ui/const-generics/mgca/bad-type_const-syntax.stderr @@ -27,13 +27,7 @@ LL | #[type_const()] | | didn't expect any arguments here | help: must be of the form: `#[type_const]` -error: `#[type_const]` must only be applied to trait associated constants - --> $DIR/bad-type_const-syntax.rs:11:5 - | -LL | #[type_const] - | ^^^^^^^^^^^^^ - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0565, E0658. For more information about an error, try `rustc --explain E0565`. diff --git a/tests/ui/const-generics/mgca/projection-error.rs b/tests/ui/const-generics/mgca/projection-error.rs index d1c4fa8a492d..edb6db098084 100644 --- a/tests/ui/const-generics/mgca/projection-error.rs +++ b/tests/ui/const-generics/mgca/projection-error.rs @@ -7,6 +7,7 @@ pub trait Tr { + #[type_const] const SIZE: usize; } diff --git a/tests/ui/const-generics/mgca/projection-error.stderr b/tests/ui/const-generics/mgca/projection-error.stderr index e6888351da13..e60acf9144b5 100644 --- a/tests/ui/const-generics/mgca/projection-error.stderr +++ b/tests/ui/const-generics/mgca/projection-error.stderr @@ -1,5 +1,5 @@ error[E0412]: cannot find type `T` in this scope - --> $DIR/projection-error.rs:13:17 + --> $DIR/projection-error.rs:14:17 | LL | pub trait Tr { | --------------- similarly named trait `Tr` defined here @@ -17,7 +17,7 @@ LL | fn mk_array(_x: T) -> [(); >::SIZE] {} | +++ error[E0412]: cannot find type `T` in this scope - --> $DIR/projection-error.rs:13:29 + --> $DIR/projection-error.rs:14:29 | LL | pub trait Tr { | --------------- similarly named trait `Tr` defined here 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 2607013ec633..57b748a6b475 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 @@ -1,6 +1,6 @@ // ICE: assertion failed: !value.has_infer() // issue: rust-lang/rust#115806 -#![feature(associated_const_equality)] +#![feature(associated_const_equality, min_generic_const_args)] #![allow(incomplete_features)] pub struct NoPin; @@ -8,6 +8,7 @@ impl Pins for NoPin {} pub trait PinA { + #[type_const] const A: &'static () = &(); } 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 9a9baaddcba3..34546349592f 100644 --- a/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.stderr +++ b/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `Pins<_>` for type `NoPin` - --> $DIR/assoc-const-no-infer-ice-115806.rs:16:1 + --> $DIR/assoc-const-no-infer-ice-115806.rs:17:1 | LL | impl Pins for NoPin {} | --------------------------- first implementation here diff --git a/tests/ui/generic-const-items/associated-const-equality.rs b/tests/ui/generic-const-items/associated-const-equality.rs index c0179f02fd2e..0620998188b2 100644 --- a/tests/ui/generic-const-items/associated-const-equality.rs +++ b/tests/ui/generic-const-items/associated-const-equality.rs @@ -1,17 +1,24 @@ //@ check-pass -#![feature(generic_const_items, associated_const_equality, adt_const_params)] +#![feature(generic_const_items, min_generic_const_args)] +#![feature(associated_const_equality, adt_const_params)] #![allow(incomplete_features)] trait Owner { + #[type_const] const C: u32; + #[type_const] const K: u32; + #[type_const] const Q: Maybe; } impl Owner for () { + #[type_const] const C: u32 = N; - const K: u32 = N + 1; + #[type_const] + const K: u32 = 99 + 1; + #[type_const] const Q: Maybe = Maybe::Nothing; } 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 f4cde1d62b2c..edea6f75444f 100644 --- a/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.rs +++ b/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.rs @@ -1,12 +1,15 @@ // Regression test for #140571. The compiler used to ICE -#![feature(associated_const_equality, specialization)] +#![feature(associated_const_equality, min_generic_const_args, specialization)] //~^ WARN the feature `specialization` is incomplete +//~| WARN the feature `min_generic_const_args` is incomplete pub trait IsVoid { + #[type_const] const IS_VOID: bool; } impl IsVoid for T { + #[type_const] default const IS_VOID: bool = false; } diff --git a/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.stderr b/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.stderr index a26b30fbb633..bf15d0fae4e5 100644 --- a/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.stderr +++ b/tests/ui/specialization/overlap-due-to-unsatisfied-const-bound.stderr @@ -1,21 +1,29 @@ -warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes +warning: the feature `min_generic_const_args` is incomplete and may not be safe to use and/or cause compiler crashes --> $DIR/overlap-due-to-unsatisfied-const-bound.rs:3:39 | -LL | #![feature(associated_const_equality, specialization)] - | ^^^^^^^^^^^^^^ +LL | #![feature(associated_const_equality, min_generic_const_args, specialization)] + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #132980 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/overlap-due-to-unsatisfied-const-bound.rs:3:63 + | +LL | #![feature(associated_const_equality, min_generic_const_args, specialization)] + | ^^^^^^^^^^^^^^ | = note: see issue #31844 for more information = help: consider using `min_specialization` instead, which is more stable and complete - = note: `#[warn(incomplete_features)]` on by default error[E0119]: conflicting implementations of trait `Maybe<()>` for type `()` - --> $DIR/overlap-due-to-unsatisfied-const-bound.rs:18:1 + --> $DIR/overlap-due-to-unsatisfied-const-bound.rs:21:1 | LL | impl Maybe for T {} | ---------------------- first implementation here LL | impl Maybe for () where T: NotVoid + ?Sized {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()` -error: aborting due to 1 previous error; 1 warning emitted +error: aborting due to 1 previous error; 2 warnings emitted For more information about this error, try `rustc --explain E0119`.