Stream: t-compiler/rust-analyzer

Topic: Format string syntax #3419


Lukas Wirth (Oct 12 2020 at 14:29, on Zulip):

For https://github.com/rust-analyzer/rust-analyzer/issues/3419 where would the checks for this ideally go? I would imagine in the syntax crate in validation?

matklad (Oct 12 2020 at 14:29, on Zulip):

Yup

matklad (Oct 12 2020 at 14:30, on Zulip):

Specifically, the syntax crate should have a pretty abstract way to tokenize a string

matklad (Oct 12 2020 at 14:30, on Zulip):

and then that should be used by other crates

matklad (Oct 12 2020 at 14:30, on Zulip):

I think we already have something like this already, for syntax highlighting

Lukas Wirth (Oct 12 2020 at 14:31, on Zulip):

Yep, there is a HasFormatSpecifier trait implemented on String and RawString which offers a lexing function for this thanks to syntax highlighting

Jonas Schievink [he/him] (Oct 12 2020 at 14:31, on Zulip):

Note that an AST validation pass is not enough to handle this – the validation needs to happen on expansion of the built-in format_args! macro

matklad (Oct 12 2020 at 14:32, on Zulip):

@veykril right! I think it might make sense to move it to a format.rs module, and maybe change the interface to work with &str, rather than with AST nodes

matklad (Oct 12 2020 at 14:32, on Zulip):

Things that can be indepemdent of AST should be independent

matklad (Oct 12 2020 at 14:33, on Zulip):

It is also true that it's only during macro expansion that we know which strings are actually format specifiers.

Lukas Wirth (Oct 12 2020 at 14:34, on Zulip):

Right, where should the check go then though? I've been looking through things for a bit earlier but couldn't find another place where it was obvious for me to check.

Lukas Wirth (Oct 12 2020 at 14:35, on Zulip):

What crate should that belong to then? stdx or still syntax?

matklad (Oct 12 2020 at 14:37, on Zulip):

format_args_expand I think is conceptually the right place to do the check

matklad (Oct 12 2020 at 14:37, on Zulip):

The problem is, we don't yet have any infra for reporting errors from macro expansion so this'll require some plumbing

Lukas Wirth (Oct 12 2020 at 14:48, on Zulip):

Oh, so invalid macro invocations aren't actually being reported at all by RA currently?

matklad (Oct 12 2020 at 15:02, on Zulip):

yup

Last update: Jul 27 2021 at 22:15UTC