Auto merge of #53612 - mark-i-m:anon_param_disallowed_2018, r=petrochenkov
Remove anonymous trait params from 2018 and beyond cc @Centril @nikomatsakis cc #41686 rust-lang/rfcs#2522 #53272 This PR removes support for anonymous trait parameters syntactically in rust 2018 and onward. TODO: - [x] Add tests
This commit is contained in:
commit
f272688bbb
9 changed files with 70 additions and 83 deletions
|
|
@ -1376,7 +1376,13 @@ impl<'a> Parser<'a> {
|
|||
// This is somewhat dubious; We don't want to allow
|
||||
// argument names to be left off if there is a
|
||||
// definition...
|
||||
p.parse_arg_general(false)
|
||||
|
||||
// We don't allow argument names to be left off in edition 2018.
|
||||
if p.span.edition() >= Edition::Edition2018 {
|
||||
p.parse_arg_general(true)
|
||||
} else {
|
||||
p.parse_arg_general(false)
|
||||
}
|
||||
})?;
|
||||
generics.where_clause = self.parse_where_clause()?;
|
||||
|
||||
|
|
|
|||
12
src/test/ui/anon-params-denied-2018.rs
Normal file
12
src/test/ui/anon-params-denied-2018.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
// Tests that anonymous parameters are a hard error in edition 2018.
|
||||
|
||||
// edition:2018
|
||||
|
||||
trait T {
|
||||
fn foo(i32); //~ expected one of `:` or `@`, found `)`
|
||||
|
||||
fn bar_with_default_impl(String, String) {}
|
||||
//~^ ERROR expected one of `:` or `@`, found `,`
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
14
src/test/ui/anon-params-denied-2018.stderr
Normal file
14
src/test/ui/anon-params-denied-2018.stderr
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
error: expected one of `:` or `@`, found `)`
|
||||
--> $DIR/anon-params-denied-2018.rs:6:15
|
||||
|
|
||||
LL | fn foo(i32); //~ expected one of `:` or `@`, found `)`
|
||||
| ^ expected one of `:` or `@` here
|
||||
|
||||
error: expected one of `:` or `@`, found `,`
|
||||
--> $DIR/anon-params-denied-2018.rs:8:36
|
||||
|
|
||||
LL | fn bar_with_default_impl(String, String) {}
|
||||
| ^ expected one of `:` or `@` here
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
19
src/test/ui/anon-params-deprecated.fixed
Normal file
19
src/test/ui/anon-params-deprecated.fixed
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#![warn(anonymous_parameters)]
|
||||
// Test for the anonymous_parameters deprecation lint (RFC 1685)
|
||||
|
||||
// compile-pass
|
||||
// edition:2015
|
||||
// run-rustfix
|
||||
|
||||
trait T {
|
||||
fn foo(_: i32); //~ WARNING anonymous parameters are deprecated
|
||||
//~| WARNING hard error
|
||||
|
||||
fn bar_with_default_impl(_: String, _: String) {}
|
||||
//~^ WARNING anonymous parameters are deprecated
|
||||
//~| WARNING hard error
|
||||
//~| WARNING anonymous parameters are deprecated
|
||||
//~| WARNING hard error
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,24 +1,18 @@
|
|||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![forbid(anonymous_parameters)]
|
||||
#![warn(anonymous_parameters)]
|
||||
// Test for the anonymous_parameters deprecation lint (RFC 1685)
|
||||
|
||||
// compile-pass
|
||||
// edition:2015
|
||||
// run-rustfix
|
||||
|
||||
trait T {
|
||||
fn foo(i32); //~ ERROR anonymous parameters are deprecated
|
||||
fn foo(i32); //~ WARNING anonymous parameters are deprecated
|
||||
//~| WARNING hard error
|
||||
|
||||
fn bar_with_default_impl(String, String) {}
|
||||
//~^ ERROR anonymous parameters are deprecated
|
||||
//~^ WARNING anonymous parameters are deprecated
|
||||
//~| WARNING hard error
|
||||
//~| ERROR anonymous parameters are deprecated
|
||||
//~| WARNING anonymous parameters are deprecated
|
||||
//~| WARNING hard error
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
error: anonymous parameters are deprecated and will be removed in the next edition.
|
||||
--> $DIR/anon-params-deprecated.rs:15:12
|
||||
warning: anonymous parameters are deprecated and will be removed in the next edition.
|
||||
--> $DIR/anon-params-deprecated.rs:9:12
|
||||
|
|
||||
LL | fn foo(i32); //~ ERROR anonymous parameters are deprecated
|
||||
LL | fn foo(i32); //~ WARNING anonymous parameters are deprecated
|
||||
| ^^^ help: Try naming the parameter or explicitly ignoring it: `_: i32`
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/anon-params-deprecated.rs:11:11
|
||||
--> $DIR/anon-params-deprecated.rs:1:9
|
||||
|
|
||||
LL | #![forbid(anonymous_parameters)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
LL | #![warn(anonymous_parameters)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
= 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 #41686 <https://github.com/rust-lang/rust/issues/41686>
|
||||
|
||||
error: anonymous parameters are deprecated and will be removed in the next edition.
|
||||
--> $DIR/anon-params-deprecated.rs:18:30
|
||||
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`
|
||||
|
|
@ -21,8 +21,8 @@ LL | fn bar_with_default_impl(String, String) {}
|
|||
= 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 #41686 <https://github.com/rust-lang/rust/issues/41686>
|
||||
|
||||
error: anonymous parameters are deprecated and will be removed in the next edition.
|
||||
--> $DIR/anon-params-deprecated.rs:18:38
|
||||
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`
|
||||
|
|
@ -30,5 +30,3 @@ LL | fn bar_with_default_impl(String, String) {}
|
|||
= 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 #41686 <https://github.com/rust-lang/rust/issues/41686>
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// tests that the anonymous_parameters lint is warn-by-default on the 2018 edition
|
||||
|
||||
// compile-pass
|
||||
// edition:2018
|
||||
// run-rustfix
|
||||
|
||||
trait Foo {
|
||||
fn foo(_: u8);
|
||||
//^ WARN anonymous parameters are deprecated
|
||||
//| WARN this was previously accepted
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// tests that the anonymous_parameters lint is warn-by-default on the 2018 edition
|
||||
|
||||
// compile-pass
|
||||
// edition:2018
|
||||
// run-rustfix
|
||||
|
||||
trait Foo {
|
||||
fn foo(u8);
|
||||
//^ WARN anonymous parameters are deprecated
|
||||
//| WARN this was previously accepted
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
warning: anonymous parameters are deprecated and will be removed in the next edition.
|
||||
--> $DIR/lint-anon-param-edition.rs:18:12
|
||||
|
|
||||
LL | fn foo(u8);
|
||||
| ^^ help: Try naming the parameter or explicitly ignoring it: `_: u8`
|
||||
|
|
||||
= note: #[warn(anonymous_parameters)] on by default
|
||||
= 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 #41686 <https://github.com/rust-lang/rust/issues/41686>
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue