rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.93k stars 12.78k forks source link

Extra umlaut causes error in rustc 1.42.0-nightly #68000

Closed apexys closed 4 years ago

apexys commented 4 years ago

Hi everyone,

I accidentally mistyped on a german keyboard and entered an additional ö-character after a Vec-declaration. This apparently causes an internal compiler error.

I tried this code:

pub struct TestStruct{
    pub test: Vec<int>ö
}

fn main() {
    println!("Hello, world!");
}

and ran cargo build.

I expected to see this happen:

Compiler complains about an extra character at the end of the definition

Instead, this happened:

 > cargo build
   Compiling umlaut v0.1.0 (C:\Users\vbuck\Desktop\umlaut)
thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: IllFormedSpan(Span { lo: BytePos(45), hi: BytePos(46), ctxt: #0 })', src\libcore\result.rs:1192:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

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.42.0-nightly (859764425 2020-01-07) running on x86_64-pc-windows-msvc

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

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

error: could not compile `umlaut`.

To learn more, run the command again with --verbose.

Meta

rustc --version --verbose:

> rustc --version --verbose
rustc 1.42.0-nightly (859764425 2020-01-07)
binary: rustc
commit-hash: 85976442558bf2d09cec3aa49c9c9ba86fb15c1f
commit-date: 2020-01-07
host: x86_64-pc-windows-msvc
release: 1.42.0-nightly
LLVM version: 9.0

Backtrace:

> $Env:RUST_BACKTRACE=1
PS C:\Users\vbuck\Desktop\umlaut> cargo build --verbose
   Compiling umlaut v0.1.0 (C:\Users\vbuck\Desktop\umlaut)
     Running `rustc --crate-name umlaut --edition=2018 'src\main.rs' --error-format=json --json=diagnostic-rendered-ansi
--crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=d3bb206b8e2e3b83 --out-dir 'C:\Users\vbuck\Desktop\umlaut\target\debug\deps' -C 'incremental=C:\Users\vbuck\Desktop\umlaut\target\debug\incremental' -L 'dependency=C:\Users\vbuck\Desktop\umlaut\target\debug\deps'`
thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: IllFormedSpan(Span { lo: BytePos(45), hi: BytePos(46), ctxt: #0 })', src\libcore\result.rs:1192:5
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: <std::io::IoSlice as core::fmt::Debug>::fmt
   3: std::panicking::take_hook
   4: std::panicking::take_hook
   5: rustc_driver::report_ice
   6: std::panicking::rust_panic_with_hook
   7: rust_begin_unwind
   8: core::panicking::panic_fmt
   9: core::result::unwrap_failed
  10: rustc_errors::emitter::is_case_difference
  11: rustc_errors::emitter::HumanReadableErrorType::new_emitter
  12: <rustc_errors::emitter::EmitterWriter as rustc_errors::emitter::Emitter>::emit_diagnostic
  13: <rustc_errors::json::JsonEmitter as rustc_errors::emitter::Emitter>::emit_diagnostic
  14: rustc_errors::HandlerInner::emit_diagnostic
  15: rustc_errors::diagnostic_builder::DiagnosticBuilder::emit
  16: rustc_parse::parser::item::<impl rustc_parse::parser::Parser>::parse_foreign_item
  17: rustc_parse::parser::item::<impl rustc_parse::parser::Parser>::parse_item
  18: rustc_parse::parser::item::<impl rustc_parse::parser::Parser>::parse_item
  19: rustc_parse::parser::item::<impl rustc_parse::parser::Parser>::parse_item
  20: rustc_parse::parser::module::<impl rustc_parse::parser::Parser>::parse_crate_mod
  21: rustc_parse::parser::module::<impl rustc_parse::parser::Parser>::parse_crate_mod
  22: rustc_parse::parse_crate_from_file
  23: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::compile
  24: rustc_interface::callbacks::setup_callbacks
  25: rustc_interface::queries::Queries::parse
  26: rustc_driver::pretty::print_after_hir_lowering
  27: <rustc_span::symbol::SymbolStr as core::fmt::Display>::fmt
  28: <rustc_driver::Compilation as core::fmt::Debug>::fmt
  29: <env_logger::filter::inner::Filter as core::fmt::Display>::fmt
  30: _rust_maybe_catch_panic
  31: rustc_driver::pretty::print_after_hir_lowering
  32: ZN244_$LT$std..error..$LT$impl$u20$core..convert..From$LT$alloc..string..String$GT$$u20$for$u20$alloc..boxed..Box$LT$dyn$u20$std..error..Error$u2b$core..marker..Send$u2b$core..marker..Sync$GT$$GT$..from..StringError$u20$as$u20$core..fmt..Display$GT$3fmt17
  33: std::sys::windows::thread::Thread::new
  34: BaseThreadInitThunk
  35: RtlUserThreadStart
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.42.0-nightly (859764425 2020-01-07) running on x86_64-pc-windows-msvc

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

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

query stack during panic:
end of query stack
error: could not compile `umlaut`.

Caused by:
  process didn't exit successfully: `rustc --crate-name umlaut --edition=2018 'src\main.rs' --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=d3bb206b8e2e3b83 --out-dir 'C:\Users\vbuck\Desktop\umlaut\target\debug\deps' -C 'incremental=C:\Users\vbuck\Desktop\umlaut\target\debug\incremental' -L 'dependency=C:\Users\vbuck\Desktop\umlaut\target\debug\deps'` (exit code: 101)
apexys commented 4 years ago

Apparently that happens in stable as well https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=d738669296f02c31dc5fe0a7b560d504

csmoe commented 4 years ago

cc @estebank https://github.com/rust-lang/rust/blob/f48e576756cd0c360e5522974fc8d5867b439092/src/librustc_errors/emitter.rs#L2098

KamilaBorowska commented 4 years ago

This started to happen in Rust 1.28 (this properly errors out in Rust 1.27).

If I write the following:

struct TestStruct{
    test: Vec<i32>zöz
}

It can be noticed the spans are different.

In Rust 1.27.1, I get this:

error: expected `,`, or `}`, found `zöz`
 --> <source>:2:19
  |
2 |     test: Vec<i32>zöz
  |                   ^^^
  |
  = help: struct fields should be separated by commas

Meanwhile in Rust 1.28, I get this:

error: expected `,`, or `}`, found `zöz`
 --> <source>:2:19
  |
2 |     test: Vec<i32>zöz
  |                   ^ help: try adding a comma: `,`

Note that it tries to point out the first character. This may suggest addition of 1 byte instead of 1 character somewhere.

is_case_difference was introduced much later than Rust 1.28, I don't think it's a cause, rather, it encountered an invalid span and exploded, while the actual cause is somewhere else (my guess is https://github.com/rust-lang/rust/blob/9e6fb538f9254884ca9f958fdce413d6c3f2016c/src/librustc_parse/parser/item.rs#L1493, but I don't know enough about Rust internals).

estebank commented 4 years ago

The bug is in next_point, where we must use find_width_of_character_at_span correctly and somehow we aren't.

pnkfelix commented 4 years ago

triage: P-high, removing I-nominated label.