Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ICE from "trivial" bound where D::Assoc: (in concert with Serde's deserialize_with macro) #65553

Closed
CrackedP0t opened this issue Oct 18, 2019 · 5 comments · Fixed by #65775
Closed
Assignees
Labels
A-borrow-checker Area: The borrow checker A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority 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

@CrackedP0t
Copy link

The following code (playground) panics the compiler in stable 1.38.0, beta 1.39.0-beta.6, and nightly 2019-10-17:

use serde::de::Deserializer;
use serde_derive::Deserialize;

#[derive(Deserialize)]
struct A {
    #[serde(deserialize_with = "d")]
    b: i64
}

pub fn d<'de, D>(_des: D) -> Result<i64, D::Error>
where
    D: Deserializer<'de>,
    D::Error:
{
    Ok(5)
}

Removing the D::Error bound or filling it with D::Error: Debug makes it compile just fine.

Error + backtrace:

error: internal compiler error: src/librustc_mir/borrow_check/nll/universal_regions.rs:764: cannot convert `ReEmpty` to a region vid

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:917:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.37/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:61
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1028
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1412
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:65
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:50
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:189
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:206
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:473
  12: std::panicking::begin_panic
  13: rustc_errors::HandlerInner::bug
  14: rustc_errors::Handler::bug
  15: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  16: rustc::ty::context::tls::with_opt::{{closure}}
  17: rustc::ty::context::tls::with_context_opt
  18: rustc::ty::context::tls::with_opt
  19: rustc::util::bug::opt_span_bug_fmt
  20: rustc::util::bug::bug_fmt
  21: rustc_mir::borrow_check::nll::universal_regions::UniversalRegionIndices::to_region_vid::{{closure}}
  22: <&mut rustc_mir::borrow_check::nll::type_check::constraint_conversion::ConstraintConversion as rustc::infer::outlives::obligations::TypeOutlivesDelegate>::push_verify
  23: rustc::infer::outlives::obligations::TypeOutlives<D>::components_must_outlive
  24: rustc::infer::outlives::obligations::TypeOutlives<D>::type_must_outlive
  25: rustc::infer::outlives::obligations::TypeOutlives<D>::components_must_outlive
  26: rustc::infer::outlives::obligations::TypeOutlives<D>::type_must_outlive
  27: rustc_mir::borrow_check::nll::type_check::constraint_conversion::ConstraintConversion::convert_all
  28: rustc_mir::borrow_check::nll::type_check::TypeChecker::prove_predicate
  29: rustc_mir::borrow_check::nll::type_check::TypeChecker::normalize_and_prove_instantiated_predicates
  30: <rustc_mir::borrow_check::nll::type_check::TypeVerifier as rustc::mir::visit::Visitor>::visit_constant
  31: <rustc_mir::borrow_check::nll::type_check::TypeVerifier as rustc::mir::visit::Visitor>::visit_body
  32: rustc_mir::borrow_check::nll::type_check::type_check
  33: rustc_mir::borrow_check::nll::compute_regions
  34: rustc_mir::borrow_check::do_mir_borrowck
  35: rustc::ty::context::GlobalCtxt::enter_local
  36: rustc_mir::borrow_check::mir_borrowck
  37: rustc::ty::query::__query_compute::mir_borrowck
  38: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::mir_borrowck>::compute
  39: rustc::dep_graph::graph::DepGraph::with_task_impl
  40: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  41: rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners
  42: rustc::util::common::time
  43: rustc_interface::passes::analysis
  44: rustc::ty::query::__query_compute::analysis
  45: rustc::dep_graph::graph::DepGraph::with_task_impl
  46: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  47: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  48: rustc_interface::passes::create_global_ctxt::{{closure}}
  49: rustc_interface::passes::BoxedGlobalCtxt::enter
  50: rustc_interface::interface::run_compiler_in_existing_thread_pool
  51: std::thread::local::LocalKey<T>::with
  52: scoped_tls::ScopedKey<T>::set
  53: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.40.0-nightly (c27f7568b 2019-10-13) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

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

query stack during panic:
#0 [mir_borrowck] processing `<<_IMPL_DESERIALIZE_FOR_A::<impl _IMPL_DESERIALIZE_FOR_A::_serde::Deserialize<'de> for A>::deserialize::__Visitor<'de> as _IMPL_DESERIALIZE_FOR_A::_serde::de::Visitor<'de>>::visit_seq::__DeserializeWith<'de> as _IMPL_DESERIALIZE_FOR_A::_serde::Deserialize<'de>>::deserialize`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

error: could not compile `rust_ice`.

To learn more, run the command again with --verbose.
@JohnTitor JohnTitor added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Oct 18, 2019
@jonas-schievink jonas-schievink added I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-borrow-checker Area: The borrow checker A-NLL Area: Non-lexical lifetimes (NLL) labels Oct 18, 2019
@Centril
Copy link
Contributor

Centril commented Oct 18, 2019

@matthewjasper matthewjasper self-assigned this Oct 20, 2019
@pnkfelix
Copy link
Member

Hmm, I didn't know that adding a "syntactically trivial bound" could cause something like this. Is there some implicit bound that gets added in cases like this?

@pnkfelix
Copy link
Member

minimized test case (play):

pub trait Deserializer<'a> { type Error; }

fn _deserialize<'de, D>(the_d: D) where D: Deserializer<'de>
{
    d(the_d);
}

pub fn d<'de, D>(_des: D) -> D::Error where D: Deserializer<'de>,
                                            D::Error:
{
    loop { }
}

fn main() { }

@pnkfelix pnkfelix changed the title Compiler panic in Serde's deserialize_with macro Compiler panic from "trivial" where D::Assoc: bound (in concert with Serde's deserialize_with macro) Oct 24, 2019
@pnkfelix pnkfelix changed the title Compiler panic from "trivial" where D::Assoc: bound (in concert with Serde's deserialize_with macro) Compiler panic from "trivial" bound where D::Assoc: (in concert with Serde's deserialize_with macro) Oct 24, 2019
@pnkfelix pnkfelix changed the title Compiler panic from "trivial" bound where D::Assoc: (in concert with Serde's deserialize_with macro) ICE from "trivial" bound where D::Assoc: (in concert with Serde's deserialize_with macro) Oct 24, 2019
@pnkfelix
Copy link
Member

The minimized test worked in previous stable Rust versions (at least in 1.33 under 2015 edition; though 2018 edition breaks there, which indicates this is with 99.999% certainty injected by MIR-borrowck...)

@pnkfelix pnkfelix added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Oct 24, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Oct 24, 2019

triage: P-high. Adding self to assignee list; removing I-nominated.

@pnkfelix pnkfelix added P-high High priority and removed I-nominated labels Oct 24, 2019
@pnkfelix pnkfelix self-assigned this Oct 24, 2019
@bors bors closed this as completed in 100c924 Oct 25, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-borrow-checker Area: The borrow checker A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority 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.

6 participants