Skip to content

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1169:9 #93705

Closed
@rik-bosch

Description

@rik-bosch

Code

enum Direction {
    Up,
    Down,
    Left,
    Right,
}

struct Vector2 {
    x: i32,
    y: i32,
}

impl Vector2 {
    fn move_in_dir(&self, dir: Direction, length: i32) -> Vector2 {
        match dir {
            Direction::Up => {
                Vector2 { x: self.x, y: self.y - length }
            }
            Direction::Down => {
                Vector2 { x: self.x, y: self.y + length }
            }
            Direction::Left => {
                Vector2 { x: self.x - length, y: self.y }
            }
            Direction::Right => {
                Vector2 { x: self.x + length, y: self.y }
            }
        }
    }
}

struct Model {
    block_pos: Vector2,
    running: bool,
}

enum Msg {
    MoveBlock(Direction),
    Quit
}

impl Model {
    fn update(&self, msg: Msg) -> Model {
        match msg {
            Msg::MoveBlock(dir) => {
                Model { block_pos: self.block_pos.move_in_dir(dir, 1), ..self.clone() }
            }
            Msg::Quit => {
                Model { running: false, ..self.clone() }
            }
        }
    }
}

Meta

rustc --version --verbose:

rustc 1.58.1
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-apple-darwin
release: 1.58.1
LLVM version: 13.0.0

Error output

error: internal compiler error: compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs:319:25: while adjusting Expr { hir_id: HirId { owner: DefId(0:47 ~ tetrust[1848]::{impl#1}::update), local_id: 14 }, kind: Path(Resolved(None, Path { span: src/main.rs:62:74: 62:78 (#0), res: Local(HirId { owner: DefId(0:47 ~ tetrust[1848]::{impl#1}::update), local_id: 2 }), segments: [PathSegment { ident: self#0, hir_id: Some(HirId { owner: DefId(0:47 ~ tetrust[1848]::{impl#1}::update), local_id: 13 }), res: Some(Local(HirId { owner: DefId(0:47 ~ tetrust[1848]::{impl#1}::update), local_id: 2 })), args: None, infer_args: true }] })), span: src/main.rs:62:74: 62:78 (#0) }, can't compose [Borrow(Ref('_#2r, Not)) -> &&Model] and [Borrow(Ref('_#6r, Not)) -> &&Model]

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1169:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.58.1 running on x86_64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [typeck] type-checking `<impl at src/main.rs:58:1: 69:2>::update`
#1 [typeck_item_bodies] type-checking all item bodies
end of query stack
error: could not compile `tetrust`
Backtrace

<backtrace>

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions