Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/ui/delegation/generics/generic-params-defaults.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![feature(fn_delegation)]
#![allow(incomplete_features)]

trait Trait<'a, 'b, 'c, A = usize, B = u32, C = String, const N: usize = 123> {
fn foo<T = usize>(&self) {
//~^ ERROR: defaults for generic parameters are not allowed here
//~| WARN: this was previously accepted by the compiler but is being phased out
}
}

reuse Trait::foo;
//~^ ERROR: type annotations needed

fn main() {}
35 changes: 35 additions & 0 deletions tests/ui/delegation/generics/generic-params-defaults.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
error: defaults for generic parameters are not allowed here
--> $DIR/generic-params-defaults.rs:5:12
|
LL | fn foo<T = usize>(&self) {
| ^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
= note: `#[deny(invalid_type_param_default)]` (part of `#[deny(future_incompatible)]`) on by default

error[E0282]: type annotations needed
--> $DIR/generic-params-defaults.rs:11:14
|
LL | reuse Trait::foo;
| ^^^ cannot infer type of the type parameter `T` declared on the method `foo`
|
help: consider specifying the generic argument
|
LL | reuse Trait::foo::<T>;
| +++++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0282`.
Future incompatibility report: Future breakage diagnostic:
error: defaults for generic parameters are not allowed here
--> $DIR/generic-params-defaults.rs:5:12
|
LL | fn foo<T = usize>(&self) {
| ^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
= note: `#[deny(invalid_type_param_default)]` (part of `#[deny(future_incompatible)]`) on by default

19 changes: 19 additions & 0 deletions tests/ui/delegation/generics/generic-params-same-names.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![feature(fn_delegation)]
#![allow(incomplete_features)]

trait Trait<'a, 'b, 'c, A, B, C, const N: usize> {
fn foo<'a, 'b, 'c, A, B, C, const N: usize>(&self) {
//~^ ERROR: lifetime name `'a` shadows a lifetime name that is already in scope
//~| ERROR: lifetime name `'b` shadows a lifetime name that is already in scope
//~| ERROR: lifetime name `'c` shadows a lifetime name that is already in scope
//~| ERROR: the name `A` is already used for a generic parameter in this item's generic parameters
//~| ERROR: the name `B` is already used for a generic parameter in this item's generic parameters
//~| ERROR: the name `C` is already used for a generic parameter in this item's generic parameters
//~| ERROR: the name `N` is already used for a generic parameter in this item's generic parameters
}
}

reuse Trait::foo;
//~^ ERROR: type annotations needed

fn main() {}
76 changes: 76 additions & 0 deletions tests/ui/delegation/generics/generic-params-same-names.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
error[E0496]: lifetime name `'a` shadows a lifetime name that is already in scope
--> $DIR/generic-params-same-names.rs:5:12
|
LL | trait Trait<'a, 'b, 'c, A, B, C, const N: usize> {
| -- first declared here
LL | fn foo<'a, 'b, 'c, A, B, C, const N: usize>(&self) {
| ^^ lifetime `'a` already in scope

error[E0496]: lifetime name `'b` shadows a lifetime name that is already in scope
--> $DIR/generic-params-same-names.rs:5:16
|
LL | trait Trait<'a, 'b, 'c, A, B, C, const N: usize> {
| -- first declared here
LL | fn foo<'a, 'b, 'c, A, B, C, const N: usize>(&self) {
| ^^ lifetime `'b` already in scope

error[E0496]: lifetime name `'c` shadows a lifetime name that is already in scope
--> $DIR/generic-params-same-names.rs:5:20
|
LL | trait Trait<'a, 'b, 'c, A, B, C, const N: usize> {
| -- first declared here
LL | fn foo<'a, 'b, 'c, A, B, C, const N: usize>(&self) {
| ^^ lifetime `'c` already in scope

