From 4e7edf3684ac96f57f918afdb560c4af7afafb60 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 16 Apr 2023 09:56:37 +0000 Subject: [PATCH] Add tests. --- tests/ui/impl-trait/issue-108591.rs | 30 +++++++++++++++++++++++++ tests/ui/impl-trait/issue-108592.rs | 21 +++++++++++++++++ tests/ui/impl-trait/issue-108592.stderr | 21 +++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 tests/ui/impl-trait/issue-108591.rs create mode 100644 tests/ui/impl-trait/issue-108592.rs create mode 100644 tests/ui/impl-trait/issue-108592.stderr diff --git a/tests/ui/impl-trait/issue-108591.rs b/tests/ui/impl-trait/issue-108591.rs new file mode 100644 index 00000000000..6b9d14941f2 --- /dev/null +++ b/tests/ui/impl-trait/issue-108591.rs @@ -0,0 +1,30 @@ +// check-pass + +#![feature(type_alias_impl_trait)] + +struct MyTy<'a>(Vec, &'a ()); + +impl MyTy<'_> { + fn one(&mut self) -> &mut impl Sized { + &mut self.0 + } + fn two(&mut self) -> &mut (impl Sized + 'static) { + self.one() + } +} + +type Opaque<'a> = impl Sized; +fn define<'a>() -> Opaque<'a> {} + +fn test<'a>() { + None::<&'static Opaque<'a>>; +} + +fn one<'a, 'b: 'b>() -> &'a impl Sized { + &() +} +fn two<'a, 'b>() { + one::<'a, 'b>(); +} + +fn main() {} diff --git a/tests/ui/impl-trait/issue-108592.rs b/tests/ui/impl-trait/issue-108592.rs new file mode 100644 index 00000000000..58a0ed9bf1a --- /dev/null +++ b/tests/ui/impl-trait/issue-108592.rs @@ -0,0 +1,21 @@ +// check-pass +#![feature(type_alias_impl_trait)] + +fn opaque<'a: 'a>() -> impl Sized {} +fn assert_static(_: T) {} + +fn test_closure() { + let closure = |_| { + assert_static(opaque()); + }; + closure(&opaque()); +} + +type Opaque<'a> = impl Sized; +fn define<'a>() -> Opaque<'a> {} + +fn test_tait(_: &Opaque<'_>) { + None::<&'static Opaque<'_>>; +} + +fn main() {} diff --git a/tests/ui/impl-trait/issue-108592.stderr b/tests/ui/impl-trait/issue-108592.stderr new file mode 100644 index 00000000000..3fbf0b266c3 --- /dev/null +++ b/tests/ui/impl-trait/issue-108592.stderr @@ -0,0 +1,21 @@ +error[E0428]: the name `test` is defined multiple times + --> $DIR/issue-108592.rs:17:1 + | +LL | fn test() { + | --------- previous definition of the value `test` here +... +LL | fn test(_: &Opaque<'_>) { + | ^^^^^^^^^^^^^^^^^^^^^^^ `test` redefined here + | + = note: `test` must be defined only once in the value namespace of this module + +error[E0601]: `main` function not found in crate `issue_108592` + --> $DIR/issue-108592.rs:20:2 + | +LL | } + | ^ consider adding a `main` function to `$DIR/issue-108592.rs` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0428, E0601. +For more information about an error, try `rustc --explain E0428`.