Skip to content

ICE with bad macro: IllFormedSpan #39848

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
koivunej opened this issue Feb 15, 2017 · 6 comments
Closed

ICE with bad macro: IllFormedSpan #39848

koivunej opened this issue Feb 15, 2017 · 6 comments
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@koivunej
Copy link

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>

@koivunej
Copy link
Author

The smallest reproducing version I could find is:

macro_rules! get_opt {
    ($tgt:expr, $field:ident) => {
        if $tgt.has_$field() {}
    }
}
fn main() {
    get_opt!(bar, foo);
}

Could not find any single variable macro examples, but it appears ICE requires that has_ (or any other ident concatenation) happens on the method name side after the dot: if prefix_$tgt.$field() { ... } produces the same error as stable and beta.

@koivunej
Copy link
Author

koivunej commented Mar 10, 2017

Verified playpen link on rustc 1.17.0-nightly (b1e31766d 2017-03-03): no change.

@wirelyre
Copy link

wirelyre commented Apr 6, 2017

Here's a very different example that produces the same error:

macro_rules! a {
    () => (
        b!( () )
    );
}
macro_rules! b {
    ($expr:expr) => (
        if true $expr
    );
}

pub fn main() {
    a!();
}

The compiler does not panic if given

pub fn main() {
    b!( () );
}

which is what the original version expands to.

@koivunej
Copy link
Author

koivunej commented Apr 7, 2017

Checking the examples against todays stable, beta and nightly:

  • rustc 1.16.0 (30cf806ef 2017-03-10)
  • rustc 1.17.0-beta.3 (ca3d11832 2017-04-05)
  • rustc 1.18.0-nightly (91ae22a01 2017-04-05)

Just checked the original example through the playpen link, still ICE with nightly, same as with the shortened example.

A link to playpen with @wirelyre example: https://is.gd/F5YCru which fails with an error on stable, ICE on both beta and nightly.

The only change I can see is that now beta ICEs as well.

@wirelyre
Copy link

wirelyre commented Apr 8, 2017

This bug was introduced in a561ad8.

@frewsxcv frewsxcv added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jun 4, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
@wirelyre
Copy link

This bug was fixed in nightly-2017-05-03 (sometime between 777ee2079 and 6a5fc9eec).

topecongiro added a commit to topecongiro/rust that referenced this issue Dec 26, 2017
bors added a commit that referenced this issue Dec 27, 2017
Add tests to fixed ICEs

Closes #27078. Closes #27985. Closes #39848. Closes #42164.
Closes #42479. Closes #45662. Closes #45965. Closes #46152.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

4 participants