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 on generic trait impl for aliased array type #58212

Closed
TechPriest opened this issue Feb 6, 2019 · 4 comments
Closed

ICE on generic trait impl for aliased array type #58212

TechPriest opened this issue Feb 6, 2019 · 4 comments
Assignees
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) 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

@TechPriest
Copy link

Following snippet is sufficient to trigger an ICE on both stable 1.32 and nightly 1.34

use std::io::Read;
use std::default::Default;

trait MyRead: Sized {
    fn read<R: Read>(r: &mut R) -> Self;
}

type Foobar = [u8;10];

impl MyRead for Foobar {
    fn read<R: Read>(r: &mut R) -> Self {
        let mut result: Self = Default::default();
        r.read(&mut result[..]).unwrap();
        result
    }
}

fn main() {
}

Meta

rustc 1.32.0 (9fda7c2 2019-01-16) running on x86_64-pc-windows-msvc

Backtrace:

    Checking rs_repro1 v0.1.0 (D:\Work\src\test\rs_repro1)
     Running `rustc --edition=2018 --crate-name rs_repro1 src\main.rs --color always --crate-type bin --emit=dep-info,metadata -C debuginfo=2 -C metadata=1fc4b6d5a86da623 -C extra-filename=-1fc4b6d5a86da623 --out-dir D:\Work\src\test\rs_repro1\target\debug\deps -C incremental=D:\Work\src\test\rs_repro1\target\debug\incremental -L dependency=D:\Work\src\test\rs_repro1\target\debug\deps`
error: internal compiler error: src\librustc\ty\sty.rs:2107: expected constant usize, got Const {
    ty: usize,
    val: Unevaluated(
        DefId(0/1:10 ~ rs_repro1[b69e]::Foobar[0]::{{constant}}[0]),
        []
    )
}

thread 'main' panicked at 'Box<Any>', src\librustc_errors\lib.rs:600:9
stack backtrace:
   0: std::sys_common::alloc::realloc_fallback
   1: std::panicking::take_hook
   2: std::panicking::take_hook
   3: <rustc::ty::sty::Binder<rustc::ty::ProjectionPredicate<'tcx>> as rustc::ty::ToPredicate<'tcx>>::to_predicate
   4: std::panicking::rust_panic_with_hook
   5: <rustc_errors::diagnostic::SubDiagnostic as core::fmt::Debug>::fmt
   6: rustc_errors::Handler::bug
   7: rustc::util::ppaux::get_highlight_region_for_bound_region
   8: rustc::util::ppaux::verbose
   9: rustc::ty::context::tls::track_diagnostic
  10: rustc::util::ppaux::verbose
  11: rustc::util::bug::bug_fmt
  12: rustc::util::bug::bug_fmt
  13: <rustc_mir::util::liveness::IdentityMap<'a, 'tcx> as core::fmt::Debug>::fmt
  14: <rustc_mir::transform::qualify_consts::Qualifier<'a, 'tcx, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_rvalue
  15: <rustc_mir::transform::qualify_consts::Qualifier<'a, 'tcx, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_assign
  16: <rustc_mir::transform::qualify_consts::QualifyAndPromoteConstants as rustc_mir::transform::MirPass>::run_pass
  17: rustc_mir::transform::run_passes
  18: rustc_mir::transform::run_passes
  19: rustc_mir::transform::run_passes
  20: <rustc::traits::query::NoSolution as core::fmt::Debug>::fmt
  21: rustc::ty::context::tls::track_diagnostic
  22: rustc::dep_graph::graph::DepGraph::assert_ignored
  23: <rustc::traits::query::type_op::subtype::Subtype<'tcx> as rustc::traits::query::type_op::QueryTypeOp<'gcx, 'tcx>>::perform_query
  24: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  25: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  26: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::mir_validated
  27: <rustc::mir::Location as rustc_mir::borrow_check::nll::type_check::NormalizeLocation>::to_locations
  28: <rustc::traits::query::NoSolution as core::fmt::Debug>::fmt
  29: <rustc::traits::query::NoSolution as core::fmt::Debug>::fmt
  30: rustc::ty::context::tls::track_diagnostic
  31: rustc::dep_graph::graph::DepGraph::assert_ignored
  32: <rustc::traits::query::type_op::subtype::Subtype<'tcx> as rustc::traits::query::type_op::QueryTypeOp<'gcx, 'tcx>>::perform_query
  33: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  35: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::mir_borrowck
  36: <rustc_driver::pretty::UserIdentifiedItem as core::fmt::Debug>::fmt
  37: <rustc_driver::pretty::UserIdentifiedItem as core::fmt::Debug>::fmt
  38: <rustc_driver::pretty::UserIdentifiedItem as core::fmt::Debug>::fmt
  39: <rustc_driver::pretty::UserIdentifiedItem as core::fmt::Debug>::fmt
  40: rustc_driver::driver::compile_input
  41: rustc_driver::run_compiler
  42: <rustc_driver::profile::trace::Query as core::fmt::Debug>::fmt
  43: rustc_driver::run_compiler
  44: <humantime::duration::Error as std::error::Error>::cause
  45: _rust_maybe_catch_panic
  46: rustc_driver::profile::dump
  47: rustc_driver::main
  48: <unknown>
  49: std::panicking::update_panic_count
  50: _rust_maybe_catch_panic
  51: std::rt::lang_start_internal
  52: <unknown>
  53: <unknown>
  54: BaseThreadInitThunk
  55: RtlUserThreadStart
