8000 Backwards compatibility for tool/clippy lints by flip1995 · Pull Request #53762 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Backwards compatibility for tool/clippy lints #53762

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 6 commits into from
Sep 1, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add deprecated_name argument to the register lint group functions
  • Loading branch information
flip1995 authored and Manishearth committed Aug 31, 2018
commit ce173c12e6416b1afa4aa460076d7c807fdcdccf
39 changes: 28 additions & 11 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ pub struct LintStore {
/// Lints indexed by name.
by_name: FxHashMap<String, TargetLint>,

/// Map of registered lint groups to what lints they expand to. The bool
/// is true if the lint group was added by a plugin.
lint_groups: FxHashMap<&'static str, (Vec<LintId>, bool)>,
/// Map of registered lint groups to what lints they expand to. The first
/// bool is true if the lint group was added by a plugin. The optional string
/// is used to store the new names of deprecated lint group names.
lint_groups: FxHashMap<&'static str, (Vec<LintId>, bool, Option<&'static str>)>,

/// Extra info for future incompatibility lints, describing the
/// issue or RFC that caused the incompatibility.
Expand Down Expand Up @@ -221,7 +222,7 @@ impl LintStore {
let lints = lints.iter().filter(|f| f.edition == Some(*edition)).map(|f| f.id)
.collect::<Vec<_>>();
if !lints.is_empty() {
self.register_group(sess, false, edition.lint_name(), lints)
self.register_group(sess, false, edition.lint_name(), None, lints)
}
}

Expand All @@ -231,19 +232,35 @@ impl LintStore {
self.future_incompatible.insert(lint.id, lint);
}

self.register_group(sess, false, "future_incompatible", future_incompatible);


self.register_group(
sess,
false,
"future_incompatible",
None,
future_incompatible,
);
}

pub fn future_incompatible(&self, id: LintId) -> Option<&FutureIncompatibleInfo> {
self.future_incompatible.get(&id)
}

pub fn register_group(&mut self, sess: Option<&Session>,
from_plugin: bool, name: &'static str,
to: Vec<LintId>) {
let new = self.lint_groups.insert(name, (to, from_plugin)).is_none();
pub fn register_group(
&mut self,
sess: Option<&Session>,
from_plugin: bool,
name: &'static str,
deprecated_name: Option<&'static str>,
to: Vec<LintId>,
) {
let new = self
.lint_groups
.insert(name, (to, from_plugin, None))
.is_none();
if let Some(deprecated) = deprecated_name {
self.lint_groups
.insert(deprecated, (vec![], from_plugin, Some(name)));
}

if !new {
let msg = format!("duplicate specification of lint group {}", name);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,8 @@ where
ls.register_late_pass(Some(sess), true, pass);
}

for (name, to) in lint_groups {
ls.register_group(Some(sess), true, name, to);
for (name, (to, deprecated_name)) in lint_groups {
ls.register_group(Some(sess), true, name, deprecated_name, to);
}

*sess.plugin_llvm_passes.borrow_mut() = llvm_passes;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {

macro_rules! add_lint_group {
($sess:ident, $name:expr, $($lint:ident),*) => (
store.register_group($sess, false, $name, vec![$(LintId::of($lint)),*]);
store.register_group($sess, false, $name, None, vec![$(LintId::of($lint)),*]);
)
}

Expand Down
13 changes: 10 additions & 3 deletions src/librustc_plugin/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct Registry<'a> {
pub late_lint_passes: Vec<LateLintPassObject>,

#[doc(hidden)]
pub lint_groups: FxHashMap<&'static str, Vec<LintId>>,
pub lint_groups: FxHashMap<&'static str, (Vec<LintId>, Option<&'static str>)>,

#[doc(hidden)]
pub llvm_passes: Vec<String>,
Expand Down Expand Up @@ -170,8 +170,15 @@ impl<'a> Registry<'a> {
self.late_lint_passes.push(lint_pass);
}
/// Register a lint group.
pub fn register_lint_group(&mut self, name: &'static str, to: Vec<&'static Lint>) {
self.lint_groups.insert(name, to.into_iter().map(|x| LintId::of(x)).collect());
pub fn register_lint_group(
&mut self,
name: &'static str,
deprecated_name: Option<&'static str>,
to: Vec<&'static Lint>
) {
self.lint_groups.insert(name,
(to.into_iter().map(|x| LintId::of(x)).collect(),
deprecated_name));
}

/// Register an LLVM pass.
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui-fulldeps/auxiliary/lint_group_plugin_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
reg.register_late_lint_pass(box Pass);
reg.register_lint_group("lint_me", vec![TEST_LINT, PLEASE_LINT]);
reg.register_lint_group("lint_me", None, vec![TEST_LINT, PLEASE_LINT]);
}
2 changes: 1 addition & 1 deletion src/tools/clippy
0