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
This commit is contained in:
commit
1fa76a4502
@ -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 {
|
||||
@ -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 => {
|
||||
@ -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 => {
|
||||
|
@ -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;
|
||||
|
@ -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)]
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user