Skip to content

Commit f272688

Browse files
committed
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
2 parents 39e6ba8 + b32b6e8 commit f272688

9 files changed

+70
-83
lines changed

src/libsyntax/parse/parser.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,13 @@ impl<'a> Parser<'a> {
13761376
// This is somewhat dubious; We don't want to allow
13771377
// argument names to be left off if there is a
13781378
// definition...
1379-
p.parse_arg_general(false)
1379+
1380+
// We don't allow argument names to be left off in edition 2018.
1381+
if p.span.edition() >= Edition::Edition2018 {
1382+
p.parse_arg_general(true)
1383+
} else {
1384+
p.parse_arg_general(false)
1385+
}
13801386
})?;
13811387
generics.where_clause = self.parse_where_clause()?;
13821388

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Tests that anonymous parameters are a hard error in edition 2018.
2+
3+
// edition:2018
4+
5+
trait T {
6+
fn foo(i32); //~ expected one of `:` or `@`, found `)`
7+
8+
fn bar_with_default_impl(String, String) {}
9+
//~^ ERROR expected one of `:` or `@`, found `,`
10+
}
11+
12+
fn main() {}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: expected one of `:` or `@`, found `)`
2+
--> $DIR/anon-params-denied-2018.rs:6:15
3+
|
4+
LL | fn foo(i32); //~ expected one of `:` or `@`, found `)`
5+
| ^ expected one of `:` or `@` here
6+
7+
error: expected one of `:` or `@`, found `,`
8+
--> $DIR/anon-params-denied-2018.rs:8:36
9+
|
10+
LL | fn bar_with_default_impl(String, String) {}
11+
| ^ expected one of `:` or `@` here
12+
13+
error: aborting due to 2 previous errors
14+
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![warn(anonymous_parameters)]
2+
// Test for the anonymous_parameters deprecation lint (RFC 1685)
3+
4+
// compile-pass
5+
// edition:2015
6+
// run-rustfix
7+
8+
trait T {
9+
fn foo(_: i32); //~ WARNING anonymous parameters are deprecated
10+
//~| WARNING hard error
11+
12+
fn bar_with_default_impl(_: String, _: String) {}
13+
//~^ WARNING anonymous parameters are deprecated
14+
//~| WARNING hard error
15+
//~| WARNING anonymous parameters are deprecated
16+
//~| WARNING hard error
17+
}
18+
19+
fn main() {}

src/test/ui/anon-params-deprecated.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2-
// file at the top-level directory of this distribution and at
3-
// http://rust-lang.org/COPYRIGHT.
4-
//
5-
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6-
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7-
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8-
// option. This file may not be copied, modified, or distributed
9-
// except according to those terms.
10-
11-
#![forbid(anonymous_parameters)]
1+
#![warn(anonymous_parameters)]
122
// Test for the anonymous_parameters deprecation lint (RFC 1685)
133

4+
// compile-pass
5+
// edition:2015
6+
// run-rustfix
7+
148
trait T {
15-
fn foo(i32); //~ ERROR anonymous parameters are deprecated
9+
fn foo(i32); //~ WARNING anonymous parameters are deprecated
1610
//~| WARNING hard error
1711

1812
fn bar_with_default_impl(String, String) {}
19-
//~^ ERROR anonymous parameters are deprecated
13+
//~^ WARNING anonymous parameters are deprecated
2014
//~| WARNING hard error
21-
//~| ERROR anonymous parameters are deprecated
15+
//~| WARNING anonymous parameters are deprecated
2216
//~| WARNING hard error
2317
}
2418

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
1-
error: anonymous parameters are deprecated and will be removed in the next edition.
2-
--> $DIR/anon-params-deprecated.rs:15:12
1+
warning: anonymous parameters are deprecated and will be removed in the next edition.
2+
--> $DIR/anon-params-deprecated.rs:9:12
33
|
4-
LL | fn foo(i32); //~ ERROR anonymous parameters are deprecated
4+
LL | fn foo(i32); //~ WARNING anonymous parameters are deprecated
55
| ^^^ help: Try naming the parameter or explicitly ignoring it: `_: i32`
66
|
77
note: lint level defined here
8-
--> $DIR/anon-params-deprecated.rs:11:11
8+
--> $DIR/anon-params-deprecated.rs:1:9
99
|
10-
LL | #![forbid(anonymous_parameters)]
11-
| ^^^^^^^^^^^^^^^^^^^^
10+
LL | #![warn(anonymous_parameters)]
11+
| ^^^^^^^^^^^^^^^^^^^^
1212
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1313
= note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>
1414

15-
error: anonymous parameters are deprecated and will be removed in the next edition.
16-
--> $DIR/anon-params-deprecated.rs:18:30
15+
warning: anonymous parameters are deprecated and will be removed in the next edition.
16+
--> $DIR/anon-params-deprecated.rs:12:30
1717
|
1818
LL | fn bar_with_default_impl(String, String) {}
1919
| ^^^^^^ help: Try naming the parameter or explicitly ignoring it: `_: String`
2020
|
2121
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2222
= note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>
2323

24-
error: anonymous parameters are deprecated and will be removed in the next edition.
25-
--> $DIR/anon-params-deprecated.rs:18:38
24+
warning: anonymous parameters are deprecated and will be removed in the next edition.
25+
--> $DIR/anon-params-deprecated.rs:12:38
2626
|
2727
LL | fn bar_with_default_impl(String, String) {}
2828
| ^^^^^^ help: Try naming the parameter or explicitly ignoring it: `_: String`
2929
|
3030
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3131
= note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>
3232

33-
error: aborting due to 3 previous errors
34-

src/test/ui/lint/lint-anon-param-edition.fixed

-23
This file was deleted.

src/test/ui/lint/lint-anon-param-edition.rs

-23
This file was deleted.

src/test/ui/lint/lint-anon-param-edition.stderr

-10
This file was deleted.

0 commit comments

Comments
 (0)