diff options
Diffstat (limited to 'src/test/ui')
30 files changed, 566 insertions, 21 deletions
diff --git a/src/test/ui/dyn-keyword/dyn-angle-brackets.fixed b/src/test/ui/dyn-keyword/dyn-angle-brackets.fixed new file mode 100644 index 00000000000..25caa6a8030 --- /dev/null +++ b/src/test/ui/dyn-keyword/dyn-angle-brackets.fixed @@ -0,0 +1,23 @@ +// See https://github.com/rust-lang/rust/issues/88508 +// run-rustfix +// edition:2018 +#![deny(bare_trait_objects)] +#![allow(dead_code)] +#![allow(unused_imports)] + +use std::fmt; + +#[derive(Debug)] +pub struct Foo; + +impl fmt::Display for Foo { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + <dyn fmt::Debug>::fmt(self, f) + //~^ ERROR trait objects without an explicit `dyn` are deprecated + //~| WARNING this is accepted in the current edition + //~| ERROR trait objects without an explicit `dyn` are deprecated + //~| WARNING this is accepted in the current edition + } +} + +fn main() {} diff --git a/src/test/ui/dyn-keyword/dyn-angle-brackets.rs b/src/test/ui/dyn-keyword/dyn-angle-brackets.rs new file mode 100644 index 00000000000..cf72da2b61e --- /dev/null +++ b/src/test/ui/dyn-keyword/dyn-angle-brackets.rs @@ -0,0 +1,23 @@ +// See https://github.com/rust-lang/rust/issues/88508 +// run-rustfix +// edition:2018 +#![deny(bare_trait_objects)] +#![allow(dead_code)] +#![allow(unused_imports)] + +use std::fmt; + +#[derive(Debug)] +pub struct Foo; + +impl fmt::Display for Foo { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + <fmt::Debug>::fmt(self, f) + //~^ ERROR trait objects without an explicit `dyn` are deprecated + //~| WARNING this is accepted in the current edition + //~| ERROR trait objects without an explicit `dyn` are deprecated + //~| WARNING this is accepted in the current edition + } +} + +fn main() {} diff --git a/src/test/ui/dyn-keyword/dyn-angle-brackets.stderr b/src/test/ui/dyn-keyword/dyn-angle-brackets.stderr new file mode 100644 index 00000000000..ef0f5b7f59d --- /dev/null +++ b/src/test/ui/dyn-keyword/dyn-angle-brackets.stderr @@ -0,0 +1,25 @@ +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-angle-brackets.rs:15:10 + | +LL | <fmt::Debug>::fmt(self, f) + | ^^^^^^^^^^ help: use `dyn`: `dyn fmt::Debug` + | +note: the lint level is defined here + --> $DIR/dyn-angle-brackets.rs:4:9 + | +LL | #![deny(bare_trait_objects)] + | ^^^^^^^^^^^^^^^^^^ + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> + +error: trait objects without an explicit `dyn` are deprecated + --> $DIR/dyn-angle-brackets.rs:15:10 + | +LL | <fmt::Debug>::fmt(self, f) + | ^^^^^^^^^^ help: use `dyn`: `dyn fmt::Debug` + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/parser/issue-87812-path.rs b/src/test/ui/parser/issue-87812-path.rs new file mode 100644 index 00000000000..b88780876db --- /dev/null +++ b/src/test/ui/parser/issue-87812-path.rs @@ -0,0 +1,11 @@ +macro_rules! foo { + ( $f:path ) => {{ + let _: usize = $f; //~ERROR + }}; +} + +struct Baz; + +fn main() { + foo!(Baz); +} diff --git a/src/test/ui/parser/issue-87812-path.stderr b/src/test/ui/parser/issue-87812-path.stderr new file mode 100644 index 00000000000..0c8e6fdd307 --- /dev/null +++ b/src/test/ui/parser/issue-87812-path.stderr @@ -0,0 +1,16 @@ +error[E0308]: mismatched types + --> $DIR/issue-87812-path.rs:3:24 + | +LL | let _: usize = $f; + | ----- ^^ expected `usize`, found struct `Baz` + | | + | expected due to this +... +LL | foo!(Baz); + | ---------- in this macro invocation + | + = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/parser/issue-87812.rs b/src/test/ui/parser/issue-87812.rs new file mode 100644 index 00000000000..0ba87b99544 --- /dev/null +++ b/src/test/ui/parser/issue-87812.rs @@ -0,0 +1,13 @@ +#![deny(break_with_label_and_loop)] + +macro_rules! foo { + ( $f:block ) => { + '_l: loop { + break '_l $f; //~ERROR + } + }; +} + +fn main() { + let x = foo!({ 3 }); +} diff --git a/src/test/ui/parser/issue-87812.stderr b/src/test/ui/parser/issue-87812.stderr new file mode 100644 index 00000000000..d61ee23a50b --- /dev/null +++ b/src/test/ui/parser/issue-87812.stderr @@ -0,0 +1,22 @@ +error: this labeled break expression is easy to confuse with an unlabeled break with a labeled value expression + --> $DIR/issue-87812.rs:6:13 + | +LL | break '_l $f; + | ^^^^^^^^^^^^ +... +LL | let x = foo!({ 3 }); + | ----------- in this macro invocation + | +note: the lint level is defined here + --> $DIR/issue-87812.rs:1:9 + | +LL | #![deny(break_with_label_and_loop)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) +help: wrap this expression in parentheses + | +LL | break '_l ($f); + | + + + +error: aborting due to previous error + diff --git a/src/test/ui/rust-2021/array-into-iter-ambiguous.fixed b/src/test/ui/rust-2021/array-into-iter-ambiguous.fixed new file mode 100644 index 00000000000..76f661baed7 --- /dev/null +++ b/src/test/ui/rust-2021/array-into-iter-ambiguous.fixed @@ -0,0 +1,27 @@ +// See https://github.com/rust-lang/rust/issues/88475 +// run-rustfix +// edition:2018 +// check-pass +#![warn(array_into_iter)] +#![allow(unused)] + +struct FooIter; + +trait MyIntoIter { + fn into_iter(self) -> FooIter; +} + +impl<T, const N: usize> MyIntoIter for [T; N] { + fn into_iter(self) -> FooIter { + FooIter + } +} + +struct Point; + +pub fn main() { + let points: [Point; 1] = [Point]; + let y = MyIntoIter::into_iter(points); + //~^ WARNING trait method `into_iter` will become ambiguous in Rust 2021 + //~| WARNING this changes meaning in Rust 2021 +} diff --git a/src/test/ui/rust-2021/array-into-iter-ambiguous.rs b/src/test/ui/rust-2021/array-into-iter-ambiguous.rs new file mode 100644 index 00000000000..83fbf8f6c21 --- /dev/null +++ b/src/test/ui/rust-2021/array-into-iter-ambiguous.rs @@ -0,0 +1,27 @@ +// See https://github.com/rust-lang/rust/issues/88475 +// run-rustfix +// edition:2018 +// check-pass +#![warn(array_into_iter)] +#![allow(unused)] + +struct FooIter; + +trait MyIntoIter { + fn into_iter(self) -> FooIter; +} + +impl<T, const N: usize> MyIntoIter for [T; N] { + fn into_iter(self) -> FooIter { + FooIter + } +} + +struct Point; + +pub fn main() { + let points: [Point; 1] = [Point]; + let y = points.into_iter(); + //~^ WARNING trait method `into_iter` will become ambiguous in Rust 2021 + //~| WARNING this changes meaning in Rust 2021 +} diff --git a/src/test/ui/rust-2021/array-into-iter-ambiguous.stderr b/src/test/ui/rust-2021/array-into-iter-ambiguous.stderr new file mode 100644 index 00000000000..fac8d21c7b4 --- /dev/null +++ b/src/test/ui/rust-2021/array-into-iter-ambiguous.stderr @@ -0,0 +1,16 @@ +warning: trait method `into_iter` will become ambiguous in Rust 2021 + --> $DIR/array-into-iter-ambiguous.rs:24:13 + | +LL | let y = points.into_iter(); + | ^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `MyIntoIter::into_iter(points)` + | +note: the lint level is defined here + --> $DIR/array-into-iter-ambiguous.rs:5:9 + | +LL | #![warn(array_into_iter)] + | ^^^^^^^^^^^^^^^ + = warning: this changes meaning in Rust 2021 + = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/IntoIterator-for-arrays.html> + +warning: 1 warning emitted + diff --git a/src/test/ui/rust-2021/future-prelude-collision-generic-trait.fixed b/src/test/ui/rust-2021/future-prelude-collision-generic-trait.fixed new file mode 100644 index 00000000000..a1b6f5b16ba --- /dev/null +++ b/src/test/ui/rust-2021/future-prelude-collision-generic-trait.fixed @@ -0,0 +1,30 @@ +// See https://github.com/rust-lang/rust/issues/88470 +// run-rustfix +// edition:2018 +// check-pass +#![warn(rust_2021_prelude_collisions)] +#![allow(dead_code)] +#![allow(unused_imports)] + +pub trait PyTryFrom<'v, T>: Sized { + fn try_from<V>(value: V) -> Result<&'v Self, T>; +} + +pub trait PyTryInto<T>: Sized { + fn try_into(&self) -> Result<&T, i32>; +} + +struct Foo; + +impl<U> PyTryInto<U> for Foo +where + U: for<'v> PyTryFrom<'v, i32>, +{ + fn try_into(&self) -> Result<&U, i32> { + <U as PyTryFrom<'_, _>>::try_from(self) + //~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021 + //~| this is accepted in the current edition (Rust 2018) + } +} + +fn main() {} diff --git a/src/test/ui/rust-2021/future-prelude-collision-generic-trait.rs b/src/test/ui/rust-2021/future-prelude-collision-generic-trait.rs new file mode 100644 index 00000000000..142ba552002 --- /dev/null +++ b/src/test/ui/rust-2021/future-prelude-collision-generic-trait.rs @@ -0,0 +1,30 @@ +// See https://github.com/rust-lang/rust/issues/88470 +// run-rustfix +// edition:2018 +// check-pass +#![warn(rust_2021_prelude_collisions)] +#![allow(dead_code)] +#![allow(unused_imports)] + +pub trait PyTryFrom<'v, T>: Sized { + fn try_from<V>(value: V) -> Result<&'v Self, T>; +} + +pub trait PyTryInto<T>: Sized { + fn try_into(&self) -> Result<&T, i32>; +} + +struct Foo; + +impl<U> PyTryInto<U> for Foo +where + U: for<'v> PyTryFrom<'v, i32>, +{ + fn try_into(&self) -> Result<&U, i32> { + U::try_from(self) + //~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021 + //~| this is accepted in the current edition (Rust 2018) + } +} + +fn main() {} diff --git a/src/test/ui/rust-2021/future-prelude-collision-generic-trait.stderr b/src/test/ui/rust-2021/future-prelude-collision-generic-trait.stderr new file mode 100644 index 00000000000..14ad9b017b6 --- /dev/null +++ b/src/test/ui/rust-2021/future-prelude-collision-generic-trait.stderr @@ -0,0 +1,16 @@ +warning: trait-associated function `try_from` will become ambiguous in Rust 2021 + --> $DIR/future-prelude-collision-generic-trait.rs:24:9 + | +LL | U::try_from(self) + | ^^^^^^^^^^^ help: disambiguate the associated function: `<U as PyTryFrom<'_, _>>::try_from` + | +note: the lint level is defined here + --> $DIR/future-prelude-collision-generic-trait.rs:5:9 + | +LL | #![warn(rust_2021_prelude_collisions)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html> + +warning: 1 warning emitted + diff --git a/src/test/ui/rust-2021/future-prelude-collision-generic.fixed b/src/test/ui/rust-2021/future-prelude-collision-generic.fixed index f0d8cb944cf..1bb9ba37774 100644 --- a/src/test/ui/rust-2021/future-prelude-collision-generic.fixed +++ b/src/test/ui/rust-2021/future-prelude-collision-generic.fixed @@ -6,32 +6,32 @@ #![allow(dead_code)] #![allow(unused_imports)] -struct Generic<T, U>(T, U); +struct Generic<'a, U>(&'a U); trait MyFromIter { fn from_iter(_: i32) -> Self; } -impl MyFromIter for Generic<i32, i32> { - fn from_iter(x: i32) -> Self { - Self(x, x) +impl MyFromIter for Generic<'static, i32> { + fn from_iter(_: i32) -> Self { + todo!() } } -impl std::iter::FromIterator<i32> for Generic<i32, i32> { +impl std::iter::FromIterator<i32> for Generic<'static, i32> { fn from_iter<T: IntoIterator<Item = i32>>(_: T) -> Self { todo!() } } fn main() { - <Generic<_, _> as MyFromIter>::from_iter(1); + <Generic<'_, _> as MyFromIter>::from_iter(1); //~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021 //~| this is accepted in the current edition (Rust 2018) - <Generic::<i32, i32> as MyFromIter>::from_iter(1); + <Generic::<'static, i32> as MyFromIter>::from_iter(1); //~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021 //~| this is accepted in the current edition (Rust 2018) - <Generic::<_, _> as MyFromIter>::from_iter(1); + <Generic::<'_, _> as MyFromIter>::from_iter(1); //~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021 //~| this is accepted in the current edition (Rust 2018) } diff --git a/src/test/ui/rust-2021/future-prelude-collision-generic.rs b/src/test/ui/rust-2021/future-prelude-collision-generic.rs index 19840537059..d7f8affc61a 100644 --- a/src/test/ui/rust-2021/future-prelude-collision-generic.rs +++ b/src/test/ui/rust-2021/future-prelude-collision-generic.rs @@ -6,19 +6,19 @@ #![allow(dead_code)] #![allow(unused_imports)] -struct Generic<T, U>(T, U); +struct Generic<'a, U>(&'a U); trait MyFromIter { fn from_iter(_: i32) -> Self; } -impl MyFromIter for Generic<i32, i32> { - fn from_iter(x: i32) -> Self { - Self(x, x) +impl MyFromIter for Generic<'static, i32> { + fn from_iter(_: i32) -> Self { + todo!() } } -impl std::iter::FromIterator<i32> for Generic<i32, i32> { +impl std::iter::FromIterator<i32> for Generic<'static, i32> { fn from_iter<T: IntoIterator<Item = i32>>(_: T) -> Self { todo!() } @@ -28,10 +28,10 @@ fn main() { Generic::from_iter(1); //~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021 //~| this is accepted in the current edition (Rust 2018) - Generic::<i32, i32>::from_iter(1); + Generic::<'static, i32>::from_iter(1); //~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021 //~| this is accepted in the current edition (Rust 2018) - Generic::<_, _>::from_iter(1); + Generic::<'_, _>::from_iter(1); //~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021 //~| this is accepted in the current edition (Rust 2018) } diff --git a/src/test/ui/rust-2021/future-prelude-collision-generic.stderr b/src/test/ui/rust-2021/future-prelude-collision-generic.stderr index 0a722baa185..e1d3f3c0a46 100644 --- a/src/test/ui/rust-2021/future-prelude-collision-generic.stderr +++ b/src/test/ui/rust-2021/future-prelude-collision-generic.stderr @@ -2,7 +2,7 @@ warning: trait-associated function `from_iter` will become ambiguous in Rust 202 --> $DIR/future-prelude-collision-generic.rs:28:5 | LL | Generic::from_iter(1); - | ^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Generic<_, _> as MyFromIter>::from_iter` + | ^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Generic<'_, _> as MyFromIter>::from_iter` | note: the lint level is defined here --> $DIR/future-prelude-collision-generic.rs:5:9 @@ -15,8 +15,8 @@ LL | #![warn(rust_2021_prelude_collisions)] warning: trait-associated function `from_iter` will become ambiguous in Rust 2021 --> $DIR/future-prelude-collision-generic.rs:31:5 | -LL | Generic::<i32, i32>::from_iter(1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Generic::<i32, i32> as MyFromIter>::from_iter` +LL | Generic::<'static, i32>::from_iter(1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Generic::<'static, i32> as MyFromIter>::from_iter` | = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html> @@ -24,8 +24,8 @@ LL | Generic::<i32, i32>::from_iter(1); warning: trait-associated function `from_iter` will become ambiguous in Rust 2021 --> $DIR/future-prelude-collision-generic.rs:34:5 | -LL | Generic::<_, _>::from_iter(1); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Generic::<_, _> as MyFromIter>::from_iter` +LL | Generic::<'_, _>::from_iter(1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Generic::<'_, _> as MyFromIter>::from_iter` | = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html> diff --git a/src/test/ui/rust-2021/future-prelude-collision-imported.fixed b/src/test/ui/rust-2021/future-prelude-collision-imported.fixed index c5ff0b4bcd0..15ccff7496e 100644 --- a/src/test/ui/rust-2021/future-prelude-collision-imported.fixed +++ b/src/test/ui/rust-2021/future-prelude-collision-imported.fixed @@ -56,4 +56,15 @@ mod c { } } +mod d { + use super::m::*; + + fn main() { + // See https://github.com/rust-lang/rust/issues/88471 + let _: u32 = TryIntoU32::try_into(3u8).unwrap(); + //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 + //~^^ WARNING this is accepted in the current edition + } +} + fn main() {} diff --git a/src/test/ui/rust-2021/future-prelude-collision-imported.rs b/src/test/ui/rust-2021/future-prelude-collision-imported.rs index cd39eec47f2..cdffcaf7545 100644 --- a/src/test/ui/rust-2021/future-prelude-collision-imported.rs +++ b/src/test/ui/rust-2021/future-prelude-collision-imported.rs @@ -56,4 +56,15 @@ mod c { } } +mod d { + use super::m::*; + + fn main() { + // See https://github.com/rust-lang/rust/issues/88471 + let _: u32 = 3u8.try_into().unwrap(); + //~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 + //~^^ WARNING this is accepted in the current edition + } +} + fn main() {} diff --git a/src/test/ui/rust-2021/future-prelude-collision-imported.stderr b/src/test/ui/rust-2021/future-prelude-collision-imported.stderr index fbda5d61f36..56abb8abd4d 100644 --- a/src/test/ui/rust-2021/future-prelude-collision-imported.stderr +++ b/src/test/ui/rust-2021/future-prelude-collision-imported.stderr @@ -30,5 +30,14 @@ LL | let _: u32 = 3u8.try_into().unwrap(); = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html> -warning: 3 warnings emitted +warning: trait method `try_into` will become ambiguous in Rust 2021 + --> $DIR/future-prelude-collision-imported.rs:64:22 + | +LL | let _: u32 = 3u8.try_into().unwrap(); + | ^^^^^^^^^^^^^^ help: disambiguate the associated function: `TryIntoU32::try_into(3u8)` + | + = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! + = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html> + +warning: 4 warnings emitted diff --git a/src/test/ui/type-alias-impl-trait/auto-trait-leakage.rs b/src/test/ui/type-alias-impl-trait/auto-trait-leakage.rs new file mode 100644 index 00000000000..a1584581e6c --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/auto-trait-leakage.rs @@ -0,0 +1,18 @@ +// check-pass + +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +mod m { + type Foo = impl std::fmt::Debug; + + pub fn foo() -> Foo { + 22_u32 + } +} + +fn is_send<T: Send>(_: T) {} + +fn main() { + is_send(m::foo()); +} diff --git a/src/test/ui/type-alias-impl-trait/auto-trait-leakage2.rs b/src/test/ui/type-alias-impl-trait/auto-trait-leakage2.rs new file mode 100644 index 00000000000..745379efa6d --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/auto-trait-leakage2.rs @@ -0,0 +1,19 @@ +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +mod m { + use std::rc::Rc; + + type Foo = impl std::fmt::Debug; + + pub fn foo() -> Foo { + Rc::new(22_u32) + } +} + +fn is_send<T: Send>(_: T) {} + +fn main() { + is_send(m::foo()); + //~^ ERROR: `Rc<u32>` cannot be sent between threads safely [E0277] +} diff --git a/src/test/ui/type-alias-impl-trait/auto-trait-leakage2.stderr b/src/test/ui/type-alias-impl-trait/auto-trait-leakage2.stderr new file mode 100644 index 00000000000..d60be4b1ccf --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/auto-trait-leakage2.stderr @@ -0,0 +1,20 @@ +error[E0277]: `Rc<u32>` cannot be sent between threads safely + --> $DIR/auto-trait-leakage2.rs:17:5 + | +LL | type Foo = impl std::fmt::Debug; + | -------------------- within this `impl Debug` +... +LL | is_send(m::foo()); + | ^^^^^^^ `Rc<u32>` cannot be sent between threads safely + | + = help: within `impl Debug`, the trait `Send` is not implemented for `Rc<u32>` + = note: required because it appears within the type `impl Debug` +note: required by a bound in `is_send` + --> $DIR/auto-trait-leakage2.rs:14:15 + | +LL | fn is_send<T: Send>(_: T) {} + | ^^^^ required by this bound in `is_send` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/auto-trait-leakage3.rs b/src/test/ui/type-alias-impl-trait/auto-trait-leakage3.rs new file mode 100644 index 00000000000..5fb7a9473d3 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/auto-trait-leakage3.rs @@ -0,0 +1,21 @@ +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +// FIXME This should compile, but it currently doesn't + +mod m { + type Foo = impl std::fmt::Debug; + //~^ ERROR: cycle detected when computing type of `m::Foo::{opaque#0}` [E0391] + + pub fn foo() -> Foo { + 22_u32 + } + + pub fn bar() { + is_send(foo()); + } + + fn is_send<T: Send>(_: T) {} +} + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/auto-trait-leakage3.stderr b/src/test/ui/type-alias-impl-trait/auto-trait-leakage3.stderr new file mode 100644 index 00000000000..ac7bbd272c7 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/auto-trait-leakage3.stderr @@ -0,0 +1,22 @@ +error[E0391]: cycle detected when computing type of `m::Foo::{opaque#0}` + --> $DIR/auto-trait-leakage3.rs:7:16 + | +LL | type Foo = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ + | +note: ...which requires type-checking `m::bar`... + --> $DIR/auto-trait-leakage3.rs:14:5 + | +LL | pub fn bar() { + | ^^^^^^^^^^^^ + = note: ...which requires evaluating trait selection obligation `impl std::fmt::Debug: std::marker::Send`... + = note: ...which again requires computing type of `m::Foo::{opaque#0}`, completing the cycle +note: cycle used when checking item types in module `m` + --> $DIR/auto-trait-leakage3.rs:6:1 + | +LL | mod m { + | ^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0391`. diff --git a/src/test/ui/type-alias-impl-trait/inference-cycle.rs b/src/test/ui/type-alias-impl-trait/inference-cycle.rs new file mode 100644 index 00000000000..c781e200bf8 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/inference-cycle.rs @@ -0,0 +1,26 @@ +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +mod m { + type Foo = impl std::fmt::Debug; + //~^ ERROR: cycle detected when computing type of `m::Foo::{opaque#0}` [E0391] + + // Cycle: error today, but it'd be nice if it eventually worked + + pub fn foo() -> Foo { + is_send(bar()) + } + + pub fn bar() { + is_send(foo()); // Today: error + } + + fn baz() { + let f: Foo = 22_u32; + //~^ ERROR: mismatched types [E0308] + } + + fn is_send<T: Send>(_: T) {} +} + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/inference-cycle.stderr b/src/test/ui/type-alias-impl-trait/inference-cycle.stderr new file mode 100644 index 00000000000..ac0ca8e048c --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/inference-cycle.stderr @@ -0,0 +1,37 @@ +error[E0391]: cycle detected when computing type of `m::Foo::{opaque#0}` + --> $DIR/inference-cycle.rs:5:16 + | +LL | type Foo = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ + | +note: ...which requires type-checking `m::bar`... + --> $DIR/inference-cycle.rs:14:5 + | +LL | pub fn bar() { + | ^^^^^^^^^^^^ + = note: ...which requires evaluating trait selection obligation `impl std::fmt::Debug: std::marker::Send`... + = note: ...which again requires computing type of `m::Foo::{opaque#0}`, completing the cycle +note: cycle used when checking item types in module `m` + --> $DIR/inference-cycle.rs:4:1 + | +LL | mod m { + | ^^^^^ + +error[E0308]: mismatched types + --> $DIR/inference-cycle.rs:19:22 + | +LL | type Foo = impl std::fmt::Debug; + | -------------------- the expected opaque type +... +LL | let f: Foo = 22_u32; + | --- ^^^^^^ expected opaque type, found `u32` + | | + | expected due to this + | + = note: expected opaque type `impl Debug` + found type `u32` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0308, E0391. +For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/type-alias-impl-trait/nested-tait-inference.rs b/src/test/ui/type-alias-impl-trait/nested-tait-inference.rs new file mode 100644 index 00000000000..efb88dabf34 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/nested-tait-inference.rs @@ -0,0 +1,18 @@ +// check-pass + +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +use std::fmt::Debug; + +type FooX = impl Debug; + +trait Foo<A> { } + +impl Foo<()> for () { } + +fn foo() -> impl Foo<FooX> { + () +} + +fn main() { } diff --git a/src/test/ui/type-alias-impl-trait/nested-tait-inference2.rs b/src/test/ui/type-alias-impl-trait/nested-tait-inference2.rs new file mode 100644 index 00000000000..9b26a652978 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/nested-tait-inference2.rs @@ -0,0 +1,19 @@ +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +use std::fmt::Debug; + +type FooX = impl Debug; +//~^ ERROR: could not find defining uses + +trait Foo<A> {} + +impl Foo<()> for () {} +impl Foo<u32> for () {} + +fn foo() -> impl Foo<FooX> { + //~^ ERROR: the trait bound `(): Foo<impl Debug>` is not satisfied [E0277] + () +} + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/nested-tait-inference2.stderr b/src/test/ui/type-alias-impl-trait/nested-tait-inference2.stderr new file mode 100644 index 00000000000..7e24ee644b1 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/nested-tait-inference2.stderr @@ -0,0 +1,19 @@ +error[E0277]: the trait bound `(): Foo<impl Debug>` is not satisfied + --> $DIR/nested-tait-inference2.rs:14:13 + | +LL | fn foo() -> impl Foo<FooX> { + | ^^^^^^^^^^^^^^ the trait `Foo<impl Debug>` is not implemented for `()` + | + = help: the following implementations were found: + <() as Foo<()>> + <() as Foo<u32>> + +error: could not find defining uses + --> $DIR/nested-tait-inference2.rs:6:13 + | +LL | type FooX = impl Debug; + | ^^^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/weird-return-types.rs b/src/test/ui/type-alias-impl-trait/weird-return-types.rs new file mode 100644 index 00000000000..faad5ee956a --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/weird-return-types.rs @@ -0,0 +1,16 @@ +// edition:2018 +// check-pass + +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +use std::future::Future; +use std::fmt::Debug; + +type Foo = impl Debug; + +fn f() -> impl Future<Output = Foo> { + async move { 22_u32 } +} + +fn main() {} |
