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

Rustc panics with comments with non-ascii characters after an error #63444

Closed
Goncalerta opened this issue Aug 10, 2019 · 3 comments
Closed

Rustc panics with comments with non-ascii characters after an error #63444

Goncalerta opened this issue Aug 10, 2019 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Goncalerta
Copy link

Running this on playground:

struct A {}

fn main() {
    let a = A; // é
}

Panics rustc:

   Compiling playground v0.0.1 (/playground)
thread 'rustc' panicked at 'byte index 44 is not a char boundary; it is inside 'é' (bytes 43..45) of `struct A {}

fn main() {
    let a = A; // é
}
`', 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.36.0 (a53f9df32 2019-07-03) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin

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

error: Could not compile `playground`.

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

Surpressing the comment:

struct A {}

fn main() {
    let a = A;
}

Makes it fail to compile as intended (without crashing):

   Compiling playground v0.0.1 (/playground)
error[E0423]: expected value, found struct `A`
 --> src/main.rs:4:13
  |
4 |     let a = A;
  |             ^ did you mean `A { /* fields */ }`?
help: possible better candidates are found in other modules, you can import them into scope
  |
1 | use futures::future::Either::A;
  |
1 | use tokio::prelude::future::Either::A;
  |

error: aborting due to previous error

For more information about this error, try `rustc --explain E0423`.
error: Could not compile `playground`.

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

Removing the line that does not compile:

struct A { }

fn main() {
    // é 
}

Also prevents panicing.

   Compiling playground v0.0.1 (/playground)
warning: struct is never constructed: `A`
 --> src/main.rs:1:1
  |
1 | struct A { }
  | ^^^^^^^^
  |
  = note: #[warn(dead_code)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 0.39s
     Running `target/debug/playground`

// é can be placed in a lot of places and still behave correctly:

struct A { 
    // é 
}
// é
fn main() {
    // é 
    let _ = 0; // é 
    let // é
    _ // é
    = // é
    A;
    let _ = 0;
} // é

But it can't be after the A if it is in the same block as A is:

struct A {}

fn main() {
   let _ = 0;
   let _ = A // é 
   ; // é 
   let _ = 0; // é 
}

Any of those three comments alone would trigger a rustc panic.

NOTE: // é was an arbitrary choice. I believe this happens with most (if not all) non-ascii characters.

@Goncalerta
Copy link
Author

Note that this won't panic:
(removed ;)

struct A {}

fn main() {
    let a = A//é 
}

Nor will this:
(é appears after at least 52 characters after A (counting //))

struct A {}

fn main() {
    let a = A//34567890123456789012345678901234567890123456789012é 
    ;
}

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 10, 2019
@ehuss
Copy link
Contributor

ehuss commented Aug 10, 2019

I believe this is a duplicate of #61226.

@jonas-schievink
Copy link
Contributor

Yep, looks like it. Closing.

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-parser Area: The parsing of Rust source code to an AST. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants