Skip to content

Commit fb31e24

Browse files
authored
Unrolled build for rust-lang#127016
Rollup merge of rust-lang#127016 - bvanjoi:fix-126986, r=GuillaumeGomez docs: check if the disambiguator matches its suffix Fixes rust-lang#126986 This PR makes it will not continue resolving when its disambiguator doesn't match the suffix format.
2 parents 9ed2ab3 + 91d3ac7 commit fb31e24

5 files changed

+552
-8
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+24-8
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,15 @@ impl Disambiguator {
15071507
fn from_str(link: &str) -> Result<Option<(Self, &str, &str)>, (String, Range<usize>)> {
15081508
use Disambiguator::{Kind, Namespace as NS, Primitive};
15091509

1510+
let suffixes = [
1511+
// If you update this list, please also update the relevant rustdoc book section!
1512+
("!()", DefKind::Macro(MacroKind::Bang)),
1513+
("!{}", DefKind::Macro(MacroKind::Bang)),
1514+
("![]", DefKind::Macro(MacroKind::Bang)),
1515+
("()", DefKind::Fn),
1516+
("!", DefKind::Macro(MacroKind::Bang)),
1517+
];
1518+
15101519
if let Some(idx) = link.find('@') {
15111520
let (prefix, rest) = link.split_at(idx);
15121521
let d = match prefix {
@@ -1530,16 +1539,23 @@ impl Disambiguator {
15301539
"prim" | "primitive" => Primitive,
15311540
_ => return Err((format!("unknown disambiguator `{prefix}`"), 0..idx)),
15321541
};
1542+
1543+
for (suffix, kind) in suffixes {
1544+
if let Some(path_str) = rest.strip_suffix(suffix) {
1545+
if d.ns() != Kind(kind).ns() {
1546+
return Err((
1547+
format!("unmatched disambiguator `{prefix}` and suffix `{suffix}`"),
1548+
0..idx,
1549+
));
1550+
} else if path_str.len() > 1 {
1551+
// path_str != "@"
1552+
return Ok(Some((d, &path_str[1..], &rest[1..])));
1553+
}
1554+
}
1555+
}
1556+
15331557
Ok(Some((d, &rest[1..], &rest[1..])))
15341558
} else {
1535-
let suffixes = [
1536-
// If you update this list, please also update the relevant rustdoc book section!
1537-
("!()", DefKind::Macro(MacroKind::Bang)),
1538-
("!{}", DefKind::Macro(MacroKind::Bang)),
1539-
("![]", DefKind::Macro(MacroKind::Bang)),
1540-
("()", DefKind::Fn),
1541-
("!", DefKind::Macro(MacroKind::Bang)),
1542-
];
15431559
for (suffix, kind) in suffixes {
15441560
if let Some(path_str) = link.strip_suffix(suffix) {
15451561
// Avoid turning `!` or `()` into an empty string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
//@ check-pass
2+
//@ normalize-stderr-test: "nightly|beta|1\.[0-9][0-9]\.[0-9]" -> "$$CHANNEL"
3+
4+
//! [struct@m!()] //~ WARN: unmatched disambiguator `struct` and suffix `!()`
5+
//! [struct@m!{}]
6+
//! [struct@m![]]
7+
//! [struct@f()] //~ WARN: unmatched disambiguator `struct` and suffix `()`
8+
//! [struct@m!] //~ WARN: unmatched disambiguator `struct` and suffix `!`
9+
//!
10+
//! [enum@m!()] //~ WARN: unmatched disambiguator `enum` and suffix `!()`
11+
//! [enum@m!{}]
12+
//! [enum@m![]]
13+
//! [enum@f()] //~ WARN: unmatched disambiguator `enum` and suffix `()`
14+
//! [enum@m!] //~ WARN: unmatched disambiguator `enum` and suffix `!`
15+
//!
16+
//! [trait@m!()] //~ WARN: unmatched disambiguator `trait` and suffix `!()`
17+
//! [trait@m!{}]
18+
//! [trait@m![]]
19+
//! [trait@f()] //~ WARN: unmatched disambiguator `trait` and suffix `()`
20+
//! [trait@m!] //~ WARN: unmatched disambiguator `trait` and suffix `!`
21+
//!
22+
//! [module@m!()] //~ WARN: unmatched disambiguator `module` and suffix `!()`
23+
//! [module@m!{}]
24+
//! [module@m![]]
25+
//! [module@f()] //~ WARN: unmatched disambiguator `module` and suffix `()`
26+
//! [module@m!] //~ WARN: unmatched disambiguator `module` and suffix `!`
27+
//!
28+
//! [mod@m!()] //~ WARN: unmatched disambiguator `mod` and suffix `!()`
29+
//! [mod@m!{}]
30+
//! [mod@m![]]
31+
//! [mod@f()] //~ WARN: unmatched disambiguator `mod` and suffix `()`
32+
//! [mod@m!] //~ WARN: unmatched disambiguator `mod` and suffix `!`
33+
//!
34+
//! [const@m!()] //~ WARN: unmatched disambiguator `const` and suffix `!()`
35+
//! [const@m!{}]
36+
//! [const@m![]]
37+
//! [const@f()] //~ WARN: incompatible link kind for `f`
38+
//! [const@m!] //~ WARN: unmatched disambiguator `const` and suffix `!`
39+
//!
40+
//! [constant@m!()] //~ WARN: unmatched disambiguator `constant` and suffix `!()`
41+
//! [constant@m!{}]
42+
//! [constant@m![]]
43+
//! [constant@f()] //~ WARN: incompatible link kind for `f`
44+
//! [constant@m!] //~ WARN: unmatched disambiguator `constant` and suffix `!`
45+
//!
46+
//! [static@m!()] //~ WARN: unmatched disambiguator `static` and suffix `!()`
47+
//! [static@m!{}]
48+
//! [static@m![]]
49+
//! [static@f()] //~ WARN: incompatible link kind for `f`
50+
//! [static@m!] //~ WARN: unmatched disambiguator `static` and suffix `!`
51+
//!
52+
//! [function@m!()] //~ WARN: unmatched disambiguator `function` and suffix `!()`
53+
//! [function@m!{}]
54+
//! [function@m![]]
55+
//! [function@f()]
56+
//! [function@m!] //~ WARN: unmatched disambiguator `function` and suffix `!`
57+
//!
58+
//! [fn@m!()] //~ WARN: unmatched disambiguator `fn` and suffix `!()`
59+
//! [fn@m!{}]
60+
//! [fn@m![]]
61+
//! [fn@f()]
62+
//! [fn@m!] //~ WARN: unmatched disambiguator `fn` and suffix `!`
63+
//!
64+
//! [method@m!()] //~ WARN: unmatched disambiguator `method` and suffix `!()`
65+
//! [method@m!{}]
66+
//! [method@m![]]
67+
//! [method@f()]
68+
//! [method@m!] //~ WARN: unmatched disambiguator `method` and suffix `!`
69+
//!
70+
//! [derive@m!()] //~ WARN: incompatible link kind for `m`
71+
//! [derive@m!{}] //~ WARN: incompatible link kind for `m`
72+
//! [derive@m![]]
73+
//! [derive@f()] //~ WARN: unmatched disambiguator `derive` and suffix `()`
74+
//! [derive@m!] //~ WARN: incompatible link kind for `m`
75+
//!
76+
//! [type@m!()] //~ WARN: unmatched disambiguator `type` and suffix `!()`
77+
//! [type@m!{}]
78+
//! [type@m![]]
79+
//! [type@f()] //~ WARN: unmatched disambiguator `type` and suffix `()`
80+
//! [type@m!] //~ WARN: unmatched disambiguator `type` and suffix `!`
81+
//!
82+
//! [value@m!()] //~ WARN: unmatched disambiguator `value` and suffix `!()`
83+
//! [value@m!{}]
84+
//! [value@m![]]
85+
//! [value@f()]
86+
//! [value@m!] //~ WARN: unmatched disambiguator `value` and suffix `!`
87+
//!
88+
//! [macro@m!()]
89+
//! [macro@m!{}]
90+
//! [macro@m![]]
91+
//! [macro@f()] //~ WARN: unmatched disambiguator `macro` and suffix `()`
92+
//! [macro@m!]
93+
//!
94+
//! [prim@m!()] //~ WARN: unmatched disambiguator `prim` and suffix `!()`
95+
//! [prim@m!{}]
96+
//! [prim@m![]]
97+
//! [prim@f()] //~ WARN: unmatched disambiguator `prim` and suffix `()`
98+
//! [prim@m!] //~ WARN: unmatched disambiguator `prim` and suffix `!`
99+
//!
100+
//! [primitive@m!()] //~ WARN: unmatched disambiguator `primitive` and suffix `!()`
101+
//! [primitive@m!{}]
102+
//! [primitive@m![]]
103+
//! [primitive@f()] //~ WARN: unmatched disambiguator `primitive` and suffix `()`
104+
//! [primitive@m!] //~ WARN: unmatched disambiguator `primitive` and suffix `!`
105+
106+
#[macro_export]
107+
macro_rules! m {
108+
() => {};
109+
}
110+
111+
pub fn f() {}

0 commit comments

Comments
 (0)