Skip to content

ICE with nested macros #4650

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

Activity

  1. catamorphism commented on Apr 25, 2013

    @catamorphism
    Contributor

    Seems non-critical for 0.7. Nominating for milestone 5 (production-ready).

  2. graydon commented on May 2, 2013

    @graydon
    Contributor

    accepted for production ready

  3. emberian commented on Jun 24, 2013

    @emberian
    Contributor

    Updated test case:

    use std::util::with;
    use std::hashmap::HashMap;
    
    fn main() {
      let mut map = HashMap::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);
    }
    $ rustc foo.rs
    foo.rs:22:12: 22:15 error: internal compiler error: No variable registered for id 20
    foo.rs:22   foo!(def, def);
                          ^~~
    foo.rs:8:2: 12:4 note: in expansion of add_foo!
    foo.rs:16:6: 16:23 note: expansion site
    foo.rs:14:2: 19:4 note: in expansion of foo!
    foo.rs:22:2: 22:17 note: expansion site
    
  4. kud1ing commented on Aug 9, 2013

    @kud1ing

    I think the tag "A-macos" is unfortunate, since this is not Mac OS specific. Or is it?

  5. emberian commented on Aug 9, 2013

    @emberian
    Contributor

    @kud1ing good catch, someone probably mistook it for macros. It's been updated to A-mac-osx though, which should prevent that.

  6. msullivan commented on Aug 10, 2013

    @msullivan
    Contributor

    Still ICEs.

  7. alexcrichton commented on Sep 26, 2013

    @alexcrichton
    MemberAuthor

    Closed with what I believe was the renumbering of the AST. There's plenty of tests for this already present, so closing issue entirely.

  8. added a commit that references this issue on Nov 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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