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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

let_chains causes a compiler panic #82290

Closed
irevoire opened this issue Feb 19, 2021 · 3 comments 路 Fixed by #82308
Closed

let_chains causes a compiler panic #82290

irevoire opened this issue Feb 19, 2021 · 3 comments 路 Fixed by #82308
Labels
C-bug Category: This is a bug. F-let_chains `#![feature(let_chains)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) 鉂勶笍 P-medium Medium priority requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@irevoire
Copy link

irevoire commented Feb 19, 2021

Code

#![feature(str_split_once)]
#![feature(let_chains)]

fn main() {
    let mut bug = "lalacoollolo".to_string();
    if !bug.contains("馃敘") && (let Some((start, end)) = bug.split_once("1234")) {
        bug = format!("{}馃敘{}", start, end);
    }

    println!("{}", bug);
}

Meta

rustc --version --verbose:

rustc 1.52.0-nightly (8e54a2113 2021-02-13)
binary: rustc
commit-hash: 8e54a21139ae96a2aca3129100b057662e2799b9
commit-date: 2021-02-13
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1

Error output

thread 'rustc' panicked at 'expected `NodeId` to be lowered already for res Local(
    NodeId(28),
)', compiler/rustc_ast_lowering/src/lib.rs:714:17
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.52.0-nightly (8e54a2113 2021-02-13) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=3 -C embed-bitcode=no --crate-type bin

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

query stack during panic:
end of query stack
Backtrace

thread 'rustc' panicked at 'expected `NodeId` to be lowered already for res Local(
    NodeId(28),
)', compiler/rustc_ast_lowering/src/lib.rs:714:17
stack backtrace:
   0: rust_begin_unwind
             at /rustc/8e54a21139ae96a2aca3129100b057662e2799b9/library/std/src/panicking.rs:493:5
   1: std::panicking::begin_panic_fmt
             at /rustc/8e54a21139ae96a2aca3129100b057662e2799b9/library/std/src/panicking.rs:435:5
   2: rustc_ast_lowering::LoweringContext::lower_node_id_generic
   3: rustc_ast_lowering::path::<impl rustc_ast_lowering::LoweringContext>::lower_qpath
   4: rustc_data_structures::stack::ensure_sufficient_stack
   5: rustc_data_structures::stack::ensure_sufficient_stack
   6: <smallvec::SmallVec<A> as core::iter::traits::collect::Extend<<A as smallvec::Array>::Item>>::extend
   7: rustc_ast_lowering::expr::<impl rustc_ast_lowering::LoweringContext>::lower_exprs
   8: rustc_data_structures::stack::ensure_sufficient_stack
   9: rustc_data_structures::stack::ensure_sufficient_stack
  10: rustc_data_structures::stack::ensure_sufficient_stack
  11: <smallvec::SmallVec<A> as core::iter::traits::collect::Extend<<A as smallvec::Array>::Item>>::extend
  12: rustc_ast_lowering::expr::<impl rustc_ast_lowering::LoweringContext>::lower_exprs
  13: rustc_data_structures::stack::ensure_sufficient_stack
  14: <smallvec::SmallVec<A> as core::iter::traits::collect::Extend<<A as smallvec::Array>::Item>>::extend
  15: rustc_ast_lowering::expr::<impl rustc_ast_lowering::LoweringContext>::lower_exprs
  16: rustc_data_structures::stack::ensure_sufficient_stack
  17: rustc_ast_lowering::LoweringContext::lower_stmt
  18: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
  19: <core::iter::adapters::flatten::Flatten<I> as core::iter::traits::iterator::Iterator>::next
  20: <smallvec::SmallVec<A> as core::iter::traits::collect::Extend<<A as smallvec::Array>::Item>>::extend
  21: rustc_arena::cold_path
  22: rustc_ast_lowering::LoweringContext::lower_block
  23: rustc_data_structures::stack::ensure_sufficient_stack
  24: rustc_ast_lowering::expr::<impl rustc_ast_lowering::LoweringContext>::lower_expr_assign
  25: rustc_data_structures::stack::ensure_sufficient_stack
  26: rustc_ast_lowering::LoweringContext::lower_stmt
  27: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
  28: <core::iter::adapters::flatten::Flatten<I> as core::iter::traits::iterator::Iterator>::next
  29: <smallvec::SmallVec<A> as core::iter::traits::collect::Extend<<A as smallvec::Array>::Item>>::extend
  30: rustc_arena::cold_path
  31: rustc_ast_lowering::expr::<impl rustc_ast_lowering::LoweringContext>::lower_expr_if
  32: rustc_data_structures::stack::ensure_sufficient_stack
  33: rustc_ast_lowering::LoweringContext::lower_stmt
  34: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
  35: <core::iter::adapters::flatten::Flatten<I> as core::iter::traits::iterator::Iterator>::next
  36: <smallvec::SmallVec<A> as core::iter::traits::collect::Extend<<A as smallvec::Array>::Item>>::extend
  37: rustc_arena::cold_path
  38: rustc_ast_lowering::item::<impl rustc_ast_lowering::LoweringContext>::lower_fn_body_block
  39: rustc_ast_lowering::item::<impl rustc_ast_lowering::LoweringContext>::lower_maybe_async_body
  40: rustc_ast_lowering::item::<impl rustc_ast_lowering::LoweringContext>::lower_item
  41: rustc_ast_lowering::LoweringContext::with_hir_id_owner
  42: <rustc_ast_lowering::item::ItemLowerer as rustc_ast::visit::Visitor>::visit_mod
  43: rustc_ast_lowering::lower_crate
  44: rustc_interface::passes::BoxedResolver::access::{{closure}}
  45: rustc_interface::passes::configure_and_expand::{{closure}}
  46: rustc_interface::queries::Queries::lower_to_hir
  47: rustc_interface::queries::Queries::global_ctxt
  48: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  49: rustc_span::with_source_map
  50: scoped_tls::ScopedKey<T>::set
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.52.0-nightly (8e54a2113 2021-02-13) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -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 `bug`

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

I made a small git repo to reproduce the bug here

@irevoire irevoire 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 19, 2021
@jyn514
Copy link
Member

jyn514 commented Feb 19, 2021

MCVE (playground):

#![feature(let_chains)]

fn main() {
    if true && let x = 1 {
        let _ = x;
    }
}

@jyn514 jyn514 added F-let_chains `#![feature(let_chains)]` requires-nightly This issue requires a nightly compiler in some way. labels Feb 19, 2021
@jyn514 jyn514 changed the title str_split_once + let_chains cause compiler panic let_chains causes a compiler panic Feb 19, 2021
@osa1
Copy link
Contributor

osa1 commented Feb 19, 2021

Probably a duplicate of #82250.

@estebank
Copy link
Contributor

I think I found the problem, lowering not being done in source order would cause this. The block of the then expression was being lowered before the condition, leading to the node corresponding to the x pattern not being populated when expected.

@jyn514 jyn514 added the P-medium Medium priority label Feb 20, 2021
fanninpm added a commit to fanninpm/glacier that referenced this issue Feb 20, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Feb 21, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Feb 23, 2021
Lower condition of `if` expression before it's "then" block

Fix rust-lang#82290, fix rust-lang#82250.
@bors bors closed this as completed in f0637e4 Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-let_chains `#![feature(let_chains)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) 鉂勶笍 P-medium Medium priority requires-nightly This issue requires a nightly compiler in some way. 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.

5 participants