Skip to content

Commit 179e3ad

Browse files
Auto merge of #132748 - lolbinarycat:rustdoc-intra-doc-link-warn-more-54191, r=<try>
get rid of some false negatives in rustdoc::broken_intra_doc_links try-job: dist-x86_64-linux-alt
2 parents adcb3d3 + a73d7e3 commit 179e3ad

File tree

11 files changed

+295
-26
lines changed

11 files changed

+295
-26
lines changed

compiler/rustc_mir_transform/src/elaborate_drop.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ where
611611
///
612612
/// For example, with 3 fields, the drop ladder is
613613
///
614+
/// ```text
614615
/// .d0:
615616
/// ELAB(drop ___location.0 [target=.d1, unwind=.c1])
616617
/// .d1:
@@ -621,8 +622,10 @@ where
621622
/// ELAB(drop ___location.1 [target=.c2])
622623
/// .c2:
623624
/// ELAB(drop ___location.2 [target=`self.unwind`])
625+
/// ```
624626
///
625627
/// For possible-async drops in coroutines we also need dropline ladder
628+
/// ```text
626629
/// .d0 (mainline):
627630
/// ELAB(drop ___location.0 [target=.d1, unwind=.c1, drop=.e1])
628631
/// .d1 (mainline):
@@ -637,6 +640,7 @@ where
637640
/// ELAB(drop ___location.1 [target=.e2, unwind=.c2])
638641
/// .e2 (dropline):
639642
/// ELAB(drop ___location.2 [target=`self.drop`, unwind=`self.unwind`])
643+
/// ```
640644
///
641645
/// NOTE: this does not clear the master drop flag, so you need
642646
/// to point succ/unwind on a `drop_ladder_bottom`.

