Skip to content

Self initialization doesn't work #248

Open

Description

@jrmuizel
struct list_head {
    struct list_head *next;
};

void f() {
        struct list_head list = { &list };
}

compiles to:

#[derive(Default)]
pub struct list_head {
    pub next: Value<Ptr<list_head>>,
}


pub fn f_0() {
    let list: Value<list_head> = Rc::new(RefCell::new(list_head {
        next: Rc::new(RefCell::new((list.as_pointer()))),
    }));
}

which fails to build with:

error[E0425]: cannot find value `list` in this scope
  --> src/main.rs:35:37
   |
35 |         next: Rc::new(RefCell::new((list.as_pointer()))),
   |                                     ^^^^ not found in this scope

Activity

  1. lucic71 commented on Oct 1, 2026

    @lucic71
    Contributor

    A similar issue appears in initializer lists that (implicitly) use this:

    struct S {
        S (int a, int b): a(0), b(a) {}
        int a;
        int b;
    };

    The initialiser of b uses this.a. We translate constructors as:

    let _this = S { a: 0, b: _this.a }

    Which fails with: cannot find _this in this scope

  2. lucic71 commented on Oct 7, 2026

    @lucic71
    Contributor

    This pattern also fails:

    struct S {
      S *this_ = this;
    }
  3. added a commit that references this issue on Nov 16, 2026
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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions