Skip to content

Commit 5384f0f

Browse files
committed
Make bad_style a silent alias for nonstandard_style
Now only `nonstandard_style` is suggested in `rustc -W help`, but `bad_style` will not produce a warning.
1 parent 90d36fb commit 5384f0f

File tree

2 files changed

+43
-30
lines changed

2 files changed

+43
-30
lines changed

src/librustc/lint/context.rs

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ pub struct LintStore {
6969

7070
/// Map of registered lint groups to what lints they expand to. The first
7171
/// 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>)>,
72+
/// is used to store the new names of deprecated lint group names and is paired
73+
/// with `true` if the deprecation is silent.
74+
lint_groups: FxHashMap<&'static str, (Vec<LintId>, bool, Option<(&'static str, bool)>)>,
7475

7576
/// Extra info for future incompatibility lints, describing the
7677
/// issue or RFC that caused the incompatibility.
@@ -160,9 +161,9 @@ impl LintStore {
160161
}
161162

162163
pub fn get_lint_groups<'t>(&'t self) -> Vec<(&'static str, Vec<LintId>, bool)> {
163-
self.lint_groups.iter().map(|(k, v)| (*k,
164-
v.0.clone(),
165-
v.1)).collect()
164+
self.lint_groups.iter()
165+
.filter(|(_, (_, _, d))| d.is_none()) // Don't display deprecated lint groups.
166+
.map(|(k, v)| (*k, v.0.clone(), v.1)).collect()
166167
}
167168

168169
pub fn register_early_pass(&mut self,
@@ -245,6 +246,14 @@ impl LintStore {
245246
self.future_incompatible.get(&id)
246247
}
247248

249+
pub fn register_group_alias(
250+
&mut self,
251+
lint_name: &'static str,
252+
alias: &'static str,
253+
) {
254+
self.lint_groups.insert(alias, (vec![], false, Some((lint_name, true))));
255+
}
256+
248257
pub fn register_group(
249258
&mut self,
250259
sess: Option<&Session>,
@@ -259,7 +268,7 @@ impl LintStore {
259268
.is_none();
260269
if let Some(deprecated) = deprecated_name {
261270
self.lint_groups
262-
.insert(deprecated, (vec![], from_plugin, Some(name)));
271+
.insert(deprecated, (vec![], from_plugin, Some((name, false))));
263272
}
264273

265274
if !new {
@@ -392,12 +401,16 @@ impl LintStore {
392401
None => self.check_tool_name_for_backwards_compat(&complete_name, "clippy"),
393402
Some(ids) => {
394403
// Check if the lint group name is deprecated
395-
if let Some(new_name) = ids.2 {
404+
if let Some((new_name, silent)) = ids.2 {
396405
let lint_ids = self.lint_groups.get(new_name).unwrap();
397-
return CheckLintNameResult::Tool(Err((
398-
Some(&lint_ids.0),
399-
new_name.to_string(),
400-
)));
406+
return if silent {
407+
CheckLintNameResult::Ok(&lint_ids.0)
408+
} else {
409+
CheckLintNameResult::Tool(Err((
410+
Some(&lint_ids.0),
411+
new_name.to_string(),
412+
)))
413+
};
401414
}
402415
CheckLintNameResult::Ok(&ids.0)
403416
}
@@ -417,13 +430,17 @@ impl LintStore {
417430
// Now we are sure, that this lint exists nowhere
418431
None => CheckLintNameResult::NoLint,
419432
Some(ids) => {
420-
// Reaching this would be weird, but lets cover this case anyway
421-
if let Some(new_name) = ids.2 {
433+
// Reaching this would be weird, but let's cover this case anyway
434+
if let Some((new_name, silent)) = ids.2 {
422435
let lint_ids = self.lint_groups.get(new_name).unwrap();
423-
return CheckLintNameResult::Tool(Err((
424-
Some(&lint_ids.0),
425-
new_name.to_string(),
426-
)));
436+
return if silent {
437+
CheckLintNameResult::Tool(Err((Some(&lint_ids.0), complete_name)))
438+
} else {
439+
CheckLintNameResult::Tool(Err((
440+
Some(&lint_ids.0),
441+
new_name.to_string(),
442+
)))
443+
};
427444
}
428445
CheckLintNameResult::Tool(Err((Some(&ids.0), complete_name)))
429446
}

src/librustc_lint/lib.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,30 +82,30 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
8282
($sess:ident, $($name:ident),*,) => (
8383
{$(
8484
store.register_early_pass($sess, false, box $name);
85-
)*}
86-
)
85+
)*}
86+
)
8787
}
8888

8989
macro_rules! add_pre_expansion_builtin {
9090
($sess:ident, $($name:ident),*,) => (
9191
{$(
9292
store.register_pre_expansion_pass($sess, box $name);
93-
)*}
94-
)
93+
)*}
94+
)
9595
}
9696

9797
macro_rules! add_early_builtin_with_new {
9898
($sess:ident, $($name:ident),*,) => (
9999
{$(
100100
store.register_early_pass($sess, false, box $name::new());
101-
)*}
102-
)
101+
)*}
102+
)
103103
}
104104

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

111111
add_pre_expansion_builtin!(sess,
@@ -159,12 +159,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
159159

160160
store.register_late_pass(sess, false, box BuiltinCombinedLateLintPass::new());
161161

162-
add_lint_group!(sess,
163-
"bad_style",
164-
NON_CAMEL_CASE_TYPES,
165-
NON_SNAKE_CASE,
166-
NON_UPPER_CASE_GLOBALS);
167-
168162
add_lint_group!(sess,
169163
"nonstandard_style",
170164
NON_CAMEL_CASE_TYPES,
@@ -353,6 +347,8 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
353347
store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate");
354348
store.register_removed("negate_unsigned", "cast a signed value instead");
355349
store.register_removed("raw_pointer_derive", "using derive with raw pointers is ok");
350+
// Register lint group aliases
351+
store.register_group_alias("nonstandard_style", "bad_style");
356352
// This was renamed to raw_pointer_derive, which was then removed,
357353
// so it is also considered removed
358354
store.register_removed("raw_pointer_deriving", "using derive with raw pointers is ok");

0 commit comments

Comments
 (0)