Skip to content

structured suggestion for renamed-and-removed-lints #52395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice if we could add a suggestion to remove the lint, but getting the right span might be a bit of a pain (specially due to the possibility of multiple lints be present).

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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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