rust/tests/ui/fmt
Nilstrieb 729185338f Properly allow macro expanded format_args invocations to uses captures
Originally, this was kinda half-allowed. There were some primitive
checks in place that looked at the span to see whether the input was
likely a literal. These "source literal" checks are needed because the
spans created during `format_args` parsing only make sense when it is
indeed a literal that was written in the source code directly.

This is orthogonal to the restriction that the first argument must be a
"direct literal", not being exanpanded from macros. This restriction was
imposed by [RFC 2795] on the basis of being too confusing. But this was
only concerned with the argument of the invocation being a literal, not
whether it was a source literal (maybe in spirit it meant it being a
source literal, this is not clear to me).

Since the original check only really cared about source literals (which
is good enough to deny the `format_args!(concat!())` example), macros
expanding to `format_args` invocations were able to use implicit
captures if they spanned the string in a way that lead back to a source
string.

The "source literal" checks were not strict enough and caused ICEs in
certain cases (see # 106191 (the space is intended to avoid spammy
backreferences)). So I tightened it up in # 106195 to really only work
if it's a direct source literal.

This caused the `indoc` crate to break. `indoc` transformed the source
literal by removing whitespace, which made it not a "source literal"
anymore (which is required to fix the ICE). But since `indoc` spanned
the literal in ways that made the old check think that it's a literal,
it was able to use implicit captures (which is useful and nice for the
users of `indoc`).

This commit properly seperates the previously introduced concepts of
"source literal" and "direct literal" and therefore allows `indoc`
invocations, which don't create "source literals" to use implicit
captures again.

[RFC 2795]: https://rust-lang.github.io/rfcs/2795-format-args-implicit-identifiers.html#macro-hygiene
2023-03-14 13:16:52 +00:00
..
auxiliary Properly allow macro expanded format_args invocations to uses captures 2023-03-14 13:16:52 +00:00
format-args-capture-first-literal-is-macro.rs Properly allow macro expanded format_args invocations to uses captures 2023-03-14 13:16:52 +00:00
format-args-capture-first-literal-is-macro.stderr Properly allow macro expanded format_args invocations to uses captures 2023-03-14 13:16:52 +00:00
format-args-capture-from-pm-first-arg-macro.rs Properly allow macro expanded format_args invocations to uses captures 2023-03-14 13:16:52 +00:00
format-args-capture-from-pm-first-arg-macro.stderr Properly allow macro expanded format_args invocations to uses captures 2023-03-14 13:16:52 +00:00
format-args-capture-issue-93378.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
format-args-capture-issue-93378.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
format-args-capture-issue-94010.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
format-args-capture-issue-94010.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
format-args-capture-issue-102057.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
format-args-capture-issue-102057.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
format-args-capture-issue-106408.rs Properly allow macro expanded format_args invocations to uses captures 2023-03-14 13:16:52 +00:00
format-args-capture-macro-hygiene-pass.rs Properly allow macro expanded format_args invocations to uses captures 2023-03-14 13:16:52 +00:00
format-args-capture-macro-hygiene.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
format-args-capture-macro-hygiene.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
format-args-capture-missing-variables.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
format-args-capture-missing-variables.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
format-args-capture.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
format-expanded-string.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
format-expanded-string.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
format-raw-string-error.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
format-raw-string-error.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
format-string-error-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
format-string-error-2.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
format-string-error.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
format-string-error.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
format-string-wrong-order.rs PR fixing wrong order of format parameters in strings. Issue #106572 2023-02-02 12:56:04 +01:00
format-string-wrong-order.stderr PR fixing wrong order of format parameters in strings. Issue #106572 2023-02-02 12:56:04 +01:00
format-with-yield-point.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
ifmt-bad-arg.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
ifmt-bad-arg.stderr Modify primary span label for E0308 2023-01-30 20:12:19 +00:00
ifmt-bad-format-args.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
ifmt-bad-format-args.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
ifmt-unimpl.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
ifmt-unimpl.stderr Update tests. 2023-01-29 20:19:26 +01:00
ifmt-unknown-trait.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
ifmt-unknown-trait.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
incorrect-separator.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
incorrect-separator.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
indoc-issue-106408.rs Revert "Improve heuristics whether format_args string is a source literal" 2023-01-18 20:33:17 +01:00
issue-75307.rs Move tests 2023-02-16 11:42:35 -03:00
issue-75307.stderr Move tests 2023-02-16 11:42:35 -03:00
issue-86085.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-86085.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-89173.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-89173.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-91556.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-91556.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-103826.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-103826.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-104142.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-104142.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
respanned-literal-issue-106191.rs Properly allow macro expanded format_args invocations to uses captures 2023-03-14 13:16:52 +00:00
respanned-literal-issue-106191.stderr Properly allow macro expanded format_args invocations to uses captures 2023-03-14 13:16:52 +00:00
send-sync.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
send-sync.stderr Update tests. 2023-01-29 20:19:26 +01:00
struct-field-as-captured-argument.fixed Move /src/test to /tests 2023-01-11 09:32:08 +00:00
struct-field-as-captured-argument.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
struct-field-as-captured-argument.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
unicode-escape-spans.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
unicode-escape-spans.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00