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

ICE with the @ .. binding pattern #74539

Closed
r1fl opened this issue Jul 19, 2020 · 10 comments · Fixed by #74557
Closed

ICE with the @ .. binding pattern #74539

r1fl opened this issue Jul 19, 2020 · 10 comments · Fixed by #74557
Assignees
Labels
C-bug Category: This is a bug. 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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@r1fl
Copy link

r1fl commented Jul 19, 2020

Code

pub enum Operands {
	Zero,
	One(u8),
	Two(u8, u8),
}

pub fn main() {
	use Operands::*;

	let operands = Zero;

	match operands {
		Zero => println!("Nothing"),
		One(operand) => println!("{:x}", operand),
		Two(operands @ ..) => println!("({:x}, {:x})", operands.0, operands.1),
	};
}

Meta

The bug exists in the beta,

rustup run beta rustc --version --verbose

rustc 1.46.0-beta.1 (e51b714db 2020-07-15)
binary: rustc
commit-hash: e51b714db8ff82ac38ea7c6742d6f5480e2e77bd
commit-date: 2020-07-15
host: x86_64-unknown-linux-gnu
release: 1.46.0-beta.1
LLVM version: 10.0

nightly,

rustup run nightly rustc --version --verbose

rustc 1.46.0-nightly (346aec9b0 2020-07-11)
binary: rustc
commit-hash: 346aec9b02f3c74f3fce97fd6bda24709d220e49
commit-date: 2020-07-11
host: x86_64-unknown-linux-gnu
release: 1.46.0-nightly
LLVM version: 10.0

and stable build channels.

rustc --version --verbose:

rustc 1.45.0 (5c1f21c3b 2020-07-13)
binary: rustc
commit-hash: 5c1f21c3b82297671ad3ae1e8c942d2ca92e84f2
commit-date: 2020-07-13
host: x86_64-unknown-linux-gnu
release: 1.45.0
LLVM version: 10.0

The error and the backtrace provided are produced by the stable build.

Error output

error: `operands @` is not allowed in a tuple struct
  --> ./a.rs:15:7
   |
15 |         Two(operands @ ..) => println!("({:x}, {:x})", operands.0, operands.1),
   |             ^^^^^^^^^^^^^ this is only allowed in slice patterns
   |
   = help: remove this and bind each tuple field independently
help: if you don't need to use the contents of operands, discard the tuple's remaining fields
   |
15 |         Two(..) => println!("({:x}, {:x})", operands.0, operands.1),
   |             ^^

error: internal compiler error: src/librustc_typeck/check/mod.rs:3023: no type for local variable unknown node (hir_id=HirId { owner: DefId(0:13 ~ a[317d]::main[0]), local_id: 9 })
  --> ./a.rs:15:50
   |
15 |         Two(operands @ ..) => println!("({:x}, {:x})", operands.0, operands.1),
   |                                                        ^^^^^^^^

thread 'rustc' panicked at 'Box<Any>', /rustc/5c1f21c3b82297671ad3ae1e8c942d2ca92e84f2/src/libstd/macros.rs:13:23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Backtrace

thread 'rustc' panicked at 'Box<Any>', /rustc/5c1f21c3b82297671ad3ae1e8c942d2ca92e84f2/src/libstd/macros.rs:13:23
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1076
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1537
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:490
  12: std::panicking::begin_panic
  13: rustc_errors::HandlerInner::span_bug
  14: rustc_errors::Handler::span_bug
  15: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
  16: rustc_middle::ty::context::tls::with_opt::{{closure}}
  17: rustc_middle::ty::context::tls::with_opt
  18: rustc_middle::util::bug::opt_span_bug_fmt
  19: rustc_middle::util::bug::span_bug_fmt
  20: rustc_typeck::check::FnCtxt::local_ty::{{closure}}
  21: rustc_typeck::check::FnCtxt::local_ty
  22: rustc_typeck::check::FnCtxt::instantiate_value_path
  23: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  24: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  25: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  26: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  27: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  28: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  29: <smallvec::SmallVec<A> as core::iter::traits::collect::Extend<<A as smallvec::Array>::Item>>::extend
  30: <T as rustc_middle::ty::context::InternIteratorElement<T,R>>::intern_with
  31: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  32: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  33: rustc_typeck::check::_match::<impl rustc_typeck::check::FnCtxt>::check_match
  34: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  35: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  36: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  37: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  38: rustc_typeck::check::FnCtxt::check_argument_types
  39: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::confirm_builtin_call
  40: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::check_call
  41: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  42: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  43: rustc_typeck::check::FnCtxt::check_argument_types
  44: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::confirm_builtin_call
  45: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::check_call
  46: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  47: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  48: rustc_typeck::check::FnCtxt::check_stmt
  49: rustc_typeck::check::FnCtxt::check_block_with_expected
  50: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  51: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  52: rustc_typeck::check::_match::<impl rustc_typeck::check::FnCtxt>::check_match
  53: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  54: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  55: rustc_typeck::check::FnCtxt::check_stmt
  56: rustc_typeck::check::FnCtxt::check_block_with_expected
  57: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  58: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  59: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_return_expr
  60: rustc_typeck::check::check_fn
  61: rustc_middle::ty::context::GlobalCtxt::enter_local
  62: rustc_typeck::check::typeck_tables_of
  63: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck_tables_of>::compute
  64: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  65: rustc_query_system::query::plumbing::get_query_impl
  66: rustc_query_system::query::plumbing::ensure_query_impl
  67: rustc_typeck::check::typeck_item_bodies
  68: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck_item_bodies>::compute
  69: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  70: rustc_query_system::query::plumbing::get_query_impl
  71: rustc_typeck::check_crate
  72: rustc_interface::passes::analysis
  73: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  74: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  75: rustc_query_system::query::plumbing::get_query_impl
  76: rustc_middle::ty::context::tls::enter_global
  77: rustc_interface::interface::run_compiler_in_existing_thread_pool
  78: rustc_ast::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

This issue has been assigned to @jakubadamw via this comment.

@r1fl r1fl 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 Jul 19, 2020
@jonas-schievink jonas-schievink added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jul 19, 2020
@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jul 20, 2020

reduced:

enum E {
	A(u8),
}

fn fun(arg: E) {
	match arg {
		A(x @ ..) => {x}
	};
}

Edit: you can actually omit the enum declaration and it still crashes 🤔

fn fun(arg: E) {fn fun(arg: E) {
	match arg {
		A(x @ ..) => {x}
	};
}

@JohnTitor JohnTitor self-assigned this Jul 20, 2020
@jakubadamw
Copy link
Contributor

@JohnTitor, oh, sorry, I've already got a fix. 🙂 I'll post it soon. Though it may not be the best one.

@JohnTitor JohnTitor removed their assignment Jul 20, 2020
@JohnTitor
Copy link
Member

JohnTitor commented Jul 20, 2020

@jakubadamw Great! You should tweak src/librustc_ast_lowering/pat.rs not losing diags. For further reference, you could do @rustbot claim when you work on an issue to avoid conflicts.

@jakubadamw
Copy link
Contributor

@JohnTitor, okay, thanks. 🙂

Better late than never…

@rustbot claim

@rustbot rustbot self-assigned this Jul 20, 2020
@JohnTitor JohnTitor added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Jul 20, 2020
@JohnTitor
Copy link
Member

This is caused by #72677, I believe. 1.44 emits errors w/o ICE'ing but 1.45 hits it.
godbolt (1.44): https://rust.godbolt.org/z/E1rbvz
godbolt (1.45): https://rust.godbolt.org/z/MGjPG4

@bors bors closed this as completed in 6bbf82d Jul 21, 2020
@JohnTitor
Copy link
Member

Let's keep this open to track stable/beta backports.

@JohnTitor JohnTitor reopened this Jul 21, 2020
@JohnTitor JohnTitor removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jul 21, 2020
@namibj
Copy link

namibj commented Jul 22, 2020

The reference suggested this to be possible, which is how I came to suggest it to OP.
We wanted to avoid naming them to not suggest any specific content.

@Dylan-DPC-zz
Copy link

bors added a commit to rust-lang-ci/rust that referenced this issue Aug 2, 2020
Fix ICEs with `@ ..` binding

This reverts rust-lang#74557 and introduces an alternative fix while ensuring that rust-lang#74954 is not broken.
The diagnostics are verbose though, it fixes three related issues.
cc rust-lang#74954, rust-lang#74539, and rust-lang#74702
@JohnTitor
Copy link
Member

The stable fix is reverted, and the nightly one is also but #74963 introduced another fix. I keep this open when that PR is beta-nominated, just in case.

@JohnTitor
Copy link
Member

We don't backport the fix in favor of this comment: #74557 (comment)
So I'm just going to close this as fixed.

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) ❄️ 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.

8 participants