1
Fork 0

Dogfood 'str_split_once() with librustdoc

This commit is contained in:
Eric Arellano 2020-12-07 14:00:31 -07:00
parent 7bd47bd7a1
commit 85e9ea0152
4 changed files with 12 additions and 17 deletions

View file

@ -397,12 +397,9 @@ impl Options {
matches matches
.opt_strs("default-setting") .opt_strs("default-setting")
.iter() .iter()
.map(|s| { .map(|s| match s.split_once('=') {
let mut kv = s.splitn(2, '='); None => (s.clone(), "true".to_string()),
// never panics because `splitn` always returns at least one element Some((k, v)) => (k.to_string(), v.to_string()),
let k = kv.next().unwrap().to_string();
let v = kv.next().unwrap_or("true").to_string();
(k, v)
}) })
.collect(), .collect(),
]; ];
@ -707,11 +704,9 @@ fn parse_extern_html_roots(
) -> Result<BTreeMap<String, String>, &'static str> { ) -> Result<BTreeMap<String, String>, &'static str> {
let mut externs = BTreeMap::new(); let mut externs = BTreeMap::new();
for arg in &matches.opt_strs("extern-html-root-url") { for arg in &matches.opt_strs("extern-html-root-url") {
let mut parts = arg.splitn(2, '='); let (name, url) =
let name = parts.next().ok_or("--extern-html-root-url must not be empty")?; arg.split_once('=').ok_or("--extern-html-root-url must be of the form name=url")?;
let url = parts.next().ok_or("--extern-html-root-url must be of the form name=url")?;
externs.insert(name.to_string(), url.to_string()); externs.insert(name.to_string(), url.to_string());
} }
Ok(externs) Ok(externs)
} }

View file

@ -167,10 +167,8 @@ impl Context {
// `style-suffix.min.css`. Path::extension would just return `css` // `style-suffix.min.css`. Path::extension would just return `css`
// which would result in `style.min-suffix.css` which isn't what we // which would result in `style.min-suffix.css` which isn't what we
// want. // want.
let mut iter = filename.splitn(2, '.'); let (base, ext) = filename.split_once('.').unwrap();
let base = iter.next().unwrap(); let filename = format!("{}{}.{}", base, self.shared.resource_suffix, ext);
let ext = iter.next().unwrap();
let filename = format!("{}{}.{}", base, self.shared.resource_suffix, ext,);
self.dst.join(&filename) self.dst.join(&filename)
} }
} }

View file

@ -16,6 +16,7 @@
#![feature(once_cell)] #![feature(once_cell)]
#![feature(type_ascription)] #![feature(type_ascription)]
#![feature(split_inclusive)] #![feature(split_inclusive)]
#![feature(str_split_once)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#[macro_use] #[macro_use]

View file

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