Skip to content

Rustc crashes when parsing an ambiguous cast and compare #42954

Closed
@kstrafe

Description

@kstrafe

An unexpected compiler panic occurs when parsing a macro that casts without parentheses surrounding the cast.

I tried this code:

macro_rules! is_plainly_printable {
	($i:ident) => {
		$i as u32 < 0
	};
}

fn main() {
	let c = 'a';
	is_plainly_printable!(c);
}

I expected to see this happen:

error: `<` is interpreted as a start of generic arguments for `u32`, not a comparison
 --> src/main.rs:9:13
  |
9 | 	c as u32 < 0;
  | 	         - ^ interpreted as generic argument
  | 	         |
  | 	         not interpreted as comparison
  |
help: if you want to compare the casted value then write:
  | 	(c as u32) < 0;

Instead, this happened: the compiler panicked

Compiling compbug v0.1.0 (file:///home/kefin/stuf/docs/compbug)
Running `rustc --crate-name compbug src/main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=fa650156f9d48338 -C extra-filename=-fa650156f9d48338 --out-dir /home/kefin/stuf/docs/compbug/target/debug/deps -L dependency=/home/kefin/stuf/docs/compbug/target/debug/deps`
error: `<` is interpreted as a start of generic arguments for `u32`, not a comparison
 --> src/main.rs:3:15
  |
3 | 		$i as u32 < 0
  | 		          - ^ interpreted as generic argument
  | 		          |
  | 		          not interpreted as comparison
  |
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: rustc 1.20.0-nightly (f590a44ce 2017-06-27) running on x86_64-unknown-linux-gnu

thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: IllFormedSpan(Span { lo: BytePos(125), hi: BytePos(64), ctxt: #0 })', /checkout/src/libcore/result.rs:860
note: Run with `RUST_BACKTRACE=1` for a backtrace.

error: Could not compile `compbug`.

Caused by:
  process didn't exit successfully: `rustc --crate-name compbug src/main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=fa650156f9d48338 -C extra-filename=-fa650156f9d48338 --out-dir /home/kefin/stuf/docs/compbug/target/debug/deps -L dependency=/home/kefin/stuf/docs/compbug/target/debug/deps` (exit code: 101)

Meta

rustc --version --verbose:

rustc 1.20.0-nightly (f590a44ce 2017-06-27)
binary: rustc
commit-hash: f590a44ce61888c78b9044817d8b798db5cd2ffd
commit-date: 2017-06-27
host: x86_64-unknown-linux-gnu
release: 1.20.0-nightly
LLVM version: 4.0

Backtrace:

   Compiling compbug v0.1.0 (file:///home/kefin/stuf/docs/compbug)
     Running `rustc --crate-name compbug src/main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=fa650156f9d48338 -C extra-filename=-fa650156f9d48338 --out-dir /home/kefin/stuf/docs/compbug/target/debug/deps -L dependency=/home/kefin/stuf/docs/compbug/target/debug/deps`
error: `<` is interpreted as a start of generic arguments for `u32`, not a comparison
 --> src/main.rs:3:15
  |
3 | 		$i as u32 < 0
  | 		          - ^ interpreted as generic argument
  | 		          |
  | 		          not interpreted as comparison
  |
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: rustc 1.20.0-nightly (f590a44ce 2017-06-27) running on x86_64-unknown-linux-gnu

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: IllFormedSpan(Span { lo: BytePos(125), hi: BytePos(64), ctxt: #0 })', /checkout/src/libcore/result.rs:860
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:60
             at /checkout/src/libstd/panicking.rs:355
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:365
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:549
   5: std::panicking::begin_panic
             at /checkout/src/libstd/panicking.rs:511
   6: std::panicking::begin_panic_fmt
             at /checkout/src/libstd/panicking.rs:495
   7: rust_begin_unwind
             at /checkout/src/libstd/panicking.rs:471
   8: core::panicking::panic_fmt
             at /checkout/src/libcore/panicking.rs:71
   9: core::result::unwrap_failed
  10: <rustc_errors::emitter::EmitterWriter as rustc_errors::emitter::Emitter>::emit
  11: rustc_errors::diagnostic_builder::DiagnosticBuilder::emit
  12: syntax::parse::parser::Parser::parse_assoc_op_as
  13: syntax::parse::parser::Parser::parse_assoc_expr_with
  14: syntax::parse::parser::Parser::parse_stmt_without_recovery::{{closure}}
  15: syntax::parse::parser::Parser::parse_stmt_without_recovery
  16: syntax::parse::parser::Parser::parse_stmt_
  17: syntax::parse::parser::Parser::parse_full_stmt
  18: syntax::ext::expand::<impl syntax::parse::parser::Parser<'a>>::parse_expansion
  19: syntax::ext::tt::macro_rules::ParserAnyMacro::make
  20: syntax::ext::expand::<impl syntax::ext::base::MacResult for syntax::ext::tt::macro_rules::ParserAnyMacro<'a>>::make_stmts
  21: syntax::ext::expand::ExpansionKind::make_from
  22: syntax::ext::expand::MacroExpander::expand_bang_invoc
  23: syntax::ext::expand::MacroExpander::expand
  24: syntax::ext::expand::MacroExpander::expand_crate
  25: rustc_driver::driver::phase_2_configure_and_expand::{{closure}}
  26: rustc_driver::driver::phase_2_configure_and_expand
  27: rustc_driver::driver::compile_input
  28: rustc_driver::run_compiler

error: Could not compile `compbug`.

Caused by:
  process didn't exit successfully: `rustc --crate-name compbug src/main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=fa650156f9d48338 -C extra-filename=-fa650156f9d48338 --out-dir /home/kefin/stuf/docs/compbug/target/debug/deps -L dependency=/home/kefin/stuf/docs/compbug/target/debug/deps` (exit code: 101)

Metadata

Metadata

Assignees

Labels

I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions