mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 19:58:32 +00:00
Use helper method in is_format_string
This commit is contained in:
parent
55c5014b76
commit
386f46a5a1
@ -1,9 +1,10 @@
|
|||||||
//! Tools to work with format string literals for the `format_args!` family of macros.
|
//! Tools to work with format string literals for the `format_args!` family of macros.
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, IsString},
|
ast::{self, IsString}, TextRange, TextSize,
|
||||||
AstNode, AstToken, TextRange, TextSize,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use super::node_ext::get_outer_macro_name;
|
||||||
|
|
||||||
pub fn is_format_string(string: &ast::String) -> bool {
|
pub fn is_format_string(string: &ast::String) -> bool {
|
||||||
// Check if `string` is a format string argument of a macro invocation.
|
// Check if `string` is a format string argument of a macro invocation.
|
||||||
// `string` is a string literal, mapped down into the innermost macro expansion.
|
// `string` is a string literal, mapped down into the innermost macro expansion.
|
||||||
@ -14,8 +15,7 @@ pub fn is_format_string(string: &ast::String) -> bool {
|
|||||||
// This setup lets us correctly highlight the components of `concat!("{}", "bla")` format
|
// This setup lets us correctly highlight the components of `concat!("{}", "bla")` format
|
||||||
// strings. It still fails for `concat!("{", "}")`, but that is rare.
|
// strings. It still fails for `concat!("{", "}")`, but that is rare.
|
||||||
(|| {
|
(|| {
|
||||||
let macro_call = string.syntax().parent_ancestors().find_map(ast::MacroCall::cast)?;
|
let name = get_outer_macro_name(string)?;
|
||||||
let name = macro_call.path()?.segment()?.name_ref()?;
|
|
||||||
|
|
||||||
if !matches!(
|
if !matches!(
|
||||||
name.text().as_str(),
|
name.text().as_str(),
|
||||||
|
Loading…
Reference in New Issue
Block a user