diff options
| author | Matthew Jasper <mjjasper1@gmail.com> | 2025-04-04 09:58:55 +0000 |
|---|---|---|
| committer | Matthew Jasper <mjjasper1@gmail.com> | 2025-04-11 16:31:28 +0000 |
| commit | ac45a672979b28670cf2e5de5afbb0b1fb42c0b2 (patch) | |
| tree | 11e18fa896aaa48199a3fd8d9f6c77172cf1c992 /tests/ui/drop | |
| parent | 71b68da1bd9fa6afb9f964a731e9c843ab0862bd (diff) | |
| download | rust-ac45a672979b28670cf2e5de5afbb0b1fb42c0b2.tar.gz rust-ac45a672979b28670cf2e5de5afbb0b1fb42c0b2.zip | |
Use delayed bug for normalization errors in drop elaboration
Normalization can fail from errors from other items so use a delayed bug instead of checking the body.
Diffstat (limited to 'tests/ui/drop')
| -rw-r--r-- | tests/ui/drop/drop_elaboration_with_errors2.rs | 33 | ||||
| -rw-r--r-- | tests/ui/drop/drop_elaboration_with_errors2.stderr | 47 | ||||
| -rw-r--r-- | tests/ui/drop/drop_elaboration_with_errors3.rs | 42 | ||||
| -rw-r--r-- | tests/ui/drop/drop_elaboration_with_errors3.stderr | 8 |
4 files changed, 130 insertions, 0 deletions
diff --git a/tests/ui/drop/drop_elaboration_with_errors2.rs b/tests/ui/drop/drop_elaboration_with_errors2.rs new file mode 100644 index 00000000000..946c253179c --- /dev/null +++ b/tests/ui/drop/drop_elaboration_with_errors2.rs @@ -0,0 +1,33 @@ +// Regression test for #137287 + +mod defining_scope { + use super::*; + pub type Alias<T> = impl Sized; + //~^ ERROR unconstrained opaque type + //~| ERROR `impl Trait` in type aliases is unstable + + pub fn cast<T>(x: Container<Alias<T>, T>) -> Container<T, T> { + x + //~^ ERROR mismatched types + } +} + +struct Container<T: Trait<U>, U> { + x: <T as Trait<U>>::Assoc, +} + +trait Trait<T> { + type Assoc; +} + +impl<T> Trait<T> for T { + type Assoc = Box<u32>; +} +impl<T> Trait<T> for defining_scope::Alias<T> { + //~^ ERROR conflicting implementations of trait `Trait<_>` + type Assoc = usize; +} + +fn main() { + let x: Box<u32> = defining_scope::cast::<()>(Container { x: 0 }).x; +} diff --git a/tests/ui/drop/drop_elaboration_with_errors2.stderr b/tests/ui/drop/drop_elaboration_with_errors2.stderr new file mode 100644 index 00000000000..15fe3f6ecc1 --- /dev/null +++ b/tests/ui/drop/drop_elaboration_with_errors2.stderr @@ -0,0 +1,47 @@ +error[E0658]: `impl Trait` in type aliases is unstable + --> $DIR/drop_elaboration_with_errors2.rs:5:25 + | +LL | pub type Alias<T> = impl Sized; + | ^^^^^^^^^^ + | + = note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0119]: conflicting implementations of trait `Trait<_>` + --> $DIR/drop_elaboration_with_errors2.rs:26:1 + | +LL | impl<T> Trait<T> for T { + | ---------------------- first implementation here +... +LL | impl<T> Trait<T> for defining_scope::Alias<T> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation + +error: unconstrained opaque type + --> $DIR/drop_elaboration_with_errors2.rs:5:25 + | +LL | pub type Alias<T> = impl Sized; + | ^^^^^^^^^^ + | + = note: `Alias` must be used in combination with a concrete type within the same crate + +error[E0308]: mismatched types + --> $DIR/drop_elaboration_with_errors2.rs:10:9 + | +LL | pub type Alias<T> = impl Sized; + | ---------- the found opaque type +... +LL | pub fn cast<T>(x: Container<Alias<T>, T>) -> Container<T, T> { + | - expected this type parameter --------------- expected `Container<T, T>` because of return type +LL | x + | ^ expected `Container<T, T>`, found `Container<Alias<T>, T>` + | + = note: expected struct `Container<T, _>` + found struct `Container<Alias<T>, _>` + = help: type parameters must be constrained to match other types + = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0119, E0308, E0658. +For more information about an error, try `rustc --explain E0119`. diff --git a/tests/ui/drop/drop_elaboration_with_errors3.rs b/tests/ui/drop/drop_elaboration_with_errors3.rs new file mode 100644 index 00000000000..c5ed63eb7ac --- /dev/null +++ b/tests/ui/drop/drop_elaboration_with_errors3.rs @@ -0,0 +1,42 @@ +// Regression test for #135668 +//@ edition: 2021 + +use std::future::Future; + +pub async fn foo() { + let _ = create_task().await; +} + +async fn create_task() -> impl Sized { + bind(documentation) +} + +async fn documentation() { + compile_error!("bonjour"); + //~^ ERROR bonjour +} + +fn bind<F>(_filter: F) -> impl Sized +where + F: FilterBase, +{ + || -> <F as FilterBase>::Assoc { panic!() } +} + +trait FilterBase { + type Assoc; +} + +impl<F, R> FilterBase for F +where + F: Fn() -> R, + // Removing the below line makes it correctly error on both stable and beta + R: Future, + // Removing the below line makes it ICE on both stable and beta + R: Send, + // Removing the above two bounds makes it ICE on stable but correctly error on beta +{ + type Assoc = F; +} + +fn main() {} diff --git a/tests/ui/drop/drop_elaboration_with_errors3.stderr b/tests/ui/drop/drop_elaboration_with_errors3.stderr new file mode 100644 index 00000000000..2d44e7c6625 --- /dev/null +++ b/tests/ui/drop/drop_elaboration_with_errors3.stderr @@ -0,0 +1,8 @@ +error: bonjour + --> $DIR/drop_elaboration_with_errors3.rs:15:5 + | +LL | compile_error!("bonjour"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + |
