Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

DiagnosticSpanLine pointing inside char boundary #59660

Closed
phansch opened this issue Apr 3, 2019 · 2 comments · Fixed by rust-lang/rustfix#167
Closed

DiagnosticSpanLine pointing inside char boundary #59660

phansch opened this issue Apr 3, 2019 · 2 comments · Fixed by rust-lang/rustfix#167
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-Unicode Area: Unicode C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@phansch
Copy link
Member

phansch commented Apr 3, 2019

A test from the rustc UI tests currently causes a crash when executed with rustfix:

Click to expand backtrace
thread 'everything' panicked at 'byte index 1 is not a char boundary; it is inside 'γ' (bytes 0..2) of `γ  //~ ERROR non-ascii idents are not fully supported`', src/libcore/str/mod.rs:2027:5
   0:     0x555eeaaef943 - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h3ea4e797e65a328d
                               at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1:     0x555eeaaeb6eb - std::sys_common::backtrace::_print::hf58574b7d5a741ab
                               at src/libstd/sys_common/backtrace.rs:71
   2:     0x555eeaaee5e6 - std::panicking::default_hook::{{closure}}::hed8b316a41353ca9
                               at src/libstd/sys_common/backtrace.rs:59
                               at src/libstd/panicking.rs:197
   3:     0x555eeaaee30e - std::panicking::default_hook::h8f4ba314e61c5eff
                               at src/libstd/panicking.rs:208
   4:     0x555eeaaeecef - std::panicking::rust_panic_with_hook::hde5d2bfa491b5add
                               at src/libstd/panicking.rs:474
   5:     0x555eeaaee871 - std::panicking::continue_panic_fmt::h928c357471014704
                               at src/libstd/panicking.rs:381
   6:     0x555eeaaee755 - rust_begin_unwind
                               at src/libstd/panicking.rs:308
   7:     0x555eeab09eac - core::panicking::panic_fmt::h5ab350f3b9a2b236
                               at src/libcore/panicking.rs:85
   8:     0x555eeab0b73f - core::str::slice_error_fail::h8551c49db625e656
                               at src/libcore/str/mod.rs:0
   9:     0x555eea8c2bff - core::str::traits::<impl core::slice::SliceIndex<str> for core::ops::range::Range<usize>>::index::{{closure}}::h2b84c0866fdd5130
                               at /rustc/0f88167f89fffe321590c5148f21b7d51d44388d/src/libcore/str/mod.rs:1751
  10:     0x555eea8c7a1f - core::option::Option<T>::unwrap_or_else::he9ebd301cf0dbcdb
                               at /rustc/0f88167f89fffe321590c5148f21b7d51d44388d/src/libcore/option.rs:386
  11:     0x555eea8c7095 - core::str::traits::<impl core::slice::SliceIndex<str> for core::ops::range::Range<usize>>::index::ha86fa6cbfda6a990
                               at /rustc/0f88167f89fffe321590c5148f21b7d51d44388d/src/libcore/str/mod.rs:1751
  12:     0x555eea8c2d80 - core::str::traits::<impl core::ops::index::Index<I> for str>::index::h12989e8413e52b49
                               at /rustc/0f88167f89fffe321590c5148f21b7d51d44388d/src/libcore/str/mod.rs:1616
  13:     0x555eea873b50 - <alloc::string::String as core::ops::index::Index<core::ops::range::Range<usize>>>::index::hc28f4c5a88ab385d
                               at /rustc/0f88167f89fffe321590c5148f21b7d51d44388d/src/liballoc/string.rs:1953
  14:     0x555eea87e464 - rustfix::parse_snippet::h40fa32a6f9ed0564
                               at src/lib.rs:110
  15:     0x555eea7ddc8f - rustfix::collect_suggestions::{{closure}}::h396f64ade2bb2873
                               at /home/phansch/code/rustfix/src/lib.rs:165

This is a trimmed down version of src/tests/ui/utf8_idents.rs which causes the crash in rustfix:

fn foo<
γ  //~ ERROR non-ascii idents are not fully supported
   //~^ WARN type parameter `γ` should have an upper camel case name
>() {}

pub fn main() {}

The DiagnosticSpanLine that rustfix receives looks like this:

DiagnosticSpanLine {
    text: "γ  //~ ERROR non-ascii idents are not fully supported",
    highlight_start: 1,
    highlight_end: 2
}

γ is 2 bytes long, which leads me to believe that this may not be a bug in rustfix, but somewhere in rustc, because highlight_end should be 3 in this case?

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints A-Unicode Area: Unicode C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 3, 2019
@estebank
Copy link
Contributor

estebank commented Apr 3, 2019

Digging a bit I believe that highlight_start and highlight_end weren't supposed to be interpreted as byte offsets but rather as character offsets. Couldn't rustfix interpret them that way?

@phansch
Copy link
Member Author

phansch commented Apr 4, 2019

Oh, you're right! It's even mentioned in the struct definition:

/// 1-based, character offset in self.text.

Thanks for taking a look. I will have a fix for rustfix ready later today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-Unicode Area: Unicode C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants