Skip to content

Commit 5f308ee

Browse files
committed
Auto merge of #48309 - mark-i-m:anon_param_lint, r=nikomatsakis
Make anon params lint warn-by-default This is intended as a followup on anonymous parameters deprecation. Cross-posting from #41686: > After having read a bit more of the discussion that I can find, I propose a more aggressive deprecation strategy: > - We make the lint warn-by-default as soon as possible > - We make anon parameters a hard error at the epoch boundary cc @matklad @est31 @aturon
2 parents ad2591c + 0e53b78 commit 5f308ee

File tree

16 files changed

+109
-22
lines changed

16 files changed

+109
-22
lines changed

src/librustc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
#![feature(catch_expr)]
7070
#![feature(test)]
7171
#![feature(in_band_lifetimes)]
72+
#![feature(macro_at_most_once_rep)]
7273

7374
#![recursion_limit="512"]
7475

src/librustc/lint/mod.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ pub struct Lint {
7777
/// e.g. "imports that are never used"
7878
pub desc: &'static str,
7979

80-
/// Deny lint after this edition
81-
pub edition_deny: Option<Edition>,
80+
/// Starting at the given edition, default to the given lint level. If this is `None`, then use
81+
/// `default_level`.
82+
pub edition_lint_opts: Option<(Edition, Level)>,
8283
}
8384

8485
impl Lint {
@@ -88,41 +89,40 @@ impl Lint {
8889
}
8990

9091
pub fn default_level(&self, session: &Session) -> Level {
91-
if let Some(edition_deny) = self.edition_deny {
92-
if session.edition() >= edition_deny {
93-
return Level::Deny
94-
}
95-
}
96-
self.default_level
92+
self.edition_lint_opts
93+
.filter(|(e, _)| *e <= session.edition())
94+
.map(|(_, l)| l)
95+
.unwrap_or(self.default_level)
9796
}
9897
}
9998

10099
/// Declare a static item of type `&'static Lint`.
101100
#[macro_export]
102101
macro_rules! declare_lint {
103-
($vis: vis $NAME: ident, $Level: ident, $desc: expr, $edition: expr) => (
102+
($vis: vis $NAME: ident, $Level: ident, $desc: expr) => (
104103
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
105104
name: stringify!($NAME),
106105
default_level: $crate::lint::$Level,
107106
desc: $desc,
108-
edition_deny: Some($edition)
107+
edition_lint_opts: None,
109108
};
110109
);
111-
($vis: vis $NAME: ident, $Level: ident, $desc: expr) => (
110+
($vis: vis $NAME: ident, $Level: ident, $desc: expr,
111+
$lint_edition: expr => $edition_level: ident $(,)?
112+
) => (
112113
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
113114
name: stringify!($NAME),
114115
default_level: $crate::lint::$Level,
115116
desc: $desc,
116-
edition_deny: None,
117+
edition_lint_opts: Some(($lint_edition, $crate::lint::Level::$edition_level)),
117118
};
118119
);
119120
}
120121

