Skip to content

ICE with nested macros #4650

Closed
Closed
@alexcrichton

Description

@alexcrichton

This program:

use core::util::with;
use core::hashmap::linear::LinearMap;

fn main() {
  let mut map = LinearMap::new();
  map.insert(1, 1);

  macro_rules! add_foo(
    ($a1:expr, $b1:expr) => ({
      map.find(&$a1).map(|&m| *m + $b1);
    })
  );

  macro_rules! foo(
    ($a:expr, $b:expr) => ({
      add_foo!($a, $b);
      add_foo!($b, $a);
    })
  );

  let def = 1;
  foo!(def, def);
}

fail with:

$ rustc --test bug2.rs
bug2.rs:22:12: 22:15 error: internal compiler error: No variable registered for id 25
bug2.rs:22   foo!(def, def);
                       ^~~
bug2.rs:8:2: 12:4 note: in expansion of add_foo!
bug2.rs:16:6: 16:23 note: expansion site
bug2.rs:14:2: 19:4 note: in expansion of foo!
bug2.rs:22:2: 22:17 note: expansion site

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-syntaxextArea: Syntax extensionsI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions