Skip to content

Commit 7c0c329

Browse files
authored
Rollup merge of rust-lang#87383 - Alexendoo:impl_trait_in_bindings-tests, r=oli-obk
Add regression tests for the impl_trait_in_bindings ICEs Closes rust-lang#54600, closes rust-lang#54840, closes rust-lang#58504, closes rust-lang#58956, closes rust-lang#70971, closes rust-lang#79099, closes rust-lang#84919, closes rust-lang#86201, closes rust-lang#86642, closes rust-lang#87295 r? ``@oli-obk``
2 parents fe5799c + 470d378 commit 7c0c329

20 files changed

+221
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use std::fmt::Debug;
2+
3+
fn main() {
4+
let x: Option<impl Debug> = Some(44_u32);
5+
//~^ `impl Trait` not allowed outside of function and method return types
6+
println!("{:?}", x);
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0562]: `impl Trait` not allowed outside of function and method return types
2+
--> $DIR/issue-54600.rs:4:19
3+
|
4+
LL | let x: Option<impl Debug> = Some(44_u32);
5+
| ^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0562`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use std::ops::Add;
2+
3+
fn main() {
4+
let i: i32 = 0;
5+
let j: &impl Add = &i;
6+
//~^ `impl Trait` not allowed outside of function and method return types
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0562]: `impl Trait` not allowed outside of function and method return types
2+
--> $DIR/issue-54840.rs:5:13
3+
|
4+
LL | let j: &impl Add = &i;
5+
| ^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0562`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(generators, generator_trait, never_type)]
2+
3+
use std::ops::Generator;
4+
5+
fn mk_gen() -> impl Generator<Return=!, Yield=()> {
6+
|| { loop { yield; } }
7+
}
8+
9+
fn main() {
10+
let gens: [impl Generator<Return=!, Yield=()>;2] = [ mk_gen(), mk_gen() ];
11+
//~^ `impl Trait` not allowed outside of function and method return types
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0562]: `impl Trait` not allowed outside of function and method return types
2+
--> $DIR/issue-58504.rs:10:16
3+
|
4+
LL | let gens: [impl Generator<Return=!, Yield=()>;2] = [ mk_gen(), mk_gen() ];
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0562`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
trait Lam {}
2+
3+
pub struct B;
4+
impl Lam for B {}
5+
pub struct Wrap<T>(T);
6+
7+
const _A: impl Lam = {
8+
//~^ `impl Trait` not allowed outside of function and method return types
9+
let x: Wrap<impl Lam> = Wrap(B);
10+
//~^ `impl Trait` not allowed outside of function and method return types
11+
x.0
12+
};
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0562]: `impl Trait` not allowed outside of function and method return types
2+
--> $DIR/issue-58956.rs:7:11
3+
|
4+
LL | const _A: impl Lam = {
5+
| ^^^^^^^^
6+
7+
error[E0562]: `impl Trait` not allowed outside of function and method return types
8+
--> $DIR/issue-58956.rs:9:17
9+
|
10+
LL | let x: Wrap<impl Lam> = Wrap(B);
11+
| ^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0562`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
let x : (impl Copy,) = (true,);
3+
//~^ `impl Trait` not allowed outside of function and method return types
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0562]: `impl Trait` not allowed outside of function and method return types
2+
--> $DIR/issue-70971.rs:2:14
3+
|
4+
LL | let x : (impl Copy,) = (true,);
5+
| ^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0562`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
struct Bug {
2+
V1: [(); {
3+
let f: impl core::future::Future<Output = u8> = async { 1 };
4+
//~^ `impl Trait` not allowed outside of function and method return types
5+
//~| expected identifier
6+
1
7+
}],
8+
}
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: expected identifier, found `1`
2+
--> $DIR/issue-79099.rs:3:65
3+
|
4+
LL | let f: impl core::future::Future<Output = u8> = async { 1 };
5+
| ----- ^ expected identifier
6+
| |
7+
| `async` blocks are only allowed in Rust 2018 or later
8+
|
9+
= help: set `edition = "2018"` in `Cargo.toml`
10+
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
11+
12+
error[E0562]: `impl Trait` not allowed outside of function and method return types
13+
--> $DIR/issue-79099.rs:3:16
14+
|
15+
LL | let f: impl core::future::Future<Output = u8> = async { 1 };
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
18+
error: aborting due to 2 previous errors
19+
20+
For more information about this error, try `rustc --explain E0562`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait Trait {}
2+
impl Trait for () {}
3+
4+
fn foo<'a: 'a>() {
5+
let _x: impl Trait = ();
6+
//~^ `impl Trait` not allowed outside of function and method return types
7+
}
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0562]: `impl Trait` not allowed outside of function and method return types
2+
--> $DIR/issue-84919.rs:5:13
3+
|
4+
LL | let _x: impl Trait = ();
5+
| ^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0562`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(unboxed_closures)]
2+
#![feature(min_type_alias_impl_trait)]
3+
4+
type FunType = impl Fn<()>;
5+
//~^ could not find defining uses
6+
static STATIC_FN: FunType = some_fn;
7+
//~^ mismatched types
8+
9+
fn some_fn() {}
10+
11+
fn main() {
12+
let _: <FunType as FnOnce<()>>::Output = STATIC_FN();
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-86201.rs:6:29
3+
|
4+
LL | type FunType = impl Fn<()>;
5+
| ----------- the expected opaque type
6+
LL |
7+
LL | static STATIC_FN: FunType = some_fn;
8+
| ^^^^^^^ expected opaque type, found fn item
9+
|
10+
= note: expected opaque type `impl Fn<()>`
11+
found fn item `fn() {some_fn}`
12+
13+
error: could not find defining uses
14+
--> $DIR/issue-86201.rs:4:16
15+
|
16+
LL | type FunType = impl Fn<()>;
17+
| ^^^^^^^^^^^
18+
19+
error: aborting due to 2 previous errors
20+
21+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
static x: impl Fn(&str) -> Result<&str, ()> = move |source| {
2+
//~^ `impl Trait` not allowed outside of function and method return types
3+
let res = (move |source| Ok(source))(source);
4+
let res = res.or((move |source| Ok(source))(source));
5+
res
6+
};
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0562]: `impl Trait` not allowed outside of function and method return types
2+
--> $DIR/issue-86642.rs:1:11
3+
|
4+
LL | static x: impl Fn(&str) -> Result<&str, ()> = move |source| {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0562`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
trait Trait {
2+
type Output;
3+
}
4+
impl Trait for () {
5+
type Output = i32;
6+
}
7+
8+
struct Struct<F>(F);
9+
impl<F> Struct<F> {
10+
pub fn new(_: F) -> Self {
11+
todo!()
12+
}
13+
}
14+
15+
fn main() {
16+
let _do_not_waste: Struct<impl Trait<Output = i32>> = Struct::new(());
17+
//~^ `impl Trait` not allowed outside of function and method return types
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0562]: `impl Trait` not allowed outside of function and method return types
2+
--> $DIR/issue-87295.rs:16:31
3+
|
4+
LL | let _do_not_waste: Struct<impl Trait<Output = i32>> = Struct::new(());
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0562`.

0 commit comments

Comments
 (0)