diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/anon-params | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/anon-params')
7 files changed, 271 insertions, 0 deletions
diff --git a/src/test/ui/anon-params/anon-params-denied-2018.rs b/src/test/ui/anon-params/anon-params-denied-2018.rs new file mode 100644 index 000000000..95533cf3d --- /dev/null +++ b/src/test/ui/anon-params/anon-params-denied-2018.rs @@ -0,0 +1,32 @@ +// Tests that anonymous parameters are a hard error in edition 2018. + +// edition:2018 + +trait T { + fn foo(i32); //~ expected one of `:`, `@`, or `|`, found `)` + + // Also checks with `&` + fn foo_with_ref(&mut i32); + //~^ ERROR expected one of `:`, `@`, or `|`, found `)` + + fn foo_with_qualified_path(<Bar as T>::Baz); + //~^ ERROR expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)` + + fn foo_with_qualified_path_and_ref(&<Bar as T>::Baz); + //~^ ERROR expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)` + + fn foo_with_multiple_qualified_paths(<Bar as T>::Baz, <Bar as T>::Baz); + //~^ ERROR expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `,` + //~| ERROR expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)` + + fn bar_with_default_impl(String, String) {} + //~^ ERROR expected one of `:` + //~| ERROR expected one of `:` + + // do not complain about missing `b` + fn baz(a:usize, b, c: usize) -> usize { //~ ERROR expected one of `:` + a + b + c + } +} + +fn main() {} diff --git a/src/test/ui/anon-params/anon-params-denied-2018.stderr b/src/test/ui/anon-params/anon-params-denied-2018.stderr new file mode 100644 index 000000000..bb60c898e --- /dev/null +++ b/src/test/ui/anon-params/anon-params-denied-2018.stderr @@ -0,0 +1,142 @@ +error: expected one of `:`, `@`, or `|`, found `)` + --> $DIR/anon-params-denied-2018.rs:6:15 + | +LL | fn foo(i32); + | ^ expected one of `:`, `@`, or `|` + | + = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) +help: if this is a `self` type, give it a parameter name + | +LL | fn foo(self: i32); + | +++++ +help: if this is a parameter name, give it a type + | +LL | fn foo(i32: TypeName); + | ++++++++++ +help: if this is a type, explicitly ignore the parameter name + | +LL | fn foo(_: i32); + | ++ + +error: expected one of `:`, `@`, or `|`, found `)` + --> $DIR/anon-params-denied-2018.rs:9:29 + | +LL | fn foo_with_ref(&mut i32); + | ^ expected one of `:`, `@`, or `|` + | + = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) +help: if this is a `self` type, give it a parameter name + | +LL | fn foo_with_ref(self: &mut i32); + | +++++ +help: if this is a parameter name, give it a type + | +LL | fn foo_with_ref(i32: &mut TypeName); + | ~~~~~~~~~~~~~~~~~~ +help: if this is a type, explicitly ignore the parameter name + | +LL | fn foo_with_ref(_: &mut i32); + | ++ + +error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)` + --> $DIR/anon-params-denied-2018.rs:12:47 + | +LL | fn foo_with_qualified_path(<Bar as T>::Baz); + | ^ expected one of 8 possible tokens + | + = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) +help: explicitly ignore the parameter name + | +LL | fn foo_with_qualified_path(_: <Bar as T>::Baz); + | ~~~~~~~~~~~~~~~~~~ + +error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)` + --> $DIR/anon-params-denied-2018.rs:15:56 + | +LL | fn foo_with_qualified_path_and_ref(&<Bar as T>::Baz); + | ^ expected one of 8 possible tokens + | + = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) +help: explicitly ignore the parameter name + | +LL | fn foo_with_qualified_path_and_ref(_: &<Bar as T>::Baz); + | ~~~~~~~~~~~~~~~~~~~ + +error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `,` + --> $DIR/anon-params-denied-2018.rs:18:57 + | +LL | fn foo_with_multiple_qualified_paths(<Bar as T>::Baz, <Bar as T>::Baz); + | ^ expected one of 8 possible tokens + | + = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) +help: explicitly ignore the parameter name + | +LL | fn foo_with_multiple_qualified_paths(_: <Bar as T>::Baz, <Bar as T>::Baz); + | ~~~~~~~~~~~~~~~~~~ + +error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)` + --> $DIR/anon-params-denied-2018.rs:18:74 + | +LL | fn foo_with_multiple_qualified_paths(<Bar as T>::Baz, <Bar as T>::Baz); + | ^ expected one of 8 possible tokens + | + = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) +help: explicitly ignore the parameter name + | +LL | fn foo_with_multiple_qualified_paths(<Bar as T>::Baz, _: <Bar as T>::Baz); + | ~~~~~~~~~~~~~~~~~~ + +error: expected one of `:`, `@`, or `|`, found `,` + --> $DIR/anon-params-denied-2018.rs:22:36 + | +LL | fn bar_with_default_impl(String, String) {} + | ^ expected one of `:`, `@`, or `|` + | + = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) +help: if this is a `self` type, give it a parameter name + | +LL | fn bar_with_default_impl(self: String, String) {} + | +++++ +help: if this is a parameter name, give it a type + | +LL | fn bar_with_default_impl(String: TypeName, String) {} + | ++++++++++ +help: if this is a type, explicitly ignore the parameter name + | +LL | fn bar_with_default_impl(_: String, String) {} + | ++ + +error: expected one of `:`, `@`, or `|`, found `)` + --> $DIR/anon-params-denied-2018.rs:22:44 + | +LL | fn bar_with_default_impl(String, String) {} + | ^ expected one of `:`, `@`, or `|` + | + = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) +help: if this is a parameter name, give it a type + | +LL | fn bar_with_default_impl(String, String: TypeName) {} + | ++++++++++ +help: if this is a type, explicitly ignore the parameter name + | +LL | fn bar_with_default_impl(String, _: String) {} + | ++ + +error: expected one of `:`, `@`, or `|`, found `,` + --> $DIR/anon-params-denied-2018.rs:27:22 + | +LL | fn baz(a:usize, b, c: usize) -> usize { + | ^ expected one of `:`, `@`, or `|` + | + = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) +help: if this is a parameter name, give it a type + | +LL | fn baz(a:usize, b: TypeName, c: usize) -> usize { + | ++++++++++ +help: if this is a type, explicitly ignore the parameter name + | +LL | fn baz(a:usize, _: b, c: usize) -> usize { + | ++ + +error: aborting due to 9 previous errors + diff --git a/src/test/ui/anon-params/anon-params-deprecated.fixed b/src/test/ui/anon-params/anon-params-deprecated.fixed new file mode 100644 index 000000000..c09e20770 --- /dev/null +++ b/src/test/ui/anon-params/anon-params-deprecated.fixed @@ -0,0 +1,19 @@ +#![warn(anonymous_parameters)] +// Test for the anonymous_parameters deprecation lint (RFC 1685) + +// check-pass +// edition:2015 +// run-rustfix + +trait T { + fn foo(_: i32); //~ WARNING anonymous parameters are deprecated + //~| WARNING this is accepted in the current edition + + fn bar_with_default_impl(_: String, _: String) {} + //~^ WARNING anonymous parameters are deprecated + //~| WARNING this is accepted in the current edition + //~| WARNING anonymous parameters are deprecated + //~| WARNING this is accepted in the current edition +} + +fn main() {} diff --git a/src/test/ui/anon-params/anon-params-deprecated.rs b/src/test/ui/anon-params/anon-params-deprecated.rs new file mode 100644 index 000000000..6f7385da0 --- /dev/null +++ b/src/test/ui/anon-params/anon-params-deprecated.rs @@ -0,0 +1,19 @@ +#![warn(anonymous_parameters)] +// Test for the anonymous_parameters deprecation lint (RFC 1685) + +// check-pass +// edition:2015 +// run-rustfix + +trait T { + fn foo(i32); //~ WARNING anonymous parameters are deprecated + //~| WARNING this is accepted in the current edition + + fn bar_with_default_impl(String, String) {} + //~^ WARNING anonymous parameters are deprecated + //~| WARNING this is accepted in the current edition + //~| WARNING anonymous parameters are deprecated + //~| WARNING this is accepted in the current edition +} + +fn main() {} diff --git a/src/test/ui/anon-params/anon-params-deprecated.stderr b/src/test/ui/anon-params/anon-params-deprecated.stderr new file mode 100644 index 000000000..474b14f59 --- /dev/null +++ b/src/test/ui/anon-params/anon-params-deprecated.stderr @@ -0,0 +1,34 @@ +warning: anonymous parameters are deprecated and will be removed in the next edition + --> $DIR/anon-params-deprecated.rs:9:12 + | +LL | fn foo(i32); + | ^^^ help: try naming the parameter or explicitly ignoring it: `_: i32` + | +note: the lint level is defined here + --> $DIR/anon-params-deprecated.rs:1:9 + | +LL | #![warn(anonymous_parameters)] + | ^^^^^^^^^^^^^^^^^^^^ + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686> + +warning: anonymous parameters are deprecated and will be removed in the next edition + --> $DIR/anon-params-deprecated.rs:12:30 + | +LL | fn bar_with_default_impl(String, String) {} + | ^^^^^^ help: try naming the parameter or explicitly ignoring it: `_: String` + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686> + +warning: anonymous parameters are deprecated and will be removed in the next edition + --> $DIR/anon-params-deprecated.rs:12:38 + | +LL | fn bar_with_default_impl(String, String) {} + | ^^^^^^ help: try naming the parameter or explicitly ignoring it: `_: String` + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! + = note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686> + +warning: 3 warnings emitted + diff --git a/src/test/ui/anon-params/anon-params-edition-hygiene.rs b/src/test/ui/anon-params/anon-params-edition-hygiene.rs new file mode 100644 index 000000000..6936205f8 --- /dev/null +++ b/src/test/ui/anon-params/anon-params-edition-hygiene.rs @@ -0,0 +1,13 @@ +// check-pass +// edition:2018 +// aux-build:anon-params-edition-hygiene.rs + +// This warning is still surfaced +#![allow(anonymous_parameters)] + +#[macro_use] +extern crate anon_params_edition_hygiene; + +generate_trait_2015!(u8); + +fn main() {} diff --git a/src/test/ui/anon-params/auxiliary/anon-params-edition-hygiene.rs b/src/test/ui/anon-params/auxiliary/anon-params-edition-hygiene.rs new file mode 100644 index 000000000..aa4221bec --- /dev/null +++ b/src/test/ui/anon-params/auxiliary/anon-params-edition-hygiene.rs @@ -0,0 +1,12 @@ +// edition:2015 + +#[macro_export] +macro_rules! generate_trait_2015 { + ($Type: ident) => { + trait Trait { + fn method($Type) {} + } + }; +} + +fn main() {} |