Skip to content

Commit

Permalink
Warn when rustdoc:: group is omitted from lint names
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 committed Jul 3, 2021
1 parent 96859db commit 7a774a8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 32 deletions.
16 changes: 0 additions & 16 deletions compiler/rustc_lint/src/context.rs
Expand Up @@ -276,22 +276,6 @@ 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.
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/lint.rs
Expand Up @@ -193,7 +193,7 @@ crate fn register_lints(_sess: &Session, lint_store: &mut LintStore) {
);
for lint in &*RUSTDOC_LINTS {
let name = lint.name_lower();
lint_store.register_alias(&name.replace("rustdoc::", ""), &name);
lint_store.register_renamed(&name.replace("rustdoc::", ""), &name);
}
lint_store
.register_renamed("intra_doc_link_resolution_failure", "rustdoc::broken_intra_doc_links");
Expand Down
3 changes: 1 addition & 2 deletions src/test/rustdoc-ui/renamed-lint-still-applies.rs
@@ -1,7 +1,6 @@
// compile-args: --crate-type lib
#![deny(broken_intra_doc_links)]
// FIXME: the old names for rustdoc lints should warn by default once `rustdoc::` makes it to the
// stable channel.
//~^ WARNING renamed to `rustdoc::broken_intra_doc_links`
//! [x]
//~^ ERROR unresolved link

Expand Down
21 changes: 13 additions & 8 deletions src/test/rustdoc-ui/renamed-lint-still-applies.stderr
@@ -1,13 +1,19 @@
warning: lint `broken_intra_doc_links` has been renamed to `rustdoc::broken_intra_doc_links`
--> $DIR/renamed-lint-still-applies.rs:2:9
|
LL | #![deny(broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `rustdoc::broken_intra_doc_links`
|
= note: `#[warn(renamed_and_removed_lints)]` on by default

warning: lint `rustdoc::non_autolinks` has been renamed to `rustdoc::bare_urls`
--> $DIR/renamed-lint-still-applies.rs:8:9
--> $DIR/renamed-lint-still-applies.rs:7:9
|
LL | #![deny(rustdoc::non_autolinks)]
| ^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `rustdoc::bare_urls`
|
= note: `#[warn(renamed_and_removed_lints)]` on by default

error: unresolved link to `x`
--> $DIR/renamed-lint-still-applies.rs:5:6
--> $DIR/renamed-lint-still-applies.rs:4:6
|
LL | //! [x]
| ^ no item named `x` in scope
Expand All @@ -17,21 +23,20 @@ note: the lint level is defined here
|
LL | #![deny(broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^
= note: `#[deny(rustdoc::broken_intra_doc_links)]` implied by `#[deny(broken_intra_doc_links)]`
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`

error: this URL is not a hyperlink
--> $DIR/renamed-lint-still-applies.rs:10:5
--> $DIR/renamed-lint-still-applies.rs:9:5
|
LL | //! http://example.com
| ^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://example.com>`
|
note: the lint level is defined here
--> $DIR/renamed-lint-still-applies.rs:8:9
--> $DIR/renamed-lint-still-applies.rs:7:9
|
LL | #![deny(rustdoc::non_autolinks)]
| ^^^^^^^^^^^^^^^^^^^^^^
= note: bare URLs are not automatically turned into clickable links

error: aborting due to 2 previous errors; 1 warning emitted
error: aborting due to 2 previous errors; 2 warnings emitted

3 changes: 1 addition & 2 deletions src/test/rustdoc-ui/unknown-renamed-lints.rs
Expand Up @@ -14,8 +14,7 @@
//~^ ERROR renamed to `rustdoc::bare_urls`

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

#![deny(rustdoc)]
//~^ ERROR removed: use `rustdoc::all` instead
Expand Down
12 changes: 9 additions & 3 deletions src/test/rustdoc-ui/unknown-renamed-lints.stderr
Expand Up @@ -40,19 +40,25 @@ error: lint `rustdoc::non_autolinks` has been renamed to `rustdoc::bare_urls`
LL | #![deny(rustdoc::non_autolinks)]
| ^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `rustdoc::bare_urls`

error: lint `private_doc_tests` has been renamed to `rustdoc::private_doc_tests`
--> $DIR/unknown-renamed-lints.rs:16:9
|
LL | #![deny(private_doc_tests)]
| ^^^^^^^^^^^^^^^^^ help: use the new name: `rustdoc::private_doc_tests`

error: lint `rustdoc` has been removed: use `rustdoc::all` instead
--> $DIR/unknown-renamed-lints.rs:20:9
--> $DIR/unknown-renamed-lints.rs:19:9
|
LL | #![deny(rustdoc)]
| ^^^^^^^

error: unknown lint: `rustdoc::intra_doc_link_resolution_failure`
--> $DIR/unknown-renamed-lints.rs:24:9
--> $DIR/unknown-renamed-lints.rs:23:9
|
LL | #![deny(rustdoc::intra_doc_link_resolution_failure)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: Compilation failed, aborting rustdoc

error: aborting due to 8 previous errors
error: aborting due to 9 previous errors

0 comments on commit 7a774a8

Please sign in to comment.