Skip to content

Commit 7bd47bd

Browse files
committed
Dogfood 'str_split_once() with linkchecker
1 parent d6baf38 commit 7bd47bd

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/tools/linkchecker/main.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
//! A few exceptions are allowed as there's known bugs in rustdoc, but this
1515
//! should catch the majority of "broken link" cases.
1616
17+
#![feature(str_split_once)]
18+
1719
use std::collections::hash_map::Entry;
1820
use std::collections::{HashMap, HashSet};
1921
use std::env;
@@ -232,11 +234,12 @@ fn check(cache: &mut Cache, root: &Path, file: &Path, errors: &mut bool) -> Opti
232234
{
233235
return;
234236
}
235-
let mut parts = url.splitn(2, '#');
236-
let url = parts.next().unwrap();
237-
let fragment = parts.next();
238-
let mut parts = url.splitn(2, '?');
239-
let url = parts.next().unwrap();
237+
let (url, fragment) = match url.split_once('#') {
238+
None => (url, None),
239+
Some((url, fragment)) => (url, Some(fragment)),
240+
};
241+
// NB: the `splitn` always succeeds, even if the delimiter is not present.
242+
let url = url.splitn(2, '?').next().unwrap();
240243

241244
// Once we've plucked out the URL, parse it using our base url and
242245
// then try to extract a file path.

0 commit comments

Comments
 (0)