compiler/rustc_thread_pool/src/sleep/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl SleepData {
4444
/// jobs are published, and it either blocks threads or wakes them in response to these
4545
/// events. See the [`README.md`] in this module for more details.
4646
///
47-
/// [`README.md`] README.md
47+
/// [`README.md`]: README.md
4848
pub(super) struct Sleep {
4949
/// One "sleep state" per worker. Used to track if a worker is sleeping and to have
5050
/// them block.

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -941,13 +941,21 @@ fn preprocess_link(
941941
ori_link: &MarkdownLink,
942942
dox: &str,
943943
) -> Option<Result<PreprocessingInfo, PreprocessingError>> {
944+
// certain link kinds cannot have their path be urls,
945+
// so they should not be ignored, no matter how much they look like urls.
946+
// e.g. [https://example.com/] is not a link to example.com.
947+
let can_be_url = !matches!(
948+
ori_link.kind,
949+
LinkType::ShortcutUnknown | LinkType::CollapsedUnknown | LinkType::ReferenceUnknown
950+
);
951+
944952
// [] is mostly likely not supposed to be a link
945953
if ori_link.link.is_empty() {
946954
return None;
947955
}
948956

949957
// Bail early for real links.
950-
if ori_link.link.contains('/') {
958+
if can_be_url && ori_link.link.contains('/') {
951959
return None;
952960
}
953961

@@ -972,7 +980,7 @@ fn preprocess_link(
972980
Ok(None) => (None, link, link),
973981
Err((err_msg, relative_range)) => {
974982
// Only report error if we would not have ignored this link. See issue #83859.
975-
if !should_ignore_link_with_disambiguators(link) {
983+
if !(can_be_url && should_ignore_link_with_disambiguators(link)) {
976984
let disambiguator_range = match range_between_backticks(&ori_link.range, dox) {
977985
MarkdownLinkRange::Destination(no_backticks_range) => {
978986
MarkdownLinkRange::Destination(
@@ -989,7 +997,25 @@ fn preprocess_link(
989997
}
990998
};
991999

992-
if should_ignore_link(path_str) {
1000+
// If there's no backticks, be lenient and revert to the old behavior.
1001+
// This is to prevent churn by linting on stuff that isn't meant to be a link.
1002+
// only shortcut links have simple enough syntax that they
1003+
// are likely to be written accidentally, collapsed and reference links
1004+
// need 4 metachars, and reference links will not usually use
1005+
// backticks in the reference name.
1006+
// therefore, only shortcut syntax gets the lenient behavior.
1007+
//
1008+
// here's a truth table for how link kinds that cannot be urls are handled:
1009+
//
1010+
// |-------------------------------------------------------|
1011+
// | | is shortcut link | not shortcut link |
1012+
// |--------------|--------------------|-------------------|
1013+
// | has backtick | never ignore | never ignore |
1014+
// | no backtick | ignore if url-like | never ignore |
1015+
// |-------------------------------------------------------|
1016+
let ignore_urllike =
1017+
can_be_url || (ori_link.kind == LinkType::ShortcutUnknown && !ori_link.link.contains('`'));
1018+
if ignore_urllike && should_ignore_link(path_str) {
9931019
return None;
9941020
}
9951021

tests/rustdoc-ui/disambiguator-endswith-named-suffix.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,67 @@
22
//@ normalize-stderr: "nightly|beta|1\.[0-9][0-9]\.[0-9]" -> "$$CHANNEL"
33

44
//! [struct@m!()] //~ WARN: unmatched disambiguator `struct` and suffix `!()`
5-
//! [struct@m!{}]
5+
//! [struct@m!{}] //~ WARN: unmatched disambiguator `struct` and suffix `!{}`
66
//! [struct@m![]]
77
//! [struct@f()] //~ WARN: unmatched disambiguator `struct` and suffix `()`
88
//! [struct@m!] //~ WARN: unmatched disambiguator `struct` and suffix `!`
99
//!
1010
//! [enum@m!()] //~ WARN: unmatched disambiguator `enum` and suffix `!()`
11-
//! [enum@m!{}]
11+
//! [enum@m!{}] //~ WARN: unmatched disambiguator `enum` and suffix `!{}`
1212
//! [enum@m![]]
1313
//! [enum@f()] //~ WARN: unmatched disambiguator `enum` and suffix `()`
1414
//! [enum@m!] //~ WARN: unmatched disambiguator `enum` and suffix `!`
1515
//!
1616
//! [trait@m!()] //~ WARN: unmatched disambiguator `trait` and suffix `!()`
17-
//! [trait@m!{}]
17+
//! [trait@m!{}] //~ WARN: unmatched disambiguator `trait` and suffix `!{}`
1818
//! [trait@m![]]
1919
//! [trait@f()] //~ WARN: unmatched disambiguator `trait` and suffix `()`
2020
//! [trait@m!] //~ WARN: unmatched disambiguator `trait` and suffix `!`
2121
//!
2222
//! [module@m!()] //~ WARN: unmatched disambiguator `module` and suffix `!()`
23-
//! [module@m!{}]
23+
//! [module@m!{}] //~ WARN: unmatched disambiguator `module` and suffix `!{}`
2424
//! [module@m![]]
2525
//! [module@f()] //~ WARN: unmatched disambiguator `module` and suffix `()`
2626
//! [module@m!] //~ WARN: unmatched disambiguator `module` and suffix `!`
2727
//!
2828
//! [mod@m!()] //~ WARN: unmatched disambiguator `mod` and suffix `!()`
29-
//! [mod@m!{}]
29+
//! [mod@m!{}] //~ WARN: unmatched disambiguator `mod` and suffix `!{}`
3030
//! [mod@m![]]
3131
//! [mod@f()] //~ WARN: unmatched disambiguator `mod` and suffix `()`
3232
//! [mod@m!] //~ WARN: unmatched disambiguator `mod` and suffix `!`
3333
//!
3434
//! [const@m!()] //~ WARN: unmatched disambiguator `const` and suffix `!()`
35-
//! [const@m!{}]
35+
//! [const@m!{}] //~ WARN: unmatched disambiguator `const` and suffix `!{}`
3636
//! [const@m![]]
3737
//! [const@f()] //~ WARN: incompatible link kind for `f`
3838
//! [const@m!] //~ WARN: unmatched disambiguator `const` and suffix `!`
3939
//!
4040
//! [constant@m!()] //~ WARN: unmatched disambiguator `constant` and suffix `!()`
41-
//! [constant@m!{}]
41+
//! [constant@m!{}] //~ WARN: unmatched disambiguator `constant` and suffix `!{}`
4242
//! [constant@m![]]
4343
//! [constant@f()] //~ WARN: incompatible link kind for `f`
4444
//! [constant@m!] //~ WARN: unmatched disambiguator `constant` and suffix `!`
4545
//!
4646
//! [static@m!()] //~ WARN: unmatched disambiguator `static` and suffix `!()`
47-
//! [static@m!{}]
47+
//! [static@m!{}] //~ WARN: unmatched disambiguator `static` and suffix `!{}`
4848
//! [static@m![]]
4949
//! [static@f()] //~ WARN: incompatible link kind for `f`
5050
//! [static@m!] //~ WARN: unmatched disambiguator `static` and suffix `!`
5151
//!
5252
//! [function@m!()] //~ WARN: unmatched disambiguator `function` and suffix `!()`
53-
//! [function@m!{}]
53+
//! [function@m!{}] //~ WARN: unmatched disambiguator `function` and suffix `!{}`
5454
//! [function@m![]]
5555
//! [function@f()]
5656
//! [function@m!] //~ WARN: unmatched disambiguator `function` and suffix `!`
5757
//!
5858
//! [fn@m!()] //~ WARN: unmatched disambiguator `fn` and suffix `!()`
59-
//! [fn@m!{}]
59+
//! [fn@m!{}] //~ WARN: unmatched disambiguator `fn` and suffix `!{}`
6060
//! [fn@m![]]
6161
//! [fn@f()]
6262
//! [fn@m!] //~ WARN: unmatched disambiguator `fn` and suffix `!`
6363
//!
6464
//! [method@m!()] //~ WARN: unmatched disambiguator `method` and suffix `!()`
65-
//! [method@m!{}]
65+
//! [method@m!{}] //~ WARN: unmatched disambiguator `method` and suffix `!{}`
6666
//! [method@m![]]
6767
//! [method@f()]
6868
//! [method@m!] //~ WARN: unmatched disambiguator `method` and suffix `!`
@@ -74,13 +74,13 @@
7474
//! [derive@m!] //~ WARN: incompatible link kind for `m`
7575
//!
7676
//! [type@m!()] //~ WARN: unmatched disambiguator `type` and suffix `!()`
77-
//! [type@m!{}]
77+
//! [type@m!{}] //~ WARN: unmatched disambiguator `type` and suffix `!{}`
7878
//! [type@m![]]
7979
//! [type@f()] //~ WARN: unmatched disambiguator `type` and suffix `()`
8080
//! [type@m!] //~ WARN: unmatched disambiguator `type` and suffix `!`
8181
//!
8282
//! [value@m!()] //~ WARN: unmatched disambiguator `value` and suffix `!()`
83-
//! [value@m!{}]
83+
//! [value@m!{}] //~ WARN: unmatched disambiguator `value` and suffix `!{}`
8484
//! [value@m![]]
8585
//! [value@f()]
8686
//! [value@m!] //~ WARN: unmatched disambiguator `value` and suffix `!`
@@ -92,13 +92,13 @@
9292
//! [macro@m!]
9393
//!
9494
//! [prim@m!()] //~ WARN: unmatched disambiguator `prim` and suffix `!()`
95-
//! [prim@m!{}]
95+
//! [prim@m!{}] //~ WARN: unmatched disambiguator `prim` and suffix `!{}`
9696
//! [prim@m![]]
9797
//! [prim@f()] //~ WARN: unmatched disambiguator `prim` and suffix `()`
9898
//! [prim@m!] //~ WARN: unmatched disambiguator `prim` and suffix `!`
9999
//!
100100
//! [primitive@m!()] //~ WARN: unmatched disambiguator `primitive` and suffix `!()`
101-
//! [primitive@m!{}]
101+
//! [primitive@m!{}] //~ WARN: unmatched disambiguator `primitive` and suffix `!{}`
102102
//! [primitive@m![]]
103103
//! [primitive@f()] //~ WARN: unmatched disambiguator `primitive` and suffix `()`
104104
//! [primitive@m!] //~ WARN: unmatched disambiguator `primitive` and suffix `!`

0 commit comments

Comments
 (0)