121122
/// Declare a static `LintArray` and return it as an expression.
122123
#[macro_export]
123124
macro_rules! lint_array {
124-
($( $lint:expr ),*,) => { lint_array!( $( $lint ),* ) };
125-
($( $lint:expr ),*) => {{
125+
($( $lint:expr ),* $(,)?) => {{
126126
static ARRAY: LintArray = &[ $( &$lint ),* ];
127127
ARRAY
128128
}}

src/librustc_lint/builtin.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use std::collections::HashSet;
4343

4444
use syntax::ast;
4545
use syntax::attr;
46+
use syntax::edition::Edition;
4647
use syntax::feature_gate::{AttributeGate, AttributeType, Stability, deprecated_attributes};
4748
use syntax_pos::{BytePos, Span, SyntaxContext};
4849
use syntax::symbol::keywords;
@@ -616,7 +617,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations {
616617
declare_lint! {
617618
pub ANONYMOUS_PARAMETERS,
618619
Allow,
619-
"detects anonymous parameters"
620+
"detects anonymous parameters",
621+
Edition::Edition2018 => Warn,
620622
}
621623

622624
/// Checks for use of anonymous parameters (RFC 1685)
@@ -637,9 +639,29 @@ impl EarlyLintPass for AnonymousParameters {
637639
match arg.pat.node {
638640
ast::PatKind::Ident(_, ident, None) => {
639641
if ident.name == keywords::Invalid.name() {
640-
cx.span_lint(ANONYMOUS_PARAMETERS,
641-
arg.pat.span,
642-
"use of deprecated anonymous parameter");
642+
let ty_snip = cx
643+
.sess
644+
.codemap()
645+
.span_to_snippet(arg.ty.span);
646+
647+
let (ty_snip, appl) = if let Ok(snip) = ty_snip {
648+
(snip, Applicability::MachineApplicable)
649+
} else {
650+
("<type>".to_owned(), Applicability::HasPlaceholders)
651+
};
652+
653+
cx.struct_span_lint(
654+
ANONYMOUS_PARAMETERS,
655+
arg.pat.span,
656+
"anonymous parameters are deprecated and will be \
657+
removed in the next edition."
658+
).span_suggestion_with_applicability(
659+
arg.pat.span,
660+
"Try naming the parameter or explicitly \
661+
ignoring it",
662+
format!("_: {}", ty_snip),
663+
appl
664+
).emit();
643665
}
644666
}
645667
_ => (),

src/librustc_lint/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#![feature(macro_vis_matcher)]
3030
#![feature(quote)]
3131
#![feature(rustc_diagnostic_macros)]
32+
#![feature(macro_at_most_once_rep)]
3233

3334
extern crate syntax;
3435
#[macro_use]

src/test/compile-fail-fulldeps/auxiliary/lint_for_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#![feature(plugin_registrar, rustc_private)]
1414
#![feature(box_syntax)]
1515
#![feature(macro_vis_matcher)]
16+
#![feature(macro_at_most_once_rep)]
1617

1718
#[macro_use] extern crate rustc;
1819
extern crate rustc_plugin;

src/test/compile-fail-fulldeps/auxiliary/lint_group_plugin_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#![feature(plugin_registrar)]
1414
#![feature(box_syntax, rustc_private)]
1515
#![feature(macro_vis_matcher)]
16+
#![feature(macro_at_most_once_rep)]
1617

1718
// Load rustc as a plugin to get macros
1819
#[macro_use]

src/test/compile-fail-fulldeps/auxiliary/lint_plugin_test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#![feature(plugin_registrar)]
1414
#![feature(box_syntax, rustc_private)]
1515
#![feature(macro_vis_matcher)]
16+
#![feature(macro_at_most_once_rep)]
1617

1718
extern crate syntax;
1819

src/test/compile-fail/anon-params-deprecated.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
// Test for the anonymous_parameters deprecation lint (RFC 1685)
1313

1414
trait T {
15-
fn foo(i32); //~ ERROR use of deprecated anonymous parameter
15+
fn foo(i32); //~ ERROR anonymous parameters are deprecated
1616
//~| WARNING hard error
1717

1818
fn bar_with_default_impl(String, String) {}
19-
//~^ ERROR use of deprecated anonymous parameter
19+
//~^ ERROR anonymous parameters are deprecated
2020
//~| WARNING hard error
21-
//~| ERROR use of deprecated anonymous parameter
21+
//~| ERROR anonymous parameters are deprecated
2222
//~| WARNING hard error
2323
}
2424

src/test/compile-fail/future-incompatible-lint-group.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#![deny(future_incompatible)]
1212

1313
trait Tr {
14-
fn f(u8) {} //~ ERROR use of deprecated anonymous parameter
14+
fn f(u8) {} //~ ERROR anonymous parameters are deprecated
1515
//~^ WARN this was previously accepted
1616
}
1717

src/test/run-pass-fulldeps/auxiliary/lint_for_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#![feature(plugin_registrar, rustc_private)]
1414
#![feature(box_syntax)]
1515
#![feature(macro_vis_matcher)]
16+
#![feature(macro_at_most_once_rep)]
1617

1718
#[macro_use] extern crate rustc;
1819
extern crate rustc_plugin;

0 commit comments

Comments
 (0)