]> git.lizzy.rs Git - rust.git/commitdiff
Improve error messages
authorJoshua Nelson <jyn514@gmail.com>
Sun, 17 Jan 2021 23:52:19 +0000 (18:52 -0500)
committerJoshua Nelson <jyn514@gmail.com>
Tue, 2 Mar 2021 00:29:15 +0000 (19:29 -0500)
- 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
src/librustdoc/lint.rs
src/test/rustdoc-ui/unknown-renamed-lints.rs
src/test/rustdoc-ui/unknown-renamed-lints.stderr
src/test/ui/lint/rustdoc-renamed.rs [new file with mode: 0644]
src/test/ui/lint/rustdoc-renamed.stderr [new file with mode: 0644]

index 67c0e999f55183ce3faceebd912dfe26f1a527ed..86ad73d482f24e6b01440d333a7e7155800efe87 100644 (file)
@@ -339,6 +339,10 @@ macro_rules! register_passes {
         // 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");
index 013b7ead5c7c98e3aec1694ce5abe18981c1581a..7d95561d039f92916447794544a637a8f8336c87 100644 (file)
@@ -167,6 +167,10 @@ macro_rules! declare_rustdoc_lint {
         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");
 }
index e2238a4004c1b93a8f38bf802162136d23b9b206..d2c78bc477410489814fa631bab847f78a8362e3 100644 (file)
@@ -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
index 1a45f68ae810f39a404f78c69ca6d519b1ec8878..0f31673fb47f27512e0dac0eab2de3b54c81ee55 100644 (file)
@@ -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 (file)
index 0000000..71e88bd
--- /dev/null
@@ -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 (file)
index 0000000..a7fe3e2
--- /dev/null
@@ -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
+