query stack during panic:
#0 [mir_validated] processing `<[u8; _] as MyRead>::read`
#1 [mir_borrowck] processing `<[u8; _] as MyRead>::read`
end of query stack
error: aborting due to previous error


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.32.0 (9fda7c223 2019-01-16) running on x86_64-pc-windows-msvc

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

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

error: Could not compile `rs_repro1`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name rs_repro1 src\main.rs --color always --crate-type bin --emit=dep-info,metadata -C debuginfo=2 -C metadata=1fc4b6d5a86da623 -C extra-filename=-1fc4b6d5a86da623 --out-dir D:\Work\src\test\rs_repro1\target\debug\deps -C incremental=D:\Work\src\test\rs_repro1\target\debug\incremental -L dependency=D:\Work\src\test\rs_repro1\target\debug\deps` (exit code: 101)```
@jonas-schievink jonas-schievink added 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. C-bug Category: This is a bug. labels Feb 6, 2019
@hellow554
Copy link
Contributor

hellow554 commented Feb 6, 2019

Minified it a little bit. If one remove the : Self it does not ICE.

use std::io::{empty, Read};

trait Foo {
    fn foo();
}

impl Foo for [u8; 10] {
    fn foo() {
        let mut result: Self = [0; 10];
        empty().read(&mut result).unwrap();
    }
}

@hellow554
Copy link
Contributor

The bug also happens on beta (of course).
Nightly-2017-09-01 does not ICE, nightly-2017-10-01 does. But I'm not sure if that's the same error. Let me know if I should bisect that further.

