From e8ddfda8138d9c282eee16cfae892ed232d8b422 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 17 Jan 2021 18:52:19 -0500 Subject: [PATCH] Improve error messages - Use `register_renamed` when rustdoc is running so the lint will still be active and use a structured suggestion - Test the behavior for rustc, not just for rustdoc (because it differs) --- compiler/rustc_lint/src/lib.rs | 4 ++++ src/librustdoc/lint.rs | 4 ++++ src/test/rustdoc-ui/unknown-renamed-lints.rs | 8 +++----- .../rustdoc-ui/unknown-renamed-lints.stderr | 8 ++++---- src/test/ui/lint/rustdoc-renamed.rs | 14 +++++++++++++ src/test/ui/lint/rustdoc-renamed.stderr | 20 +++++++++++++++++++ 6 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 src/test/ui/lint/rustdoc-renamed.rs create mode 100644 src/test/ui/lint/rustdoc-renamed.stderr diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 67c0e999f55..86ad73d482f 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -339,6 +339,10 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) { // FIXME: maybe we could get `register_renamed` to work for tool lints? store.register_removed(rustdoc_lint, &format!("use `rustdoc::{}` instead", rustdoc_lint)); } + store.register_removed( + "intra_doc_link_resolution_failure", + "use `rustdoc::broken_intra_doc_links` instead", + ); store.register_removed("unknown_features", "replaced by an error"); store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate"); diff --git a/src/librustdoc/lint.rs b/src/librustdoc/lint.rs index 013b7ead5c7..7d95561d039 100644 --- a/src/librustdoc/lint.rs +++ b/src/librustdoc/lint.rs @@ -167,6 +167,10 @@ crate fn register_lints(_sess: &Session, lint_store: &mut LintStore) { None, RUSTDOC_LINTS.iter().map(|&lint| LintId::of(lint)).collect(), ); + for lint in &*RUSTDOC_LINTS { + let name = lint.name_lower(); + lint_store.register_renamed(&name.replace("rustdoc::", ""), &name); + } lint_store .register_renamed("intra_doc_link_resolution_failure", "rustdoc::broken_intra_doc_links"); } diff --git a/src/test/rustdoc-ui/unknown-renamed-lints.rs b/src/test/rustdoc-ui/unknown-renamed-lints.rs index e2238a4004c..d2c78bc4774 100644 --- a/src/test/rustdoc-ui/unknown-renamed-lints.rs +++ b/src/test/rustdoc-ui/unknown-renamed-lints.rs @@ -7,13 +7,11 @@ #![deny(rustdoc::x)] //~^ ERROR unknown lint: `rustdoc::x` #![deny(intra_doc_link_resolution_failure)] -//~^ ERROR has been renamed +//~^ ERROR renamed to `rustdoc::broken_intra_doc_links` -// This would ideally say 'renamed to rustdoc::non_autolinks', but this is close enough. #![deny(non_autolinks)] -//~^ ERROR has been removed: use `rustdoc::non_autolinks` instead [renamed_and_removed_lints] +//~^ ERROR renamed to `rustdoc::non_autolinks` -// This doesn't give you the right code directly, but at least points you on the -// right path. +// Explicitly don't try to handle this case, it was never valid #![deny(rustdoc::intra_doc_link_resolution_failure)] //~^ ERROR unknown lint diff --git a/src/test/rustdoc-ui/unknown-renamed-lints.stderr b/src/test/rustdoc-ui/unknown-renamed-lints.stderr index 1a45f68ae81..0f31673fb47 100644 --- a/src/test/rustdoc-ui/unknown-renamed-lints.stderr +++ b/src/test/rustdoc-ui/unknown-renamed-lints.stderr @@ -28,14 +28,14 @@ note: the lint level is defined here LL | #![deny(renamed_and_removed_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `non_autolinks` has been removed: use `rustdoc::non_autolinks` instead - --> $DIR/unknown-renamed-lints.rs:13:9 +error: lint `non_autolinks` has been renamed to `rustdoc::non_autolinks` + --> $DIR/unknown-renamed-lints.rs:12:9 | LL | #![deny(non_autolinks)] - | ^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ help: use the new name: `rustdoc::non_autolinks` error: unknown lint: `rustdoc::intra_doc_link_resolution_failure` - --> $DIR/unknown-renamed-lints.rs:18:9 + --> $DIR/unknown-renamed-lints.rs:16:9 | LL | #![deny(rustdoc::intra_doc_link_resolution_failure)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/lint/rustdoc-renamed.rs b/src/test/ui/lint/rustdoc-renamed.rs new file mode 100644 index 00000000000..71e88bd7f54 --- /dev/null +++ b/src/test/ui/lint/rustdoc-renamed.rs @@ -0,0 +1,14 @@ +#![crate_type = "lib"] + +#![deny(unknown_lints)] +#![deny(renamed_and_removed_lints)] +//~^ NOTE lint level is defined + +// both allowed, since the compiler doesn't yet know what rustdoc lints are valid +#![deny(rustdoc::x)] +#![deny(rustdoc::intra_doc_link_resolution_failure)] + +#![deny(intra_doc_link_resolution_failure)] +//~^ ERROR removed: use `rustdoc::broken_intra_doc_links` +#![deny(non_autolinks)] +//~^ ERROR removed: use `rustdoc::non_autolinks` diff --git a/src/test/ui/lint/rustdoc-renamed.stderr b/src/test/ui/lint/rustdoc-renamed.stderr new file mode 100644 index 00000000000..a7fe3e29d5b --- /dev/null +++ b/src/test/ui/lint/rustdoc-renamed.stderr @@ -0,0 +1,20 @@ +error: lint `intra_doc_link_resolution_failure` has been removed: use `rustdoc::broken_intra_doc_links` instead + --> $DIR/rustdoc-renamed.rs:11:9 + | +LL | #![deny(intra_doc_link_resolution_failure)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/rustdoc-renamed.rs:4:9 + | +LL | #![deny(renamed_and_removed_lints)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: lint `non_autolinks` has been removed: use `rustdoc::non_autolinks` instead + --> $DIR/rustdoc-renamed.rs:13:9 + | +LL | #![deny(non_autolinks)] + | ^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors +