Skip to content

ICE due to invalid assignment in macro: illegal left-hand side expression / capacity overflow / unprintable span #26093

Closed
@theemathas

Description

@theemathas

Code:

macro_rules! not_an_lvalue {
    ($thing:expr) => {
        $thing = 42;
    }
}

fn main() {
    not_an_lvalue!(99);
}

playpen

Error on stable Rust:

<anon>:8:20: 3:20 error: illegal left-hand side expression [E0070]
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'capacity overflow', /home/rustbuild/src/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/option.rs:330

Error on nightly Rust:

<anon>:8:20: 3:20 error: illegal left-hand side expression [E0070]
(internal compiler error: unprintable span)
<anon>:1:1: 5:2 note: in expansion of not_an_lvalue!
<anon>:8:5: 8:24 note: expansion site
<anon>:8:20: 3:20 help: see the detailed explanation for E0070
error: aborting due to previous error

This also causes the same ICE:

macro_rules! not_an_lvalue {
    ($thing:expr) => {
        $thing = 42;
    }
}

fn foo() {}

fn main() {
    not_an_lvalue!(foo);
}

playpen

Possibly related issues: #24761, #25793, #25353, #25385

Metadata

Metadata

Assignees

No one assigned

    Labels

    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