Skip to content

The ability to remove the warning label name T shadows a label name that is already in scope #70496

Closed
@denisandroid

Description

@denisandroid

It was necessary to generate such code, everything works, but I get warning. The question is how to remove this warning if the “rust” does not give such an opportunity, or is there an error here?

Executable code:

macro_rules! gen_code {
    [$l:lifetime: $b:block, $b2: block $(,)?] => {
        $l: loop {
            $b
            break $l;
        }
        $l: loop {
            $b2
            break $l;
        }
    };
}

fn main() {
    gen_code! {
        'root:
        
        {
            println!("Block1");
        },
        {
            println!("Block2");
        },
        
    }
}

Output:

   Compiling playground v0.0.1 (/playground)
warning: label name `'root` shadows a label name that is already in scope
  --> src/main.rs:17:9
   |
17 |         'root:
   |         ^^^^^
   |         |
   |         first declared here
   |         lifetime 'root already in scope

    Finished dev [unoptimized + debuginfo] target(s) in 0.39s
     Running `target/debug/playground`

Standard Output

Block1
Block2

Play: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=28fa5504d1c601d272e5cef0f2b66cbc

Version:

rustc 1.43.0-nightly (58b834344 2020-02-05)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions