Skip to content

ICE with bad macro: IllFormedSpan #39848

Closed
@koivunej

Description

@koivunej

Tried to add a helper macro to work with rust-protobuf generated structs. The macro itself is illegal without concat_idents but it ICEs either way with latest nightly.

I tried this code (playpen):

struct Bar {
    foo: Option<String>
}

impl Bar {
    fn has_foo(&self) -> bool { self.foo.is_some() }
    fn get_foo(&self) -> &str { self.foo.unwrap_or("") }
}

macro_rules! get_opt {
    ($tgt:expr, $field:ident) => {
        if $tgt.has_$field() {
            Some($tgt.get_$field().clone())
        } else {
            None
        }
    }
}

fn main() {
    let bar = Bar { foo: Some("asdf".to_string()) };
    let x = get_opt!(bar, foo);
}

I expected this to see this happen: Current stable 1.15.1 reports this as a rather newbie-unfriendly error:

rustc 1.15.1 (021bd294c 2017-02-08)
error: expected `{`, found `foo`
  --> <anon>:22:27
   |
22 |     let x = get_opt!(bar, foo);
   |                           ^^^
   |
help: try placing this code inside a block
  --> <anon>:22:27
   |
22 |     let x = get_opt!(bar, foo);
   |                           ^

Same error is reported by play.rust-lang.org 1.16.0-beta.1 (5276ba72e 2017-01-31).

Instead, this happened: With 1.17.0-nightly (956e2bcba 2017-02-12)

thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: IllFormedSpan(Span { lo: BytePos(441), hi: BytePos(250), expn_id: ExpnId(4294967295) })', /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libcore/result.rs:860

Meta

rustc --version --verbose: For the ICE:

rustc 1.17.0-nightly (956e2bcba 2017-02-12)
binary: rustc
commit-hash: 956e2bcbaa00c05e051718b1375375915064f1c3
commit-date: 2017-02-12
host: x86_64-unknown-linux-gnu
release: 1.17.0-nightly
LLVM version: 3.9
Full output with RUST_BACKTRACE=1

thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: IllFormedSpan(Span { lo: BytePos(441), hi: BytePos(250), expn_id: ExpnId(4294967295) })', /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libcore/result.rs:860
stack backtrace:
   1:     0x7ffbf3784c6c - std::sys::imp::backtrace::tracing::imp::write::h55f5b644254d8997
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:42
   2:     0x7ffbf379325e - std::panicking::default_hook::{{closure}}::h5341ac454af9dec5
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:351
   3:     0x7ffbf3792e03 - std::panicking::default_hook::h93374761c3362d10
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:361
   4:     0x7ffbf37936fb - std::panicking::rust_panic_with_hook::h0c50036d8a952120
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:545
   5:     0x7ffbf3793544 - std::panicking::begin_panic::h549a5cdf22ed84a1
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:507
   6:     0x7ffbf37934b9 - std::panicking::begin_panic_fmt::h1e2376a100034ec9
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:491
   7:     0x7ffbf3793447 - rust_begin_unwind
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:467
   8:     0x7ffbf37d096d - core::panicking::panic_fmt::hfaaf47fca562bd04
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libcore/panicking.rs:69
   9:     0x7ffbebd98d79 - core::result::unwrap_failed::h7adbca4f72b882fb
  10:     0x7ffbebd9f7e6 - <rustc_errors::emitter::EmitterWriter as rustc_errors::emitter::Emitter>::emit::hddc883d124bb3e50
  11:     0x7ffbebd9db6a - rustc_errors::diagnostic_builder::DiagnosticBuilder::emit::had59d55435caff78
  12:     0x7ffbec43bcef - syntax::ext::tt::macro_rules::ParserAnyMacro::make::h774ae72c0d822ee0
  13:     0x7ffbec46b91e - syntax::ext::expand::<impl syntax::ext::base::MacResult for syntax::ext::tt::macro_rules::ParserAnyMacro<'a>>::make_expr::hb9a140133a69c891
  14:     0x7ffbec45c79d - syntax::ext::expand::ExpansionKind::make_from::h503071c3523d137e
  15:     0x7ffbec410ca1 - syntax::ext::expand::MacroExpander::expand_invoc::h8c740b40c25e30d1
  16:     0x7ffbec40b62f - syntax::ext::expand::MacroExpander::expand::h32c0cdf50a69c606
  17:     0x7ffbec409f15 - syntax::ext::expand::MacroExpander::expand_crate::h1c8ecd75edc55074
  18:     0x7ffbf3b1f5bc - rustc_driver::driver::phase_2_configure_and_expand::{{closure}}::h1399e5c1d9ed880b
  19:     0x7ffbf3b16a95 - rustc_driver::driver::phase_2_configure_and_expand::h56d98b82e0728ce5
  20:     0x7ffbf3b0f6aa - rustc_driver::driver::compile_input::hd9baec2c0523bb60
  21:     0x7ffbf3b5bd44 - rustc_driver::run_compiler::h9e5a091222716caf
  22:     0x7ffbf3a6807b - std::panicking::try::do_call::h757c674b34a8850d
  23:     0x7ffbf379c53a - __rust_maybe_catch_panic
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libpanic_unwind/lib.rs:98
  24:     0x7ffbf3a90432 - <F as alloc::boxed::FnBox<A>>::call_box::h55ee922c166804f9
  25:     0x7ffbf37920b4 - std::sys::imp::thread::Thread::new::thread_start::ha75da433220e7c63
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/liballoc/boxed.rs:640
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys_common/thread.rs:21
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys/unix/thread.rs:84
  26:     0x7ffbeb5426b9 - start_thread
  27:     0x7ffbf344782c - clone
  28:                0x0 - <unknown>

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.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