Remove SymbolStr.

By changing `as_str()` to take `&self` instead of `self`, we can just
return `&str`. We're still lying about lifetimes, but it's a smaller lie
than before, where `SymbolStr` contained a (fake) `&'static str`!
This commit is contained in:
Nicholas Nethercote 2021-12-15 08:32:21 +11:00
parent 0167c5303f
commit b4afb38f2f
2 changed files with 8 additions and 6 deletions

View File

@ -31,9 +31,9 @@ fn compare_items(a: &ast::Item, b: &ast::Item) -> Ordering {
(&ast::ItemKind::ExternCrate(ref a_name), &ast::ItemKind::ExternCrate(ref b_name)) => {
// `extern crate foo as bar;`
// ^^^ Comparing this.
let a_orig_name = a_name.map_or_else(|| a.ident.as_str(), rustc_span::Symbol::as_str);
let b_orig_name = b_name.map_or_else(|| b.ident.as_str(), rustc_span::Symbol::as_str);
let result = a_orig_name.cmp(&b_orig_name);
let a_orig_name = a_name.unwrap_or(a.ident.name);
let b_orig_name = b_name.unwrap_or(b.ident.name);
let result = a_orig_name.as_str().cmp(b_orig_name.as_str());
if result != Ordering::Equal {
return result;
}

View File

@ -95,15 +95,17 @@ pub(crate) enum ParserError {
impl<'a> Parser<'a> {
pub(crate) fn submod_path_from_attr(attrs: &[ast::Attribute], path: &Path) -> Option<PathBuf> {
let path_string = first_attr_value_str_by_name(attrs, sym::path)?.as_str();
let path_sym = first_attr_value_str_by_name(attrs, sym::path)?;
let path_str = path_sym.as_str();
// On windows, the base path might have the form
// `\\?\foo\bar` in which case it does not tolerate
// mixed `/` and `\` separators, so canonicalize
// `/` to `\`.
#[cfg(windows)]
let path_string = path_string.replace("/", "\\");
let path_str = path_str.replace("/", "\\");
Some(path.join(&*path_string))
Some(path.join(path_str))
}
pub(crate) fn parse_file_as_module(