Skip to content

Commit 837856d

Browse files
committed
Test illustrating that the nested_impl_trait lint should only catch shallow cases.
1 parent c993033 commit 837856d

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// rust-lang/rust#57979 : the initial support for `impl Trait` didn't
2+
// properly check syntax hidden behind an associated type projection,
3+
// but it did catch *some cases*. This is checking that we continue to
4+
// properly emit errors for those, even with the new
5+
// future-incompatibility warnings.
6+
//
7+
// issue-57979-nested-impl-trait-in-assoc-proj.rs shows the main case
8+
// that we were previously failing to catch.
9+
10+
struct Deeper<T>(T);
11+
12+
mod allowed {
13+
#![allow(nested_impl_trait)]
14+
15+
pub trait Foo<T> { }
16+
pub trait Bar { }
17+
pub trait Quux { type Assoc; }
18+
pub fn demo(_: impl Quux<Assoc=super::Deeper<impl Foo<impl Bar>>>) { }
19+
//~^ ERROR nested `impl Trait` is not allowed
20+
}
21+
22+
mod warned {
23+
#![warn(nested_impl_trait)]
24+
25+
pub trait Foo<T> { }
26+
pub trait Bar { }
27+
pub trait Quux { type Assoc; }
28+
pub fn demo(_: impl Quux<Assoc=super::Deeper<impl Foo<impl Bar>>>) { }
29+
//~^ ERROR nested `impl Trait` is not allowed
30+
}
31+
32+
mod denied {
33+
#![deny(nested_impl_trait)]
34+
35+
pub trait Foo<T> { }
36+
pub trait Bar { }
37+
pub trait Quux { type Assoc; }
38+
pub fn demo(_: impl Quux<Assoc=super::Deeper<impl Foo<impl Bar>>>) { }
39+
//~^ ERROR nested `impl Trait` is not allowed
40+
}
41+
42+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error[E0666]: nested `impl Trait` is not allowed
2+
--> $DIR/issue-57979-deeply-nested-impl-trait-in-assoc-proj.rs:18:59
3+
|
4+
LL | pub fn demo(_: impl Quux<Assoc=super::Deeper<impl Foo<impl Bar>>>) { }
5+
| ---------^^^^^^^^-
6+
| | |
7+
| | nested `impl Trait` here
8+
| outer `impl Trait`
9+
10+
error[E0666]: nested `impl Trait` is not allowed
11+
--> $DIR/issue-57979-deeply-nested-impl-trait-in-assoc-proj.rs:28:59
12+
|
13+
LL | pub fn demo(_: impl Quux<Assoc=super::Deeper<impl Foo<impl Bar>>>) { }
14+
| ---------^^^^^^^^-
15+
| | |
16+
| | nested `impl Trait` here
17+
| outer `impl Trait`
18+
19+
error[E0666]: nested `impl Trait` is not allowed
20+
--> $DIR/issue-57979-deeply-nested-impl-trait-in-assoc-proj.rs:38:59
21+
|
22+
LL | pub fn demo(_: impl Quux<Assoc=super::Deeper<impl Foo<impl Bar>>>) { }
23+
| ---------^^^^^^^^-
24+
| | |
25+
| | nested `impl Trait` here
26+
| outer `impl Trait`
27+
28+
error: aborting due to 3 previous errors
29+
30+
For more information about this error, try `rustc --explain E0666`.

0 commit comments

Comments
 (0)