From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../type-alias-impl-trait2.rs | 84 ++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/test/ui/type-alias-impl-trait/type-alias-impl-trait2.rs (limited to 'src/test/ui/type-alias-impl-trait/type-alias-impl-trait2.rs') diff --git a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait2.rs b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait2.rs new file mode 100644 index 000000000..67f56bcde --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait2.rs @@ -0,0 +1,84 @@ +// check-pass + +#![allow(dead_code)] +#![allow(unused_assignments)] +#![allow(unused_variables)] +#![feature(type_alias_impl_trait)] + +fn main() { + assert_eq!(foo().to_string(), "foo"); + assert_eq!(bar1().to_string(), "bar1"); + assert_eq!(bar2().to_string(), "bar2"); + let mut x = bar1(); + x = bar2(); + assert_eq!(my_iter(42u8).collect::>(), vec![42u8]); +} + +use defining_use_scope::*; + +mod defining_use_scope { + // single definition + pub type Foo = impl std::fmt::Display; + + pub fn foo() -> Foo { + "foo" + } + + // two definitions + pub type Bar = impl std::fmt::Display; + + pub fn bar1() -> Bar { + "bar1" + } + + pub fn bar2() -> Bar { + "bar2" + } + + pub type MyIter = impl Iterator; + + pub fn my_iter(t: T) -> MyIter { + std::iter::once(t) + } + + fn my_iter2(t: T) -> MyIter { + std::iter::once(t) + } + + // param names should not have an effect! + fn my_iter3(u: U) -> MyIter { + std::iter::once(u) + } + + // param position should not have an effect! + fn my_iter4(_: U, v: V) -> MyIter { + std::iter::once(v) + } + + // param names should not have an effect! + type MyOtherIter = impl Iterator; + + fn my_other_iter(u: U) -> MyOtherIter { + std::iter::once(u) + } + + trait Trait {} + type GenericBound<'a, T: Trait + 'a> = impl Sized + 'a; + + fn generic_bound<'a, T: Trait + 'a>(t: T) -> GenericBound<'a, T> { + t + } + + mod pass_through { + pub type Passthrough = impl Sized + 'static; + + fn define_passthrough(t: T) -> Passthrough { + t + } + } + + fn use_passthrough(x: pass_through::Passthrough) -> pass_through::Passthrough { + x + } + +} -- cgit v1.2.3