From a16442e0b3f7f0614c422e0fc0515dd0968a6bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Wed, 19 Aug 2026 15:21:39 +0200 Subject: [PATCH] Also enforce dyn compatibility in (unchecked) type aliases --- .../src/error_codes/E0224.md | 2 +- .../rustc_hir_analysis/src/check/check.rs | 21 +++++---- .../inline_cross/auxiliary/dyn_trait.rs | 2 +- .../cfg-generic-params.rs | 8 ++-- .../cfg-generic-params.stderr | 4 +- .../in-unchecked-type-alias.rs | 15 +++++++ .../in-unchecked-type-alias.stderr | 45 +++++++++++++++++++ tests/ui/hygiene/assoc_ty_bindings.rs | 8 ++-- tests/ui/resolve/issue-3907-2.rs | 6 +-- tests/ui/resolve/issue-3907-2.stderr | 15 ++++++- tests/ui/resolve/issue-3907.rs | 2 +- tests/ui/resolve/issue-3907.stderr | 18 +++++++- .../trait-alias-elaboration.rs | 2 +- .../trait-alias-elaboration.stderr | 6 +-- .../lack-of-wfcheck-gat-generic-const-args.rs | 21 --------- ...k-of-wfcheck-gat-generic-const-args.stderr | 34 -------------- ...k-of-wfcheck-generic-const-args.gca.stderr | 16 +++---- ...f-wfcheck-generic-const-args.no_gca.stderr | 19 ++++++++ .../lack-of-wfcheck-generic-const-args.rs | 26 +++++------ tests/ui/type-alias/lack-of-wfcheck.rs | 24 +++++----- 20 files changed, 173 insertions(+), 121 deletions(-) create mode 100644 tests/ui/dyn-compatibility/in-unchecked-type-alias.rs create mode 100644 tests/ui/dyn-compatibility/in-unchecked-type-alias.stderr delete mode 100644 tests/ui/type-alias/lack-of-wfcheck-gat-generic-const-args.rs delete mode 100644 tests/ui/type-alias/lack-of-wfcheck-gat-generic-const-args.stderr create mode 100644 tests/ui/type-alias/lack-of-wfcheck-generic-const-args.no_gca.stderr diff --git a/compiler/rustc_error_codes/src/error_codes/E0224.md b/compiler/rustc_error_codes/src/error_codes/E0224.md index 628488575b2f8..a6fd0e0fd3a48 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0224.md +++ b/compiler/rustc_error_codes/src/error_codes/E0224.md @@ -11,5 +11,5 @@ Rust does not currently support this. To solve, ensure that the trait object has at least one trait: ``` -type Foo = dyn 'static + Copy; +type Foo = dyn 'static + std::fmt::Debug; ``` diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 01df2e199a5ac..ace32c7088406 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -985,6 +985,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), } else { check_type_alias_type_params_are_used(tcx, def_id); res = res.and(enter_wf_checking_ctxt(tcx, def_id, |wfcx| { + // FIXME(fmease): Update comment. // HACK: We sometimes incidentally check that const arguments have the correct // type as a side effect of the anon const desugaring. To make this "consistent" // for users we explicitly check `ConstArgHasType` clauses so that const args @@ -995,15 +996,19 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), // // Changing this to normalized obligations is a breaking change: // `type Bar = [(); panic!()];` would become an error - if let Some(unnormalized_obligations) = wfcx.unnormalized_obligations(span, ty.skip_norm_wip()) + if let Some(obligations) = + wfcx.unnormalized_obligations(span, ty.skip_norm_wip()) { - let filtered_obligations = - unnormalized_obligations.into_iter().filter(|o| { - matches!(o.predicate.kind().skip_binder(), - ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, _)) - if matches!(ct.kind(), ty::ConstKind::Param(..))) - }); - wfcx.ocx.register_obligations(filtered_obligations) + wfcx.ocx.register_obligations(obligations.into_iter().filter(|o| { + match o.predicate.kind().skip_binder() { + ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType( + ct, + _, + )) => matches!(ct.kind(), ty::ConstKind::Param(..)), + ty::PredicateKind::DynCompatible(_) => true, + _ => false, + } + })) } Ok(()) })); diff --git a/tests/rustdoc-html/inline_cross/auxiliary/dyn_trait.rs b/tests/rustdoc-html/inline_cross/auxiliary/dyn_trait.rs index 07a95af7b54e8..35bca80ce3f34 100644 --- a/tests/rustdoc-html/inline_cross/auxiliary/dyn_trait.rs +++ b/tests/rustdoc-html/inline_cross/auxiliary/dyn_trait.rs @@ -9,7 +9,7 @@ pub type Ty2 = dyn for<'a, 'r> Container<'r, Item<'a, 'static> = ()>; pub type Ty3<'s> = &'s dyn ToString; pub trait Container<'r> { - type Item<'a, 'ctx>; + type Item<'a, 'ctx> where Self: Sized; } // Trait-object types inside of a container type that has lifetime bounds ("wrapped"). diff --git a/tests/ui/conditional-compilation/cfg-generic-params.rs b/tests/ui/conditional-compilation/cfg-generic-params.rs index 6480a0f24794c..9044fd65ac978 100644 --- a/tests/ui/conditional-compilation/cfg-generic-params.rs +++ b/tests/ui/conditional-compilation/cfg-generic-params.rs @@ -7,8 +7,8 @@ type FnGood = for<#[cfg(yes)] 'a, #[cfg(false)] T> fn(); // OK type FnBad = for<#[cfg(false)] 'a, #[cfg(yes)] T> fn(); //~^ ERROR only lifetime parameters can be used in this context -type PolyGood = dyn for<#[cfg(yes)] 'a, #[cfg(false)] T> Copy; // OK -type PolyBad = dyn for<#[cfg(false)] 'a, #[cfg(yes)] T> Copy; +type PolyGood = dyn for<#[cfg(yes)] 'a, #[cfg(false)] T> std::any::Any; // OK +type PolyBad = dyn for<#[cfg(false)] 'a, #[cfg(yes)] T> std::any::Any; //~^ ERROR only lifetime parameters can be used in this context struct WhereGood where for<#[cfg(yes)] 'a, #[cfg(false)] T> u8: Copy; // OK @@ -26,8 +26,8 @@ type FnNo = for<#[cfg_attr(FALSE, unknown)] 'a> fn(); // OK type FnYes = for<#[cfg_attr(yes, unknown)] 'a> fn(); //~^ ERROR cannot find attribute `unknown` in this scope -type PolyNo = dyn for<#[cfg_attr(FALSE, unknown)] 'a> Copy; // OK -type PolyYes = dyn for<#[cfg_attr(yes, unknown)] 'a> Copy; +type PolyNo = dyn for<#[cfg_attr(FALSE, unknown)] 'a> std::any::Any; // OK +type PolyYes = dyn for<#[cfg_attr(yes, unknown)] 'a> std::any::Any; //~^ ERROR cannot find attribute `unknown` in this scope struct WhereNo where for<#[cfg_attr(FALSE, unknown)] 'a> u8: Copy; // OK diff --git a/tests/ui/conditional-compilation/cfg-generic-params.stderr b/tests/ui/conditional-compilation/cfg-generic-params.stderr index bae75dd0deb03..572ff815e351e 100644 --- a/tests/ui/conditional-compilation/cfg-generic-params.stderr +++ b/tests/ui/conditional-compilation/cfg-generic-params.stderr @@ -19,7 +19,7 @@ LL | type FnYes = for<#[cfg_attr(yes, unknown)] 'a> fn(); error: cannot find attribute `unknown` in this scope --> $DIR/cfg-generic-params.rs:30:40 | -LL | type PolyYes = dyn for<#[cfg_attr(yes, unknown)] 'a> Copy; +LL | type PolyYes = dyn for<#[cfg_attr(yes, unknown)] 'a> std::any::Any; | ^^^^^^^ error: cannot find attribute `unknown` in this scope @@ -41,7 +41,7 @@ LL | type FnBad = for<#[cfg(false)] 'a, #[cfg(yes)] T> fn(); error[E0658]: only lifetime parameters can be used in this context --> $DIR/cfg-generic-params.rs:11:54 | -LL | type PolyBad = dyn for<#[cfg(false)] 'a, #[cfg(yes)] T> Copy; +LL | type PolyBad = dyn for<#[cfg(false)] 'a, #[cfg(yes)] T> std::any::Any; | ^ | = note: see issue #108185 for more information diff --git a/tests/ui/dyn-compatibility/in-unchecked-type-alias.rs b/tests/ui/dyn-compatibility/in-unchecked-type-alias.rs new file mode 100644 index 0000000000000..8a83b6a4de68a --- /dev/null +++ b/tests/ui/dyn-compatibility/in-unchecked-type-alias.rs @@ -0,0 +1,15 @@ +// FIXME(fmease): Write a description. + +type DynIncompat0 = dyn Sized; //~ ERROR not dyn compatible + +// FIXME(fmease): Well, if this breakage got accepted linking to this issue +// would be moot / nonsensical. Remove the link. +// issue: +type DynIncompat1 = dyn HasAssocConst; //~ ERROR not dyn compatible + +type DynIncompat2<'a> = dyn HasGenericAssocType = ()>; //~ ERROR not dyn compatible + +trait HasAssocConst { const N: usize; } +trait HasGenericAssocType { type Type; } + +fn main() {} diff --git a/tests/ui/dyn-compatibility/in-unchecked-type-alias.stderr b/tests/ui/dyn-compatibility/in-unchecked-type-alias.stderr new file mode 100644 index 0000000000000..edcc748e0d192 --- /dev/null +++ b/tests/ui/dyn-compatibility/in-unchecked-type-alias.stderr @@ -0,0 +1,45 @@ +error[E0038]: the trait `Sized` is not dyn compatible + --> $DIR/in-unchecked-type-alias.rs:3:1 + | +LL | type DynIncompat0 = dyn Sized; + | ^^^^^^^^^^^^^^^^^ `Sized` is not dyn compatible + | + = note: the trait is not dyn compatible because it requires `Self: Sized` + = note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + +error[E0038]: the trait `HasAssocConst` is not dyn compatible + --> $DIR/in-unchecked-type-alias.rs:8:1 + | +LL | type DynIncompat1 = dyn HasAssocConst; + | ^^^^^^^^^^^^^^^^^ `HasAssocConst` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $DIR/in-unchecked-type-alias.rs:12:29 + | +LL | trait HasAssocConst { const N: usize; } + | ------------- ^ ...because it contains associated const `N` + | | + | this trait is not dyn compatible... + = help: consider moving `N` to another trait + +error[E0038]: the trait `HasGenericAssocType` is not dyn compatible + --> $DIR/in-unchecked-type-alias.rs:10:1 + | +LL | type DynIncompat2<'a> = dyn HasGenericAssocType = ()>; + | ^^^^^^^^^^^^^^^^^^^^^ `HasGenericAssocType` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $DIR/in-unchecked-type-alias.rs:13:34 + | +LL | trait HasGenericAssocType { type Type; } + | ------------------- ^^^^ ...because it contains generic associated type `Type` + | | + | this trait is not dyn compatible... + = help: consider moving `Type` to another trait + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0038`. diff --git a/tests/ui/hygiene/assoc_ty_bindings.rs b/tests/ui/hygiene/assoc_ty_bindings.rs index 5e42e27062fbd..f548b892a7049 100644 --- a/tests/ui/hygiene/assoc_ty_bindings.rs +++ b/tests/ui/hygiene/assoc_ty_bindings.rs @@ -4,10 +4,10 @@ trait Base { type AssocTy; - fn f(); + fn f(self); } trait Derived: Base { - fn g(); + fn g(self); } macro mac() { @@ -16,12 +16,12 @@ macro mac() { impl Base for u8 { type AssocTy = u8; - fn f() { + fn f(self) { let _: Self::AssocTy; } } impl Derived for u8 { - fn g() { + fn g(self) { let _: Self::AssocTy; } } diff --git a/tests/ui/resolve/issue-3907-2.rs b/tests/ui/resolve/issue-3907-2.rs index f261de5f4025a..33bfd03237862 100644 --- a/tests/ui/resolve/issue-3907-2.rs +++ b/tests/ui/resolve/issue-3907-2.rs @@ -2,14 +2,14 @@ extern crate issue_3907; -type Foo = dyn issue_3907::Foo + 'static; +type Foo = dyn issue_3907::Foo + 'static; //~ ERROR not dyn compatible [E0038] struct S { name: isize } fn bar(_x: Foo) {} -//~^ ERROR E0038 -//~| ERROR E0277 +//~^ ERROR not dyn compatible [E0038] +//~| ERROR cannot be known at compilation time [E0277] fn main() {} diff --git a/tests/ui/resolve/issue-3907-2.stderr b/tests/ui/resolve/issue-3907-2.stderr index 40cdfb7a30255..64ed3d88b3fdc 100644 --- a/tests/ui/resolve/issue-3907-2.stderr +++ b/tests/ui/resolve/issue-3907-2.stderr @@ -1,3 +1,16 @@ +error[E0038]: the trait `issue_3907::Foo` is not dyn compatible + --> $DIR/issue-3907-2.rs:5:1 + | +LL | type Foo = dyn issue_3907::Foo + 'static; + | ^^^^^^^^ `issue_3907::Foo` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $DIR/auxiliary/issue-3907.rs:2:8 + | +LL | fn bar(); + | ^^^ the trait is not dyn compatible because associated function `bar` has no `self` parameter + error[E0038]: the trait `issue_3907::Foo` is not dyn compatible --> $DIR/issue-3907-2.rs:11:12 | @@ -24,7 +37,7 @@ help: function arguments must have a statically known size, borrowed types alway LL | fn bar(_x: &Foo) {} | + -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0038, E0277. For more information about an error, try `rustc --explain E0038`. diff --git a/tests/ui/resolve/issue-3907.rs b/tests/ui/resolve/issue-3907.rs index fd08c360d3627..19d83515066eb 100644 --- a/tests/ui/resolve/issue-3907.rs +++ b/tests/ui/resolve/issue-3907.rs @@ -2,7 +2,7 @@ extern crate issue_3907; -type Foo = dyn issue_3907::Foo; +type Foo = dyn issue_3907::Foo; //~ ERROR not dyn compatible struct S { name: isize diff --git a/tests/ui/resolve/issue-3907.stderr b/tests/ui/resolve/issue-3907.stderr index 0dc85829160bf..7999fd0c9eddf 100644 --- a/tests/ui/resolve/issue-3907.stderr +++ b/tests/ui/resolve/issue-3907.stderr @@ -14,6 +14,20 @@ help: consider importing this trait instead LL + use issue_3907::Foo; | -error: aborting due to 1 previous error +error[E0038]: the trait `issue_3907::Foo` is not dyn compatible + --> $DIR/issue-3907.rs:5:1 + | +LL | type Foo = dyn issue_3907::Foo; + | ^^^^^^^^ `issue_3907::Foo` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $DIR/auxiliary/issue-3907.rs:2:8 + | +LL | fn bar(); + | ^^^ the trait is not dyn compatible because associated function `bar` has no `self` parameter + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0404`. +Some errors have detailed explanations: E0038, E0404. +For more information about an error, try `rustc --explain E0038`. diff --git a/tests/ui/sized-hierarchy/trait-alias-elaboration.rs b/tests/ui/sized-hierarchy/trait-alias-elaboration.rs index a5b4443ffddd3..0f65e80590ddd 100644 --- a/tests/ui/sized-hierarchy/trait-alias-elaboration.rs +++ b/tests/ui/sized-hierarchy/trait-alias-elaboration.rs @@ -6,7 +6,7 @@ use std::marker::MetaSized; // wrote `MetaSized` in the `dyn Trait` then that should still be an error so as not to accidentally // accept this going forwards. -trait Qux = Clone; +trait Qux = std::fmt::Debug; type Foo = dyn Qux + MetaSized; //~^ ERROR: only auto traits can be used as additional traits in a trait object diff --git a/tests/ui/sized-hierarchy/trait-alias-elaboration.stderr b/tests/ui/sized-hierarchy/trait-alias-elaboration.stderr index 394aae6f8e32f..815fd7da2771a 100644 --- a/tests/ui/sized-hierarchy/trait-alias-elaboration.stderr +++ b/tests/ui/sized-hierarchy/trait-alias-elaboration.stderr @@ -1,15 +1,15 @@ error[E0225]: only auto traits can be used as additional traits in a trait object --> $DIR/trait-alias-elaboration.rs:11:16 | -LL | trait Qux = Clone; - | ------------------ additional non-auto trait +LL | trait Qux = std::fmt::Debug; + | ---------------------------- additional non-auto trait LL | LL | type Foo = dyn Qux + MetaSized; | ^^^ --------- first non-auto trait | | | second non-auto trait comes from this alias | - = help: consider creating a new trait with all of these as supertraits and using that trait here instead: `trait NewTrait: MetaSized + MetaSized + Clone {}` + = help: consider creating a new trait with all of these as supertraits and using that trait here instead: `trait NewTrait: MetaSized + MetaSized + Debug {}` = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit error: aborting due to 1 previous error diff --git a/tests/ui/type-alias/lack-of-wfcheck-gat-generic-const-args.rs b/tests/ui/type-alias/lack-of-wfcheck-gat-generic-const-args.rs deleted file mode 100644 index 58bc4daedfcc1..0000000000000 --- a/tests/ui/type-alias/lack-of-wfcheck-gat-generic-const-args.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Demonstrate that generic const arguments in GAT constraints are rejected at -// the definition site of an eager type alias. - -//@ compile-flags: -Znext-solver=globally - -#![feature(generic_const_args, min_generic_const_args)] -#![expect(incomplete_features)] - -// * dyn incompatible due to GAT -// * `'a: 'static`, `String: Copy` and `[u8]: Sized` unsatisfied, `loop {}` diverging -type Several<'a> = dyn HasGenericAssocType = [u8]>; -//~^ ERROR - -trait HasGenericAssocType { - type Type<'a: 'static, T: Copy, const N: usize>; -} - -fn main() { - let _: &Several<'_>; - //~^ ERROR the trait `HasGenericAssocType` is not dyn compatible -} diff --git a/tests/ui/type-alias/lack-of-wfcheck-gat-generic-const-args.stderr b/tests/ui/type-alias/lack-of-wfcheck-gat-generic-const-args.stderr deleted file mode 100644 index 6b06ba9cb14fe..0000000000000 --- a/tests/ui/type-alias/lack-of-wfcheck-gat-generic-const-args.stderr +++ /dev/null @@ -1,34 +0,0 @@ -error: constant evaluation is taking a long time - --> $DIR/lack-of-wfcheck-gat-generic-const-args.rs:11:63 - | -LL | type Several<'a> = dyn HasGenericAssocType = [u8]>; - | ^^^^^^^ - | - = note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval. - If your compilation actually takes a long time, you can safely allow the lint -help: the constant being evaluated - --> $DIR/lack-of-wfcheck-gat-generic-const-args.rs:11:61 - | -LL | type Several<'a> = dyn HasGenericAssocType = [u8]>; - | ^^^^^^^^^^^ - = note: `#[deny(long_running_const_eval)]` on by default - -error[E0038]: the trait `HasGenericAssocType` is not dyn compatible - --> $DIR/lack-of-wfcheck-gat-generic-const-args.rs:19:12 - | -LL | let _: &Several<'_>; - | ^^^^^^^^^^^^ `HasGenericAssocType` is not dyn compatible - | -note: for a trait to be dyn compatible it needs to allow building a vtable - for more information, visit - --> $DIR/lack-of-wfcheck-gat-generic-const-args.rs:15:10 - | -LL | trait HasGenericAssocType { - | ------------------- this trait is not dyn compatible... -LL | type Type<'a: 'static, T: Copy, const N: usize>; - | ^^^^ ...because it contains generic associated type `Type` - = help: consider moving `Type` to another trait - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0038`. diff --git a/tests/ui/type-alias/lack-of-wfcheck-generic-const-args.gca.stderr b/tests/ui/type-alias/lack-of-wfcheck-generic-const-args.gca.stderr index 52edd50aaaaad..4f1b284821041 100644 --- a/tests/ui/type-alias/lack-of-wfcheck-generic-const-args.gca.stderr +++ b/tests/ui/type-alias/lack-of-wfcheck-generic-const-args.gca.stderr @@ -1,16 +1,16 @@ -error[E0191]: the value of the associated constant `N` in `HasAssocConst` must be specified - --> $DIR/lack-of-wfcheck-generic-const-args.rs:19:25 +error[E0191]: the value of the associated constant `N` in `HasNonTypeAssocConst` must be specified + --> $DIR/lack-of-wfcheck-generic-const-args.rs:13:20 | -LL | type DynIncompat1 = dyn HasAssocConst; - | ^^^^^^^^^^^^^ +LL | type TyAlias = dyn HasNonTypeAssocConst; + | ^^^^^^^^^^^^^^^^^^^^ ... -LL | const N: usize; - | -------------- `N` defined here +LL | /*non-type */const N: usize; + | -------------- `N` defined here | help: specify the associated constant | -LL | type DynIncompat1 = dyn HasAssocConst; - | +++++++++++++++++ +LL | type TyAlias = dyn HasNonTypeAssocConst; + | +++++++++++++++++ error: aborting due to 1 previous error diff --git a/tests/ui/type-alias/lack-of-wfcheck-generic-const-args.no_gca.stderr b/tests/ui/type-alias/lack-of-wfcheck-generic-const-args.no_gca.stderr new file mode 100644 index 0000000000000..c41a2f91763b0 --- /dev/null +++ b/tests/ui/type-alias/lack-of-wfcheck-generic-const-args.no_gca.stderr @@ -0,0 +1,19 @@ +error[E0038]: the trait `HasNonTypeAssocConst` is not dyn compatible + --> $DIR/lack-of-wfcheck-generic-const-args.rs:13:1 + | +LL | type TyAlias = dyn HasNonTypeAssocConst; + | ^^^^^^^^^^^^ `HasNonTypeAssocConst` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $DIR/lack-of-wfcheck-generic-const-args.rs:17:24 + | +LL | trait HasNonTypeAssocConst { + | -------------------- this trait is not dyn compatible... +LL | /*non-type */const N: usize; + | ^ ...because it contains associated const `N` + = help: consider moving `N` to another trait + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0038`. diff --git a/tests/ui/type-alias/lack-of-wfcheck-generic-const-args.rs b/tests/ui/type-alias/lack-of-wfcheck-generic-const-args.rs index afca550944ffc..d995cb7989ab8 100644 --- a/tests/ui/type-alias/lack-of-wfcheck-generic-const-args.rs +++ b/tests/ui/type-alias/lack-of-wfcheck-generic-const-args.rs @@ -1,26 +1,20 @@ -// Demonstrate that generic_const_args changes the behavior for dyn trait aliases -// with non-type associated consts: the associated const must be specified. +// FIXME(fmease): Re-audit this test! Rewrite its description! Probably rename the entire file, too! + +// Demonstrate that enabling `generic_const_args` changes the behavior for trait object types in +// (unchecked) type aliases where the corresponding trait has non-type associated consts: +// The associated const must be specified. //@ revisions: no_gca gca //@ compile-flags: -Znext-solver=globally -//@ [no_gca] check-pass #![cfg_attr(gca, feature(generic_const_args, min_generic_const_args))] -#![cfg_attr(gca, expect(incomplete_features))] - -type UnsatTraitBound0 = [str]; // `str: Sized` unsatisfied -type UnsatTraitBound1> = T; // `str: Sized` unsatisfied -type UnsatOutlivesBound<'a> = &'static &'a (); // `'a: 'static` unsatisfied - -type Diverging = [(); panic!()]; // `panic!()` diverging -type DynIncompat0 = dyn Sized; // `Sized` axiomatically dyn incompatible -// issue: -type DynIncompat1 = dyn HasAssocConst; -//[gca]~^ ERROR the value of the associated constant `N` in `HasAssocConst` must be specified +//[no_gca]~v ERROR not dyn compatible +type TyAlias = dyn HasNonTypeAssocConst; +//[gca]~^ ERROR the value of the associated constant `N` in `HasNonTypeAssocConst` must be specified -trait HasAssocConst { - const N: usize; +trait HasNonTypeAssocConst { + /*non-type */const N: usize; } fn main() {} diff --git a/tests/ui/type-alias/lack-of-wfcheck.rs b/tests/ui/type-alias/lack-of-wfcheck.rs index 91fbee8d3f198..4935eff8b2dfe 100644 --- a/tests/ui/type-alias/lack-of-wfcheck.rs +++ b/tests/ui/type-alias/lack-of-wfcheck.rs @@ -1,11 +1,14 @@ -// Demonstrate that we don't check the definition site of (eager) type aliases for well-formedness. +// Demonstrate that we don't check the def site of (unchecked) type aliases for well-formedness. // // Listed below are ill-formed type system entities which we don't reject since they appear inside -// the definition of (eager) type aliases. These type aliases are intentionally not referenced from -// anywhere to prevent the eagerly expanded / instantiated aliased types from getting wfchecked +// the definition of (unchecked) type aliases. These type aliases are intentionally not referenced +// from anywhere to prevent the eagerly expanded / instantiated aliased types from getting wfchecked // since that's not what we're testing here. //@ check-pass +//@ revisions: current next +//@ ignore-compare-mode-next-solver (explicit revisions) +//@[next] compile-flags: -Znext-solver type UnsatTraitBound0 = [str]; // `str: Sized` unsatisfied type UnsatTraitBound1> = T; // `str: Sized` unsatisfied @@ -13,15 +16,14 @@ type UnsatOutlivesBound<'a> = &'static &'a (); // `'a: 'static` unsatisfied type Diverging = [(); panic!()]; // `panic!()` diverging -type DynIncompat0 = dyn Sized; // `Sized` axiomatically dyn incompatible -// issue: -type DynIncompat1 = dyn HasAssocConst; // dyn incompatible due to (non-type-level) assoc const - -// * dyn incompatible due to GAT // * `'a: 'static`, `String: Copy` and `[u8]: Sized` unsatisfied, `loop {}` diverging -type Several<'a> = dyn HasGenericAssocType = [u8]>; +#[expect(unused_associated_type_bounds)] +type Several<'a> = dyn Trait = [u8]>; -trait HasAssocConst { const N: usize; } -trait HasGenericAssocType { type Type<'a: 'static, T: Copy, const N: usize>; } +trait Trait { + type Type<'a: 'static, T: Copy, const N: usize> + where + Self: Sized; +} fn main() {}