error[E0403]: the name `A` is already used for a generic parameter in this item's generic parameters
--> $DIR/generic-params-same-names.rs:5:24
|
LL | trait Trait<'a, 'b, 'c, A, B, C, const N: usize> {
| - first use of `A`
LL | fn foo<'a, 'b, 'c, A, B, C, const N: usize>(&self) {
| ^ already used

error[E0403]: the name `B` is already used for a generic parameter in this item's generic parameters
--> $DIR/generic-params-same-names.rs:5:27
|
LL | trait Trait<'a, 'b, 'c, A, B, C, const N: usize> {
| - first use of `B`
LL | fn foo<'a, 'b, 'c, A, B, C, const N: usize>(&self) {
| ^ already used

error[E0403]: the name `C` is already used for a generic parameter in this item's generic parameters
--> $DIR/generic-params-same-names.rs:5:30
|
LL | trait Trait<'a, 'b, 'c, A, B, C, const N: usize> {
| - first use of `C`
LL | fn foo<'a, 'b, 'c, A, B, C, const N: usize>(&self) {
| ^ already used

error[E0403]: the name `N` is already used for a generic parameter in this item's generic parameters
--> $DIR/generic-params-same-names.rs:5:39
|
LL | trait Trait<'a, 'b, 'c, A, B, C, const N: usize> {
| - first use of `N`
LL | fn foo<'a, 'b, 'c, A, B, C, const N: usize>(&self) {
| ^ already used

error[E0284]: type annotations needed
--> $DIR/generic-params-same-names.rs:16:14
|
LL | reuse Trait::foo;
| ^^^ cannot infer the value of the const parameter `N` declared on the method `foo`
|
note: required by a const generic parameter in `Trait::foo`
--> $DIR/generic-params-same-names.rs:5:33
|
LL | fn foo<'a, 'b, 'c, A, B, C, const N: usize>(&self) {
| ^^^^^^^^^^^^^^ required by this const generic parameter in `Trait::foo`
help: consider specifying the generic arguments
|
LL | reuse Trait::foo::<A, B, C, N>;
| ++++++++++++++

error: aborting due to 8 previous errors

Some errors have detailed explanations: E0284, E0403, E0496.
For more information about an error, try `rustc --explain E0284`.
114 changes: 114 additions & 0 deletions tests/ui/delegation/generics/generics-gen-args-errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
//@ compile-flags: -Z deduplicate-diagnostics=yes

#![feature(fn_delegation)]
#![allow(incomplete_features)]

mod test_1 {
fn foo<'a: 'a, 'b: 'b, T: Clone, U: Clone, const N: usize>() {}
reuse foo as bar;
//~^ ERROR: type annotations needed

fn check<A, B, C>() {
bar::<1, 2, 3, 4, 5, 6>();
//~^ ERROR: function takes 3 generic arguments but 6 generic arguments were supplied

bar::<String, String, { String }>();
//~^ ERROR: expected value, found struct `String` [E0423]

bar::<'static, 'static, 'static, 'static, 'static>();
//~^ ERROR: function takes 2 lifetime arguments but 5 lifetime arguments were supplied

bar::<String, 1, 'static, i32, 'static>();
//~^ ERROR: constant provided when a type was expected

bar();

bar::<_, _, _, _, _>();
//~^ ERROR: function takes 3 generic arguments but 5 generic arguments were supplied

bar::<asd, asd, asd>();
//~^ ERROR: cannot find type `asd` in this scope
//~| ERROR: cannot find type `asd` in this scope
//~| ERROR: cannot find type `asd` in this scope
//~| ERROR: unresolved item provided when a constant was expected

reuse foo::<A, B, C> as xd;
//~^ ERROR can't use generic parameters from outer item
//~| ERROR can't use generic parameters from outer item
//~| ERROR can't use generic parameters from outer item
//~| ERROR: unresolved item provided when a constant was expected
}
}

