Skip to content

Commit 1fa76a4

Browse files
committed
Auto merge of #52395 - zackmdavis:and_the_case_of_the_renamed_lint, r=estebank
structured suggestion for renamed-and-removed-lints ![lint_renamed](https://user-images.githubusercontent.com/1076988/42730470-f74688dc-87a9-11e8-8dfd-b3e1d70b0af8.png) r? @estebank
2 parents 88b025b + d351370 commit 1fa76a4

File tree

6 files changed

+27
-17
lines changed

6 files changed

+27
-17
lines changed

src/librustc/lint/context.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ pub enum CheckLintNameResult<'a> {
131131
/// Lint doesn't exist
132132
NoLint,
133133
/// The lint is either renamed or removed. This is the warning
134-
/// message.
135-
Warning(String),
134+
/// message, and an optional new name (`None` if removed).
135+
Warning(String, Option<String>),
136136
}
137137

138138
impl LintStore {
@@ -280,7 +280,7 @@ impl LintStore {
280280
level: Level) {
281281
let db = match self.check_lint_name(lint_name) {
282282
CheckLintNameResult::Ok(_) => None,
283-
CheckLintNameResult::Warning(ref msg) => {
283+
CheckLintNameResult::Warning(ref msg, _) => {
284284
Some(sess.struct_warn(msg))
285285
},
286286
CheckLintNameResult::NoLint => {
@@ -313,12 +313,14 @@ impl LintStore {
313313
match self.by_name.get(lint_name) {
314314
Some(&Renamed(ref new_name, _)) => {
315315
CheckLintNameResult::Warning(
316-
format!("lint {} has been renamed to {}", lint_name, new_name)
316+
format!("lint `{}` has been renamed to `{}`", lint_name, new_name),
317+
Some(new_name.to_owned())
317318
)
318319
},
319320
Some(&Removed(ref reason)) => {
320321
CheckLintNameResult::Warning(
321-
format!("lint {} has been removed: {}", lint_name, reason)
322+
format!("lint `{}` has been removed: `{}`", lint_name, reason),
323+
None
322324
)
323325
},
324326
None => {

src/librustc/lint/levels.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -260,19 +260,27 @@ impl<'a> LintLevelsBuilder<'a> {
260260

261261
_ if !self.warn_about_weird_lints => {}
262262

263-
CheckLintNameResult::Warning(ref msg) => {
263+
CheckLintNameResult::Warning(msg, renamed) => {
264264
let lint = builtin::RENAMED_AND_REMOVED_LINTS;
265265
let (level, src) = self.sets.get_lint_level(lint,
266266
self.cur,
267267
Some(&specs),
268268
&sess);
269-
lint::struct_lint_level(self.sess,
270-
lint,
271-
level,
272-
src,
273-
Some(li.span.into()),
274-
msg)
275-
.emit();
269+
let mut err = lint::struct_lint_level(self.sess,
270+
lint,
271+
level,
272+
src,
273+
Some(li.span.into()),
274+
&msg);
275+
if let Some(new_name) = renamed {
276+
err.span_suggestion_with_applicability(
277+
li.span,
278+
"use the new name",
279+
new_name,
280+
Applicability::MachineApplicable
281+
);
282+
}
283+
err.emit();
276284
}
277285
CheckLintNameResult::NoLint => {
278286
let lint = builtin::UNKNOWN_LINTS;

src/test/compile-fail/lint-removed-cmdline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
// compile-flags:-D raw_pointer_derive
1515

16-
// error-pattern:lint raw_pointer_derive has been removed
16+
// error-pattern:lint `raw_pointer_derive` has been removed
1717
// error-pattern:requested on the command line with `-D raw_pointer_derive`
1818

1919
#![warn(unused)]

src/test/compile-fail/lint-removed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
// default, and allowed in cargo dependency builds.
1414
// cc #30346
1515

16-
#[deny(raw_pointer_derive)] //~ WARN raw_pointer_derive has been removed
16+
#[deny(raw_pointer_derive)] //~ WARN `raw_pointer_derive` has been removed
1717
#[deny(unused_variables)]
1818
fn main() { let unused = (); } //~ ERROR unused

src/test/compile-fail/lint-renamed-cmdline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// compile-flags:-D unknown_features
1212

13-
// error-pattern:lint unknown_features has been renamed to unused_features
13+
// error-pattern:lint `unknown_features` has been renamed to `unused_features`
1414
// error-pattern:requested on the command line with `-D unknown_features`
1515
// error-pattern:unused
1616

src/test/compile-fail/lint-renamed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[deny(unknown_features)] //~ WARN lint unknown_features has been renamed to unused_features
11+
#[deny(unknown_features)] //~ WARN lint `unknown_features` has been renamed to `unused_features`
1212
#[deny(unused)]
1313
fn main() { let unused = (); } //~ ERROR unused

0 commit comments

Comments
 (0)