Use :ident matcher instead of :ty matcher#17
Merged
calebzulawski merged 1 commit intocalebzulawski:masterfrom Aug 22, 2020
Merged
Use :ident matcher instead of :ty matcher#17calebzulawski merged 1 commit intocalebzulawski:masterfrom
:ident matcher instead of :ty matcher#17calebzulawski merged 1 commit intocalebzulawski:masterfrom
Conversation
When a `:ty` matcher is used in a `macro_rules!` macro, the captured
argument can no longer be used to match a literal in a new
`macro_rules!` invocation. For example, the following code:
```rust
macro_rules! inner {
(my_val) => {}
}
macro_rules! outer {
($val:ty) => {
inner!($val);
}
}
outer!(my_val);
```
produces the following error:
```
error: no rules expected the token `my_val`
--> src/lib.rs:7:16
|
1 | macro_rules! inner {
| ------------------ when calling this macro
...
7 | inner!($val);
| ^^^^ no rules expected this token in macro call
...
11 | outer!(my_val);
| --------------- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
```
That is, once `my_val` is captured as a `:ty`, it will not match a `my_val` literal
in the `inner!` invocation.
Due to a bug in rustc, code like this was accepted by the compiler
when a proc-macro attribute was applied to the macro invocation.
This affects `fourier-algorithms` due to the following code:
```rust
#[target_cfg(target = "[x86|x86_64]+avx")]
crate::avx_vector! { $type };
```
The `avx_vector!` macro is expecting either `f32` or `f64`
as an ordinary token. However, the `$type` metavariable uses a
`:ty` matcher, which will prevent it from matching against `f32`
or `f64` (even though the captured type is always `f32` or `f64`).
Due to the `target_cfg` attribute proc-macro, this code was incorrectly
allowed to compile. When the underlying bug in rustc is fixed
in rust-lang/rust#73084, `fourier-algorithms`
will stop compiling.
This commit changes two `:ty` matchers to `:ident` matchers, which can
be used as arguments to a `macro_rules!` macro expecting a plain `f32`
or `f64` token. This will still compile on existing compile versions,
and will allow `fourier-algorithms` to continue to compile once
rust-lang/rust#73084 is merged into rustc.
Owner
|
Thanks! Looks good. |
Contributor
Author
|
@calebzulawski: Would you mind making a new point release? I'm planning to merge rust-lang/rust#73084 soon, and it would be nice for there to be an upgrade path for all downstream crates affected by it. |
Owner
|
Done! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a
:tymatcher is used in amacro_rules!macro, the capturedargument can no longer be used to match a literal in a new
macro_rules!invocation. For example, the following code:produces the following error:
That is, once
my_valis captured as a:ty, it will not match amy_valliteralin the
inner!invocation.Due to a bug in rustc, code like this was accepted by the compiler
when a proc-macro attribute was applied to the macro invocation.
This affects
fourier-algorithmsdue to the following code:The
avx_vector!macro is expecting eitherf32orf64as an ordinary token. However, the
$typemetavariable uses a:tymatcher, which will prevent it from matching againstf32or
f64(even though the captured type is alwaysf32orf64).Due to the
target_cfgattribute proc-macro, this code was incorrectlyallowed to compile. When the underlying bug in rustc is fixed
in rust-lang/rust#73084,
fourier-algorithmswill stop compiling.
This commit changes two
:tymatchers to:identmatchers, which canbe used as arguments to a
macro_rules!macro expecting a plainf32or
f64token. This will still compile on existing compile versions,and will allow
fourier-algorithmsto continue to compile oncerust-lang/rust#73084 is merged into rustc.