Skip to content

Crash with move || closure and self #20228

Closed
@simias

Description

@simias

The following code:

struct S;

impl S {
    fn foo(&self) {
        let _ = move || { self };
    }
}

fn main() {
}

Triggers an assertion in LLVM:

crash.rs:1:1: 1:10 warning: struct is never used: `S`, #[warn(dead_code)] on by default
crash.rs:1 struct S;
           ^~~~~~~~~
crash.rs:4:5: 6:6 warning: method is never used: `foo`, #[warn(dead_code)] on by default
crash.rs:4     fn foo(&self) {
crash.rs:5         let _ = move || { self };
crash.rs:6     }
rustc: /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/llvm/lib/IR/Instructions.cpp:1086: void llvm::StoreInst::AssertOK(): Assertion `getOperand(0)->getType() == cast<PointerType>(getOperand(1)->getType())->getElementType() && "Ptr must be a pointer to Val type!"' failed.

I get a slight variation if I change the code in the closure to call a member function instead:

struct S;

impl S {
    fn foo(&self) {
        let _ = move || { self.foo() };
    }
}

fn main() {
}

Gives:

crash.rs:1:1: 1:10 warning: struct is never used: `S`, #[warn(dead_code)] on by default
crash.rs:1 struct S;
           ^~~~~~~~~
crash.rs:4:5: 6:6 warning: method is never used: `foo`, #[warn(dead_code)] on by default
crash.rs:4     fn foo(&self) {
crash.rs:5         let _ = move || { self.foo() };
crash.rs:6     }
rustc: /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/llvm/lib/IR/Instructions.cpp:2522: static llvm::CastInst* llvm::CastInst::CreatePointerCast(llvm::Value*, llvm::Type*, const llvm::Twine&, llvm::Instruction*): Assertion `S->getType()->isPtrOrPtrVectorTy() && "Invalid cast"' failed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)I-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