fix associated_const_equality tests

This commit is contained in:
Boxy Uwu
2025-10-13 21:58:36 +01:00
committed by Noah Lev
parent a7626dc996
commit 0a355170c0
39 changed files with 194 additions and 164 deletions
@@ -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(_) => {}
@@ -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)
}
-20
View File
@@ -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)]
+3 -10
View File
@@ -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();
}
}
@@ -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<i32> + Parent0<u32> {}
trait Parent0<T> { const K: (); }
trait Parent0<T> {
#[type_const]
const K: ();
}
fn take0(_: impl Trait0<K = { () }>) {}
//~^ 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<C = "?">) {}
//~^ ERROR ambiguous associated constant `C` in bounds of `Trait1`
@@ -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<T> { const K: (); }
| -----------
| |
| ambiguous `K` from `Parent0<u32>`
| ambiguous `K` from `Parent0<i32>`
LL |
LL | const K: ();
| -----------
| |
| ambiguous `K` from `Parent0<u32>`
| ambiguous `K` from `Parent0<i32>`
...
LL | fn take0(_: impl Trait0<K = { () }>) {}
| ^^^^^^^^^^ ambiguous associated constant `K`
|
@@ -17,13 +17,14 @@ LL | fn take0(_: impl Trait0<K = { () }>) {}
T: Parent0<i32>::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<C = "?">) {}
| ^^^^^^^ ambiguous associated constant `C`
@@ -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<T> {
#[type_const]
const K: T;
}
@@ -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<
| _____________^
@@ -3,9 +3,11 @@
//
//@ check-pass
#![feature(associated_const_equality)]
#![feature(associated_const_equality, min_generic_const_args)]
#![allow(incomplete_features)]
trait Trait<T> {
#[type_const]
const K: T;
}
@@ -4,9 +4,13 @@
//
// issue: <https://github.com/rust-lang/rust/issues/108220>
//@ check-pass
#![feature(associated_const_equality)]
#![feature(associated_const_equality, min_generic_const_args)]
#![allow(incomplete_features)]
pub trait TraitA<T> { const K: u8 = 0; }
pub trait TraitA<T> {
#[type_const]
const K: u8 = 0;
}
pub trait TraitB<T> {}
impl<T> TraitA<T> for () {}
@@ -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 ();
}
@@ -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`
@@ -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;
}
@@ -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<SELF = {}>) {}
| -------------^^^^------
@@ -34,7 +34,7 @@ LL | fn take1(_: impl Project<SELF = {}>) {}
| 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: Project<SELF = {}>>(_: P) {}
| - ^^^^ its type must not depend on the type parameter `P`
@@ -44,7 +44,7 @@ LL | fn take2<P: Project<SELF = {}>>(_: 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<const Q: usize>: 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<const Q: usize>: Trait<'r, Self, Q, K = { loop {} }>
| ^ its type must not depend on `Self`
@@ -63,7 +63,7 @@ LL | type Assoc<const Q: usize>: 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<const Q: usize>: Trait<'r, Self, Q, K = { loop {} }>
| - ^ its type must not depend on the const parameter `Q`
@@ -73,7 +73,7 @@ LL | type Assoc<const Q: usize>: 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<const Q: usize>: 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<const Q: usize>: Trait<'r, Self, Q, K = { loop {} }>
| ^ its type must not depend on `Self`
@@ -94,7 +94,7 @@ LL | type Assoc<const Q: usize>: 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<const Q: usize>: Trait<'r, Self, Q, K = { loop {} }>
| - ^ its type must not depend on the const parameter `Q`
@@ -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<i32> {}
trait SuperSuperTrait<T> {
#[type_const]
const K: T;
}
@@ -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;
}
+4 -2
View File
@@ -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;
}
@@ -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<I = 1> {}
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<J = 1, K = 1> {}
mod t {
pub trait Tr3 {
#[type_const]
const L: i32;
}
impl Tr3 for () {
#[type_const]
const L: i32 = 1;
}
}
@@ -1,4 +1,5 @@
#![feature(associated_const_equality)]
#![feature(associated_const_equality, min_generic_const_args)]
#![allow(incomplete_features)]
trait T {
type A: S<C<X = 0i32> = 34>;
@@ -7,6 +8,7 @@ trait T {
}
trait S {
#[type_const]
const C: i32;
}
@@ -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<C<X = 0i32> = 34>;
| ^^^^^^^^ associated item constraint not allowed here
@@ -11,7 +11,7 @@ LL + type A: S<C = 34>;
|
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<C<X = 0i32> = 34>;
| ^^^^^^^^ associated item constraint not allowed here
+3 -1
View File
@@ -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;
}
@@ -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;
}
@@ -1,5 +1,5 @@
error[E0271]: type mismatch resolving `<T as TraitWAssocConst>::A == 32`
--> $DIR/projection-unspecified-but-bounded.rs:12:11
--> $DIR/projection-unspecified-but-bounded.rs:14:11
|
LL | foo::<T>();
| ^ expected `32`, found `<T as TraitWAssocConst>::A`
@@ -7,7 +7,7 @@ LL | foo::<T>();
= note: expected constant `32`
found constant `<T as TraitWAssocConst>::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<T: TraitWAssocConst<A = 32>>() {}
| ^^^^^^ required by this bound in `foo`
@@ -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 <https://github.com/rust-lang/rust/issues/76560> for more information
= note: `#[warn(incomplete_features)]` on by default
error[E0271]: type mismatch resolving `<T as TraitWAssocConst>::A == 1`
--> $DIR/const-projection-err.rs:14:11
--> $DIR/const-projection-err.rs:16:11
|
LL | foo::<T>();
| ^ 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<T: TraitWAssocConst<A = 1>>() {}
| ^^^^^ 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`.
@@ -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;
}
@@ -1,13 +1,13 @@
error[E0271]: type mismatch resolving `<T as TraitWAssocConst>::A == 1`
--> $DIR/const-projection-err.rs:14:11
--> $DIR/const-projection-err.rs:16:11
|
LL | foo::<T>();
| ^ expected `1`, found `<T as TraitWAssocConst>::A`
| ^ expected `1`, found `0`
|
= note: expected constant `1`
found constant `<T as TraitWAssocConst>::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<T: TraitWAssocConst<A = 1>>() {}
| ^^^^^ required by this bound in `foo`
@@ -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<const N: u32>: u32;
}
impl Foo for () {
#[type_const]
const ASSOC<const N: u32>: u32 = N;
}
@@ -16,9 +20,4 @@ fn bar<const N: u32, T: Foo<ASSOC<N> = 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
}
@@ -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<const N: u32, T: Foo<ASSOC<N> = 10>>() {}
| ^^^^^^^^^^^^^ required by this bound in `bar`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0271`.
@@ -19,7 +19,7 @@ impl<U> Trait for () where (U,): AssocConst<A = { 0 }> {}
fn foo()
where
(): Trait,
//~^ ERROR type mismatch resolving
//~^ ERROR type annotations needed
{
}
@@ -14,26 +14,13 @@ error[E0207]: the type parameter `U` is not constrained by the impl trait, self
LL | impl<U> Trait for () where (U,): AssocConst<A = { 0 }> {}
| ^ 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<U> Trait for () where (U,): AssocConst<A = { 0 }> {}
| ^^^^^ ^^ --------- 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`.
@@ -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;
}
@@ -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`.
@@ -7,6 +7,7 @@
pub trait Tr<A> {
#[type_const]
const SIZE: usize;
}
@@ -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<A> {
| --------------- similarly named trait `Tr` defined here
@@ -17,7 +17,7 @@ LL | fn mk_array<T>(_x: T) -> [(); <T as Tr<bool>>::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<A> {
| --------------- similarly named trait `Tr` defined here
@@ -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<TA> Pins<TA> for NoPin {}
pub trait PinA<PER> {
#[type_const]
const A: &'static () = &();
}
@@ -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<TA> Pins<TA> for NoPin {}
| --------------------------- first implementation here
@@ -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<const N: u32>: u32;
#[type_const]
const K<const N: u32>: u32;
#[type_const]
const Q<T>: Maybe<T>;
}
impl Owner for () {
#[type_const]
const C<const N: u32>: u32 = N;
const K<const N: u32>: u32 = N + 1;
#[type_const]
const K<const N: u32>: u32 = 99 + 1;
#[type_const]
const Q<T>: Maybe<T> = Maybe::Nothing;
}
@@ -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<T> IsVoid for T {
#[type_const]
default const IS_VOID: bool = false;
}
@@ -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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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<T> Maybe<T> for T {}
| ---------------------- first implementation here
LL | impl<T> Maybe<T> 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`.