Closed
Description
Code
struct TestClass {
nominated: i32,
name: String,
}
impl TestClass {
const NAMES: [str; 4] = ["a", "b", "c", "d"];
pub fn new(name: &str) -> Self {
TestClass { nominated: 0, name: name.to_string() }
}
}
fn main() {
let mut a = TestClass::new("Name");
}
Meta
rustc --version --verbose
:
rustc 1.55.0 (c8dfcfe04 2021-09-06)
binary: rustc
commit-hash: c8dfcfe046a7680554bf4eb612bad840e7631c4b
commit-date: 2021-09-06
host: x86_64-unknown-linux-gnu
release: 1.55.0
LLVM version: 12.0.1
Error output
Compiling network-controller v0.1.0 (/path/to/project)
error: internal compiler error: compiler/rustc_typeck/src/hir_wf_check.rs:129:29: Unexpected ImplItem Const(Ty { hir_id: HirId { owner: DefId(0:7 ~ network_controller[c8bb]::{impl#0}::NAMES), local_id: 5 }, kind: Array(Ty { hir_id: HirId { owner: DefId(0:7 ~ network_controller[c8bb]::{impl#0}::NAMES), local_id: 1 }, kind: Path(Resolved(None, Path { span: src/main.rs:7:16: 7:19 (#0), res: PrimTy(Str), segments: [PathSegment { ident: str#0, hir_id: Some(HirId { owner: DefId(0:7 ~ network_controller[c8bb]::{impl#0}::NAMES), local_id: 2 }), res: Some(Err), args: None, infer_args: false }] })), span: src/main.rs:7:16: 7:19 (#0) }, AnonConst { hir_id: HirId { owner: DefId(0:7 ~ network_controller[c8bb]::{impl#0}::NAMES), local_id: 3 }, body: BodyId { hir_id: HirId { owner: DefId(0:7 ~ network_controller[c8bb]::{impl#0}::NAMES), local_id: 4 } } }), span: src/main.rs:7:15: 7:23 (#0) }, BodyId { hir_id: HirId { owner: DefId(0:7 ~ network_controller[c8bb]::{impl#0}::NAMES), local_id: 10 } })
thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1034: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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: rustc 1.55.0 (c8dfcfe04 2021-09-06) running on x86_64-unknown-linux-gnu
note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
#0 [diagnostic_hir_wf_check] performing HIR wf-checking for predicate Binder(TraitPredicate(<str as std::marker::Sized>), []) at item Ty(DefId(0:7 ~ network_controller[c8bb]::{impl#0}::NAMES))
#1 [check_impl_item_well_formed] checking that `<impl at src/main.rs:6:1: 13:2>::NAMES` is well-formed
end of query stack
Backtrace
thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1034:9
stack backtrace:
0: std::panicking::begin_panic
1: std::panic::panic_any
2: rustc_errors::HandlerInner::bug
3: rustc_errors::Handler::bug
4: rustc_middle::ty::context::tls::with_opt
5: rustc_middle::util::bug::opt_span_bug_fmt
6: rustc_middle::util::bug::bug_fmt
7: rustc_typeck::hir_wf_check::diagnostic_hir_wf_check
8: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
9: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
10: rustc_data_structures::stack::ensure_sufficient_stack
11: rustc_query_system::query::plumbing::get_query_impl
12: rustc_query_system::query::plumbing::get_query
13: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtExt>::report_selection_error
14: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtPrivExt>::report_fulfillment_error
15: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtExt>::report_fulfillment_errors
16: rustc_typeck::check::fn_ctxt::_impl::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::select_all_obligations_or_error
17: rustc_infer::infer::InferCtxtBuilder::enter
18: rustc_typeck::check::wfcheck::check_associated_item
19: rustc_typeck::check::check::check_impl_item_well_formed
20: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
21: rustc_data_structures::stack::ensure_sufficient_stack
22: rustc_query_system::query::plumbing::force_query_with_job
23: rustc_query_system::query::plumbing::get_query_impl
24: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_impl_item_well_formed
25: <rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor as rustc_hir::intravisit::Visitor>::visit_impl_item
26: rustc_data_structures::sync::par_for_each_in
27: rustc_hir::hir::Crate::par_visit_all_item_likes
28: rustc_session::session::Session::track_errors
29: rustc_typeck::check_crate
30: rustc_interface::passes::analysis
31: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
32: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
33: rustc_query_system::dep_graph::graph::DepGraph<K>::with_eval_always_task
34: rustc_data_structures::stack::ensure_sufficient_stack
35: rustc_query_system::query::plumbing::force_query_with_job
36: rustc_query_system::query::plumbing::get_query_impl
37: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
38: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
39: rustc_span::with_source_map
40: rustc_interface::interface::create_compiler_and_run
41: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
The only way I can help is by saying that the problem is in the "const" line in the impl block. Without that line, the code compiles flawlessly