Skip to content

Commit 6cc765d

Browse files
committed
Add a lint to disallow anonymous parameters
1 parent 4cb396c commit 6cc765d

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

src/librustc_lint/builtin.rs

+39
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ use syntax::ast;
4545
use syntax::attr;
4646
use syntax::feature_gate::{AttributeGate, AttributeType, Stability, deprecated_attributes};
4747
use syntax_pos::Span;
48+
use syntax::symbol::keywords;
4849

4950
use rustc::hir::{self, PatKind};
5051
use rustc::hir::intravisit::FnKind;
@@ -605,6 +606,44 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations {
605606
}
606607
}
607608

609+
declare_lint! {
610+
pub ANONYMOUS_PARAMETERS,
611+
Allow,
612+
"detects anonymous parameters"
613+
}
614+
615+
/// Checks for use of anonymous parameters (RFC 1685)
616+
#[derive(Clone)]
617+
pub struct AnonymousParameters;
618+
619+
impl LintPass for AnonymousParameters {
620+
fn get_lints(&self) -> LintArray {
621+
lint_array!(ANONYMOUS_PARAMETERS)
622+
}
623+
}
624+
625+
impl EarlyLintPass for AnonymousParameters {
626+
fn check_trait_item(&mut self, cx: &EarlyContext, it: &ast::TraitItem) {
627+
match it.node {
628+
ast::TraitItemKind::Method(ref sig, _) => {
629+
for arg in sig.decl.inputs.iter() {
630+
match arg.pat.node {
631+
ast::PatKind::Ident(_, ident, None) => {
632+
if ident.node.name == keywords::Invalid.name() {
633+
cx.span_lint(ANONYMOUS_PARAMETERS,
634+
arg.pat.span,
635+
"use of deprecated anonymous parameter");
636+
}
637+
}
638+
_ => (),
639+
}
640+
}
641+
},
642+
_ => (),
643+
}
644+
}
645+
}
646+
608647
declare_lint! {
609648
DEPRECATED_ATTR,
610649
Warn,

src/librustc_lint/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
112112
add_early_builtin!(sess,
113113
UnusedParens,
114114
UnusedImportBraces,
115+
AnonymousParameters,
115116
);
116117

117118
add_early_builtin_with_new!(sess,
@@ -244,6 +245,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
244245
id: LintId::of(MISSING_FRAGMENT_SPECIFIER),
245246
reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>",
246247
},
248+
FutureIncompatibleInfo {
249+
id: LintId::of(ANONYMOUS_PARAMETERS),
250+
reference: "issue #41686 <https://github.com/rust-lang/rust/issues/41686>",
251+
},
247252
]);
248253

249254
// Register renamed and removed lints
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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)]
12+
// Test for the anonymous_parameters deprecation lint (RFC 1685)
13+
14+
trait T {
15+
fn foo(i32); //~ ERROR use of deprecated anonymous parameter
16+
//~| WARNING hard error
17+
18+
fn bar_with_default_impl(String, String) {}
19+
//~^ ERROR use of deprecated anonymous parameter
20+
//~| WARNING hard error
21+
//~| ERROR use of deprecated anonymous parameter
22+
//~| WARNING hard error
23+
}
24+
25+
fn main() {}

0 commit comments

Comments
 (0)