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

in comment cause unexpected rustc panic #61226

Closed
dduan opened this issue May 27, 2019 · 11 comments · Fixed by #63508
Closed

in comment cause unexpected rustc panic #61226

dduan opened this issue May 27, 2019 · 11 comments · Fixed by #63508
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name resolution A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dduan
Copy link

dduan commented May 27, 2019

When I used the character in comment, combined with some (invalid) code preceding it, the compiler panicked.

I tried this code:

struct X {}
fn f() {
    vec![X]; //…
}

I expected to see this happen: rustc compiles this code.

Instead, this happened: rustc panicked with the following output

thread 'rustc' panicked at 'byte index 38 is not a char boundary; it is inside '…' (bytes 36..39) of `struct X {}
fn f() {
    vec![X]; //…
}
`', src/libcore/str/mod.rs:2027: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.35.0 (3c235d560 2019-05-20) running on x86_64-apple-darwin

Meta

rustc --version --verbose:

rustc 1.35.0 (3c235d560 2019-05-20)
binary: rustc
commit-hash: 3c235d5600393dfe6c36eeed34042efad8d4f26e
commit-date: 2019-05-20
host: x86_64-apple-darwin
release: 1.35.0
LLVM version: 8.0

Backtrace:

stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::_print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::continue_panic_fmt
   7: rust_begin_unwind
   8: core::panicking::panic_fmt
   9: core::str::slice_error_fail
  10: core::str::traits::<impl core::slice::SliceIndex<str> for core::ops::range::Range<usize>>::index::{{closure}}
  11: syntax::source_map::SourceMap::span_to_snippet
  12: rustc_resolve::error_reporting::<impl rustc_resolve::Resolver>::smart_resolve_report_errors
  13: rustc_resolve::Resolver::smart_resolve_path_fragment::{{closure}}
  14: rustc_resolve::Resolver::smart_resolve_path_fragment
  15: rustc_resolve::Resolver::smart_resolve_path
  16: rustc_resolve::Resolver::resolve_expr
  17: syntax::visit::walk_expr
  18: rustc_resolve::Resolver::resolve_expr
  19: rustc_resolve::Resolver::resolve_expr
  20: rustc_resolve::Resolver::resolve_expr
  21: <rustc_resolve::Resolver as syntax::visit::Visitor>::visit_block
  22: <rustc_resolve::Resolver as syntax::visit::Visitor>::visit_fn
  23: syntax::visit::walk_item
  24: rustc_resolve::Resolver::resolve_item
  25: rustc_resolve::Resolver::resolve_crate
  26: rustc::util::common::time
  27: rustc_interface::passes::configure_and_expand_inner
  28: rustc_interface::passes::configure_and_expand::{{closure}}
  29: rustc_data_structures::box_region::PinnedGenerator<I,A,R>::new
  30: rustc_interface::passes::configure_and_expand
  31: rustc_interface::queries::Query<T>::compute
  32: rustc_interface::queries::Query<T>::compute
  33: rustc_interface::queries::Query<T>::compute
  34: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::prepare_outputs
  35: rustc_interface::interface::run_compiler_in_existing_thread_pool
  36: std::thread::local::LocalKey<T>::with
  37: scoped_tls::ScopedKey<T>::set
  38: syntax::with_globals
@Centril Centril added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-stable Performance or correctness regression from one stable version to another. A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-resolve Area: Name resolution labels May 27, 2019
@Centril
Copy link
Contributor

Centril commented May 27, 2019

Regressed in 1.34.0. Used to be:

error[E0423]: expected value, found struct `X`
 --> <source>:3:10
  |
3 |     vec![X]; //…
  |          ^
  |          |
  |          did you mean `X { /* fields */ }`?
  |          help: a function with a similar name exists: `f`

error: aborting due to previous error

@Centril
Copy link
Contributor

Centril commented May 27, 2019

cc @petrochenkov @estebank

@oli-obk
Copy link
Contributor

oli-obk commented May 27, 2019

Miminized:

struct X {}
fn f() {
    X; //…
}

Probably some span handcrafting?

@petrochenkov
Copy link
Contributor

Probably some span handcrafting?

+1

@ehuss
Copy link
Contributor

ehuss commented May 29, 2019

I was idly curious, so I took a brief look at this. The diagnostic that triggers this was introduced in #57725, but I don't think it is responsible for the error (it's just stepping through characters looking for a closing brace). There is some strange math in SourceMap::next_point (introduced in #47420). It oscillates between zero-length and 1+ length spans as it is stepping over characters. When it hits a multi-byte character, it returns an invalid span. Example:

//\xe2\x80\xa6

Starting with a span of (0,1), using next_point would result in (1,1), then (1,2), then (2,2), then (2,4). That last one slices into the middle of the multi-byte character (because of width - 1, where width is 3), causing a panic.

I'm not familiar enough with this stuff to say how it should behave. It seems like next_point is being used for two different purposes (getting the next zero-length span, and getting the "next" character), and it's not clear to me what the behavior should be since it is used in a variety of places. I don't think it can be changed to always return zero-length spans, and it can't be changed to always return non-zero length spans. Perhaps there should be two different functions?

@pnkfelix
Copy link
Member

pnkfelix commented Jun 6, 2019

triage: P-medium, removing nomination; the ICE to me appears to include enough information for a user to identify the offending character and work-around the problem (namely by getting rid of the character).

I do agree with @ehuss that there should probably be two distinct functions corresponding to the two distinct purposes that they identified for the current callers of SourceMap::next_point.

@pnkfelix pnkfelix added E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. P-medium Medium priority and removed I-nominated E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. labels Jun 6, 2019
@jonas-schievink jonas-schievink added the C-bug Category: This is a bug. label Aug 6, 2019
@jonas-schievink
Copy link
Contributor

More test cases have been brought up in #63444

@estebank estebank self-assigned this Aug 13, 2019
Centril added a commit to Centril/rust that referenced this issue Aug 14, 2019
Do not ICE when synthesizing spans falling inside unicode chars

Fix rust-lang#61226.
@miikkas
Copy link

miikkas commented Aug 15, 2019

I guess this is the same bug, but the examples I've seen here concern non-ASCII characters in comments. I'm getting a similar rustc panic from an erroneous code without comments:

main.rs:

struct TestStruct {
    my_str: String
}

fn main() {
    let x = TestStruct("ä");
}

Compilation attempt:

thread 'rustc' panicked at 'byte index 79 is not a char boundary; it is inside 'ä' (bytes 78..80) of `struct TestStruct {
    my_str: String
}

fn main() {
    let x = TestStruct("ä");
}
`', src/libcore/str/mod.rs:2034: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.37.0 (eae3437df 2019-08-13) running on x86_64-unknown-linux-gnu

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 `structs-1`.

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

@Centril
Copy link
Contributor

Centril commented Aug 15, 2019

@miikkas Please file a new issue and reference this one.

@ehuss
Copy link
Contributor

ehuss commented Aug 15, 2019

note: rustc 1.37.0 (eae3437 2019-08-13) running on x86_64-unknown-linux-gnu

I think it's fixed, try nightly-2019-08-14.

@estebank
Copy link
Contributor

@miikkas @ehuss confirmed fixed by #63508.

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-resolve Area: Name resolution A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. 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.

9 participants