Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support macro invocations in match branch position #2654

Open
canndrew opened this issue Mar 3, 2019 · 4 comments
Open

Support macro invocations in match branch position #2654

canndrew opened this issue Mar 3, 2019 · 4 comments
Labels
A-control-flow Proposals relating to control flow. A-macros Macro related proposals and issues A-patterns Pattern matching related proposals & ideas A-syntax Syntax related proposals & ideas T-lang Relevant to the language team, which will review and decide on the RFC.

Comments

@canndrew
Copy link
Contributor

canndrew commented Mar 3, 2019

Sorry if there's already and issue for this, but I couldn't find one.

On many occasions I've wanted to use macros to generate match branches. eg.

match x {
    macro_which_outputs_some_branches!(),
    Foo::Bar => 23,
}

Is there a reason not to support this?

@petrochenkov
Copy link
Contributor

petrochenkov commented Mar 3, 2019

Do you mean macros expanding to multiple match arms?
For a single branch this will be automatically supported by rust-lang/rust#54883.

@canndrew
Copy link
Contributor Author

canndrew commented Mar 7, 2019

Multiple match arms would be nice, yeah.

@Centril Centril added T-lang Relevant to the language team, which will review and decide on the RFC. A-macros Macro related proposals and issues A-syntax Syntax related proposals & ideas A-patterns Pattern matching related proposals & ideas A-control-flow Proposals relating to control flow. labels Mar 7, 2019
@Centril
Copy link
Contributor

Centril commented Mar 7, 2019

@petrochenkov That just supports or-patterns; but afaik you cannot generate match arms (pat (if expr?) => expr) today...?

@mcmah309
Copy link

mcmah309 commented Jul 23, 2024

This would be useful for this crate: https://github.com/mcmah309/error_set

Currently users have to do this if they want to handle disjointedness with a macro

let val = coerce!(setx => {
      Ok(val) => val,
      Err(SetX::X) => {}, // handle disjointedness
      { Err(SetX) => return Err(SetY) } // terminal coercion
  });

But this would be a lot better if it was possible

let val = match setx {
      Ok(val) => val,
      Err(SetX::X) => {}, // handle disjointedness
      coerce!(Err(SetX) => return Err(SetY)) // terminal coercion
  };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-control-flow Proposals relating to control flow. A-macros Macro related proposals and issues A-patterns Pattern matching related proposals & ideas A-syntax Syntax related proposals & ideas T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

4 participants