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

if let compound statement #83504

Closed
dfarnham opened this issue Mar 26, 2021 · 4 comments
Closed

if let compound statement #83504

dfarnham opened this issue Mar 26, 2021 · 4 comments
Labels
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

@dfarnham
Copy link

Code

fn main() {
    let jobj = json::parse(r#"{ "config": [ { "label": { "active": true } } ] }"#).unwrap();

    for obj in jobj["config"].members() {
        for (k, v) in obj.entries().take(1) {
            if let json::JsonValue::Boolean(state) = v["active"] && true {
                if state {
                    println!("{}", k)
                }
            }
        }
    }
}

Meta

rustc --version --verbose:

rustc 1.51.0 (2fd73fabe 2021-03-23)
binary: rustc
commit-hash: 2fd73fabe469357a12c2c974c140f67e7cdd76d0
commit-date: 2021-03-23
host: x86_64-apple-darwin
release: 1.51.0
LLVM version: 11.0.1

Error output

<output>
Backtrace

$ RUST_BACKTRACE=1 cargo build
   Compiling bug v0.1.0 (/private/tmp/bug)
error[E0658]: `let` expressions in this position are experimental
 --> src/main.rs:6:16
  |
6 |             if let json::JsonValue::Boolean(state) = v["active"] && true {
  |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information

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

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: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.
error: could not compile `bug`

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

@dfarnham dfarnham 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 Mar 26, 2021
@rustbot rustbot added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Mar 26, 2021
@osa1
Copy link
Contributor

osa1 commented Mar 26, 2021

I can't reproduce this with current master (7637fd5).

$ cargo +stage1 build
   Compiling issue83504 v0.1.0 (/home/omer/rust/issue83504)
error[E0658]: `let` expressions in this position are experimental
 --> src/main.rs:6:16
  |
6 |             if let json::JsonValue::Boolean(state) = v["active"] && true {
  |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
  = help: add `#![feature(let_chains)]` to the crate attributes to enable
  = help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`

error: `let` expressions are not supported here
 --> src/main.rs:6:16
  |
6 |             if let json::JsonValue::Boolean(state) = v["active"] && true {
  |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: only supported directly without parentheses in conditions of `if`- and `while`-expressions, as well as in `let` chains within parentheses

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.
error: could not compile `issue83504`

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

My Cargo.toml:

[package]
name = "issue83504"
version = "0.1.0"
edition = "2018"

[dependencies]
json = "0.12.4"

@dfarnham could you share the Cargo.toml you used? I'm able to reproduce using 1.51 so the Cargo.toml should be right.

@osa1
Copy link
Contributor

osa1 commented Mar 26, 2021

Smaller repro, without deps:

struct MyBool(bool);

fn f() -> MyBool {
    MyBool(true)
}

fn main() {
    if let MyBool(b) = f() && true {
        if b {}
    }
}

Panics with 1.51 as in the original report. Does not panic with nightly.

@rustbot label -E-needs-mcve

@rustbot rustbot removed the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Mar 26, 2021
@SNCPlay42
Copy link
Contributor

Duplicate of #82290, which is fixed on nightly.

@JohnTitor
Copy link
Member

Triage: Indeed this should be a duplicate of #82290, and #82308 has a regression test that should cover the issue, closing as fixed/duplicate.

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. 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

5 participants