Skip to content

Commit d6cee67

Browse files
committed
Unit (and regression) tests for warning cycle code.
1 parent 98e4017 commit d6cee67

6 files changed

+140
-59
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// rust-lang/rust#57979 : the initial support for `impl Trait` didn't
2+
// properly check syntax hidden behind an associated type projection.
3+
// Here we test behavior of occurrences of `impl Trait` within a path
4+
// component in that context.
5+
6+
mod allowed {
7+
#![allow(nested_impl_trait)]
8+
9+
pub trait Bar { }
10+
pub trait Quux<T> { type Assoc; }
11+
pub fn demo(_: impl Quux<(), Assoc=<() as Quux<impl Bar>>::Assoc>) { }
12+
impl<T> Quux<T> for () { type Assoc = u32; }
13+
}
14+
15+
mod warned {
16+
#![warn(nested_impl_trait)]
17+
18+
pub trait Bar { }
19+
pub trait Quux<T> { type Assoc; }
20+
pub fn demo(_: impl Quux<(), Assoc=<() as Quux<impl Bar>>::Assoc>) { }
21+
//~^ WARN `impl Trait` is not allowed in path parameters
22+
//~| WARN will become a hard error in a future release!
23+
impl<T> Quux<T> for () { type Assoc = u32; }
24+
}
25+
26+
mod denied {
27+
#![deny(nested_impl_trait)]
28+
29+
pub trait Bar { }
30+
pub trait Quux<T> { type Assoc; }
31+
pub fn demo(_: impl Quux<(), Assoc=<() as Quux<impl Bar>>::Assoc>) { }
32+
//~^ ERROR `impl Trait` is not allowed in path parameters
33+
//~| WARN will become a hard error in a future release!
34+
impl<T> Quux<T> for () { type Assoc = u32; }
35+
}
36+
37+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
warning: `impl Trait` is not allowed in path parameters
2+
--> $DIR/issue-57979-impl-trait-in-path.rs:20:52
3+
|
4+
LL | pub fn demo(_: impl Quux<(), Assoc=<() as Quux<impl Bar>>::Assoc>) { }
5+
| ^^^^^^^^
6+
|
7+
note: lint level defined here
8+
--> $DIR/issue-57979-impl-trait-in-path.rs:16:13
9+
|
10+
LL | #![warn(nested_impl_trait)]
11+
| ^^^^^^^^^^^^^^^^^
12+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
13+
= note: for more information, see issue #59014 <https://github.com/rust-lang/rust/issues/59014>
14+
15+
error: `impl Trait` is not allowed in path parameters
16+
--> $DIR/issue-57979-impl-trait-in-path.rs:31:52
17+
|
18+
LL | pub fn demo(_: impl Quux<(), Assoc=<() as Quux<impl Bar>>::Assoc>) { }
19+
| ^^^^^^^^
20+
|
21+
note: lint level defined here
22+
--> $DIR/issue-57979-impl-trait-in-path.rs:27:13
23+
|
24+
LL | #![deny(nested_impl_trait)]
25+
| ^^^^^^^^^^^^^^^^^
26+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
27+
= note: for more information, see issue #59014 <https://github.com/rust-lang/rust/issues/59014>
28+
29+
error: aborting due to previous error
30+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// rust-lang/rust#57979 : the initial support for `impl Trait` didn't
2+
// properly check syntax hidden behind an associated type projection.
3+
// Here we test behavior of occurrences of `impl Trait` within an
4+
// `impl Trait` in that context.
5+
6+
mod allowed {
7+
#![allow(nested_impl_trait)]
8+
9+
pub trait Foo<T> { }
10+
pub trait Bar { }
11+
pub trait Quux { type Assoc; }
12+
pub fn demo(_: impl Quux<Assoc=impl Foo<impl Bar>>) { }
13+
}
14+
15+
mod warned {
16+
#![warn(nested_impl_trait)]
17+
18+
pub trait Foo<T> { }
19+
pub trait Bar { }
20+
pub trait Quux { type Assoc; }
21+
pub fn demo(_: impl Quux<Assoc=impl Foo<impl Bar>>) { }
22+
//~^ WARN nested `impl Trait` is not allowed
23+
//~| WARN will become a hard error in a future release!
24+
}
25+
26+
mod denied {
27+
#![deny(nested_impl_trait)]
28+
29+
pub trait Foo<T> { }
30+
pub trait Bar { }
31+
pub trait Quux { type Assoc; }
32+
pub fn demo(_: impl Quux<Assoc=impl Foo<impl Bar>>) { }
33+
//~^ ERROR nested `impl Trait` is not allowed
34+
//~| WARN will become a hard error in a future release!
35+
}
36+
37+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
warning: nested `impl Trait` is not allowed
2+
--> $DIR/issue-57979-nested-impl-trait-in-assoc-proj.rs:21:45
3+
|
4+
LL | pub fn demo(_: impl Quux<Assoc=impl Foo<impl Bar>>) { }
5+
| ---------^^^^^^^^-
6+
| | |
7+
| | nested `impl Trait` here
8+
| outer `impl Trait`
9+
|
10+
note: lint level defined here
11+
--> $DIR/issue-57979-nested-impl-trait-in-assoc-proj.rs:16:13
12+
|
13+
LL | #![warn(nested_impl_trait)]
14+
| ^^^^^^^^^^^^^^^^^
15+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
16+
= note: for more information, see issue #59014 <https://github.com/rust-lang/rust/issues/59014>
17+
18+
error: nested `impl Trait` is not allowed
19+
--> $DIR/issue-57979-nested-impl-trait-in-assoc-proj.rs:32:45
20+
|
21+
LL | pub fn demo(_: impl Quux<Assoc=impl Foo<impl Bar>>) { }
22+
| ---------^^^^^^^^-
23+
| | |
24+
| | nested `impl Trait` here
25+
| outer `impl Trait`
26+
|
27+
note: lint level defined here
28+
--> $DIR/issue-57979-nested-impl-trait-in-assoc-proj.rs:27:13
29+
|
30+
LL | #![deny(nested_impl_trait)]
31+
| ^^^^^^^^^^^^^^^^^
32+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
33+
= note: for more information, see issue #59014 <https://github.com/rust-lang/rust/issues/59014>
34+
35+
error: aborting due to previous error
36+

src/test/ui/issues/issue-57979.rs

-42
This file was deleted.

src/test/ui/issues/issue-57979.stderr

-17
This file was deleted.

0 commit comments

Comments
 (0)