From dbadab54df148b55b2e884440bfaeaa38517e6e8 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 24 Aug 2021 22:52:41 -0300 Subject: [PATCH] Add type of a let tait test impl trait straight in let --- .../type-alias-impl-trait/type_of_a_let2.rs | 25 +++++++++++++++++++ .../type_of_a_let2.stderr | 21 ++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/test/ui/type-alias-impl-trait/type_of_a_let2.rs create mode 100644 src/test/ui/type-alias-impl-trait/type_of_a_let2.stderr diff --git a/src/test/ui/type-alias-impl-trait/type_of_a_let2.rs b/src/test/ui/type-alias-impl-trait/type_of_a_let2.rs new file mode 100644 index 00000000000..33d3f164ce1 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/type_of_a_let2.rs @@ -0,0 +1,25 @@ +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +// FIXME This should be under a feature flag + +use std::fmt::Debug; + +fn foo1() -> u32 { + let x: impl Debug = 22_u32; + //~^ ERROR: `impl Trait` not allowed outside of function and method return types [E0562] + x // ERROR: we only know x: Debug, we don't know x = u32 +} + +fn foo2() -> u32 { + let x: impl Debug = 22_u32; + //~^ ERROR: `impl Trait` not allowed outside of function and method return types [E0562] + let y: impl Debug = x; + //~^ ERROR: `impl Trait` not allowed outside of function and method return types [E0562] + same_type((x, y)); // ERROR + x +} + +fn same_type(x: (T, T)) {} + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/type_of_a_let2.stderr b/src/test/ui/type-alias-impl-trait/type_of_a_let2.stderr new file mode 100644 index 00000000000..7a1825a8e2d --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/type_of_a_let2.stderr @@ -0,0 +1,21 @@ +error[E0562]: `impl Trait` not allowed outside of function and method return types + --> $DIR/type_of_a_let2.rs:9:12 + | +LL | let x: impl Debug = 22_u32; + | ^^^^^^^^^^ + +error[E0562]: `impl Trait` not allowed outside of function and method return types + --> $DIR/type_of_a_let2.rs:15:12 + | +LL | let x: impl Debug = 22_u32; + | ^^^^^^^^^^ + +error[E0562]: `impl Trait` not allowed outside of function and method return types + --> $DIR/type_of_a_let2.rs:17:12 + | +LL | let y: impl Debug = x; + | ^^^^^^^^^^ + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0562`. -- GitLab