Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/hir/format_args.rs')
-rw-r--r--crates/hir-def/src/hir/format_args.rs17
1 files changed, 9 insertions, 8 deletions
diff --git a/crates/hir-def/src/hir/format_args.rs b/crates/hir-def/src/hir/format_args.rs
index de0fa982c8..390e7da677 100644
--- a/crates/hir-def/src/hir/format_args.rs
+++ b/crates/hir-def/src/hir/format_args.rs
@@ -1,12 +1,13 @@
//! Parses `format_args` input.
-use std::mem;
use hir_expand::name::Name;
+use intern::Symbol;
use rustc_parse_format as parse;
+use span::SyntaxContextId;
use stdx::TupleExt;
use syntax::{
ast::{self, IsString},
- SmolStr, TextRange, TextSize,
+ TextRange, TextSize,
};
use crate::hir::ExprId;
@@ -28,7 +29,7 @@ pub struct FormatArguments {
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FormatArgsPiece {
- Literal(Box<str>),
+ Literal(Symbol),
Placeholder(FormatPlaceholder),
}
@@ -174,6 +175,7 @@ pub(crate) fn parse(
is_direct_literal: bool,
mut synth: impl FnMut(Name) -> ExprId,
mut record_usage: impl FnMut(Name, Option<TextRange>),
+ call_ctx: SyntaxContextId,
) -> FormatArgs {
let Ok(text) = s.value() else {
return FormatArgs {
@@ -248,7 +250,7 @@ pub(crate) fn parse(
}
}
ArgRef::Name(name, span) => {
- let name = Name::new_text_dont_use(SmolStr::new(name));
+ let name = Name::new(name, tt::IdentIsRaw::No, call_ctx);
if let Some((index, _)) = args.by_name(&name) {
record_usage(name, span);
// Name found in `args`, so we resolve it to its index.
@@ -289,9 +291,8 @@ pub(crate) fn parse(
parse::Piece::NextArgument(arg) => {
let parse::Argument { position, position_span, format } = *arg;
if !unfinished_literal.is_empty() {
- template.push(FormatArgsPiece::Literal(
- mem::take(&mut unfinished_literal).into_boxed_str(),
- ));
+ template.push(FormatArgsPiece::Literal(Symbol::intern(&unfinished_literal)));
+ unfinished_literal.clear();
}
let span = parser.arg_places.get(placeholder_index).and_then(|&s| to_span(s));
@@ -411,7 +412,7 @@ pub(crate) fn parse(
}
if !unfinished_literal.is_empty() {
- template.push(FormatArgsPiece::Literal(unfinished_literal.into_boxed_str()));
+ template.push(FormatArgsPiece::Literal(Symbol::intern(&unfinished_literal)));
}
if !invalid_refs.is_empty() {