You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error[E0425]: cannot find value `a` in this scope
--> tests/tests.rs:15:46
|
15 | assert_eq!(stylish::plain::format!("{a}"), "1");
| ^ not found in this scope
Biggest blocker seems to be detecting the quotes, for simple " quoted strings this works:
diff --git macros/src/lib.rs macros/src/lib.rs
index a328ed3..9fde367 100644
--- macros/src/lib.rs+++ macros/src/lib.rs@@ -107,9 +107,9 @@ fn format_args_impl(
let export: syn::Path = syn::parse_quote!(#krate::𓀄);
let span = format.span();
- let format_string = &format;- let format = format.value();- let (leftover, format) = Format::parse(&format).unwrap();+ let format_lit = &format;+ let format_string = format.value();+ let (leftover, format) = Format::parse(&format_string).unwrap();
assert!(leftover.is_empty());
let num_positional_args = positional_args.len();
let positional_args = positional_args.into_iter();
@@ -161,12 +161,14 @@ fn format_args_impl(
quote!(__stylish_named_args.#index)
} else {
let i = implicit_named_args_values.len();
+ let start = (name.as_ptr() as usize) - (format_string.as_str().as_ptr() as usize) + 1;+ let end = start + name.len();
implicit_named_args_values.push(ExprPath {
attrs: Vec::new(),
qself: None,
path: Ident::new(
name,
- Span::call_site().resolved_at(format_string.span()),+ format_lit.token().subspan(start..end).unwrap_or_else(|| format_lit.span()),
)
.into(),
});
But it gets misaligned for r#"" strings:
error[E0425]: cannot find value `a` in this scope
--> tests/tests.rs:16:46
|
16 | assert_eq!(stylish::plain::format!(r#"{a}"#), "1");
| ^ not found in this scope
The text was updated successfully, but these errors were encountered:
Another issue, escapes get interpreted making the offset off:
error[E0425]: cannot find value `a` in this scope
--> tests/tests.rs:17:47
|
17 | assert_eq!(stylish::plain::format!("\u{0000}{a}"), "1");
| ^ not found in this scope
https://doc.rust-lang.org/nightly/proc_macro/struct.Literal.html#method.subspan
Seems to work well with a hacked together usage:
Biggest blocker seems to be detecting the quotes, for simple
"
quoted strings this works:But it gets misaligned for
r#""
strings:The text was updated successfully, but these errors were encountered: