Skip to content

ICE: errors resolving bounds after type-checking for fmt::Display #65774

Closed
@bradjc

Description

@bradjc

pnkfelix: here is the reduced test case (play):

#![feature(associated_type_defaults)]

trait MyDisplay { fn method(&self) { } }

impl<'a, T: MyDisplay> MyDisplay for &'a mut T { }

struct T;

trait MPU {
    type MpuConfig: MyDisplay = T;
}

struct S;

impl MPU for S { }

trait MyWrite {
    fn my_write(&self, _: &dyn MyDisplay) { }
}

trait ProcessType {
    fn process_detail_fmt(&self, _: &mut dyn MyWrite);
}

struct Process;

impl ProcessType for Process {
    fn process_detail_fmt(&self, writer: &mut dyn MyWrite)
    {

        let mut val: Option<<S as MPU>::MpuConfig> = None;
        let valref: &mut <S as MPU>::MpuConfig = val.as_mut().unwrap();

        // // This causes a different ICE (but its similar if you squint right):
        // //
        // // `Unimplemented` selecting `Binder(<T as MyDisplay>)` during codegen
        //
        // writer.my_write(valref)

        // This one causes the ICE:
        // FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<T as MyDisplay>)), depth=1),Unimplemented)
        let closure = |config: &mut <S as MPU>::MpuConfig| writer.my_write(&config);
        closure(valref);
    }
}

fn create() -> &'static dyn ProcessType {
    let input: Option<&mut Process> = None;
    let process: &mut Process = input.unwrap();
    process
}

pub fn main() {
    create();
}

(Sadly I have not been able to reduce it further. But this should serve us well enough.)

Original bug report follows:


I'm getting a compiler error when trying to compile:

impl fmt::Display for PMPConfig {
    fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
        Ok(())
    }
}

I'm compiling for the riscv32imac-unknown-none-elf target.

Full branch here:

https://github.com/tock/tock/blob/f29f8aa9bf9925893e905feb1aa42db2ce57d36f/arch/rv32i/src/pmp.rs#L26

error: internal compiler error: src/librustc/traits/codegen/mod.rs:127: Encountered errors `[FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<() as core::fmt::Display>)), depth=1),Unimplemented)]` resolving bounds after type-checking

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:925:9
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: rustc_driver::report_ice
   6: std::panicking::rust_panic_with_hook
   7: std::panicking::begin_panic
   8: rustc_errors::HandlerInner::bug
   9: rustc_errors::Handler::bug
  10: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  11: rustc::ty::context::tls::with_opt::{{closure}}
  12: rustc::ty::context::tls::with_context_opt
  13: rustc::ty::context::tls::with_opt
  14: rustc::util::bug::opt_span_bug_fmt
  15: rustc::util::bug::bug_fmt
  16: rustc::traits::codegen::<impl rustc::infer::InferCtxt>::drain_fulfillment_cx_or_panic
  17: rustc::ty::context::GlobalCtxt::enter_local
  18: rustc::traits::codegen::codegen_fulfill_obligation
  19: rustc::ty::query::__query_compute::codegen_fulfill_obligation
  20: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::codegen_fulfill_obligation>::compute
  21: rustc::dep_graph::graph::DepGraph::with_task_impl
  22: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  23: rustc::ty::instance::Instance::resolve
  24: rustc::ty::instance::Instance::resolve_for_fn_ptr
  25: <rustc_mir::monomorphize::collector::MirNeighborCollector as rustc::mir::visit::Visitor>::visit_rvalue
  26: rustc_mir::monomorphize::collector::collect_items_rec
  27: rustc_mir::monomorphize::collector::collect_items_rec
  28: rustc_mir::monomorphize::collector::collect_items_rec
  29: rustc_mir::monomorphize::collector::collect_items_rec
  30: rustc_mir::monomorphize::collector::collect_items_rec
  31: rustc_mir::monomorphize::collector::collect_items_rec
  32: rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}
  33: rustc::util::common::time
  34: rustc_mir::monomorphize::collector::collect_crate_mono_items
  35: rustc::util::common::time
  36: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
  37: rustc::ty::query::__query_compute::collect_and_partition_mono_items
  38: rustc::dep_graph::graph::DepGraph::with_task_impl
  39: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  40: rustc_codegen_ssa::base::codegen_crate
  41: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  42: rustc_interface::passes::start_codegen::{{closure}}
  43: rustc::util::common::time
  44: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  45: rustc_interface::passes::create_global_ctxt::{{closure}}
  46: rustc_interface::queries::Query<T>::compute
  47: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::ongoing_codegen
  48: rustc_interface::interface::run_compiler_in_existing_thread_pool
  49: std::thread::local::LocalKey<T>::with
  50: scoped_tls::ScopedKey<T>::set
  51: syntax::with_globals

or with full backtrace:

error: internal compiler error: src/librustc/traits/codegen/mod.rs:127: Encountered errors `[FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<() as core::fmt::Display>)), depth=1),Unimplemented)]` resolving bounds after type-checking

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:925:9
stack backtrace:
   0:        0x107ee4765 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hc92d616cef8f0450
   1:        0x107f1afe0 - core::fmt::write::h716de5060e2e2331
   2:        0x107ed7eab - std::io::Write::write_fmt::hcf7751f7cc575a83
   3:        0x107ee8ac3 - std::panicking::default_hook::{{closure}}::hcbef2dce5efa48e4
   4:        0x107ee87da - std::panicking::default_hook::h8d36105439fe91d2
   5:        0x10886f852 - rustc_driver::report_ice::hfa643614a34e50c3
   6:        0x107ee9302 - std::panicking::rust_panic_with_hook::h66761634aad950e8
   7:        0x10a3f0631 - std::panicking::begin_panic::h34e760fb9453ebea
   8:        0x10a3ed727 - rustc_errors::HandlerInner::bug::h6632965e0eab1113
   9:        0x10a3ec3bd - rustc_errors::Handler::bug::hcfa8e791cebcb41f
  10:        0x109b82ebb - rustc::util::bug::opt_span_bug_fmt::{{closure}}::h1f12cbc5d5c9e30d
  11:        0x109b81fc6 - rustc::ty::context::tls::with_opt::{{closure}}::h3c1d0ef67ec726db
  12:        0x109b81f54 - rustc::ty::context::tls::with_context_opt::h0bc959fbaa3c960b
  13:        0x109b81f82 - rustc::ty::context::tls::with_opt::h5b98f20d68bd6455
  14:        0x109b82dd8 - rustc::util::bug::opt_span_bug_fmt::h4b691449484f2e2d
  15:        0x109b82d2b - rustc::util::bug::bug_fmt::h94ea7325307137cb
  16:        0x109bee1de - rustc::traits::codegen::<impl rustc::infer::InferCtxt>::drain_fulfillment_cx_or_panic::haf0249c10c545ad4
  17:        0x10a085320 - rustc::ty::context::GlobalCtxt::enter_local::hc3ed889af372304b
  18:        0x109de43a6 - rustc::traits::codegen::codegen_fulfill_obligation::h2083639e26b40870
  19:        0x109ada6ca - rustc::ty::query::__query_compute::codegen_fulfill_obligation::h47add3629ad3c7c9
  20:        0x10a090f30 - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::codegen_fulfill_obligation>::compute::h367720f4ad252193
  21:        0x109b25685 - rustc::dep_graph::graph::DepGraph::with_task_impl::hdb658fea3c8e03a0
  22:        0x109f73e7e - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::hc4e638aed84e9309
  23:        0x109a4ee08 - rustc::ty::instance::Instance::resolve::h7f14c4b030d04908
  24:        0x109a4f40a - rustc::ty::instance::Instance::resolve_for_fn_ptr::hd3f49848b140835f
  25:        0x109304298 - <rustc_mir::monomorphize::collector::MirNeighborCollector as rustc::mir::visit::Visitor>::visit_rvalue::hc49ddd5adf94cfe8
  26:        0x109302eb7 - rustc_mir::monomorphize::collector::collect_items_rec::h2f0cd94f91ffd624
  27:        0x1093038cf - rustc_mir::monomorphize::collector::collect_items_rec::h2f0cd94f91ffd624
  28:        0x1093038cf - rustc_mir::monomorphize::collector::collect_items_rec::h2f0cd94f91ffd624
  29:        0x1093038cf - rustc_mir::monomorphize::collector::collect_items_rec::h2f0cd94f91ffd624
  30:        0x1093038cf - rustc_mir::monomorphize::collector::collect_items_rec::h2f0cd94f91ffd624
  31:        0x1093038cf - rustc_mir::monomorphize::collector::collect_items_rec::h2f0cd94f91ffd624
  32:        0x109174c1e - rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}::h4b9955786c837751
  33:        0x10913f7d3 - rustc::util::common::time::h7f14ec4a929068d5
  34:        0x109301530 - rustc_mir::monomorphize::collector::collect_crate_mono_items::hb405aac8f6d07af3
  35:        0x10913f8f8 - rustc::util::common::time::hbfb52e7fe607ac6c
  36:        0x10940bfba - rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items::h9dba4196ae508ffb
  37:        0x10b65bad2 - rustc::ty::query::__query_compute::collect_and_partition_mono_items::h7b08395218e7aba3
  38:        0x10b6706fa - rustc::dep_graph::graph::DepGraph::with_task_impl::h25d923dce7eb1416
  39:        0x10b7236af - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h9078560050296908
  40:        0x10b73eedd - rustc_codegen_ssa::base::codegen_crate::hef4e5fc37e1a7a0e
  41:        0x10b6e0b49 - <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate::ha5087cf525770987
  42:        0x10893605e - rustc_interface::passes::start_codegen::{{closure}}::h63426f234991945a
  43:        0x108931068 - rustc::util::common::time::h9caa4ccff6ec0bfb
  44:        0x10890b16f - rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}::ha08746ee0b93b578
  45:        0x10893529b - rustc_interface::passes::create_global_ctxt::{{closure}}::h600047dc314d4bba
  46:        0x108907399 - rustc_interface::queries::Query<T>::compute::h9cd0fdded8634953
  47:        0x10899f19c - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::ongoing_codegen::h51958e05ed750756
  48:        0x108874d25 - rustc_interface::interface::run_compiler_in_existing_thread_pool::haa58e61254d8def5
  49:        0x1088877e4 - std::thread::local::LocalKey<T>::with::h702dc95be888a0e1
  50:        0x1088719a2 - scoped_tls::ScopedKey<T>::set::hb39b6f973e4a5679
  51:        0x1088a22d5 - syntax::with_globals::h58d861cb85a086c0
  52:        0x1088a6e37 - std::sys_common::backtrace::__rust_begin_short_backtrace::hdf8e7185d0994576
  53:        0x107ef84af - __rust_maybe_catch_panic
  54:        0x1088b0f17 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h7bb4ccc9b14ced04
  55:        0x107eca6ce - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h87e32ddb36700069
  56:        0x107ef72be - std::sys::unix::thread::Thread::new::thread_start::h20e18e6fa0d2566a
  57:     0x7fff744f62eb - _pthread_body
  58:     0x7fff744f9249 - _pthread_start

and more debug output on my build:

*******************************************************
TOCK KERNEL BUILD SYSTEM -- VERBOSE BUILD CONFIGURATION
*******************************************************
PLATFORM            = arty-e21
TARGET              = riscv32imac-unknown-none-elf
TOCK_KERNEL_VERSION = release-1.4-61-g4c6b652c6
RUSTFLAGS_FOR_CARGO = -C link-arg=-Tlayout.ld -C linker=rust-lld -C linker-flavor=ld.lld -C relocation-model=dynamic-no-pic -C link-arg=-zmax-page-size=512
MAKEFLAGS           =  -r -R
OBJDUMP_FLAGS       = --disassemble-all --source --section-headers

TOOLCHAIN           = "/Users/bradjc/.rustup/toolchains/nightly-2019-10-17-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/bin/llvm"
SIZE                = "/Users/bradjc/.rustup/toolchains/nightly-2019-10-17-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/bin/llvm"-size
OBJCOPY             = "/Users/bradjc/.rustup/toolchains/nightly-2019-10-17-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/bin/llvm"-objcopy
OBJDUMP             = "/Users/bradjc/.rustup/toolchains/nightly-2019-10-17-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/bin/llvm"-objdump
CARGO               = cargo
RUSTUP              = rustup

cargo --version     = cargo 1.40.0-nightly (3a9abe3f0 2019-10-15)
rustc --version     = rustc 1.40.0-nightly (0e8a4b441 2019-10-16)
rustup --version    = rustup 1.20.2 (13979c968 2019-10-16)
*******************************************************

