Skip to content

Commit 42e6d42

Browse files
authored
Rollup merge of #83203 - jyn514:rustdoc-warnings, r=Manishearth
Don't warn about old rustdoc lint names (temporarily) Since #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 (#66079 (comment)). 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`
2 parents b7863f9 + c1b99f0 commit 42e6d42

9 files changed

+49
-31
lines changed

compiler/rustc_lint/src/context.rs

+34
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ enum TargetLint {
100100
/// Lint with this name existed previously, but has been removed/deprecated.
101101
/// The string argument is the reason for removal.
102102
Removed(String),
103+
104+
/// A lint name that should give no warnings and have no effect.
105+
///
106+
/// This is used by rustc to avoid warning about old rustdoc lints before rustdoc registers them as tool lints.
107+
Ignored,
103108
}
104109

105110
pub enum FindLintError {
@@ -266,6 +271,33 @@ impl LintStore {
266271
}
267272
}
268273

274+
/// This lint should be available with either the old or the new name.
275+
///
276+
/// Using the old name will not give a warning.
277+
/// You must register a lint with the new name before calling this function.
278+
#[track_caller]
279+
pub fn register_alias(&mut self, old_name: &str, new_name: &str) {
280+
let target = match self.by_name.get(new_name) {
281+
Some(&Id(lint_id)) => lint_id,
282+
_ => bug!("cannot add alias {} for lint {} that does not exist", old_name, new_name),
283+
};
284+
match self.by_name.insert(old_name.to_string(), Id(target)) {
285+
None | Some(Ignored) => {}
286+
Some(x) => bug!("duplicate specification of lint {} (was {:?})", old_name, x),
287+
}
288+
}
289+
290+
/// This lint should give no warning and have no effect.
291+
///
292+
/// This is used by rustc to avoid warning about old rustdoc lints before rustdoc registers them as tool lints.
293+
#[track_caller]
294+
pub fn register_ignored(&mut self, name: &str) {
295+
if self.by_name.insert(name.to_string(), Ignored).is_some() {
296+
bug!("duplicate specification of lint {}", name);
297+
}
298+
}
299+
300+
/// This lint has been renamed; warn about using the new name and apply the lint.
269301
#[track_caller]
270302
pub fn register_renamed(&mut self, old_name: &str, new_name: &str) {
271303
let target = match self.by_name.get(new_name) {
@@ -284,6 +316,7 @@ impl LintStore {
284316
Some(&Id(lint_id)) => Ok(vec![lint_id]),
285317
Some(&Renamed(_, lint_id)) => Ok(vec![lint_id]),
286318
Some(&Removed(_)) => Err(FindLintError::Removed),
319+
Some(&Ignored) => Ok(vec![]),
287320
None => loop {
288321
return match self.lint_groups.get(lint_name) {
289322
Some(LintGroup { lint_ids, depr, .. }) => {
@@ -427,6 +460,7 @@ impl LintStore {
427460
}
428461
},
429462
Some(&Id(ref id)) => CheckLintNameResult::Ok(slice::from_ref(id)),
463+
Some(&Ignored) => CheckLintNameResult::Ok(&[]),
430464
}
431465
}
432466

compiler/rustc_lint/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
340340
"non_autolinks",
341341
];
342342
for rustdoc_lint in RUSTDOC_LINTS {
343-
store.register_removed(rustdoc_lint, &format!("use `rustdoc::{}` instead", rustdoc_lint));
343+
store.register_ignored(rustdoc_lint);
344344
}
345345
store.register_removed(
346346
"intra_doc_link_resolution_failure",

src/librustdoc/lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ crate fn register_lints(_sess: &Session, lint_store: &mut LintStore) {
181181
);
182182
for lint in &*RUSTDOC_LINTS {
183183
let name = lint.name_lower();
184-
lint_store.register_renamed(&name.replace("rustdoc::", ""), &name);
184+
lint_store.register_alias(&name.replace("rustdoc::", ""), &name);
185185
}
186186
lint_store
187187
.register_renamed("intra_doc_link_resolution_failure", "rustdoc::broken_intra_doc_links");
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// compile-args: --crate-type lib
22
#![deny(broken_intra_doc_links)]
3-
//~^ WARNING renamed
3+
// FIXME: the old names for rustdoc lints should warn by default once `rustdoc::` makes it to the
4+
// stable channel.
45
//! [x]
56
//~^ ERROR unresolved link
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
warning: lint `broken_intra_doc_links` has been renamed to `rustdoc::broken_intra_doc_links`
2-
--> $DIR/renamed-lint-still-applies.rs:2:9
3-
|
4-
LL | #![deny(broken_intra_doc_links)]
5-
| ^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `rustdoc::broken_intra_doc_links`
6-
|
7-
= note: `#[warn(renamed_and_removed_lints)]` on by default
8-
91
error: unresolved link to `x`
10-
--> $DIR/renamed-lint-still-applies.rs:4:6
2+
--> $DIR/renamed-lint-still-applies.rs:5:6
113
|
124
LL | //! [x]
135
| ^ no item named `x` in scope
@@ -17,7 +9,8 @@ note: the lint level is defined here
179
|
1810
LL | #![deny(broken_intra_doc_links)]
1911
| ^^^^^^^^^^^^^^^^^^^^^^
12+
= note: `#[deny(rustdoc::broken_intra_doc_links)]` implied by `#[deny(broken_intra_doc_links)]`
2013
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
2114

22-
error: aborting due to previous error; 1 warning emitted
15+
error: aborting due to previous error
2316

src/test/rustdoc-ui/unknown-renamed-lints.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
//~^ ERROR renamed to `rustdoc::broken_intra_doc_links`
1111

1212
#![deny(non_autolinks)]
13-
//~^ ERROR renamed to `rustdoc::non_autolinks`
13+
// FIXME: the old names for rustdoc lints should warn by default once `rustdoc::` makes it to the
14+
// stable channel.
1415

1516
#![deny(rustdoc)]
1617
//~^ ERROR removed: use `rustdoc::all` instead

src/test/rustdoc-ui/unknown-renamed-lints.stderr

+3-9
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,19 @@ note: the lint level is defined here
2828
LL | #![deny(renamed_and_removed_lints)]
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^
3030

31-
error: lint `non_autolinks` has been renamed to `rustdoc::non_autolinks`
32-
--> $DIR/unknown-renamed-lints.rs:12:9
33-
|
34-
LL | #![deny(non_autolinks)]
35-
| ^^^^^^^^^^^^^ help: use the new name: `rustdoc::non_autolinks`
36-
3731
error: lint `rustdoc` has been removed: use `rustdoc::all` instead
38-
--> $DIR/unknown-renamed-lints.rs:15:9
32+
--> $DIR/unknown-renamed-lints.rs:16:9
3933
|
4034
LL | #![deny(rustdoc)]
4135
| ^^^^^^^
4236

4337
error: unknown lint: `rustdoc::intra_doc_link_resolution_failure`
44-
--> $DIR/unknown-renamed-lints.rs:19:9
38+
--> $DIR/unknown-renamed-lints.rs:20:9
4539
|
4640
LL | #![deny(rustdoc::intra_doc_link_resolution_failure)]
4741
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4842

4943
error: Compilation failed, aborting rustdoc
5044

51-
error: aborting due to 7 previous errors
45+
error: aborting due to 6 previous errors
5246

src/test/ui/lint/rustdoc-renamed.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
#![deny(intra_doc_link_resolution_failure)]
1212
//~^ ERROR removed: use `rustdoc::broken_intra_doc_links`
1313
#![deny(non_autolinks)]
14-
//~^ ERROR removed: use `rustdoc::non_autolinks`
14+
// FIXME: the old names for rustdoc lints should warn by default once `rustdoc::` makes it to the
15+
// stable channel.

src/test/ui/lint/rustdoc-renamed.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,5 @@ note: the lint level is defined here
1010
LL | #![deny(renamed_and_removed_lints)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13-
error: lint `non_autolinks` has been removed: use `rustdoc::non_autolinks` instead
14-
--> $DIR/rustdoc-renamed.rs:13:9
15-
|
16-
LL | #![deny(non_autolinks)]
17-
| ^^^^^^^^^^^^^
18-
19-
error: aborting due to 2 previous errors
13+
error: aborting due to previous error
2014

0 commit comments

Comments
 (0)