Skip to content

Commit 85e9ea0

Browse files
committed
Dogfood 'str_split_once() with librustdoc
1 parent 7bd47bd commit 85e9ea0

File tree

4 files changed

+12
-17
lines changed

4 files changed

+12
-17
lines changed

src/librustdoc/config.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,9 @@ impl Options {
397397
matches
398398
.opt_strs("default-setting")
399399
.iter()
400-
.map(|s| {
401-
let mut kv = s.splitn(2, '=');
402-
// never panics because `splitn` always returns at least one element
403-
let k = kv.next().unwrap().to_string();
404-
let v = kv.next().unwrap_or("true").to_string();
405-
(k, v)
400+
.map(|s| match s.split_once('=') {
401+
None => (s.clone(), "true".to_string()),
402+
Some((k, v)) => (k.to_string(), v.to_string()),
406403
})
407404
.collect(),
408405
];
@@ -707,11 +704,9 @@ fn parse_extern_html_roots(
707704
) -> Result<BTreeMap<String, String>, &'static str> {
708705
let mut externs = BTreeMap::new();
709706
for arg in &matches.opt_strs("extern-html-root-url") {
710-
let mut parts = arg.splitn(2, '=');
711-
let name = parts.next().ok_or("--extern-html-root-url must not be empty")?;
712-
let url = parts.next().ok_or("--extern-html-root-url must be of the form name=url")?;
707+
let (name, url) =
708+
arg.split_once('=').ok_or("--extern-html-root-url must be of the form name=url")?;
713709
externs.insert(name.to_string(), url.to_string());
714710
}
715-
716711
Ok(externs)
717712
}

src/librustdoc/html/render/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,8 @@ impl Context {
167167
// `style-suffix.min.css`. Path::extension would just return `css`
168168
// which would result in `style.min-suffix.css` which isn't what we
169169
// want.
170-
let mut iter = filename.splitn(2, '.');
171-
let base = iter.next().unwrap();
172-
let ext = iter.next().unwrap();
173-
let filename = format!("{}{}.{}", base, self.shared.resource_suffix, ext,);
170+
let (base, ext) = filename.split_once('.').unwrap();
171+
let filename = format!("{}{}.{}", base, self.shared.resource_suffix, ext);
174172
self.dst.join(&filename)
175173
}
176174
}

src/librustdoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#![feature(once_cell)]
1717
#![feature(type_ascription)]
1818
#![feature(split_inclusive)]
19+
#![feature(str_split_once)]
1920
#![recursion_limit = "256"]
2021

2122
#[macro_use]

src/librustdoc/passes/collect_intra_doc_links.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,9 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
435435

436436
// Try looking for methods and associated items.
437437
let mut split = path_str.rsplitn(2, "::");
438-
// this can be an `unwrap()` because we ensure the link is never empty
439-
let (item_str, item_name) = split.next().map(|i| (i, Symbol::intern(i))).unwrap();
438+
// NB: the `splitn`'s first element is always defined, even if the delimiter is not present.
439+
let item_str = split.next().unwrap();
440+
let item_name = Symbol::intern(item_str);
440441
let path_root = split
441442
.next()
442443
.map(|f| f.to_owned())
@@ -447,7 +448,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
447448
ResolutionFailure::NotResolved {
448449
module_id,
449450
partial_res: None,
450-
unresolved: item_str.into(),
451+
unresolved: path_str.into(),
451452
}
452453
})?;
453454

0 commit comments

Comments
 (0)