@@ -23,6 +23,31 @@ use std::rc::Rc;
23
23
24
24
use crate :: Redirect :: * ;
25
25
26
+ // Add linkcheck exceptions here
27
+ // If at all possible you should use intra-doc links to avoid linkcheck issues. These
28
+ // are cases where that does not work
29
+ const LINKCHECK_EXCEPTIONS : & [ ( & str , & [ & str ] ) ] = & [
30
+ // These are methods on slice, and `Self` does not work on primitive impls
31
+ // in intra-doc links (intra-doc links are weird)
32
+ // https://github.com/rust-lang/rust/issues/62834 is necessary to be
33
+ // able to link to slices
34
+ (
35
+ "std/io/struct.IoSlice.html" ,
36
+ & [
37
+ "#method.as_mut_ptr" ,
38
+ "#method.sort_by_key" ,
39
+ "#method.make_ascii_uppercase" ,
40
+ "#method.make_ascii_lowercase" ,
41
+ ] ,
42
+ ) ,
43
+ // These try to link to std::collections, but are defined in alloc
44
+ // https://github.com/rust-lang/rust/issues/74481
45
+ ( "std/collections/btree_map/struct.BTreeMap.html" , & [ "#insert-and-complex-keys" ] ) ,
46
+ ( "std/collections/btree_set/struct.BTreeSet.html" , & [ "#insert-and-complex-keys" ] ) ,
47
+ ( "alloc/collections/btree_map/struct.BTreeMap.html" , & [ "#insert-and-complex-keys" ] ) ,
48
+ ( "alloc/collections/btree_set/struct.BTreeSet.html" , & [ "#insert-and-complex-keys" ] ) ,
49
+ ] ;
50
+
26
51
macro_rules! t {
27
52
( $e: expr) => {
28
53
match $e {
@@ -111,30 +136,20 @@ fn walk(cache: &mut Cache, root: &Path, dir: &Path, errors: &mut bool) {
111
136
}
112
137
}
113
138
139
+ fn is_exception ( file : & Path , link : & str ) -> bool {
140
+ if let Some ( entry) = LINKCHECK_EXCEPTIONS . iter ( ) . find ( |& ( f, _) | file. ends_with ( f) ) {
141
+ entry. 1 . contains ( & link)
142
+ } else {
143
+ false
144
+ }
145
+ }
146
+
114
147
fn check ( cache : & mut Cache , root : & Path , file : & Path , errors : & mut bool ) -> Option < PathBuf > {
115
148
// Ignore non-HTML files.
116
149
if file. extension ( ) . and_then ( |s| s. to_str ( ) ) != Some ( "html" ) {
117
150
return None ;
118
151
}
119
152
120
- // Unfortunately we're not 100% full of valid links today to we need a few
121
- // exceptions to get this past `make check` today.
122
- // FIXME(#32129)
123
- if file. ends_with ( "std/io/struct.IoSlice.html" )
124
- {
125
- return None ;
126
- }
127
-
128
- // FIXME(#32130)
129
- if file. ends_with ( "alloc/collections/btree_map/struct.BTreeMap.html" )
130
- || file. ends_with ( "alloc/collections/btree_set/struct.BTreeSet.html" )
131
- || file. ends_with ( "std/collections/btree_map/struct.BTreeMap.html" )
132
- || file. ends_with ( "std/collections/btree_set/struct.BTreeSet.html" )
133
- || file. ends_with ( "std/collections/hash_set/struct.HashSet.html" )
134
- {
135
- return None ;
136
- }
137
-
138
153
let res = load_file ( cache, root, file, SkipRedirect ) ;
139
154
let ( pretty_file, contents) = match res {
140
155
Ok ( res) => res,
@@ -249,17 +264,20 @@ fn check(cache: &mut Cache, root: &Path, file: &Path, errors: &mut bool) -> Opti
249
264
let entry = & mut cache. get_mut ( & pretty_path) . unwrap ( ) ;
250
265
entry. parse_ids ( & pretty_path, & contents, errors) ;
251
266
252
- if !entry. ids . contains ( * fragment) {
267
+ if !entry. ids . contains ( * fragment) && !is_exception ( file, & format ! ( "#{}" , fragment) )
268
+ {
253
269
* errors = true ;
254
270
print ! ( "{}:{}: broken link fragment " , pretty_file. display( ) , i + 1 ) ;
255
271
println ! ( "`#{}` pointing to `{}`" , fragment, pretty_path. display( ) ) ;
256
272
} ;
257
273
}
258
274
} else {
259
- * errors = true ;
260
- print ! ( "{}:{}: broken link - " , pretty_file. display( ) , i + 1 ) ;
261
275
let pretty_path = path. strip_prefix ( root) . unwrap_or ( & path) ;
262
- println ! ( "{}" , pretty_path. display( ) ) ;
276
+ if !is_exception ( file, pretty_path. to_str ( ) . unwrap ( ) ) {
277
+ * errors = true ;
278
+ print ! ( "{}:{}: broken link - " , pretty_file. display( ) , i + 1 ) ;
279
+ println ! ( "{}" , pretty_path. display( ) ) ;
280
+ }
263
281
}
264
282
} ) ;
265
283
Some ( pretty_file)
0 commit comments