rust/compiler/rustc_builtin_macros/src
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
..
assert Remove box_syntax from AST and use in tools 2023-03-12 13:19:46 +00:00
deriving Address the new odd backticks tidy lint in compiler/ 2023-03-11 20:40:18 +01:00
format_foreign Use as_deref in compiler (but only where it makes sense) 2022-11-16 21:58:58 +00:00
alloc_error_handler.rs Use ThinVec in ast::Block. 2023-02-21 11:51:56 +11:00
asm.rs Rollup merge of #105798 - Amanieu:relax-asm, r=joshtriplett 2023-03-10 21:15:42 +01:00
assert.rs Use ThinVec in various AST types. 2023-02-21 11:51:56 +11:00
cfg_accessible.rs Avoid unnecessary MetaItem/Attribute conversions. 2022-11-29 12:08:57 +11:00
cfg_eval.rs Workaround unstable stmt_expr_attributes for method receiver expressions. 2022-10-23 09:27:12 +00:00
cfg.rs Migrate all diagnostics 2022-10-23 10:09:44 +02:00
cmdline_attrs.rs make mk_attr_id part of ParseSess 2022-09-14 08:49:10 +08:00
compile_error.rs check_doc_keyword: don't alloc string for emptiness check 2022-04-08 11:45:57 +03:00
concat_bytes.rs Rollup merge of #105620 - TaKO8Ki:remove-unnecessary-uses-of-clone, r=compiler-errors 2022-12-13 01:17:10 +01:00
concat_idents.rs Remove TreeAndSpacing. 2022-07-29 15:52:15 +10:00
concat.rs allow negative numeric literals in concat! 2023-01-15 12:48:53 +13:00
derive.rs Remove token::Lit from ast::MetaItemLit. 2022-12-02 13:49:19 +11:00
edition_panic.rs Prefer doc comments over //-comments in compiler 2022-11-27 11:19:04 +00:00
env.rs Explain compile-time vs run-time difference in env!() error message 2023-02-28 16:44:59 +00:00
format_foreign.rs Remove double spaces after dots in comments 2023-01-17 08:09:33 +00:00
format.rs Properly allow macro expanded format_args invocations to uses captures 2023-03-14 13:16:52 +00:00
global_allocator.rs Use ThinVec in various AST types. 2023-02-21 11:51:56 +11:00
lib.rs Simplify message paths 2023-03-11 22:51:57 +01:00
log_syntax.rs mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
proc_macro_harness.rs Use ThinVec in ast::Block. 2023-02-21 11:51:56 +11:00
source_util.rs Prefer doc comments over //-comments in compiler 2022-11-27 11:19:04 +00:00
standard_library_imports.rs Replace some thens with some then_somes 2023-02-16 15:26:03 +00:00
test_harness.rs Use ThinVec in ast::Block. 2023-02-21 11:51:56 +11:00
test.rs Use ThinVec in a few more AST types. 2023-02-21 11:51:56 +11:00
trace_macros.rs Remove TreeAndSpacing. 2022-07-29 15:52:15 +10:00
type_ascribe.rs Add unstable type_ascribe macro 2022-11-19 22:16:42 +01:00
util.rs Avoid unnecessary MetaItem/Attribute conversions. 2022-11-29 12:08:57 +11:00