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 "Cannot copy into already initialized unsized place" #67696

Closed
matthiaskrgr opened this issue Dec 29, 2019 · 2 comments · Fixed by #67914
Closed

ICE "Cannot copy into already initialized unsized place" #67696

matthiaskrgr opened this issue Dec 29, 2019 · 2 comments · Fixed by #67914
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html A-pretty Area: Pretty printing (including `-Z unpretty`) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

rustc ./src/test/ui/trivial-bounds/trivial-bounds-inconsistent-associated-functions.rs --emit mir
code:

// run-pass
// Inconsistent bounds with trait implementations

#![feature(trivial_bounds)]
#![allow(unused)]

trait A {
    fn foo(&self) -> Self where Self: Copy;
}

impl A for str {
    fn foo(&self) -> Self where Self: Copy { *"" }
}

impl A for i32 {
    fn foo(&self) -> Self { 3 }
}

backtrace:

thread 'rustc' panicked at 'Cannot copy into already initialized unsized place', src/librustc_mir/interpret/place.rs:891:13
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /home/matthias/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /home/matthias/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:77
   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:1057
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1426
   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:195
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:215
  10: <alloc::boxed::Box<F> as core::ops::function::Fn<A>>::call
             at /home/matthias/vcs/github/rust_debug_assertions/src/liballoc/boxed.rs:1029
  11: rustc_driver::report_ice
             at src/librustc_driver/lib.rs:1160
  12: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:476
  13: std::panicking::begin_panic
             at /home/matthias/vcs/github/rust_debug_assertions/src/libstd/panicking.rs:401
  14: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::eval_rvalue_into_place
             at /home/matthias/vcs/github/rust_debug_assertions/src/libcore/option.rs:0
  15: rustc_mir::transform::const_prop::ConstPropagator::const_prop::{{closure}}
             at src/librustc_mir/transform/const_prop.rs:561
  16: rustc_mir::transform::const_prop::ConstPropagator::use_ecx
             at src/librustc_mir/transform/const_prop.rs:367
  17: rustc_mir::transform::const_prop::ConstPropagator::const_prop
             at src/librustc_mir/transform/const_prop.rs:559
  18: <rustc_mir::transform::const_prop::ConstPropagator as rustc::mir::visit::MutVisitor>::visit_statement
             at src/librustc_mir/transform/const_prop.rs:762
  19: rustc::mir::visit::MutVisitor::super_basic_block_data
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/mir/visit.rs:322
  20: rustc::mir::visit::MutVisitor::visit_basic_block_data
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/mir/visit.rs:93
  21: rustc::mir::visit::MutVisitor::super_body
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/mir/visit.rs:275
  22: rustc::mir::visit::MutVisitor::visit_body
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/mir/visit.rs:87
  23: <rustc_mir::transform::const_prop::ConstProp as rustc_mir::transform::MirPass>::run_pass
             at src/librustc_mir/transform/const_prop.rs:97
  24: rustc_mir::transform::run_passes::{{closure}}
             at src/librustc_mir/transform/mod.rs:171
  25: rustc_mir::transform::run_passes
             at src/librustc_mir/transform/mod.rs:178
  26: rustc_mir::transform::run_optimization_passes
             at src/librustc_mir/transform/mod.rs:273
  27: rustc_mir::transform::optimized_mir
             at src/librustc_mir/transform/mod.rs:343
  28: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::optimized_mir>::compute::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:971
  29: rustc::ty::query::__query_compute::optimized_mir
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:922
  30: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::optimized_mir>::compute
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:963
  31: rustc::dep_graph::graph::DepGraph::with_task_impl
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/dep_graph/graph.rs:325
  32: rustc::dep_graph::graph::DepGraph::with_task
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/dep_graph/graph.rs:193
  33: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job::{{closure}}::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:543
  34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:267
  35: rustc::ty::context::tls::enter_context::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1753
  36: rustc::ty::context::tls::set_tlv
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1686
  37: rustc::ty::context::tls::enter_context
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1753
  38: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:267
  39: rustc::ty::context::tls::with_related_context::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1841
  40: rustc::ty::context::tls::with_context::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1825
  41: rustc::ty::context::tls::with_context_opt
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1814
  42: rustc::ty::context::tls::with_context
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1825
  43: rustc::ty::context::tls::with_related_context
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1838
  44: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:256
  45: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:533
  46: rustc::ty::query::plumbing::with_diagnostics
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:201
  47: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:532
  48: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:369
  49: rustc::ty::query::TyCtxtAt::optimized_mir
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:1048
  50: rustc::ty::query::<impl rustc::ty::context::TyCtxt>::optimized_mir
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/query/plumbing.rs:1040
  51: rustc_mir::util::pretty::write_mir_pretty
             at src/librustc_mir/util/pretty.rs:239
  52: rustc_mir::transform::dump_mir::emit_mir
             at src/librustc_mir/transform/dump_mir.rs:65
  53: rustc_interface::passes::start_codegen
             at src/librustc_interface/passes.rs:994
  54: rustc_interface::queries::Queries::ongoing_codegen::{{closure}}::{{closure}}
             at src/librustc_interface/queries.rs:282
  55: rustc_interface::passes::QueryContext::enter::{{closure}}
             at src/librustc_interface/passes.rs:711
  56: rustc::ty::context::tls::enter_global::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1776
  57: rustc::ty::context::tls::enter_context::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1753
  58: rustc::ty::context::tls::set_tlv
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1686
  59: rustc::ty::context::tls::enter_context
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1753
  60: rustc::ty::context::tls::enter_global
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1776
  61: rustc_interface::passes::QueryContext::enter
             at src/librustc_interface/passes.rs:711
  62: rustc_interface::queries::Queries::ongoing_codegen::{{closure}}
             at src/librustc_interface/queries.rs:276
  63: rustc_interface::queries::Query<T>::compute
             at src/librustc_interface/queries.rs:34
  64: rustc_interface::queries::Queries::ongoing_codegen
             at src/librustc_interface/queries.rs:274
  65: rustc_driver::run_compiler::{{closure}}::{{closure}}
             at src/librustc_driver/lib.rs:404
  66: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc_interface/queries.rs:332
  67: rustc_driver::run_compiler::{{closure}}
             at src/librustc_driver/lib.rs:295
  68: rustc_interface::interface::run_compiler_in_existing_thread_pool
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc_interface/interface.rs:184
  69: rustc_interface::interface::run_compiler::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc_interface/interface.rs:193
  70: rustc_interface::util::spawn_thread_pool::{{closure}}::{{closure}}::{{closure}}::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc_interface/util.rs:154
  71: rustc::ty::context::tls::with_thread_locals::{{closure}}::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1742
  72: std::thread::local::LocalKey<T>::try_with
             at /home/matthias/vcs/github/rust_debug_assertions/src/libstd/thread/local.rs:262
  73: std::thread::local::LocalKey<T>::with
             at /home/matthias/vcs/github/rust_debug_assertions/src/libstd/thread/local.rs:239
  74: rustc::ty::context::tls::with_thread_locals::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1734
  75: std::thread::local::LocalKey<T>::try_with
             at /home/matthias/vcs/github/rust_debug_assertions/src/libstd/thread/local.rs:262
  76: std::thread::local::LocalKey<T>::with
             at /home/matthias/vcs/github/rust_debug_assertions/src/libstd/thread/local.rs:239
  77: rustc::ty::context::tls::with_thread_locals
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc/ty/context.rs:1726
  78: rustc_interface::util::spawn_thread_pool::{{closure}}::{{closure}}::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc_interface/util.rs:154
  79: scoped_tls::ScopedKey<T>::set
             at /home/matthias/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  80: rustc_interface::util::spawn_thread_pool::{{closure}}::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc_interface/util.rs:150
  81: scoped_tls::ScopedKey<T>::set
             at /home/matthias/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  82: syntax::with_globals::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/libsyntax/lib.rs:60
  83: scoped_tls::ScopedKey<T>::set
             at /home/matthias/.cargo/registry/src/gh.neting.cc-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  84: syntax::with_globals
             at /home/matthias/vcs/github/rust_debug_assertions/src/libsyntax/lib.rs:60
  85: rustc_interface::util::spawn_thread_pool::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc_interface/util.rs:149
  86: rustc_interface::util::scoped_thread::{{closure}}
             at /home/matthias/vcs/github/rust_debug_assertions/src/librustc_interface/util.rs:126
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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.42.0-dev running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [optimized_mir] processing `<str as A>::foo`
end of query stack
@jonas-schievink jonas-schievink added A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html A-pretty Area: Pretty printing (including `-Z unpretty`) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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. labels Dec 29, 2019
@matthewjasper matthewjasper removed the requires-nightly This issue requires a nightly compiler in some way. label Jan 2, 2020
@matthewjasper
Copy link
Contributor