env RUST_BACKTRACE=1 cargo build
   Compiling foo v0.1.0 (file:///tmp/tmp.LgU9STqlid/foo)
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.22.0-nightly (c6884b12d 2017-09-30) running on x86_64-unknown-linux-gnu

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /checkout/src/libcore/option.rs:335:20
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:60
             at /checkout/src/libstd/panicking.rs:381
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:391
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:577
   5: std::panicking::begin_panic
             at /checkout/src/libstd/panicking.rs:538
   6: std::panicking::begin_panic_fmt
             at /checkout/src/libstd/panicking.rs:522
   7: rust_begin_unwind
             at /checkout/src/libstd/panicking.rs:498
   8: core::panicking::panic_fmt
             at /checkout/src/libcore/panicking.rs:71
   9: core::panicking::panic
             at /checkout/src/libcore/panicking.rs:51
  10: <rustc_mir::transform::qualify_consts::Qualifier<'a, 'tcx, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_rvalue
  11: <rustc_mir::transform::qualify_consts::Qualifier<'a, 'tcx, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_assign
  12: rustc::mir::visit::Visitor::visit_basic_block_data
  13: <rustc_mir::transform::qualify_consts::QualifyAndPromoteConstants as rustc::mir::transform::MirPass>::run_pass
  14: rustc_mir::transform::run_suite
  15: rustc_mir::transform::mir_validated
  16: rustc::ty::maps::<impl rustc::ty::maps::queries::mir_validated<'tcx>>::try_get_with::{{closure}}::{{closure}}::run_provider
  17: rustc::dep_graph::graph::DepGraph::with_task
  18: rustc::ty::maps::<impl rustc::ty::maps::queries::mir_validated<'tcx>>::try_get
  19: rustc::ty::maps::TyCtxtAt::mir_validated
  20: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::mir_validated
  21: rustc_borrowck::borrowck::borrowck
  22: rustc::ty::maps::<impl rustc::ty::maps::queries::borrowck<'tcx>>::try_get_with::{{closure}}::{{closure}}::run_provider
  23: rustc::dep_graph::graph::DepGraph::with_task
  24: rustc::ty::maps::<impl rustc::ty::maps::queries::borrowck<'tcx>>::try_get
  25: rustc::ty::maps::TyCtxtAt::borrowck
  26: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::borrowck
  27: rustc_borrowck::borrowck::check_crate
  28: rustc::ty::context::TyCtxt::create_and_enter
  29: rustc_driver::driver::compile_input
  30: rustc_driver::run_compiler

@arielb1
Copy link
Contributor

arielb1 commented Feb 6, 2019

cc @oli-obk

@arielb1 arielb1 added the A-const-eval Area: Constant evaluation (MIR interpretation) label Feb 6, 2019
@oli-obk oli-obk self-assigned this Feb 7, 2019
@hellow554
Copy link
Contributor

Possible dup of #57796

aoikonomopoulos pushed a commit to aoikonomopoulos/rust that referenced this issue Feb 26, 2019
This is required at the very least in order to evaluate associated
constants for arrays (see rust-lang#58212).
Centril added a commit to Centril/rust that referenced this issue Feb 27, 2019
Normalize the type Self resolves to in an impl

This is required at the very least in order to evaluate associated
constants for arrays.

Fixes rust-lang#57796
Fixes rust-lang#58212.

r? @oli-obk
cc @hellow554
Centril added a commit to Centril/rust that referenced this issue Feb 27, 2019
Normalize the type Self resolves to in an impl

This is required at the very least in order to evaluate associated
constants for arrays.

Fixes rust-lang#57796
Fixes rust-lang#58212.

r? @oli-obk
cc @hellow554
Centril added a commit to Centril/rust that referenced this issue Feb 27, 2019
Normalize the type Self resolves to in an impl

This is required at the very least in order to evaluate associated
constants for arrays.

Fixes rust-lang#57796
Fixes rust-lang#58212.

r? @oli-obk
cc @hellow554
Centril added a commit to Centril/rust that referenced this issue Feb 27, 2019
Normalize the type Self resolves to in an impl

This is required at the very least in order to evaluate associated
constants for arrays.

Fixes rust-lang#57796
Fixes rust-lang#58212.

r? @oli-obk
cc @hellow554
Centril added a commit to Centril/rust that referenced this issue Feb 27, 2019
Normalize the type Self resolves to in an impl

This is required at the very least in order to evaluate associated
constants for arrays.

Fixes rust-lang#57796
Fixes rust-lang#58212.

r? @oli-obk
cc @hellow554
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) 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

5 participants