diff options
| author | bors <bors@rust-lang.org> | 2024-03-13 13:20:42 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-03-13 13:20:42 +0000 |
| commit | 184c5ab1807a5e605cc8235d3734a97552768c22 (patch) | |
| tree | bcec9d7cab06bc4e3886671c9362bc7053c5773b /compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp | |
| parent | 9ce37dc7290e60bd0dfc7a5d4fcdbbd836f989f0 (diff) | |
| parent | 8fcdf54a6b98c129e951caf3a97cbf20db677ee3 (diff) | |
| download | rust-184c5ab1807a5e605cc8235d3734a97552768c22.tar.gz rust-184c5ab1807a5e605cc8235d3734a97552768c22.zip | |
Auto merge of #121589 - bvanjoi:fix-98291, r=petrochenkov
delay expand macro bang when there has indeterminate path
Related #98291
I will attempt to clarify the root problem through several examples:
Firstly,
```rs
// rustc code.rs --edition=2018
macro_rules! wrap {
() => {
macro_rules! _a {
() => {
"Hello world"
};
}
};
}
wrap!();
use _a as a;
fn main() {
format_args!(_a!());
}
```
The above case will compile successfully because `_a` is defined after the `wrap` expaned, ensuring `_a` can be resolved without any issues.
And,
```rs
// rustc code.rs --edition=2018
macro_rules! wrap {
() => {
macro_rules! _a {
() => {
"Hello world"
};
}
};
}
wrap!();
use _a as a;
fn main() {
format_args!("{}", a!());
}
```
The above example will also compile successfully because the `parse_args` in `expand_format_args_impl` will return a value `MacroInput { fmtstr: Expr::Lit::Str, args: [Expr::MacroCall]}`. Since the graph for `args` will be build lately, `a` will eventually be resolved.
However, in the case of:
```rs
// rustc code.rs --edition=2018
macro_rules! wrap {
() => {
macro_rules! _a {
() => {
"Hello world"
};
}
};
}
wrap!();
use _a as a;
fn main() {
format_args!(a!());
}
```
The result of `parse_args` is `MacroInput {fmtstr: Expr::Lit::Macro, args: [] }`, we attempt to expand `fmtstr` **eagerly** within `expr_to_spanned_string`. Although we have recorded `(root, _a)` into resolutions, `use _a as a` is an indeterminate import, which will not try to resolve under the conditions of `expander.monotonic = false`.
Therefore, I've altered the strategy for resolving indeterminate imports, ensuring it will also resolve during eager expansion. This could be a significant change to the resolution infra. However, I think it's acceptable if the goal of avoiding resolution under eager expansion is to save time.
r? `@petrochenkov`
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