This doesn't require nightly:

#![allow(unused)]

trait A {
    fn foo(&self) -> Self where Self: Copy;
}

impl A for [fn(&())] {
    fn foo(&self) -> Self where Self: Copy { *(&[] as &[_]) }
}

impl A for i32 {
    fn foo(&self) -> Self { 3 }
}

@pnkfelix
Copy link
Member

pnkfelix commented Jan 9, 2020

triage: has PR. P-high, removing I-nominated label.

@pnkfelix pnkfelix added P-high High priority and removed I-nominated labels Jan 9, 2020
Centril added a commit to Centril/rust that referenced this issue Jan 12, 2020
…, r=matthewjasper

Don't run const propagation on items with inconsistent bounds

Fixes rust-lang#67696

Using `#![feature(trivial_bounds)]`, it's possible to write functions
with unsatisfiable 'where' clauses, making them uncallable. However, the
user can act as if these 'where' clauses are true inside the body of the
function, leading to code that would normally be impossible to write.

Since const propgation can run even without any user-written calls to a
function, we need to explcitly check for these uncallable functions.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jan 14, 2020
…, r=matthewjasper,oli-obk

Don't run const propagation on items with inconsistent bounds

Fixes rust-lang#67696

Using `#![feature(trivial_bounds)]`, it's possible to write functions
with unsatisfiable 'where' clauses, making them uncallable. However, the
user can act as if these 'where' clauses are true inside the body of the
function, leading to code that would normally be impossible to write.

Since const propgation can run even without any user-written calls to a
function, we need to explcitly check for these uncallable functions.
@bors bors closed this as completed in 89b065d Jan 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html A-pretty Area: Pretty printing (including `-Z unpretty`) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High 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.

4 participants