Skip to content

Commit

Permalink
structured suggestion for renamed-and-removed-lints
Browse files Browse the repository at this point in the history
  • Loading branch information
zackmdavis committed Jul 15, 2018
1 parent 7e32059 commit d351370
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
12 changes: 7 additions & 5 deletions src/librustc/lint/context.rs
Expand Up @@ -131,8 +131,8 @@ pub enum CheckLintNameResult<'a> {
/// Lint doesn't exist
NoLint,
/// The lint is either renamed or removed. This is the warning
/// message.
Warning(String),
/// message, and an optional new name (`None` if removed).
Warning(String, Option<String>),
}

impl LintStore {
Expand Down Expand Up @@ -280,7 +280,7 @@ impl LintStore {
level: Level) {
let db = match self.check_lint_name(lint_name) {
CheckLintNameResult::Ok(_) => None,
CheckLintNameResult::Warning(ref msg) => {
CheckLintNameResult::Warning(ref msg, _) => {
Some(sess.struct_warn(msg))
},
CheckLintNameResult::NoLint => {
Expand Down Expand Up @@ -313,12 +313,14 @@ impl LintStore {
match self.by_name.get(lint_name) {
Some(&Renamed(ref new_name, _)) => {
CheckLintNameResult::Warning(
format!("lint {} has been renamed to {}", lint_name, new_name)
format!("lint `{}` has been renamed to `{}`", lint_name, new_name),
Some(new_name.to_owned())
)
},
Some(&Removed(ref reason)) => {
CheckLintNameResult::Warning(
format!("lint {} has been removed: {}", lint_name, reason)
format!("lint `{}` has been removed: `{}`", lint_name, reason),
None
)
},
None => {
Expand Down
24 changes: 16 additions & 8 deletions src/librustc/lint/levels.rs
Expand Up @@ -260,19 +260,27 @@ impl<'a> LintLevelsBuilder<'a> {

_ if !self.warn_about_weird_lints => {}

CheckLintNameResult::Warning(ref msg) => {
CheckLintNameResult::Warning(msg, renamed) => {
let lint = builtin::RENAMED_AND_REMOVED_LINTS;
let (level, src) = self.sets.get_lint_level(lint,
self.cur,
Some(&specs),
&sess);
lint::struct_lint_level(self.sess,
lint,
level,
src,
Some(li.span.into()),
msg)
.emit();
let mut err = lint::struct_lint_level(self.sess,
lint,
level,
src,
Some(li.span.into()),
&msg);
if let Some(new_name) = renamed {
err.span_suggestion_with_applicability(
li.span,
"use the new name",
new_name,
Applicability::MachineApplicable
);
}
err.emit();
}
CheckLintNameResult::NoLint => {
let lint = builtin::UNKNOWN_LINTS;
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/lint-removed-cmdline.rs
Expand Up @@ -13,7 +13,7 @@

// compile-flags:-D raw_pointer_derive

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

#![warn(unused)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/lint-removed.rs
Expand Up @@ -13,6 +13,6 @@
// default, and allowed in cargo dependency builds.
// cc #30346

#[deny(raw_pointer_derive)] //~ WARN raw_pointer_derive has been removed
#[deny(raw_pointer_derive)] //~ WARN `raw_pointer_derive` has been removed
#[deny(unused_variables)]
fn main() { let unused = (); } //~ ERROR unused
2 changes: 1 addition & 1 deletion src/test/compile-fail/lint-renamed-cmdline.rs
Expand Up @@ -10,7 +10,7 @@

// compile-flags:-D unknown_features

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

Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/lint-renamed.rs
Expand Up @@ -8,6 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

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

0 comments on commit d351370

Please sign in to comment.