Description
(minimized test case provided by @tmandry )
This is triggered by accessing an associated constant of a generic impl. Here's a minimized testcase that ICEs on nightly (playground link):
pub struct Foo<T>(T);
impl<T> Foo<T> {
const HASH_LEN: usize = 20;
fn stuff() {
let _ = Self::HASH_LEN;
}
}
If a lifetime parameter is used instead of a type parameter, no ICE occurs.
Original bug report follows
Compiling mysql_common fails on rustc 1.31.0-nightly (78ff609d7 2018-10-19)
, but works on the previous nightly rustc 1.31.0-nightly (e7f5d4805 2018-10-18)
.
Compiling mysql_common v0.10.0 (/home/mee/code/rust_mysql_common)
thread 'main' panicked at 'assertion failed: !impl_self_ty.has_infer_types()', librustc_mir/borrow_check/nll/type_check/mod.rs:1033:21
stack backtrace:
0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
1: std::sys_common::backtrace::print
at libstd/sys_common/backtrace.rs:71
at libstd/sys_common/backtrace.rs:59
2: std::panicking::default_hook::{{closure}}
at libstd/panicking.rs:211
3: std::panicking::default_hook
at libstd/panicking.rs:227
4: rustc::util::common::panic_hook
5: std::panicking::rust_panic_with_hook
at libstd/panicking.rs:480
6: std::panicking::begin_panic
7: rustc_mir::borrow_check::nll::type_check::TypeChecker::relate_type_and_user_type
8: <rustc_mir::borrow_check::nll::type_check::TypeVerifier<'a, 'b, 'gcx, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_constant
9: <rustc_mir::borrow_check::nll::type_check::TypeVerifier<'a, 'b, 'gcx, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_rvalue
10: <rustc_mir::borrow_check::nll::type_check::TypeVerifier<'a, 'b, 'gcx, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_mir
11: rustc_mir::borrow_check::nll::type_check::type_check_internal
12: rustc::ty::context::tls::with_related_context
13: rustc::infer::InferCtxtBuilder::enter
14: <rustc_mir::borrow_check::nll::type_check::TypeckMir as rustc_mir::transform::MirPass>::run_pass
15: rustc_mir::transform::mir_const::{{closure}}
16: rustc_mir::transform::mir_const
17: rustc::ty::query::__query_compute::mir_const
18: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::mir_const<'tcx>>::compute
19: rustc::ty::context::tls::with_context
20: rustc::dep_graph::graph::DepGraph::with_task_impl
21: rustc::ty::context::tls::with_related_context
22: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
23: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
24: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::mir_const
25: rustc_mir::transform::mir_validated
26: rustc::ty::query::__query_compute::mir_validated
27: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::mir_validated<'tcx>>::compute
28: rustc::ty::context::tls::with_context
29: rustc::dep_graph::graph::DepGraph::with_task_impl
30: rustc::ty::context::tls::with_related_context
31: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
32: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
33: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::ensure_query
34: rustc_borrowck::borrowck::borrowck
35: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::borrowck<'tcx>>::compute
36: rustc::ty::context::tls::with_context
37: rustc::dep_graph::graph::DepGraph::with_task_impl
38: rustc::ty::context::tls::with_related_context
39: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
40: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
41: rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::par_body_owners
42: rustc_borrowck::borrowck::check_crate
43: rustc::util::common::time
44: rustc::ty::context::tls::enter_context
45: <std::thread::local::LocalKey<T>>::with
46: rustc::ty::context::TyCtxt::create_and_enter
47: rustc_driver::driver::compile_input
48: rustc_driver::run_compiler_with_pool
49: rustc_driver::driver::spawn_thread_pool
50: rustc_driver::run_compiler
51: <scoped_tls::ScopedKey<T>>::set
52: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
53: __rust_maybe_catch_panic
at libpanic_unwind/lib.rs:102
54: rustc_driver::run
55: rustc_driver::main
56: std::rt::lang_start::{{closure}}
57: std::panicking::try::do_call
at libstd/rt.rs:59
at libstd/panicking.rs:310
58: __rust_maybe_catch_panic
at libpanic_unwind/lib.rs:102
59: std::rt::lang_start_internal
at libstd/panicking.rs:289
at libstd/panic.rs:392
at libstd/rt.rs:58
60: main
61: __libc_start_main
62: <unknown>
query stack during panic:
#0 [mir_const] processing `<crypto::rsa::Pkcs1OaepPadding<T>>::mgf1`
#1 [mir_validated] processing `<crypto::rsa::Pkcs1OaepPadding<T>>::mgf1`
#2 [borrowck] processing `<crypto::rsa::Pkcs1OaepPadding<T>>::mgf1`
end of query stack
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.31.0-nightly (78ff609d7 2018-10-19) running on x86_64-unknown-linux-gnu
note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib
note: some of the compiler flags provided by cargo are hidden
error: Could not compile `mysql_common`.
To learn more, run the command again with --verbose.
thread 'main' panicked at 'assertion failed: !impl_self_ty.has_infer_types()', librustc_mir/borrow_check/nll/type_check/mod.rs:1033:21
Some additional detail with RUST_LOG=debug before and after the stack trace:
INFO 2018-10-20T04:27:03Z: rustc_mir::build: fn_id DefId(0/0:65 ~ mysql_common[73d2]::crypto[0]::rsa[0]::{{impl}}[2]::mgf1[0]) has attrs Borrowed([Attribute { id: AttrId(52), style: Outer, path: path(doc), tokens: TokenStream { kind: Stream([TokenStream { kind: Tree(Token(src/crypto/rsa.rs:70:5: 70:56, Eq)) }, TokenStream { kind: Tree(Token(src/crypto/rsa.rs:70:5: 70:56, Literal(Str_(/// Mask Generation Function as defined in rfc2437.), None))) }]) }, is_sugared_doc: true, span: src/crypto/rsa.rs:70:5: 70:56 }, Attribute { id: AttrId(53), style: Outer, path: path(doc), tokens: TokenStream { kind: Stream([TokenStream { kind: Tree(Token(src/crypto/rsa.rs:71:5: 71:8, Eq)) }, TokenStream { kind: Tree(Token(src/crypto/rsa.rs:71:5: 71:8, Literal(Str_(///), None))) }]) }, is_sugared_doc: true, span: src/crypto/rsa.rs:71:5: 71:8 }, Attribute { id: AttrId(54), style: Outer, path: path(doc), tokens: TokenStream { kind: Stream([TokenStream { kind: Tree(Token(src/crypto/rsa.rs:72:5: 72:46, Eq)) }, TokenStream { kind: Tree(Token(src/crypto/rsa.rs:72:5: 72:46, Literal(Str_(/// It will use SHA-1 as a hash function.), None))) }]) }, is_sugared_doc: true, span: src/crypto/rsa.rs:72:5: 72:46 }])
INFO 2018-10-20T04:27:03Z: rustc_mir::build: fn_id DefId(0/1:18 ~ mysql_common[73d2]::crypto[0]::rsa[0]::{{impl}}[2]::mgf1[0]::{{closure}}[0]) has attrs Borrowed([])
thread 'main' panicked at 'assertion failed: !impl_self_ty.has_infer_types()', librustc_mir/borrow_check/nll/type_check/mod.rs:1033:21
[stack backtrace]
The problematic code appears to be https://github.com/blackbeam/rust_mysql_common/blob/master/src/crypto/rsa.rs#L88
PR #55152 looks like a likely cause as it touched the failing assert!
and nearby code, cc @nikomatsakis
EDIT: typo in PR number.