Closed
Description
Modified from an example that @ahwatts provided in issue #22933:
struct Apple;
enum Delicious {
ApplePie = Apple::PIE,
}
fn main() {}
Output with a recent nightly:
test_argl.rs:5:16: 5:26 error: no associated item named `PIE` found for type `Apple` in the current scope
test_argl.rs:5 ApplePie = Apple::PIE,
^~~~~~~~~~
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
thread 'rustc' panicked at 'path not fully resolved: PathResolution { base_def: DefTy(DefId { krate: 0, node: 4 }, false), last_private: LastMod(AllPublic), depth: 1 }', ../src/librustc/middle/def.rs:81
stack backtrace:
1: 0x317dd4983d3 - sys::backtrace::write::h42760ef5ab82bcd2irs
2: 0x317dd4a0521 - panicking::on_panic::h12f68dc29fcc5657Tax
3: 0x317dd45f28a - rt::unwind::begin_unwind_inner::h68e746642e433893DQw
4: 0x317dd45fec7 - rt::unwind::begin_unwind_fmt::h22d77de4e1204a17JPw
5: 0x317db414e0b - middle::const_eval::eval_const_expr_with_substs::h6757944525066075748
6: 0x317db3d94c1 - middle::ty::enum_variants::hf5833ad9292c8ac5HAb
7: 0x317dcc71c9d - check::check_enum_variants::h52e7fb747609e307ALs
8: 0x317dcc63995 - check::check_item_type::ha7187a1df3f0e4ddEco
9: 0x317dcc6aa44 - check::check_item_types::h8615aaad832dd957tRn
10: 0x317dcd2bbb0 - check_crate::h15b94c5d979eb877VgD
11: 0x317dd9ffcb9 - driver::phase_3_run_analysis_passes::h535099e77e0d0b0aHGa
12: 0x317dd9e155a - driver::compile_input::hf94b88e60b92b1d3Sba
13: 0x317dda9d2e7 - run_compiler::hd38788069be51651F7b
14: 0x317dda9a8d6 - boxed::F.FnBox<A>::call_box::h10971823990562187917
15: 0x317dda9a0d9 - rt::unwind::try::try_fn::h13260011850501376318
16: 0x317dd51cea8 - rust_try_inner
17: 0x317dd51ce95 - rust_try
18: 0x317dd48b147 - rt::unwind::try::inner_try::hb6dce8ad1d668192wMw
19: 0x317dda9a2f9 - boxed::F.FnBox<A>::call_box::h7963608429107561708
20: 0x317dd49f151 - sys::thread::Thread::new::thread_start::h82e421ca205cff91sWv
21: 0x317d702369b - <unknown>
22: 0x317dd0f932c - clone
23: 0x0 - <unknown>
The original example gets an error through a different code path (check_casts
-> middle::CastTy::from_ty
-> ty::type_is_c_like_enum
), but the result is still that ty::enum_variants
is called, which then attempts to evaluate the constant expression, causing an error.
For unresolved paths I think we should have the const_eval
functions return an error rather than panicking. This is a bit of a mess (e.g. lots of unhelpful uses of Option
rather than Error
for error handling), and should be fixed anyway.