RUSTFLAGS="-C link-arg=-Tlayout.ld -C linker=rust-lld -C linker-flavor=ld.lld -C relocation-model=dynamic-no-pic -C link-arg=-zmax-page-size=512" cargo build --target=riscv32imac-unknown-none-elf --verbose --release
       Fresh tock-registers v0.3.0 (/Users/bradjc/git/tock/libraries/tock-register-interface)
       Fresh tock-cells v0.1.0 (/Users/bradjc/git/tock/libraries/tock-cells)
       Fresh tock_rt0 v0.1.0 (/Users/bradjc/git/tock/libraries/tock-rt0)
       Fresh enum_primitive v0.1.0 (/Users/bradjc/git/tock/libraries/enum_primitive)
       Fresh riscv-csr v0.1.0 (/Users/bradjc/git/tock/libraries/riscv-csr)
       Fresh kernel v0.1.0 (/Users/bradjc/git/tock/kernel)
       Fresh rv32i v0.1.0 (/Users/bradjc/git/tock/arch/rv32i)
       Fresh capsules v0.1.0 (/Users/bradjc/git/tock/capsules)
       Fresh sifive v0.1.0 (/Users/bradjc/git/tock/chips/sifive)
       Fresh arty_e21 v0.1.0 (/Users/bradjc/git/tock/chips/arty_e21)
   Compiling arty-e21 v0.1.0 (/Users/bradjc/git/tock/boards/arty-e21)
     Running `rustc --edition=2018 --crate-name arty_e21 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=z -C panic=abort -C lto -C debuginfo=2 -C metadata=c1355c6c3289bbe0 -C extra-filename=-c1355c6c3289bbe0 --out-dir /Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps --target riscv32imac-unknown-none-elf -L dependency=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps -L dependency=/Users/bradjc/git/tock/boards/arty-e21/target/release/deps --extern arty_e21=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps/libarty_e21-fe0d635f7042045b.rlib --extern capsules=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps/libcapsules-16a235e3bdbefd38.rlib --extern kernel=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps/libkernel-1dbef041a1db2265.rlib --extern rv32i=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps/librv32i-854677d7afde0e8d.rlib --extern sifive=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps/libsifive-1da1c765f34d5c05.rlib -C link-arg=-Tlayout.ld -C linker=rust-lld -C linker-flavor=ld.lld -C relocation-model=dynamic-no-pic -C link-arg=-zmax-page-size=512`
error: internal compiler error: src/librustc/traits/codegen/mod.rs:127: Encountered errors `[FulfillmentError(Obligation(predicate=Binder(TraitPredicate(<() as core::fmt::Display>)), depth=1),Unimplemented)]` resolving bounds after type-checking

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:925:9
note: run with `RUST_BACKTRACE=1` environment variable to display a 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 (0e8a4b441 2019-10-16) running on x86_64-apple-darwin

note: compiler flags: -C opt-level=z -C panic=abort -C lto -C debuginfo=2 -C link-arg=-Tlayout.ld -C linker=rust-lld -C linker-flavor=ld.lld -C relocation-model=dynamic-no-pic -C link-arg=-zmax-page-size=512 --crate-type bin

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

error: aborting due to previous error

error: could not compile `arty-e21`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name arty_e21 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=z -C panic=abort -C lto -C debuginfo=2 -C metadata=c1355c6c3289bbe0 -C extra-filename=-c1355c6c3289bbe0 --out-dir /Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps --target riscv32imac-unknown-none-elf -L dependency=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps -L dependency=/Users/bradjc/git/tock/boards/arty-e21/target/release/deps --extern arty_e21=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps/libarty_e21-fe0d635f7042045b.rlib --extern capsules=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps/libcapsules-16a235e3bdbefd38.rlib --extern kernel=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps/libkernel-1dbef041a1db2265.rlib --extern rv32i=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps/librv32i-854677d7afde0e8d.rlib --extern sifive=/Users/bradjc/git/tock/boards/arty-e21/target/riscv32imac-unknown-none-elf/release/deps/libsifive-1da1c765f34d5c05.rlib -C link-arg=-Tlayout.ld -C linker=rust-lld -C linker-flavor=ld.lld -C relocation-model=dynamic-no-pic -C link-arg=-zmax-page-size=512` (exit code: 101)
make: *** [target/riscv32imac-unknown-none-elf/release/arty-e21] Error 101

Travis also seems to agree that it will not compile: https://travis-ci.org/tock/tock/builds/602484885

Metadata

Metadata

Labels

A-associated-itemsArea: Associated items (types, constants & functions)A-trait-systemArea: Trait systemC-bugCategory: This is a bug.F-associated_type_defaults`#![feature(associated_type_defaults)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions