Skip to content

Commit ce173c1

Browse files
flip1995Manishearth
authored andcommitted
Add deprecated_name argument to the register lint group functions
1 parent 9521dee commit ce173c1

File tree

6 files changed

+43
-19
lines changed

6 files changed

+43
-19
lines changed

src/librustc/lint/context.rs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ pub struct LintStore {
6767
/// Lints indexed by name.
6868
by_name: FxHashMap<String, TargetLint>,
6969

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

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

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

234-
self.register_group(sess, false, "future_incompatible", future_incompatible);
235-
236-
235+
self.register_group(
236+
sess,
237+
false,
238+
"future_incompatible",
239+
None,
240+
future_incompatible,
241+
);
237242
}
238243

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

243-
pub fn register_group(&mut self, sess: Option<&Session>,
244-
from_plugin: bool, name: &'static str,
245-
to: Vec<LintId>) {
246-
let new = self.lint_groups.insert(name, (to, from_plugin)).is_none();
248+
pub fn register_group(
249+
&mut self,
250+
sess: Option<&Session>,
251+
from_plugin: bool,
252+
name: &'static str,
253+
deprecated_name: Option<&'static str>,
254+
to: Vec<LintId>,
255+
) {
256+
let new = self
257+
.lint_groups
258+
.insert(name, (to, from_plugin, None))
259+
.is_none();
260+
if let Some(deprecated) = deprecated_name {
261+
self.lint_groups
262+
.insert(deprecated, (vec![], from_plugin, Some(name)));
263+
}
247264

248265
if !new {
249266
let msg = format!("duplicate specification of lint group {}", name);

src/librustc_driver/driver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -924,8 +924,8 @@ where
924924
ls.register_late_pass(Some(sess), true, pass);
925925
}
926926

927-
for (name, to) in lint_groups {
928-
ls.register_group(Some(sess), true, name, to);
927+
for (name, (to, deprecated_name)) in lint_groups {
928+
ls.register_group(Some(sess), true, name, deprecated_name, to);
929929
}
930930

931931
*sess.plugin_llvm_passes.borrow_mut() = llvm_passes;

src/librustc_lint/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
105105

106106
macro_rules! add_lint_group {
107107
($sess:ident, $name:expr, $($lint:ident),*) => (
108-
store.register_group($sess, false, $name, vec![$(LintId::of($lint)),*]);
108+
store.register_group($sess, false, $name, None, vec![$(LintId::of($lint)),*]);
109109
)
110110
}
111111

src/librustc_plugin/registry.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub struct Registry<'a> {
5353
pub late_lint_passes: Vec<LateLintPassObject>,
5454

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

5858
#[doc(hidden)]
5959
pub llvm_passes: Vec<String>,
@@ -170,8 +170,15 @@ impl<'a> Registry<'a> {
170170
self.late_lint_passes.push(lint_pass);
171171
}
172172
/// Register a lint group.
173-
pub fn register_lint_group(&mut self, name: &'static str, to: Vec<&'static Lint>) {
174-
self.lint_groups.insert(name, to.into_iter().map(|x| LintId::of(x)).collect());
173+
pub fn register_lint_group(
174+
&mut self,
175+
name: &'static str,
176+
deprecated_name: Option<&'static str>,
177+
to: Vec<&'static Lint>
178+
) {
179+
self.lint_groups.insert(name,
180+
(to.into_iter().map(|x| LintId::of(x)).collect(),
181+
deprecated_name));
175182
}
176183

177184
/// Register an LLVM pass.

src/test/ui-fulldeps/auxiliary/lint_group_plugin_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
4949
#[plugin_registrar]
5050
pub fn plugin_registrar(reg: &mut Registry) {
5151
reg.register_late_lint_pass(box Pass);
52-
reg.register_lint_group("lint_me", vec![TEST_LINT, PLEASE_LINT]);
52+
reg.register_lint_group("lint_me", None, vec![TEST_LINT, PLEASE_LINT]);
5353
}

src/tools/clippy

0 commit comments

Comments
 (0)