Skip to content

Commit

Permalink
Correctly escape strings in our quote macro
Browse files Browse the repository at this point in the history
This is a small change, but it was the cause of 90% of the errors in `rust-analyzer diagnostics .` 🫢

With this change and rust-lang#18085 together, all remaining errors are type errors.

This may mean we can enable more errors, but this is out of scope for this PR.
  • Loading branch information
ChayimFriedman2 committed Sep 10, 2024
1 parent f13c776 commit d5a884e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions crates/hir-expand/src/builtin/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use intern::{sym, Symbol};
use span::Span;
use syntax::ToSmolStr;
use tt::IdentIsRaw;

use crate::name::Name;
Expand Down Expand Up @@ -211,8 +212,8 @@ impl_to_to_tokentrees! {
_span: crate::tt::Literal => self { self };
_span: crate::tt::Ident => self { self };
_span: crate::tt::Punct => self { self };
span: &str => self { crate::tt::Literal{symbol: Symbol::intern(self), span, kind: tt::LitKind::Str, suffix: None }};
span: String => self { crate::tt::Literal{symbol: Symbol::intern(&self), span, kind: tt::LitKind::Str, suffix: None }};
span: &str => self { crate::tt::Literal{symbol: Symbol::intern(&self.escape_default().to_smolstr()), span, kind: tt::LitKind::Str, suffix: None }};
span: String => self { crate::tt::Literal{symbol: Symbol::intern(&self.escape_default().to_smolstr()), span, kind: tt::LitKind::Str, suffix: None }};
span: Name => self {
let (is_raw, s) = IdentIsRaw::split_from_symbol(self.as_str());
crate::tt::Ident{sym: Symbol::intern(s), span, is_raw }
Expand Down

0 comments on commit d5a884e

Please sign in to comment.