@@ -23,6 +23,31 @@ use std::rc::Rc;
2323
2424use crate :: Redirect :: * ;
2525
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+
2651macro_rules! t {
2752 ( $e: expr) => {
2853 match $e {
@@ -111,30 +136,20 @@ fn walk(cache: &mut Cache, root: &Path, dir: &Path, errors: &mut bool) {
111136 }
112137}
113138
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+
114147fn check ( cache : & mut Cache , root : & Path , file : & Path , errors : & mut bool ) -> Option < PathBuf > {
115148 // Ignore non-HTML files.
116149 if file. extension ( ) . and_then ( |s| s. to_str ( ) ) != Some ( "html" ) {
117150 return None ;
118151 }
119152
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-
138153 let res = load_file ( cache, root, file, SkipRedirect ) ;
139154 let ( pretty_file, contents) = match res {
140155 Ok ( res) => res,
@@ -249,17 +264,20 @@ fn check(cache: &mut Cache, root: &Path, file: &Path, errors: &mut bool) -> Opti
249264 let entry = & mut cache. get_mut ( & pretty_path) . unwrap ( ) ;
250265 entry. parse_ids ( & pretty_path, & contents, errors) ;
251266
252- if !entry. ids . contains ( * fragment) {
267+ if !entry. ids . contains ( * fragment) && !is_exception ( file, & format ! ( "#{}" , fragment) )
268+ {
253269 * errors = true ;
254270 print ! ( "{}:{}: broken link fragment " , pretty_file. display( ) , i + 1 ) ;
255271 println ! ( "`#{}` pointing to `{}`" , fragment, pretty_path. display( ) ) ;
256272 } ;
257273 }
258274 } else {
259- * errors = true ;
260- print ! ( "{}:{}: broken link - " , pretty_file. display( ) , i + 1 ) ;
261275 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+ }
263281 }
264282 } ) ;
265283 Some ( pretty_file)
0 commit comments