diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-03-17 14:27:21 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-03-28 17:09:50 +0000 |
| commit | b262c7c2dace54d58557fc79b9320c03593a21be (patch) | |
| tree | ef319694b5f10e5b30c43216ee79c3c71480b5ee | |
| parent | 5d3941878e664f152347331c69ddd078aa880c0c (diff) | |
| download | rust-b262c7c2dace54d58557fc79b9320c03593a21be.tar.gz rust-b262c7c2dace54d58557fc79b9320c03593a21be.zip | |
Add test for revealing auto traits in the defining scope
| -rw-r--r-- | src/test/ui/type-alias-impl-trait/reveal_local.rs | 26 | ||||
| -rw-r--r-- | src/test/ui/type-alias-impl-trait/reveal_local.stderr | 51 |
2 files changed, 77 insertions, 0 deletions
diff --git a/src/test/ui/type-alias-impl-trait/reveal_local.rs b/src/test/ui/type-alias-impl-trait/reveal_local.rs new file mode 100644 index 00000000000..145186baa1f --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/reveal_local.rs @@ -0,0 +1,26 @@ +#![feature(type_alias_impl_trait)] + +use std::fmt::Debug; + +type Foo = impl Debug; +//~^ ERROR cycle detected +//~| ERROR cycle detected + +fn is_send<T: Send>() { } + +fn not_good() { + // Error: this function does not constrain `Foo` to any particular + // hidden type, so it cannot rely on `Send` being true. + is_send::<Foo>(); +} + +fn not_gooder() { + // Constrain `Foo = u32` + let x: Foo = 22_u32; + + // while we could know this from the hidden type, it would + // need extra roundabout logic to support it. + is_send::<Foo>(); +} + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/reveal_local.stderr b/src/test/ui/type-alias-impl-trait/reveal_local.stderr new file mode 100644 index 00000000000..5d48dd5b2bf --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/reveal_local.stderr @@ -0,0 +1,51 @@ +error[E0391]: cycle detected when computing type of `Foo::{opaque#0}` + --> $DIR/reveal_local.rs:5:12 + | +LL | type Foo = impl Debug; + | ^^^^^^^^^^ + | +note: ...which requires type-checking `not_good`... + --> $DIR/reveal_local.rs:11:1 + | +LL | fn not_good() { + | ^^^^^^^^^^^^^ + = note: ...which again requires computing type of `Foo::{opaque#0}`, completing the cycle +note: cycle used when checking item types in top-level module + --> $DIR/reveal_local.rs:1:1 + | +LL | / #![feature(type_alias_impl_trait)] +LL | | +LL | | use std::fmt::Debug; +LL | | +... | +LL | | +LL | | fn main() {} + | |____________^ + +error[E0391]: cycle detected when computing type of `Foo::{opaque#0}` + --> $DIR/reveal_local.rs:5:12 + | +LL | type Foo = impl Debug; + | ^^^^^^^^^^ + | +note: ...which requires type-checking `not_gooder`... + --> $DIR/reveal_local.rs:17:1 + | +LL | fn not_gooder() { + | ^^^^^^^^^^^^^^^ + = note: ...which again requires computing type of `Foo::{opaque#0}`, completing the cycle +note: cycle used when checking item types in top-level module + --> $DIR/reveal_local.rs:1:1 + | +LL | / #![feature(type_alias_impl_trait)] +LL | | +LL | | use std::fmt::Debug; +LL | | +... | +LL | | +LL | | fn main() {} + | |____________^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0391`. |
