Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-expand/src/name.rs')
-rw-r--r--crates/hir-expand/src/name.rs23
1 files changed, 18 insertions, 5 deletions
diff --git a/crates/hir-expand/src/name.rs b/crates/hir-expand/src/name.rs
index d43ef38f29..217d991d11 100644
--- a/crates/hir-expand/src/name.rs
+++ b/crates/hir-expand/src/name.rs
@@ -191,7 +191,7 @@ impl Name {
// FIXME: Remove this in favor of `display`, see fixme on `as_str`
#[doc(hidden)]
pub fn display_no_db(&self, edition: Edition) -> impl fmt::Display + '_ {
- Display { name: self, needs_escaping: is_raw_identifier(self.symbol.as_str(), edition) }
+ Display { name: self, edition }
}
pub fn symbol(&self) -> &Symbol {
@@ -201,15 +201,28 @@ impl Name {
struct Display<'a> {
name: &'a Name,
- needs_escaping: bool,
+ edition: Edition,
}
impl fmt::Display for Display<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- if self.needs_escaping {
- write!(f, "r#")?;
+ let mut symbol = self.name.symbol.as_str();
+
+ if symbol == "'static" {
+ // FIXME: '`static` can also be a label, and there it does need escaping.
+ // But knowing where it is will require adding a parameter to `display()`,
+ // and that is an infectious change.
+ return f.write_str(symbol);
+ }
+
+ if let Some(s) = symbol.strip_prefix('\'') {
+ f.write_str("'")?;
+ symbol = s;
+ }
+ if is_raw_identifier(symbol, self.edition) {
+ f.write_str("r#")?;
}
- fmt::Display::fmt(self.name.symbol.as_str(), f)
+ f.write_str(symbol)
}
}