Rollup merge of #83203 - jyn514:rustdoc-warnings, r=Manishearth
Don't warn about old rustdoc lint names (temporarily) Since https://github.com/rust-lang/rust/pull/80527, rustdoc users have an unpleasant situation: they can either use the new tool lint names (`rustdoc::non_autolinks`) or they can use the old names (`non_autolinks`). If they use the tool lints, they get a hard error on stable compilers, because rustc rejects all tool names it doesn't recognize (https://github.com/rust-lang/rust/issues/66079#issuecomment-788589193). If they use the old name, they get a warning to rename the lint to the new name. The only way to compile without warnings is to add `#[allow(renamed_removed_lints)]`, which defeats the whole point of the change: we *want* people to switch to the new name. To avoid people silencing the lint and never migrating to the tool lint, this avoids warning about the old name, while still allowing you to use the new name. Once the new `rustdoc` tool name makes it to the stable channel, we can change these lints to warn again. This adds the new lint functions `register_alias` and `register_ignored` - I didn't see an existing way to do this. r? `@Manishearth` cc `@rust-lang/rustdoc`
This commit is contained in:
commit
42e6d429c6
9 changed files with 49 additions and 31 deletions
|
@ -100,6 +100,11 @@ enum TargetLint {
|
|||
/// Lint with this name existed previously, but has been removed/deprecated.
|
||||
/// The string argument is the reason for removal.
|
||||
Removed(String),
|
||||
|
||||
/// A lint name that should give no warnings and have no effect.
|
||||
///
|
||||
/// This is used by rustc to avoid warning about old rustdoc lints before rustdoc registers them as tool lints.
|
||||
Ignored,
|
||||
}
|
||||
|
||||
pub enum FindLintError {
|
||||
|
@ -266,6 +271,33 @@ impl LintStore {
|
|||
}
|
||||
}
|
||||
|
||||
/// This lint should be available with either the old or the new name.
|
||||
///
|
||||
/// Using the old name will not give a warning.
|
||||
/// You must register a lint with the new name before calling this function.
|
||||
#[track_caller]
|
||||
pub fn register_alias(&mut self, old_name: &str, new_name: &str) {
|
||||
let target = match self.by_name.get(new_name) {
|
||||
Some(&Id(lint_id)) => lint_id,
|
||||
_ => bug!("cannot add alias {} for lint {} that does not exist", old_name, new_name),
|
||||
};
|
||||
match self.by_name.insert(old_name.to_string(), Id(target)) {
|
||||
None | Some(Ignored) => {}
|
||||
Some(x) => bug!("duplicate specification of lint {} (was {:?})", old_name, x),
|
||||
}
|
||||
}
|
||||
|
||||
/// This lint should give no warning and have no effect.
|
||||
///
|
||||
/// This is used by rustc to avoid warning about old rustdoc lints before rustdoc registers them as tool lints.
|
||||
#[track_caller]
|
||||
pub fn register_ignored(&mut self, name: &str) {
|
||||
if self.by_name.insert(name.to_string(), Ignored).is_some() {
|
||||
bug!("duplicate specification of lint {}", name);
|
||||
}
|
||||
}
|
||||
|
||||
/// This lint has been renamed; warn about using the new name and apply the lint.
|
||||
#[track_caller]
|
||||
pub fn register_renamed(&mut self, old_name: &str, new_name: &str) {
|
||||
let target = match self.by_name.get(new_name) {
|
||||
|
@ -284,6 +316,7 @@ impl LintStore {
|
|||
Some(&Id(lint_id)) => Ok(vec![lint_id]),
|
||||
Some(&Renamed(_, lint_id)) => Ok(vec![lint_id]),
|
||||
Some(&Removed(_)) => Err(FindLintError::Removed),
|
||||
Some(&Ignored) => Ok(vec![]),
|
||||
None => loop {
|
||||
return match self.lint_groups.get(lint_name) {
|
||||
Some(LintGroup { lint_ids, depr, .. }) => {
|
||||
|
@ -427,6 +460,7 @@ impl LintStore {
|
|||
}
|
||||
},
|
||||
Some(&Id(ref id)) => CheckLintNameResult::Ok(slice::from_ref(id)),
|
||||
Some(&Ignored) => CheckLintNameResult::Ok(&[]),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -340,7 +340,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
|
|||
"non_autolinks",
|
||||
];
|
||||
for rustdoc_lint in RUSTDOC_LINTS {
|
||||
store.register_removed(rustdoc_lint, &format!("use `rustdoc::{}` instead", rustdoc_lint));
|
||||
store.register_ignored(rustdoc_lint);
|
||||
}
|
||||
store.register_removed(
|
||||
"intra_doc_link_resolution_failure",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue