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 panic when assigning a dereferenced box as the condition in an if statement #78389

Closed
Arc-blroth opened this issue Oct 26, 2020 · 1 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.

Comments

@Arc-blroth
Copy link

Code

Note that this code is invalid in terms of expected behavior: line 5 should test for equality rather than perform assignment.

use std::ops::Deref;

fn main() {
    println!("Do urchins dream of gophers?");
    if "Rust" = Box::new("Go").deref() {
        println!("Definitely!");
    }
    println!("Maybe!");
}

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (ffa2e7ae8 2020-10-24)
binary: rustc
commit-hash: ffa2e7ae8fbf9badc035740db949b9dae271c29f
commit-date: 2020-10-24
host: x86_64-pc-windows-msvc
release: 1.49.0-nightly
LLVM version: 11.0

Error output

error: internal compiler error: compiler\rustc_typeck\src\check\fn_ctxt\_impl.rs:308:25: while adjusting Expr { hir_id: HirId { owner: DefId(0:4 ~ panicc[d4b8]::main), local_id: 67 }, kind: Call(Expr { hir_id: HirId { owner: DefId(0:4 ~ panicc[d4b8]::main), local_id: 65 }, kind: Path(TypeRelative(Ty { hir_id: HirId { owner: DefId(0:4 ~ panicc[d4b8]::main), local_id: 63 }, kind: Path(Resolved(None, Path { span: src\main.rs:5:17: 5:25 (#0), res: Def(Struct, DefId(5:91 ~ alloc[730d]::boxed::Box)), segments: [PathSegment { ident: Box#0, hir_id: Some(HirId { owner: DefId(0:4 ~ panicc[d4b8]::main), local_id: 62 }), res: Some(Err), args: None, infer_args: true }] })), span: src\main.rs:5:17: 5:25 (#0) }, PathSegment { ident: new#0, hir_id: Some(HirId { owner: DefId(0:4 ~ panicc[d4b8]::main), local_id: 64 }), res: Some(Err), args: None, infer_args: true })), attrs: ThinVec(None), span: src\main.rs:5:17: 5:25 (#0) }, [Expr { hir_id: HirId { owner: DefId(0:4 ~ panicc[d4b8]::main), local_id: 66 }, kind: Lit(Spanned { node: Str("Go", Cooked), span: src\main.rs:5:26: 5:30 (#0) }), attrs: ThinVec(None), span: src\main.rs:5:26: 5:30 (#0) }]), attrs: ThinVec(None), span: src\main.rs:5:17: 5:31 (#0) }, can't compose [Borrow(Ref('_#19r, Not)) -> &Box<&str>] and [Borrow(Ref('_#24r, Not)) -> &Box<&str>]

thread 'rustc' panicked at 'Box<Any>', compiler\rustc_errors\src\lib.rs:945:9

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.49.0-nightly (ffa2e7ae8 2020-10-24) running on x86_64-pc-windows-msvc

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:
#0 [typeck] type-checking `main`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error
Backtrace

   0:     0x7ff95db39b7e - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hbb7524420f9ae79f
   1:     0x7ff95db67adb - core::fmt::write::h435be716304d26a1
   2:     0x7ff95db2b508 - <std::io::IoSliceMut as core::fmt::Debug>::fmt::h89e6d3fd1c80838c
   3:     0x7ff95db3f0bd - std::panicking::take_hook::h1b5ffd09c3541ec0
   4:     0x7ff95db3ec98 - std::panicking::take_hook::h1b5ffd09c3541ec0
   5:     0x7ff954422587 - rustc_driver::report_ice::h0a6a09ce1a074efd
   6:     0x7ff95db3fb10 - std::panicking::rust_panic_with_hook::he9661a82982eed74
   7:     0x7ff958a8b3d0 - <rustc_errors::registry::InvalidErrorCode as core::fmt::Debug>::fmt::haa47007281d8d69d
   8:     0x7ff958a8b379 - <rustc_errors::registry::InvalidErrorCode as core::fmt::Debug>::fmt::haa47007281d8d69d
   9:     0x7ff958a93661 - <rustc_errors::diagnostic::StringPart as core::fmt::Debug>::fmt::h0e74c1792db6aa41
  10:     0x7ff958ac5d6f - rustc_errors::HandlerInner::err_count::h3797b647eeace099
  11:     0x7ff958ac4422 - rustc_errors::Handler::bug::h0a174d32ca88e813
  12:     0x7ff9586f65df - rustc_middle::util::bug::bug_fmt::h42bac936f78c8dfd
  13:     0x7ff9586f13c0 - rustc_middle::ty::walk::<impl rustc_middle::ty::subst::GenericArg>::walk_shallow::h0d56592a32eb5063
  14:     0x7ff9586f1363 - rustc_middle::ty::walk::<impl rustc_middle::ty::subst::GenericArg>::walk_shallow::h0d56592a32eb5063
  15:     0x7ff9586f650c - rustc_middle::util::bug::bug_fmt::h42bac936f78c8dfd
  16:     0x7ff9586f6470 - rustc_middle::util::bug::bug_fmt::h42bac936f78c8dfd
  17:     0x7ff956a64906 - rustc_typeck::check::fn_ctxt::_impl::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::apply_adjustments::hf110cdba23a2cd0e
  18:     0x7ff956ce8d27 - <rustc_typeck::check::dropck::SimpleEqRelation as rustc_middle::ty::relate::TypeRelation>::consts::h457188dbba040b2c
  19:     0x7ff956a83b41 - rustc_typeck::check::method::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::lookup_method::h7243b08e064ce505
  20:     0x7ff956a536af - rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation::hdb5f692ff025cdbe
  21:     0x7ff956a53016 - rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation::hdb5f692ff025cdbe
  22:     0x7ff956a52e41 - rustc_typeck::check::demand::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_for_cast::hb500583c43a84416
  23:     0x7ff956a560d7 - rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation::hdb5f692ff025cdbe
  24:     0x7ff956a53016 - rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation::hdb5f692ff025cdbe
  25:     0x7ff956a5363d - rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation::hdb5f692ff025cdbe
  26:     0x7ff956a53016 - rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation::hdb5f692ff025cdbe
  27:     0x7ff956a39b70 - rustc_typeck::check::_match::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_match::h6d42c08016f9a803
  28:     0x7ff956a53e20 - rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation::hdb5f692ff025cdbe
  29:     0x7ff956a53016 - rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation::hdb5f692ff025cdbe
  30:     0x7ff956a70445 - rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_stmt::h017d3e5d2e493fca
  31:     0x7ff956a70ea6 - rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_no_value::h665bf96a03f6498e
  32:     0x7ff956a53b5f - rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation::hdb5f692ff025cdbe
  33:     0x7ff956a53016 - rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation::hdb5f692ff025cdbe
  34:     0x7ff956a5dba8 - rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation::hdb5f692ff025cdbe
  35:     0x7ff956b82b81 - rustc_typeck::check::check::check_wf_new::h19e270445413f329
  36:     0x7ff956cbfbb0 - <rustc_typeck::astconv::PathSeg as core::fmt::Debug>::fmt::hfd86fd5c2458e7e2
  37:     0x7ff956d54e1a - <rustc_typeck::check::fixup_opaque_types::FixupFolder as rustc_middle::ty::fold::TypeFolder>::fold_ty::hcdc6c08b5c1ca355
  38:     0x7ff956c5f40e - <rustc_typeck::bounds::Bounds as core::fmt::Debug>::fmt::ha3a532628cf583e4
  39:     0x7ff956b70966 - <rustc_typeck::outlives::implicit_infer::InferVisitor as rustc_hir::itemlikevisit::ItemLikeVisitor>::visit_item::h8baf1728e76b3c64
  40:     0x7ff956c35d54 - <<rustc_typeck::collect::const_evaluatable_predicates_of::ConstCollector as rustc_hir::intravisit::Visitor>::visit_ty::TyAliasVisitor as rustc_middle::ty::fold::TypeVisitor>::visit_const::hf3927083f687e271
  41:     0x7ff956bd158d - <rustc_typeck::outlives::explicit::ExplicitPredicatesMap as core::fmt::Debug>::fmt::hd3d7c0c50e41d57c
  42:     0x7ff956abcd4e - rustc_typeck::check::writeback::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::resolve_type_vars_in_body::h4c9e8bc9efe88ee2
  43:     0x7ff956b44c72 - rustc_typeck::check::writeback::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::resolve_type_vars_in_body::h4c9e8bc9efe88ee2
  44:     0x7ff956d5a5a4 - <rustc_typeck::check::CheckItemTypesVisitor as rustc_hir::itemlikevisit::ItemLikeVisitor>::visit_item::h42a56a7a7b0b6e7b
  45:     0x7ff956c2418d - <<rustc_typeck::collect::const_evaluatable_predicates_of::ConstCollector as rustc_hir::intravisit::Visitor>::visit_ty::TyAliasVisitor as rustc_middle::ty::fold::TypeVisitor>::visit_const::hf3927083f687e271
  46:     0x7ff956b71466 - <rustc_typeck::outlives::implicit_infer::InferVisitor as rustc_hir::itemlikevisit::ItemLikeVisitor>::visit_item::h8baf1728e76b3c64
  47:     0x7ff956c37f7f - <<rustc_typeck::collect::const_evaluatable_predicates_of::ConstCollector as rustc_hir::intravisit::Visitor>::visit_ty::TyAliasVisitor as rustc_middle::ty::fold::TypeVisitor>::visit_const::hf3927083f687e271
  48:     0x7ff956bd2789 - <rustc_typeck::outlives::explicit::ExplicitPredicatesMap as core::fmt::Debug>::fmt::hd3d7c0c50e41d57c
  49:     0x7ff956adedeb - rustc_typeck::check::writeback::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::resolve_type_vars_in_body::h4c9e8bc9efe88ee2
  50:     0x7ff956c78bba - rustc_typeck::check_crate::he8b36c3222a01778
  51:     0x7ff954639b83 - rustc_interface::passes::QueryContext::print_stats::h83316569f356654e
  52:     0x7ff9543a90ab - <[i64] as rand::AsByteSliceMut>::to_le::he7bd17e5835d34e6
  53:     0x7ff9543aa7b6 - <[i64] as rand::AsByteSliceMut>::to_le::he7bd17e5835d34e6
  54:     0x7ff95443f8af - rustc_ast::util::parser::prec_let_scrutinee_needs_par::h67b9ec40d4cf07ae
  55:     0x7ff9544399be - <rustc_driver::Compilation as core::fmt::Debug>::fmt::h514b7a76f78a44e9
  56:     0x7ff9543cc912 - <rustc_span::symbol::SymbolStr as core::fmt::Display>::fmt::h58939e9964733da9
  57:     0x7ff9543ab44c - <[i64] as rand::AsByteSliceMut>::to_le::he7bd17e5835d34e6
  58:     0x7ff95443b308 - rustc_ast::util::parser::prec_let_scrutinee_needs_par::h67b9ec40d4cf07ae
  59:     0x7ff954402d66 - <rustc_ast::ast::Item<rustc_ast::ast::AssocItemKind> as rustc_ast::attr::HasAttrs>::attrs::hd867a83e3b0f360d
  60:     0x7ff95443e5c8 - rustc_ast::util::parser::prec_let_scrutinee_needs_par::h67b9ec40d4cf07ae
  61:     0x7ff954426f00 - <rustc_driver::Compilation as core::fmt::Debug>::fmt::h514b7a76f78a44e9
  62:     0x7ff9544429cb - rustc_ast::util::parser::prec_let_scrutinee_needs_par::h67b9ec40d4cf07ae
  63:     0x7ff9543c4723 - <rustc_span::symbol::SymbolStr as core::fmt::Display>::fmt::h58939e9964733da9
  64:     0x7ff95db4fb37 - std::sys::windows::thread::Thread::new::hdbe5c1228d1cf93a
  65:     0x7ff9b7e17034 - BaseThreadInitThunk
  66:     0x7ff9b99dcec1 - RtlUserThreadStart

@Arc-blroth Arc-blroth 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 Oct 26, 2020
@SNCPlay42
Copy link
Contributor

This is probably a duplicate of #77218, which just got fixed and the fix hasn't made it to nightly yet.

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

3 participants