From 25f20f56d309e6a100a103059c952de860b39757 Mon Sep 17 00:00:00 2001 From: Jacob Adam Date: Sun, 2 Aug 2026 08:57:31 +0100 Subject: [PATCH 1/7] Add a regression test for casting a `fn` item with an illegal `self` parameter to a trait object --- .../typeck/self-param-in-fn-item-cast-to-fn-trait.rs | 7 +++++++ .../self-param-in-fn-item-cast-to-fn-trait.stderr | 10 ++++++++++ 2 files changed, 17 insertions(+) create mode 100644 tests/ui/typeck/self-param-in-fn-item-cast-to-fn-trait.rs create mode 100644 tests/ui/typeck/self-param-in-fn-item-cast-to-fn-trait.stderr diff --git a/tests/ui/typeck/self-param-in-fn-item-cast-to-fn-trait.rs b/tests/ui/typeck/self-param-in-fn-item-cast-to-fn-trait.rs new file mode 100644 index 0000000000000..3c9e98e2abbb4 --- /dev/null +++ b/tests/ui/typeck/self-param-in-fn-item-cast-to-fn-trait.rs @@ -0,0 +1,7 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/111411. + +pub fn main() { + fn baz(&self) {} + //~^ ERROR `self` parameter is only allowed in associated functions + let _ = &baz as &dyn Fn(i32); +} diff --git a/tests/ui/typeck/self-param-in-fn-item-cast-to-fn-trait.stderr b/tests/ui/typeck/self-param-in-fn-item-cast-to-fn-trait.stderr new file mode 100644 index 0000000000000..f6c2479e1f8e9 --- /dev/null +++ b/tests/ui/typeck/self-param-in-fn-item-cast-to-fn-trait.stderr @@ -0,0 +1,10 @@ +error: `self` parameter is only allowed in associated functions + --> $DIR/self-param-in-fn-item-cast-to-fn-trait.rs:4:12 + | +LL | fn baz(&self) {} + | ^^^^^ not semantically valid as function parameter + | + = note: associated functions are those in `impl` or `trait` definitions + +error: aborting due to 1 previous error + From cfafd1587ceb6f325e369e76a57fc49635062fc5 Mon Sep 17 00:00:00 2001 From: Jacob Adam Date: Sun, 2 Aug 2026 08:59:54 +0100 Subject: [PATCH 2/7] Add a regression test for a trait alias mentioning `Self` in a trait object --- .../trait-alias-with-self-in-dyn-object.rs | 10 +++++++ ...trait-alias-with-self-in-dyn-object.stderr | 26 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/ui/traits/alias/trait-alias-with-self-in-dyn-object.rs create mode 100644 tests/ui/traits/alias/trait-alias-with-self-in-dyn-object.stderr diff --git a/tests/ui/traits/alias/trait-alias-with-self-in-dyn-object.rs b/tests/ui/traits/alias/trait-alias-with-self-in-dyn-object.rs new file mode 100644 index 0000000000000..aa27e41a94187 --- /dev/null +++ b/tests/ui/traits/alias/trait-alias-with-self-in-dyn-object.rs @@ -0,0 +1,10 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/138891. + +#![feature(trait_alias)] +trait F = Fn() -> Self; + +fn _f3(a: dyn F) {} +//~^ ERROR trait alias takes 0 generic arguments but 1 generic argument was supplied +//~| ERROR associated type binding in trait object type mentions `Self` + +fn main() {} diff --git a/tests/ui/traits/alias/trait-alias-with-self-in-dyn-object.stderr b/tests/ui/traits/alias/trait-alias-with-self-in-dyn-object.stderr new file mode 100644 index 0000000000000..ef12c36448262 --- /dev/null +++ b/tests/ui/traits/alias/trait-alias-with-self-in-dyn-object.stderr @@ -0,0 +1,26 @@ +error[E0107]: trait alias takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/trait-alias-with-self-in-dyn-object.rs:6:20 + | +LL | fn _f3(a: dyn F) {} + | ^----- help: remove the unnecessary generics + | | + | expected 0 generic arguments + | +note: trait alias defined here, with 0 generic parameters + --> $DIR/trait-alias-with-self-in-dyn-object.rs:4:7 + | +LL | trait F = Fn() -> Self; + | ^ + +error: associated type binding in trait object type mentions `Self` + --> $DIR/trait-alias-with-self-in-dyn-object.rs:6:16 + | +LL | trait F = Fn() -> Self; + | ---- this binding mentions `Self` +LL | +LL | fn _f3(a: dyn F) {} + | ^^^^^^^^^^ contains a mention of `Self` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0107`. From 17446a6ad8a34d9c1bc102754f9514a65c27f84c Mon Sep 17 00:00:00 2001 From: Jacob Adam Date: Sun, 2 Aug 2026 09:03:35 +0100 Subject: [PATCH 3/7] Add a regression test for the layout of an unsafe binder over an opaque type --- .../unsafe-binder-opaque-type-layout.rs | 17 ++++++++++++ .../unsafe-binder-opaque-type-layout.stderr | 26 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/ui/transmutability/unsafe-binder-opaque-type-layout.rs create mode 100644 tests/ui/transmutability/unsafe-binder-opaque-type-layout.stderr diff --git a/tests/ui/transmutability/unsafe-binder-opaque-type-layout.rs b/tests/ui/transmutability/unsafe-binder-opaque-type-layout.rs new file mode 100644 index 0000000000000..e456e88e4a383 --- /dev/null +++ b/tests/ui/transmutability/unsafe-binder-opaque-type-layout.rs @@ -0,0 +1,17 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/141400. + +#![feature(unsafe_binders)] +#![feature(transmutability)] +#![feature(type_alias_impl_trait)] +#![allow(incomplete_features)] + +trait OpaqueTrait {} +type OpaqueType = unsafe<> impl OpaqueTrait; +//~^ ERROR the trait bound `OpaqueType::{opaque#0}: Copy` is not satisfied +//~| ERROR unconstrained opaque type +trait AnotherTrait {} +impl> AnotherTrait for T {} +impl AnotherTrait for OpaqueType {} +//~^ ERROR conflicting implementations of trait `AnotherTrait` + +pub fn main() {} diff --git a/tests/ui/transmutability/unsafe-binder-opaque-type-layout.stderr b/tests/ui/transmutability/unsafe-binder-opaque-type-layout.stderr new file mode 100644 index 0000000000000..d2bfbfbf3a095 --- /dev/null +++ b/tests/ui/transmutability/unsafe-binder-opaque-type-layout.stderr @@ -0,0 +1,26 @@ +error[E0277]: the trait bound `OpaqueType::{opaque#0}: Copy` is not satisfied + --> $DIR/unsafe-binder-opaque-type-layout.rs:9:19 + | +LL | type OpaqueType = unsafe<> impl OpaqueTrait; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `OpaqueType::{opaque#0}` + +error[E0119]: conflicting implementations of trait `AnotherTrait` for type `unsafe<> _` + --> $DIR/unsafe-binder-opaque-type-layout.rs:14:1 + | +LL | impl> AnotherTrait for T {} + | ------------------------------------------------------- first implementation here +LL | impl AnotherTrait for OpaqueType {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `unsafe<> _` + +error: unconstrained opaque type + --> $DIR/unsafe-binder-opaque-type-layout.rs:9:28 + | +LL | type OpaqueType = unsafe<> impl OpaqueTrait; + | ^^^^^^^^^^^^^^^^ + | + = note: `OpaqueType` must be used in combination with a concrete type within the same crate + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0119, E0277. +For more information about an error, try `rustc --explain E0119`. From 6f4fdb0022a29e2cedd3b30352eefab7d6cbd931 Mon Sep 17 00:00:00 2001 From: Jacob Adam Date: Sun, 2 Aug 2026 09:24:51 +0100 Subject: [PATCH 4/7] Add a regression test for transmuting a `usize` to a `rust-call` fn pointer --- .../transmute-usize-to-rust-call-fn-ptr.rs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tests/ui/unboxed-closures/transmute-usize-to-rust-call-fn-ptr.rs diff --git a/tests/ui/unboxed-closures/transmute-usize-to-rust-call-fn-ptr.rs b/tests/ui/unboxed-closures/transmute-usize-to-rust-call-fn-ptr.rs new file mode 100644 index 0000000000000..03507d22e8643 --- /dev/null +++ b/tests/ui/unboxed-closures/transmute-usize-to-rust-call-fn-ptr.rs @@ -0,0 +1,9 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/114665. + +//@ build-pass +//@ compile-flags: -Zmir-opt-level=0 + +#![feature(unboxed_closures)] +fn main() { + unsafe { std::mem::transmute::(5); } +} From a0efa72c2c1dd4af2d2ab2d9f6ec3cf055772de8 Mon Sep 17 00:00:00 2001 From: Jacob Adam Date: Sun, 2 Aug 2026 09:26:38 +0100 Subject: [PATCH 5/7] Add a regression test for MIR validation of a nested type-alias `impl Trait` --- .../nested-tait-inline-mir-validation.rs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/ui/type-alias-impl-trait/nested-tait-inline-mir-validation.rs diff --git a/tests/ui/type-alias-impl-trait/nested-tait-inline-mir-validation.rs b/tests/ui/type-alias-impl-trait/nested-tait-inline-mir-validation.rs new file mode 100644 index 0000000000000..f70a08e2eae78 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/nested-tait-inline-mir-validation.rs @@ -0,0 +1,35 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/118478. + +//@ check-pass +//@ compile-flags: -Zmir-opt-level=3 + +#![feature(type_alias_impl_trait)] +#![crate_type = "lib"] +pub trait Tr { + fn get(&self) -> u32; +} + +impl Tr for (u32,) { + #[inline] + fn get(&self) -> u32 { self.0 } +} + +pub fn tr1() -> impl Tr { + (32,) +} + +pub fn tr2() -> impl Tr { + struct Inner { + x: X, + } + type X = impl Tr; + impl Tr for Inner { + fn get(&self) -> u32 { + self.x.get() + } + } + + Inner { + x: tr1(), + } +} From 62505193440d9886d1eda13d1166de4fd4b8b0be Mon Sep 17 00:00:00 2001 From: Jacob Adam Date: Sun, 2 Aug 2026 09:35:38 +0100 Subject: [PATCH 6/7] Restore a crash test for a higher-ranked generic associated type The test was removed on the assumption that it no longer crashed the compiler, but it still does, both on the nightly the issue was reported against and on current master. The assertion has since moved out of the debug info code and into `normalize_erasing_regions`, but it is the same one. --- tests/crashes/129372.rs | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/crashes/129372.rs diff --git a/tests/crashes/129372.rs b/tests/crashes/129372.rs new file mode 100644 index 0000000000000..824e6fbfc4dd0 --- /dev/null +++ b/tests/crashes/129372.rs @@ -0,0 +1,53 @@ +//@ known-bug: #129372 +//@ compile-flags: -Cdebuginfo=2 -Copt-level=0 +//@ ignore-backends: gcc + +pub struct Wrapper(T); +struct Struct; + +pub trait TraitA { + type AssocA<'t>; +} +pub trait TraitB { + type AssocB; +} + +pub fn helper(v: impl MethodTrait) { + let _local_that_causes_ice = v.method(); +} + +pub fn main() { + helper(Wrapper(Struct)); +} + +pub trait MethodTrait { + type Assoc<'a>; + + fn method(self) -> impl for<'a> FnMut(&'a ()) -> Self::Assoc<'a>; +} + +impl MethodTrait for T +where + ::AssocB: TraitA, +{ + type Assoc<'a> = ::AssocA<'a>; + + fn method(self) -> impl for<'a> FnMut(&'a ()) -> Self::Assoc<'a> { + move |_| loop {} + } +} + +impl TraitB for Wrapper +where + B: TraitB, +{ + type AssocB = T; +} + +impl TraitB for Struct { + type AssocB = Struct; +} + +impl TraitA for Struct { + type AssocA<'t> = Self; +} From 28b62fa30e5c8af0e700c711aa44259de555b090 Mon Sep 17 00:00:00 2001 From: Jacob Adam Date: Sun, 2 Aug 2026 09:38:46 +0100 Subject: [PATCH 7/7] Add a regression test for a malformed `impl Trait` in an associated type with a `const` parameter --- ...med-tait-impl-with-const-param.incr.stderr | 27 +++++++++++++++++++ ...d-tait-impl-with-const-param.normal.stderr | 27 +++++++++++++++++++ .../malformed-tait-impl-with-const-param.rs | 24 +++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 tests/ui/impl-trait/malformed-tait-impl-with-const-param.incr.stderr create mode 100644 tests/ui/impl-trait/malformed-tait-impl-with-const-param.normal.stderr create mode 100644 tests/ui/impl-trait/malformed-tait-impl-with-const-param.rs diff --git a/tests/ui/impl-trait/malformed-tait-impl-with-const-param.incr.stderr b/tests/ui/impl-trait/malformed-tait-impl-with-const-param.incr.stderr new file mode 100644 index 0000000000000..f940a1e5011cf --- /dev/null +++ b/tests/ui/impl-trait/malformed-tait-impl-with-const-param.incr.stderr @@ -0,0 +1,27 @@ +error[E0261]: use of undeclared lifetime name `'a` + --> $DIR/malformed-tait-impl-with-const-param.rs:15:32 + | +LL | impl Trait for &'a () { + | ^^ undeclared lifetime + | +help: consider introducing lifetime `'a` here + | +LL | impl<'a, const B: Word> Trait for &'a () { + | +++ + +error[E0407]: method `constrain` is not a member of trait `Trait` + --> $DIR/malformed-tait-impl-with-const-param.rs:20:5 + | +LL | fn constrain(self) -> (Self::Opaque1,) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a member of trait `Trait` + +error[E0425]: cannot find type `Word` in this scope + --> $DIR/malformed-tait-impl-with-const-param.rs:15:15 + | +LL | impl Trait for &'a () { + | ^^^^ not found in this scope + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0261, E0407, E0425. +For more information about an error, try `rustc --explain E0261`. diff --git a/tests/ui/impl-trait/malformed-tait-impl-with-const-param.normal.stderr b/tests/ui/impl-trait/malformed-tait-impl-with-const-param.normal.stderr new file mode 100644 index 0000000000000..f940a1e5011cf --- /dev/null +++ b/tests/ui/impl-trait/malformed-tait-impl-with-const-param.normal.stderr @@ -0,0 +1,27 @@ +error[E0261]: use of undeclared lifetime name `'a` + --> $DIR/malformed-tait-impl-with-const-param.rs:15:32 + | +LL | impl Trait for &'a () { + | ^^ undeclared lifetime + | +help: consider introducing lifetime `'a` here + | +LL | impl<'a, const B: Word> Trait for &'a () { + | +++ + +error[E0407]: method `constrain` is not a member of trait `Trait` + --> $DIR/malformed-tait-impl-with-const-param.rs:20:5 + | +LL | fn constrain(self) -> (Self::Opaque1,) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a member of trait `Trait` + +error[E0425]: cannot find type `Word` in this scope + --> $DIR/malformed-tait-impl-with-const-param.rs:15:15 + | +LL | impl Trait for &'a () { + | ^^^^ not found in this scope + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0261, E0407, E0425. +For more information about an error, try `rustc --explain E0261`. diff --git a/tests/ui/impl-trait/malformed-tait-impl-with-const-param.rs b/tests/ui/impl-trait/malformed-tait-impl-with-const-param.rs new file mode 100644 index 0000000000000..d5374fc99f71a --- /dev/null +++ b/tests/ui/impl-trait/malformed-tait-impl-with-const-param.rs @@ -0,0 +1,24 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/122214. +//! +//! The reported ICE only happened under incremental compilation, where the const inference +//! variable reached `HashStable`, but this used to crash without it as well, so check both. + +//@ revisions: normal incr +//@[incr] incremental + +#![feature(impl_trait_in_assoc_type, const_precise_live_drops)] + +trait Trait { + type Opaque1; +} + +impl Trait for &'a () { + //~^ ERROR use of undeclared lifetime name `'a` + //~| ERROR cannot find type `Word` in this scope + type Opaque1 = impl Sized; + + fn constrain(self) -> (Self::Opaque1,) {} + //~^ ERROR method `constrain` is not a member of trait `Trait` +} + +fn main() {}