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

Strange behavior decl_macro + try_blocks + type_ascription #54455

Closed
kgv opened this issue Sep 22, 2018 · 2 comments
Closed

Strange behavior decl_macro + try_blocks + type_ascription #54455

kgv opened this issue Sep 22, 2018 · 2 comments
Labels
A-macros-2.0 Area: Declarative macros 2.0 (#39412) C-bug Category: This is a bug. F-try_blocks `#![feature(try_blocks)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kgv
Copy link

kgv commented Sep 22, 2018

First line in main function compiles with error, but second and third compiles without error.

#![allow(unused)]
#![feature(decl_macro)]
#![feature(try_blocks)]
#![feature(type_ascription)]

pub macro test_macro {
    () => {
        try {
            let mut exit_code = 0;
            if exit_code < 0 {
                Err(exit_code)?;
            }
            exit_code
        }: Result<usize, usize>
    }
}

fn main() {
    test_macro!(); // Err
    // test_macro!().unwrap(); // Ok
    // let t = test_macro!(); // Ok
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error: expected expression, found `:`
  --> src/main.rs:14:10
   |
14 |         }: Result<usize, usize>
   |          ^ expected expression
...
19 |     test_macro!(); // Err
   |     -------------- in this macro invocation

error: aborting due to previous error

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

@Centril
Copy link
Contributor

Centril commented Sep 23, 2018

cc #31436, #23416, #39412

@jonas-schievink jonas-schievink added A-macros-2.0 Area: Declarative macros 2.0 (#39412) C-bug Category: This is a bug. labels Jan 27, 2019
@jonas-schievink jonas-schievink added F-try_blocks `#![feature(try_blocks)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 6, 2019
@lolbinarycat
Copy link
Contributor

triage: type ascription has been removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros-2.0 Area: Declarative macros 2.0 (#39412) C-bug Category: This is a bug. F-try_blocks `#![feature(try_blocks)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants