]> git.lizzy.rs Git - rust.git/blob - src/test/ui/impl-trait/issue-57979-deeply-nested-impl-trait-in-assoc-proj.rs
Test illustrating that the nested_impl_trait lint should only catch shallow cases.
[rust.git] / src / test / ui / impl-trait / issue-57979-deeply-nested-impl-trait-in-assoc-proj.rs
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() { }