Skip to content

Commit 29c05cb

Browse files
authored
Unrolled build for #152907
Rollup merge of #152907 - aerooneqq:delegation-generics-new-tests, r=petrochenkov Add tests for delegation generics This PR adds tests from #151864 as discussed in this [comment](#151864 (comment)). Part of #118212. The majority of new tests are added in `mapping` folder, (`ast-hir-engine` folder in #151864), those tests test mapping between generic params of delegee and our generated function for delegation (that is why the name of the folder was changed, I think it better reflects what those tests testing). In each mapping test comments were added to each test case and one comment describing the goal of mapping tests was added at the top of each file. Next, tests for defaults in generic params (`generic-params-defaults.rs`), params with the same name (`generic-params-same-names`), errors in providing user-specified generic args (`generics-gen-args-errors.rs`) and wrong signature of a generated function in impl trait case (`impl-trait-wrong-args-count.rs`, renamed from `wrong-args-count-ice.rs` in #151864). `generic-aux-pass.rs` test was not added, as all reuses in this test produce known ICE `DefId::expect_local DefId(..) isn't local` #143498 (which will be fixed in #151864, however it will not close mentioned issue, as synthetic generic params are not yet supported in new generics implementation). r? @petrochenkov
2 parents 0376d43 + 7348ffb commit 29c05cb

24 files changed

