Skip to content

Commit e8ddfda

Browse files
committed
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)
1 parent 7195355 commit e8ddfda

File tree

6 files changed

+49
-9
lines changed

6 files changed

+49
-9
lines changed

compiler/rustc_lint/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
339339
// FIXME: maybe we could get `register_renamed` to work for tool lints?
340340
store.register_removed(rustdoc_lint, &format!("use `rustdoc::{}` instead", rustdoc_lint));
341341
}
342+
store.register_removed(
343+
"intra_doc_link_resolution_failure",
344+
"use `rustdoc::broken_intra_doc_links` instead",
345+
);
342346

343347
store.register_removed("unknown_features", "replaced by an error");
344348
store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate");

src/librustdoc/lint.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ crate fn register_lints(_sess: &Session, lint_store: &mut LintStore) {
167167
None,
168168
RUSTDOC_LINTS.iter().map(|&lint| LintId::of(lint)).collect(),
169169
);
170+
for lint in &*RUSTDOC_LINTS {
171+
let name = lint.name_lower();
172+
lint_store.register_renamed(&name.replace("rustdoc::", ""), &name);
173+
}
170174
lint_store
171175
.register_renamed("intra_doc_link_resolution_failure", "rustdoc::broken_intra_doc_links");
172176
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
#![deny(rustdoc::x)]
88
//~^ ERROR unknown lint: `rustdoc::x`
99
#![deny(intra_doc_link_resolution_failure)]
10-
//~^ ERROR has been renamed
10+
//~^ ERROR renamed to `rustdoc::broken_intra_doc_links`
1111

12-
// This would ideally say 'renamed to rustdoc::non_autolinks', but this is close enough.
1312
#![deny(non_autolinks)]
14-
//~^ ERROR has been removed: use `rustdoc::non_autolinks` instead [renamed_and_removed_lints]
13+
//~^ ERROR renamed to `rustdoc::non_autolinks`
1514

16-
// This doesn't give you the right code directly, but at least points you on the
17-
// right path.
15+
// Explicitly don't try to handle this case, it was never valid
1816
#![deny(rustdoc::intra_doc_link_resolution_failure)]
1917
//~^ ERROR unknown lint

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ note: the lint level is defined here
2828
LL | #![deny(renamed_and_removed_lints)]
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^
3030

31-
error: lint `non_autolinks` has been removed: use `rustdoc::non_autolinks` instead
32-
--> $DIR/unknown-renamed-lints.rs:13:9
31+
error: lint `non_autolinks` has been renamed to `rustdoc::non_autolinks`
32+
--> $DIR/unknown-renamed-lints.rs:12:9
3333
|
3434
LL | #![deny(non_autolinks)]
35-
| ^^^^^^^^^^^^^
35+
| ^^^^^^^^^^^^^ help: use the new name: `rustdoc::non_autolinks`
3636

3737
error: unknown lint: `rustdoc::intra_doc_link_resolution_failure`
38-
--> $DIR/unknown-renamed-lints.rs:18:9
38+
--> $DIR/unknown-renamed-lints.rs:16:9
3939
|
4040
LL | #![deny(rustdoc::intra_doc_link_resolution_failure)]
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![crate_type = "lib"]
2+
3+
#![deny(unknown_lints)]
4+
#![deny(renamed_and_removed_lints)]
5+
//~^ NOTE lint level is defined
6+
7+
// both allowed, since the compiler doesn't yet know what rustdoc lints are valid
8+
#![deny(rustdoc::x)]
9+
#![deny(rustdoc::intra_doc_link_resolution_failure)]
10+
11+
#![deny(intra_doc_link_resolution_failure)]
12+
//~^ ERROR removed: use `rustdoc::broken_intra_doc_links`
13+
#![deny(non_autolinks)]
14+
//~^ ERROR removed: use `rustdoc::non_autolinks`
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: lint `intra_doc_link_resolution_failure` has been removed: use `rustdoc::broken_intra_doc_links` instead
2+
--> $DIR/rustdoc-renamed.rs:11:9
3+
|
4+
LL | #![deny(intra_doc_link_resolution_failure)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/rustdoc-renamed.rs:4:9
9+
|
10+
LL | #![deny(renamed_and_removed_lints)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
12+
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
20+

0 commit comments

Comments
 (0)