Skip to content

Commit 664c3e7

Browse files
committed
Turn old edition lints (anonymous-parameters, keyword-idents) into warn-by-default on 2015
1 parent c18c0ad commit 664c3e7

14 files changed

+92
-81
lines changed

compiler/rustc_lint/src/builtin.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -857,19 +857,18 @@ declare_lint! {
857857
/// ```
858858
///
859859
/// This syntax is now a hard error in the 2018 edition. In the 2015
860-
/// edition, this lint is "allow" by default, because the old code is
861-
/// still valid, and warning for all old code can be noisy. This lint
860+
/// edition, this lint is "warn" by default. This lint
862861
/// enables the [`cargo fix`] tool with the `--edition` flag to
863862
/// automatically transition old code from the 2015 edition to 2018. The
864-
/// tool will switch this lint to "warn" and will automatically apply the
863+
/// tool will run this lint and automatically apply the
865864
/// suggested fix from the compiler (which is to add `_` to each
866865
/// parameter). This provides a completely automated way to update old
867866
/// code for a new edition. See [issue #41686] for more details.
868867
///
869868
/// [issue #41686]: https://github.com/rust-lang/rust/issues/41686
870869
/// [`cargo fix`]: https://doc.rust-lang.org/cargo/commands/cargo-fix.html
871870
pub ANONYMOUS_PARAMETERS,
872-
Allow,
871+
Warn,
873872
"detects anonymous parameters",
874873
@future_incompatible = FutureIncompatibleInfo {
875874
reference: "issue #41686 <https://github.com/rust-lang/rust/issues/41686>",
@@ -884,6 +883,10 @@ declare_lint_pass!(
884883

885884
impl EarlyLintPass for AnonymousParameters {
886885
fn check_trait_item(&mut self, cx: &EarlyContext<'_>, it: &ast::AssocItem) {
886+
if cx.sess.edition() != Edition::Edition2015 {
887+
// This is a hard error in future editions; avoid linting and erroring
888+
return;
889+
}
887890
if let ast::AssocItemKind::Fn(box FnKind(_, ref sig, _, _)) = it.kind {
888891
for arg in sig.decl.inputs.iter() {
889892
if let ast::PatKind::Ident(_, ident, None) = arg.pat.kind {

library/std/src/keyword_docs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,7 @@ mod super_keyword {}
17681768
/// In the 2015 edition the parameters pattern was not needed for traits:
17691769
///
17701770
/// ```rust,edition2015
1771+
/// # #![allow(anonymous_parameters)]
17711772
/// trait Tr {
17721773
/// fn f(i32);
17731774
/// }

src/test/ui/anon-params/anon-params-edition-hygiene.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// edition:2018
33
// aux-build:anon-params-edition-hygiene.rs
44

5+
// This warning is still surfaced
6+
#![allow(anonymous_parameters)]
7+
58
#[macro_use]
69
extern crate anon_params_edition_hygiene;
710

src/test/ui/feature-gates/feature-gate-object_safe_for_dispatch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait NonObjectSafe3 {
1212
}
1313

1414
trait NonObjectSafe4 {
15-
fn foo(&self, &Self);
15+
fn foo(&self, s: &Self);
1616
}
1717

1818
fn takes_non_object_safe_ref<T>(obj: &dyn NonObjectSafe1) {

src/test/ui/feature-gates/feature-gate-object_safe_for_dispatch.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ LL | fn return_non_object_safe_rc() -> std::rc::Rc<dyn NonObjectSafe4> {
5757
|
5858
= help: consider moving `foo` to another trait
5959
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
60-
--> $DIR/feature-gate-object_safe_for_dispatch.rs:15:19
60+
--> $DIR/feature-gate-object_safe_for_dispatch.rs:15:22
6161
|
6262
LL | trait NonObjectSafe4 {
6363
| -------------- this trait cannot be made into an object...
64-
LL | fn foo(&self, &Self);
65-
| ^^^^^ ...because method `foo` references the `Self` type in this parameter
64+
LL | fn foo(&self, s: &Self);
65+
| ^^^^^ ...because method `foo` references the `Self` type in this parameter
6666

6767
error[E0038]: the trait `NonObjectSafe1` cannot be made into an object
6868
--> $DIR/feature-gate-object_safe_for_dispatch.rs:38:16

src/test/ui/issues/issue-78720.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ fn server() -> impl {
44
}
55

66
trait FilterBase2 {
7-
fn map2<F>(self, F) -> Map2<F> {}
7+
fn map2<F>(self, f: F) -> Map2<F> {}
88
//~^ ERROR mismatched types
99
//~^^ ERROR the size for values of type `Self` cannot be known at compilation time
1010
}

src/test/ui/issues/issue-78720.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,28 @@ LL | struct Map2<Segment2, F> {
2525
| ^^^
2626

2727
error[E0308]: mismatched types
28-
--> $DIR/issue-78720.rs:7:36
28+
--> $DIR/issue-78720.rs:7:39
2929
|
30-
LL | fn map2<F>(self, F) -> Map2<F> {}
31-
| ^^ expected struct `Map2`, found `()`
30+
LL | fn map2<F>(self, f: F) -> Map2<F> {}
31+
| ^^ expected struct `Map2`, found `()`
3232
|
3333
= note: expected struct `Map2<F>`
3434
found unit type `()`
3535

3636
error[E0277]: the size for values of type `Self` cannot be known at compilation time
3737
--> $DIR/issue-78720.rs:7:16
3838
|
39-
LL | fn map2<F>(self, F) -> Map2<F> {}
39+
LL | fn map2<F>(self, f: F) -> Map2<F> {}
4040
| ^^^^ doesn't have a size known at compile-time
4141
|
4242
= help: unsized fn params are gated as an unstable feature
4343
help: consider further restricting `Self`
4444
|
45-
LL | fn map2<F>(self, F) -> Map2<F> where Self: Sized {}
46-
| ^^^^^^^^^^^^^^^^^
45+
LL | fn map2<F>(self, f: F) -> Map2<F> where Self: Sized {}
46+
| ^^^^^^^^^^^^^^^^^
4747
help: function arguments must have a statically known size, borrowed types always have a known size
4848
|
49-
LL | fn map2<F>(&self, F) -> Map2<F> {}
49+
LL | fn map2<F>(&self, f: F) -> Map2<F> {}
5050
| ^
5151

5252
error: aborting due to 4 previous errors

src/test/ui/parser/variadic-ffi-semantic-restrictions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(c_variadic)]
2+
#![allow(anonymous_parameters)]
23

34
fn main() {}
45

src/test/ui/parser/variadic-ffi-semantic-restrictions.stderr

+34-34
Original file line numberDiff line numberDiff line change
@@ -1,203 +1,203 @@
11
error: only foreign or `unsafe extern "C" functions may be C-variadic
2-
--> $DIR/variadic-ffi-semantic-restrictions.rs:5:19
2+
--> $DIR/variadic-ffi-semantic-restrictions.rs:6:19
33
|
44
LL | fn f1_1(x: isize, ...) {}
55
| ^^^
66

77
error: C-variadic function must be declared with at least one named argument
8-
--> $DIR/variadic-ffi-semantic-restrictions.rs:8:9
8+
--> $DIR/variadic-ffi-semantic-restrictions.rs:9:9
99
|
1010
LL | fn f1_2(...) {}
1111
| ^^^
1212

1313
error: only foreign or `unsafe extern "C" functions may be C-variadic
14-
--> $DIR/variadic-ffi-semantic-restrictions.rs:8:9
14+
--> $DIR/variadic-ffi-semantic-restrictions.rs:9:9
1515
|
1616
LL | fn f1_2(...) {}
1717
| ^^^
1818

1919
error: only foreign or `unsafe extern "C" functions may be C-variadic
20-
--> $DIR/variadic-ffi-semantic-restrictions.rs:12:30
20+
--> $DIR/variadic-ffi-semantic-restrictions.rs:13:30
2121
|
2222
LL | extern "C" fn f2_1(x: isize, ...) {}
2323
| ^^^
2424

2525
error: C-variadic function must be declared with at least one named argument
26-
--> $DIR/variadic-ffi-semantic-restrictions.rs:15:20
26+
--> $DIR/variadic-ffi-semantic-restrictions.rs:16:20
2727
|
2828
LL | extern "C" fn f2_2(...) {}
2929
| ^^^
3030

3131
error: only foreign or `unsafe extern "C" functions may be C-variadic
32-
--> $DIR/variadic-ffi-semantic-restrictions.rs:15:20
32+
--> $DIR/variadic-ffi-semantic-restrictions.rs:16:20
3333
|
3434
LL | extern "C" fn f2_2(...) {}
3535
| ^^^
3636

3737
error: `...` must be the last argument of a C-variadic function
38-
--> $DIR/variadic-ffi-semantic-restrictions.rs:19:20
38+
--> $DIR/variadic-ffi-semantic-restrictions.rs:20:20
3939
|
4040
LL | extern "C" fn f2_3(..., x: isize) {}
4141
| ^^^
4242

4343
error: only foreign or `unsafe extern "C" functions may be C-variadic
44-
--> $DIR/variadic-ffi-semantic-restrictions.rs:19:20
44+
--> $DIR/variadic-ffi-semantic-restrictions.rs:20:20
4545
|
4646
LL | extern "C" fn f2_3(..., x: isize) {}
4747
| ^^^
4848

4949
error: only foreign or `unsafe extern "C" functions may be C-variadic
50-
--> $DIR/variadic-ffi-semantic-restrictions.rs:23:30
50+
--> $DIR/variadic-ffi-semantic-restrictions.rs:24:30
5151
|
5252
LL | extern "C" fn f3_1(x: isize, ...) {}
5353
| ^^^
5454

5555
error: C-variadic function must be declared with at least one named argument
56-
--> $DIR/variadic-ffi-semantic-restrictions.rs:26:20
56+
--> $DIR/variadic-ffi-semantic-restrictions.rs:27:20
5757
|
5858
LL | extern "C" fn f3_2(...) {}
5959
| ^^^
6060

6161
error: only foreign or `unsafe extern "C" functions may be C-variadic
62-
--> $DIR/variadic-ffi-semantic-restrictions.rs:26:20
62+
--> $DIR/variadic-ffi-semantic-restrictions.rs:27:20
6363
|
6464
LL | extern "C" fn f3_2(...) {}
6565
| ^^^
6666

6767
error: `...` must be the last argument of a C-variadic function
68-
--> $DIR/variadic-ffi-semantic-restrictions.rs:30:20
68+
--> $DIR/variadic-ffi-semantic-restrictions.rs:31:20
6969
|
7070
LL | extern "C" fn f3_3(..., x: isize) {}
7171
| ^^^
7272

7373
error: only foreign or `unsafe extern "C" functions may be C-variadic
74-
--> $DIR/variadic-ffi-semantic-restrictions.rs:30:20
74+
--> $DIR/variadic-ffi-semantic-restrictions.rs:31:20
7575
|
7676
LL | extern "C" fn f3_3(..., x: isize) {}
7777
| ^^^
7878

7979
error: C-variadic function must be declared with at least one named argument
80-
--> $DIR/variadic-ffi-semantic-restrictions.rs:35:13
80+
--> $DIR/variadic-ffi-semantic-restrictions.rs:36:13
8181
|
8282
LL | fn e_f1(...);
8383
| ^^^
8484

8585
error: `...` must be the last argument of a C-variadic function
86-
--> $DIR/variadic-ffi-semantic-restrictions.rs:37:13
86+
--> $DIR/variadic-ffi-semantic-restrictions.rs:38:13
8787
|
8888
LL | fn e_f2(..., x: isize);
8989
| ^^^
9090

9191
error: only foreign or `unsafe extern "C" functions may be C-variadic
92-
--> $DIR/variadic-ffi-semantic-restrictions.rs:44:23
92+
--> $DIR/variadic-ffi-semantic-restrictions.rs:45:23
9393
|
9494
LL | fn i_f1(x: isize, ...) {}
9595
| ^^^
9696

9797
error: C-variadic function must be declared with at least one named argument
98-
--> $DIR/variadic-ffi-semantic-restrictions.rs:46:13
98+
--> $DIR/variadic-ffi-semantic-restrictions.rs:47:13
9999
|
100100
LL | fn i_f2(...) {}
101101
| ^^^
102102

103103
error: only foreign or `unsafe extern "C" functions may be C-variadic
104-
--> $DIR/variadic-ffi-semantic-restrictions.rs:46:13
104+
--> $DIR/variadic-ffi-semantic-restrictions.rs:47:13
105105
|
106106
LL | fn i_f2(...) {}
107107
| ^^^
108108

109109
error: `...` must be the last argument of a C-variadic function
110-
--> $DIR/variadic-ffi-semantic-restrictions.rs:49:13
110+
--> $DIR/variadic-ffi-semantic-restrictions.rs:50:13
111111
|
112112
LL | fn i_f3(..., x: isize, ...) {}
113113
| ^^^
114114

115115
error: only foreign or `unsafe extern "C" functions may be C-variadic
116-
--> $DIR/variadic-ffi-semantic-restrictions.rs:49:13
116+
--> $DIR/variadic-ffi-semantic-restrictions.rs:50:13
117117
|
118118
LL | fn i_f3(..., x: isize, ...) {}
119119
| ^^^
120120

121121
error: only foreign or `unsafe extern "C" functions may be C-variadic
122-
--> $DIR/variadic-ffi-semantic-restrictions.rs:49:28
122+
--> $DIR/variadic-ffi-semantic-restrictions.rs:50:28
123123
|
124124
LL | fn i_f3(..., x: isize, ...) {}
125125
| ^^^
126126

127127
error: `...` must be the last argument of a C-variadic function
128-
--> $DIR/variadic-ffi-semantic-restrictions.rs:53:13
128+
--> $DIR/variadic-ffi-semantic-restrictions.rs:54:13
129129
|
130130
LL | fn i_f4(..., x: isize, ...) {}
131131
| ^^^
132132

133133
error: only foreign or `unsafe extern "C" functions may be C-variadic
134-
--> $DIR/variadic-ffi-semantic-restrictions.rs:53:13
134+
--> $DIR/variadic-ffi-semantic-restrictions.rs:54:13
135135
|
136136
LL | fn i_f4(..., x: isize, ...) {}
137137
| ^^^
138138

139139
error: only foreign or `unsafe extern "C" functions may be C-variadic
140-
--> $DIR/variadic-ffi-semantic-restrictions.rs:53:28
140+
--> $DIR/variadic-ffi-semantic-restrictions.rs:54:28
141141
|
142142
LL | fn i_f4(..., x: isize, ...) {}
143143
| ^^^
144144

145145
error: only foreign or `unsafe extern "C" functions may be C-variadic
146-
--> $DIR/variadic-ffi-semantic-restrictions.rs:60:23
146+
--> $DIR/variadic-ffi-semantic-restrictions.rs:61:23
147147
|
148148
LL | fn t_f1(x: isize, ...) {}
149149
| ^^^
150150

151151
error: only foreign or `unsafe extern "C" functions may be C-variadic
152-
--> $DIR/variadic-ffi-semantic-restrictions.rs:62:23
152+
--> $DIR/variadic-ffi-semantic-restrictions.rs:63:23
153153
|
154154
LL | fn t_f2(x: isize, ...);
155155
| ^^^
156156

157157
error: C-variadic function must be declared with at least one named argument
158-
--> $DIR/variadic-ffi-semantic-restrictions.rs:64:13
158+
--> $DIR/variadic-ffi-semantic-restrictions.rs:65:13
159159
|
160160
LL | fn t_f3(...) {}
161161
| ^^^
162162

163163
error: only foreign or `unsafe extern "C" functions may be C-variadic
164-
--> $DIR/variadic-ffi-semantic-restrictions.rs:64:13
164+
--> $DIR/variadic-ffi-semantic-restrictions.rs:65:13
165165
|
166166
LL | fn t_f3(...) {}
167167
| ^^^
168168

169169
error: C-variadic function must be declared with at least one named argument
170-
--> $DIR/variadic-ffi-semantic-restrictions.rs:67:13
170+
--> $DIR/variadic-ffi-semantic-restrictions.rs:68:13
171171
|
172172
LL | fn t_f4(...);
173173
| ^^^
174174

175175
error: only foreign or `unsafe extern "C" functions may be C-variadic
176-
--> $DIR/variadic-ffi-semantic-restrictions.rs:67:13
176+
--> $DIR/variadic-ffi-semantic-restrictions.rs:68:13
177177
|
178178
LL | fn t_f4(...);
179179
| ^^^
180180

181181
error: `...` must be the last argument of a C-variadic function
182-
--> $DIR/variadic-ffi-semantic-restrictions.rs:70:13
182+
--> $DIR/variadic-ffi-semantic-restrictions.rs:71:13
183183
|
184184
LL | fn t_f5(..., x: isize) {}
185185
| ^^^
186186

187187
error: only foreign or `unsafe extern "C" functions may be C-variadic
188-
--> $DIR/variadic-ffi-semantic-restrictions.rs:70:13
188+
--> $DIR/variadic-ffi-semantic-restrictions.rs:71:13
189189
|
190190
LL | fn t_f5(..., x: isize) {}
191191
| ^^^
192192

193193
error: `...` must be the last argument of a C-variadic function
194-
--> $DIR/variadic-ffi-semantic-restrictions.rs:73:13
194+
--> $DIR/variadic-ffi-semantic-restrictions.rs:74:13
195195
|
196196
LL | fn t_f6(..., x: isize);
197197
| ^^^
198198

199199
error: only foreign or `unsafe extern "C" functions may be C-variadic
200-
--> $DIR/variadic-ffi-semantic-restrictions.rs:73:13
200+
--> $DIR/variadic-ffi-semantic-restrictions.rs:74:13
201201
|
202202
LL | fn t_f6(..., x: isize);
203203
| ^^^

src/test/ui/proc-macro/trait-fn-args-2015.rs

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// check-pass
44
// aux-build:test-macros.rs
55

6+
#![allow(anonymous_parameters)]
7+
68
#[macro_use]
79
extern crate test_macros;
810

src/test/ui/rfc-2565-param-attrs/proc-macro-cannot-be-used.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// aux-build:ident-mac.rs
22

33
#![feature(c_variadic)]
4+
#![allow(anonymous_parameters)]
45

56
extern crate ident_mac;
67
use ident_mac::id;

0 commit comments

Comments
 (0)