+6034
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![feature(fn_delegation)]
2+
#![allow(incomplete_features)]
3+
4+
trait Trait<'a, 'b, 'c, A = usize, B = u32, C = String, const N: usize = 123> {
5+
fn foo<T = usize>(&self) {
6+
//~^ ERROR: defaults for generic parameters are not allowed here
7+
//~| WARN: this was previously accepted by the compiler but is being phased out
8+
}
9+
}
10+
11+
reuse Trait::foo;
12+
//~^ ERROR: type annotations needed
13+
14+
fn main() {}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
error: defaults for generic parameters are not allowed here
2+
--> $DIR/generic-params-defaults.rs:5:12
3+
|
4+
LL | fn foo<T = usize>(&self) {
5+
| ^^^^^^^^^
6+
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
9+
= note: `#[deny(invalid_type_param_default)]` (part of `#[deny(future_incompatible)]`) on by default
10+
11+
error[E0282]: type annotations needed
12+
--> $DIR/generic-params-defaults.rs:11:14
13+
|
14+
LL | reuse Trait::foo;
15+
| ^^^ cannot infer type of the type parameter `T` declared on the method `foo`
16+
|
17+
help: consider specifying the generic argument
18+
|
19+
LL | reuse Trait::foo::<T>;
20+
| +++++
21+
22+
error: aborting due to 2 previous errors
23+
24+
For more information about this error, try `rustc --explain E0282`.
25+
Future incompatibility report: Future breakage diagnostic:
26+
error: defaults for generic parameters are not allowed here
27+
--> $DIR/generic-params-defaults.rs:5:12
28+
|
29+
LL | fn foo<T = usize>(&self) {
30+
| ^^^^^^^^^
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 #36887 <https://github.com/rust-lang/rust/issues/36887>
34+
= note: `#[deny(invalid_type_param_default)]` (part of `#[deny(future_incompatible)]`) on by default
35+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![feature(fn_delegation)]
2+
#![allow(incomplete_features)]
3+
4+
trait Trait<'a, 'b, 'c, A, B, C, const N: usize> {
5+
fn foo<'a, 'b, 'c, A, B, C, const N: usize>(&self) {
6+
//~^ ERROR: lifetime name `'a` shadows a lifetime name that is already in scope
7+
//~| ERROR: lifetime name `'b` shadows a lifetime name that is already in scope
8+
//~| ERROR: lifetime name `'c` shadows a lifetime name that is already in scope
9+
//~| ERROR: the name `A` is already used for a generic parameter in this item's generic parameters
10+
//~| ERROR: the name `B` is already used for a generic parameter in this item's generic parameters
11+
//~| ERROR: the name `C` is already used for a generic parameter in this item's generic parameters
12+
//~| ERROR: the name `N` is already used for a generic parameter in this item's generic parameters
13+
}
14+
}
15+
16+
reuse Trait::foo;
17+
//~^ ERROR: type annotations needed
18+
19+
fn main() {}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
error[E0496]: lifetime name `'a` shadows a lifetime name that is already in scope
2+
--> $DIR/generic-params-same-names.rs:5:12
3+
|
4+
LL | trait Trait<'a, 'b, 'c, A, B, C, const N: usize> {
5+
| -- first declared here
6+
LL | fn foo<'a, 'b, 'c, A, B, C, const N: usize>(&self) {
7+
| ^^ lifetime `'a` already in scope
8+
9+
error[E0496]: lifetime name `'b` shadows a lifetime name that is already in scope
10+
--> $DIR/generic-params-same-names.rs:5:16
11+
|
12+
LL | trait Trait<'a, 'b, 'c, A, B, C, const N: usize> {
13+
| -- first declared here
14+
LL | fn foo<'a, 'b, 'c, A, B, C, const N: usize>(&self) {
15+
| ^^ lifetime `'b` already in scope
16+
17+
error[E0496]: lifetime name `'c` shadows a lifetime name that is already in scope
18+
--> $DIR/generic-params-same-names.rs:5:20
19+
|
20+
LL | trait Trait<'a, 'b, 'c, A, B, C, const N: usize> {
21+
| -- first declared here
22+
LL | fn foo<'a, 'b, 'c, A, B, C, const N: usize>(&self) {
23+
| ^^ lifetime `'c` already in scope
24+
25+
error[E0403]: the name `A` is already used for a generic parameter in this item's generic parameters
26+
--> $DIR/generic-params-same-names.rs:5:24
27+
|
28+
LL | trait Trait<'a, 'b, 'c, A, B, C, const N: usize> {
29+
| - first use of `A`
30+
LL | fn foo<'a, 'b, 'c, A, B, C, const N: usize>(&self) {
31+
| ^ already used
32+
33+
error[E0403]: the name `B` is already used for a generic parameter in this item's generic parameters
34+
--> $DIR/generic-params-same-names.rs:5:27
35+
|
36+
LL | trait Trait<'a, 'b, 'c, A, B, C, const N: usize> {
37+
| - first use of `B`
38+
LL | fn foo<'a, 'b, 'c, A, B, C, const N: usize>(&self) {
39+
| ^ already used
40+
41+
error[E0403]: the name `C` is already used for a generic parameter in this item's generic parameters
42+
--> $DIR/generic-params-same-names.rs:5:30
43+
|
44+
LL | trait Trait<'a, 'b, 'c, A, B, C, const N: usize> {
45+
| - first use of `C`
46+
LL | fn foo<'a, 'b, 'c, A, B, C, const N: usize>(&self) {
47+
| ^ already used
48+
49+
error[E0403]: the name `N` is already used for a generic parameter in this item's generic parameters
50+
--> $DIR/generic-params-same-names.rs:5:39
51+
|
52+
LL | trait Trait<'a, 'b, 'c, A, B, C, const N: usize> {
53+
| - first use of `N`
54+
LL | fn foo<'a, 'b, 'c, A, B, C, const N: usize>(&self) {
55+
| ^ already used
56+
57+
error[E0284]: type annotations needed
58+
--> $DIR/generic-params-same-names.rs:16:14
59+
|
60+
LL | reuse Trait::foo;
61+
| ^^^ cannot infer the value of the const parameter `N` declared on the method `foo`
62+
|
63+
note: required by a const generic parameter in `Trait::foo`
64+
--> $DIR/generic-params-same-names.rs:5:33
65+
|
66+
LL | fn foo<'a, 'b, 'c, A, B, C, const N: usize>(&self) {
67+
| ^^^^^^^^^^^^^^ required by this const generic parameter in `Trait::foo`
68+
help: consider specifying the generic arguments
69+
|
70+
LL | reuse Trait::foo::<A, B, C, N>;
71+
| ++++++++++++++
72+
73+
error: aborting due to 8 previous errors
74+
75+
Some errors have detailed explanations: E0284, E0403, E0496.
76+
For more information about an error, try `rustc --explain E0284`.
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
//@ compile-flags: -Z deduplicate-diagnostics=yes
2+
3+
#![feature(fn_delegation)]
4+
#![allow(incomplete_features)]
5+
6+
mod test_1 {
7+
fn foo<'a: 'a, 'b: 'b, T: Clone, U: Clone, const N: usize>() {}
8+
reuse foo as bar;
9+
//~^ ERROR: type annotations needed
10+
11+
fn check<A, B, C>() {
12+
bar::<1, 2, 3, 4, 5, 6>();
13+
//~^ ERROR: function takes 3 generic arguments but 6 generic arguments were supplied
14+
15+
bar::<String, String, { String }>();
16+
//~^ ERROR: expected value, found struct `String` [E0423]
17+
18+
bar::<'static, 'static, 'static, 'static, 'static>();
19+
//~^ ERROR: function takes 2 lifetime arguments but 5 lifetime arguments were supplied
20+
21+
bar::<String, 1, 'static, i32, 'static>();
22+
//~^ ERROR: constant provided when a type was expected
23+
24+
bar();
25+
26+
bar::<_, _, _, _, _>();
27+
//~^ ERROR: function takes 3 generic arguments but 5 generic arguments were supplied
28+
29+
bar::<asd, asd, asd>();
30+
//~^ ERROR: cannot find type `asd` in this scope
31+
//~| ERROR: cannot find type `asd` in this scope
32+
//~| ERROR: cannot find type `asd` in this scope
33+
//~| ERROR: unresolved item provided when a constant was expected
34+
35+
reuse foo::<A, B, C> as xd;
36+
//~^ ERROR can't use generic parameters from outer item
37+
//~| ERROR can't use generic parameters from outer item
38+
//~| ERROR can't use generic parameters from outer item
39+
//~| ERROR: unresolved item provided when a constant was expected
40+
}
41+
}
42+
43+
mod test_2 {
44+
fn foo<'a: 'a, 'b: 'b, T: Clone, U: Clone, const N: usize>() {}
45+
46+
reuse foo::<> as bar1;
47+
//~^ ERROR: type annotations needed
48+
49+
reuse foo::<String, String> as bar2;
50+
//~^ ERROR: function takes 3 generic arguments but 2 generic arguments were supplied
51+
52+
reuse foo::<'static, _, 'asdasd, 'static, 'static, 'static, _> as bar3;
53+
//~^ ERROR: use of undeclared lifetime name `'asdasd`
54+
//~| ERROR: function takes 2 lifetime arguments but 5 lifetime arguments were supplied
55+
//~| ERROR: function takes 3 generic arguments but 2 generic arguments were supplied
56+
reuse foo::<String, 'static, 123, asdasd> as bar4;
57+
//~^ ERROR: cannot find type `asdasd` in this scope
58+
//~| ERROR: function takes 2 lifetime arguments but 1 lifetime argument was supplied
59+
60+
reuse foo::<1, 2, _, 4, 5, _> as bar5;
61+
//~^ ERROR: function takes 3 generic arguments but 6 generic arguments were supplied
62+
63+
reuse foo::<1, 2,asd,String, { let x = 0; }> as bar6;
64+
//~^ ERROR: cannot find type `asd` in this scope
65+
//~| ERROR: function takes 3 generic arguments but 5 generic arguments were supplied
66+
67+
reuse foo::<"asdasd", asd, "askdn", 'static, 'a> as bar7;
68+
//~^ ERROR: use of undeclared lifetime name `'a`
69+
//~| ERROR: cannot find type `asd` in this scope
70+
//~| ERROR: constant provided when a type was expected
71+
72+
reuse foo::<{}, {}, {}> as bar8;
73+
//~^ ERROR: constant provided when a type was expected
74+
}
75+
76+
mod test_3 {
77+
trait Trait<'b, 'c, 'a, T, const N: usize>: Sized {
78+
fn foo<'d: 'd, U, const M: bool>(self) {}
79+
}
80+
81+
reuse Trait::<asd, asd, asd, asd, asd, asdasa>::foo as bar1;
82+
//~^ ERROR: cannot find type `asd` in this scope
83+
//~| ERROR: cannot find type `asd` in this scope
84+
//~| ERROR: cannot find type `asd` in this scope
85+
//~| ERROR: cannot find type `asd` in this scope
86+
//~| ERROR: cannot find type `asd` in this scope
87+
//~| ERROR: cannot find type `asdasa` in this scope
88+
//~| ERROR: trait takes 2 generic arguments but 6 generic arguments were supplied
89+
90+
reuse Trait::<'static, 'static>::foo as bar2;
91+
//~^ ERROR: trait takes 3 lifetime arguments but 2 lifetime arguments were supplied
92+
reuse Trait::<1, 2, 3, 4, 5>::foo as bar3;
93+
//~^ ERROR: trait takes 2 generic arguments but 5 generic arguments were supplied
94+
95+
reuse Trait::<1, 2, true>::foo as bar4;
96+
//~^ ERROR: trait takes 2 generic arguments but 3 generic arguments were supplied
97+
98+
reuse Trait::<'static>::foo as bar5;
99+
//~^ ERROR: trait takes 3 lifetime arguments but 1 lifetime argument was supplied
100+
101+
reuse Trait::<1, 2, 'static, DDDD>::foo::<1, 2, 3, 4, 5, 6> as bar6;
102+
//~^ ERROR: cannot find type `DDDD` in this scope [E0425]
103+
//~| ERROR: trait takes 3 lifetime arguments but 1 lifetime argument was supplied
104+
//~| ERROR: trait takes 2 generic arguments but 3 generic arguments were supplied
105+
//~| ERROR: method takes 2 generic arguments but 6 generic arguments were supplied
106+
107+
reuse Trait::<Trait, Clone, _, 'static, dyn Send, _>::foo::<1, 2, 3, _, 6> as bar7;
108+
//~^ ERROR: missing lifetime specifiers [E0106]
109+
//~| ERROR: trait takes 3 lifetime arguments but 1 lifetime argument was supplied
110+
//~| ERROR: trait takes 2 generic arguments but 5 generic arguments were supplied
111+
//~| ERROR: method takes 2 generic arguments but 5 generic arguments were supplied
112+
}
113+
114+
fn main() {}

0 commit comments

Comments
 (0)