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

'error constructed but not emitted' when parsing const keyword #81806

Closed
ZhangZhuoSJTU opened this issue Feb 5, 2021 · 1 comment · Fixed by #81876
Closed

'error constructed but not emitted' when parsing const keyword #81806

ZhangZhuoSJTU opened this issue Feb 5, 2021 · 1 comment · Fixed by #81876
Assignees
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. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ZhangZhuoSJTU
Copy link

ZhangZhuoSJTU commented Feb 5, 2021

Code

trait t { const
impl

md5 of poc.rs: 7593012a00629a632a7b06982cbccb2f

The bug can be reproduced via rustc poc.rs

Meta

The bug is reproduced with nightly and beta versions, but not with stable version.

rustc --version --verbose:

rustc 1.51.0-nightly (4f4656d46 2021-02-04)
binary: rustc
commit-hash: 4f4656d46d84a488ae3df34b08f362d7071036a0
commit-date: 2021-02-04
host: x86_64-unknown-linux-gnu
release: 1.51.0-nightly
LLVM version: 11.0.1

rustc 1.50.0-beta.8 (1cd030396 2021-01-20)
binary: rustc
commit-hash: 1cd0303963629f317a08e7e52162ccca7232ae7f
commit-date: 2021-01-20
host: x86_64-unknown-linux-gnu
release: 1.50.0-beta.8

Error output

The output is from nightly version.

➜  playground rustc poc.rs
error: this file contains an unclosed delimiter
 --> out.rs:2:6
  |
1 | trait t { const
  |         - unclosed delimiter
2 | impl
  |      ^

error: internal compiler error: the following error was constructed but not emitted

error: expected identifier, found keyword `impl`
 --> out.rs:2:1
  |
2 | impl
  | ^^^^ expected identifier, found keyword
  |
help: you can escape reserved keywords to use them as identifiers
  |
2 | r#impl
  |

thread 'rustc' panicked at 'explicit panic', compiler/rustc_errors/src/diagnostic_builder.rs:460:13
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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.51.0-nightly (4f4656d46 2021-02-04) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
error: aborting due to 3 previous errors
Backtrace

➜  playground RURUST_BACKTRACE=1 rustc poc.rs
error: this file contains an unclosed delimiter
 --> out.rs:2:6
  |
1 | trait t { const
  |         - unclosed delimiter
2 | impl
  |      ^

error: internal compiler error: the following error was constructed but not emitted

error: expected identifier, found keyword `impl`
 --> out.rs:2:1
  |
2 | impl
  | ^^^^ expected identifier, found keyword
  |
help: you can escape reserved keywords to use them as identifiers
  |
2 | r#impl
  |

thread 'rustc' panicked at 'explicit panic', compiler/rustc_errors/src/diagnostic_builder.rs:460:13
stack backtrace:
   0: std::panicking::begin_panic
   1: <rustc_errors::diagnostic_builder::DiagnosticBuilder as core::ops::drop::Drop>::drop
   2: rustc_parse::parser::item::<impl rustc_parse::parser::Parser>::recover_const_impl
   3: rustc_parse::parser::item::<impl rustc_parse::parser::Parser>::parse_item_common_
   4: rustc_parse::parser::item::<impl rustc_parse::parser::Parser>::parse_item_common
   5: rustc_parse::parser::item::<impl rustc_parse::parser::Parser>::parse_assoc_item
   6: rustc_parse::parser::item::<impl rustc_parse::parser::Parser>::parse_item_common_
   7: rustc_parse::parser::item::<impl rustc_parse::parser::Parser>::parse_item_common
   8: rustc_parse::parser::item::<impl rustc_parse::parser::Parser>::parse_mod
   9: rustc_parse::parse_crate_from_file
  10: rustc_session::utils::<impl rustc_session::session::Session>::time
  11: rustc_interface::passes::parse
  12: rustc_interface::queries::Queries::parse
  13: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  14: rustc_span::with_source_map
  15: rustc_interface::interface::create_compiler_and_run
  16: rustc_span::with_session_globals
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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.51.0-nightly (4f4656d46 2021-02-04) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
error: aborting due to 3 previous errors

@ZhangZhuoSJTU ZhangZhuoSJTU added 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. labels Feb 5, 2021
@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 5, 2021
@jyn514 jyn514 changed the title Thread 'rustc' panicked at 'explicit panic' 'error constructed but not emitted' when parsing const keyword Feb 5, 2021
@jyn514 jyn514 added the A-parser Area: The parsing of Rust source code to an AST. label Feb 5, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Feb 7, 2021
@osa1
Copy link
Contributor

osa1 commented Feb 8, 2021

@rustbot claim

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Feb 9, 2021
parser: Fix panic in 'const impl' recovery

The panic happens when in recovery parsing a full `impl`
(`parse_item_impl`) fails and we drop the `DiagnosticBuilder` for the
recovery suggestion and return the `parse_item_impl` error.

We now raise the original error "expected identifier found `impl`" when
parsing the `impl` fails.

Note that the regression test is slightly simplified version of the
original repro in rust-lang#81806, to make the error output smaller and more
resilient to unrelated changes in parser error messages.

Fixes rust-lang#81806
@bors bors closed this as completed in 6eb1bd4 Feb 9, 2021
@apiraino apiraino added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 10, 2021
Mark-Simulacrum pushed a commit to Mark-Simulacrum/rust that referenced this issue Feb 13, 2021
The panic happens when in recovery parsing a full `impl`
(`parse_item_impl`) fails and we drop the `DiagnosticBuilder` for the
recovery suggestion and return the `parse_item_impl` error.

We now raise the original error "expected identifier found `impl`" when
parsing the `impl` fails.

Note that the regression test is slightly simplified version of the
original repro in rust-lang#81806, to make the error output smaller and more
resilient to unrelated changes in parser error messages.

Fixes rust-lang#81806
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. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority 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.

6 participants