mod test_2 {
fn foo<'a: 'a, 'b: 'b, T: Clone, U: Clone, const N: usize>() {}

reuse foo::<> as bar1;
//~^ ERROR: type annotations needed

reuse foo::<String, String> as bar2;
//~^ ERROR: function takes 3 generic arguments but 2 generic arguments were supplied

reuse foo::<'static, _, 'asdasd, 'static, 'static, 'static, _> as bar3;
//~^ ERROR: use of undeclared lifetime name `'asdasd`
//~| ERROR: function takes 2 lifetime arguments but 5 lifetime arguments were supplied
//~| ERROR: function takes 3 generic arguments but 2 generic arguments were supplied
reuse foo::<String, 'static, 123, asdasd> as bar4;
//~^ ERROR: cannot find type `asdasd` in this scope
//~| ERROR: function takes 2 lifetime arguments but 1 lifetime argument was supplied

reuse foo::<1, 2, _, 4, 5, _> as bar5;
//~^ ERROR: function takes 3 generic arguments but 6 generic arguments were supplied

reuse foo::<1, 2,asd,String, { let x = 0; }> as bar6;
//~^ ERROR: cannot find type `asd` in this scope
//~| ERROR: function takes 3 generic arguments but 5 generic arguments were supplied

reuse foo::<"asdasd", asd, "askdn", 'static, 'a> as bar7;
//~^ ERROR: use of undeclared lifetime name `'a`
//~| ERROR: cannot find type `asd` in this scope
//~| ERROR: constant provided when a type was expected

reuse foo::<{}, {}, {}> as bar8;
//~^ ERROR: constant provided when a type was expected
}

mod test_3 {
trait Trait<'b, 'c, 'a, T, const N: usize>: Sized {
fn foo<'d: 'd, U, const M: bool>(self) {}
}

reuse Trait::<asd, asd, asd, asd, asd, asdasa>::foo as bar1;
//~^ ERROR: cannot find type `asd` in this scope
//~| ERROR: cannot find type `asd` in this scope
//~| ERROR: cannot find type `asd` in this scope
//~| ERROR: cannot find type `asd` in this scope
//~| ERROR: cannot find type `asd` in this scope
//~| ERROR: cannot find type `asdasa` in this scope
//~| ERROR: trait takes 2 generic arguments but 6 generic arguments were supplied

reuse Trait::<'static, 'static>::foo as bar2;
//~^ ERROR: trait takes 3 lifetime arguments but 2 lifetime arguments were supplied
reuse Trait::<1, 2, 3, 4, 5>::foo as bar3;
//~^ ERROR: trait takes 2 generic arguments but 5 generic arguments were supplied

reuse Trait::<1, 2, true>::foo as bar4;
//~^ ERROR: trait takes 2 generic arguments but 3 generic arguments were supplied

reuse Trait::<'static>::foo as bar5;
//~^ ERROR: trait takes 3 lifetime arguments but 1 lifetime argument was supplied

reuse Trait::<1, 2, 'static, DDDD>::foo::<1, 2, 3, 4, 5, 6> as bar6;
//~^ ERROR: cannot find type `DDDD` in this scope [E0425]
//~| ERROR: trait takes 3 lifetime arguments but 1 lifetime argument was supplied
//~| ERROR: trait takes 2 generic arguments but 3 generic arguments were supplied
//~| ERROR: method takes 2 generic arguments but 6 generic arguments were supplied

reuse Trait::<Trait, Clone, _, 'static, dyn Send, _>::foo::<1, 2, 3, _, 6> as bar7;
//~^ ERROR: missing lifetime specifiers [E0106]
//~| ERROR: trait takes 3 lifetime arguments but 1 lifetime argument was supplied
//~| ERROR: trait takes 2 generic arguments but 5 generic arguments were supplied
//~| ERROR: method takes 2 generic arguments but 5 generic arguments were supplied
}

fn main() {}
Loading
Loading