From b4afb38f2f506e9f4d558449e2e303340d4fdb35 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 15 Dec 2021 08:32:21 +1100 Subject: [PATCH] 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`! --- src/reorder.rs | 6 +++--- src/syntux/parser.rs | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/reorder.rs b/src/reorder.rs index 0732c8ee7005..fe8e5c6b61e1 100644 --- a/src/reorder.rs +++ b/src/reorder.rs @@ -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; } diff --git a/src/syntux/parser.rs b/src/syntux/parser.rs index d1bb2f80004a..23d065c9cc95 100644 --- a/src/syntux/parser.rs +++ b/src/syntux/parser.rs @@ -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 { - 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(