Macro input future proofing#20563
Macro input future proofing#20563alexcrichton merged 5 commits intorust-lang:masterfrom emberian:macro-input-future-proofing
Conversation
|
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
See RFC 550 (rust-lang/rfcs#550) for the motivation and details. If this breaks your code, add one of the listed tokens after the relevant non-terminal in your matcher. [breaking-change]
src/libsyntax/ext/tt/macro_rules.rs
Outdated
There was a problem hiding this comment.
This case doesn't need to exist, does it?
|
OK, reviewed. Algorithm seems close but not quite right, particularly around adjacent non-terminals (which can't be soundly permitted without a |
|
@cmr I'm ok with |
|
Sorry, that was too strong. And we don't need type ascription, we already have |
|
I use this macro a lot: macro_rules! is_match {
($value:expr, $($pattern:pat)|+) => {
match $value {
$($pattern)|+ => true,
_ => false
}
}
}But it now gives |
|
For what it’s worth, upgrading rust-url to the latest nightly is blocked on this. |
|
@SimonSapin that combination is disallowed to provide for extending patterns with The only tokens allowed to follow |
|
@cmr, so there is no way to write a macro the accepts multiple patterns with the same syntax as |
|
@SimonSapin thanks for pointing this out! We were deliberately quite conservative in choosing the "follow sets" for this RFC as we can always expand them over time! For patterns specifically, I think we must allow If you'd like, you could open a PR modifying the relevant code to have a bit more discussion (someone should validate my thinking) |
Per rust-lang#20563 (comment) This enables writing macros that accept `$($pattern:pat)|+` and expand to the same thing in a `match` statement. See for example [the `matches!` macro](https://github.com/SimonSapin/rust-std-candidates#the-matches-macro).
|
Ok, @huonw suggested a work around that I’m happy with: #[macro_export]
macro_rules! matches {
($expression: expr, $($pattern:tt)+) => {
_tt_as_expr_hack! {
match $expression {
$($pattern)+ => true,
_ => false
}
}
}
}
/// Work around "error: unexpected token: `an interpolated tt`", whatever that means.
#[macro_export]
macro_rules! _tt_as_expr_hack {
($value:expr) => ($value)
}
matches!("foo", "bar" | "baz" => 42 > 9000, "fuzz"); |
Semicolon after ty is no longer supported. See rust-lang/rust#20563
Also, update description of macro invocation syntax: after rust-lang#20563 there is a number of additional limitations on macro syntax.
…-dyn-auto-trait fix: When mapping next-solver's `dyn` type, add `Self` (aka. bound var ^1.0) to auto traits' substitutions
Implements RFC 550 (rust-lang/rfcs#550)