Skip to content

Commit 4546d77

Browse files
committed
Fix more ICEs
1 parent 53aea53 commit 4546d77

File tree

4 files changed

+28
-53
lines changed

4 files changed

+28
-53
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,29 @@ pub fn eval_to_const_value_raw_provider<'tcx>(
294294
)
295295
},
296296
);
297+
} else if let ty::InstanceKind::Item(def_id) = key.value.instance.def
298+
&& matches!(tcx.def_kind(def_id), DefKind::Const | DefKind::AssocConst)
299+
{
300+
let ct = tcx.const_of_item(def_id).instantiate(tcx, key.value.instance.args);
301+
match ct.kind() {
302+
ty::ConstKind::Unevaluated(_) => {
303+
return Err(ErrorHandled::TooGeneric(DUMMY_SP));
304+
}
305+
ty::ConstKind::Value(cv) => return Ok(tcx.valtree_to_const_val(cv)),
306+
ty::ConstKind::Error(guar) => {
307+
return Err(ErrorHandled::Reported(
308+
ReportedErrorInfo::const_eval_error(guar),
309+
DUMMY_SP,
310+
));
311+
}
312+
ty::ConstKind::Expr(_) => return Err(ErrorHandled::TooGeneric(DUMMY_SP)),
313+
ty::ConstKind::Param(_) | ty::ConstKind::Placeholder(_) => {
314+
return Err(ErrorHandled::TooGeneric(DUMMY_SP));
315+
}
316+
ty::ConstKind::Infer(_) | ty::ConstKind::Bound(..) => {
317+
bug!("unexpected constant {ct:?}")
318+
}
319+
}
297320
}
298321

299322
tcx.eval_to_allocation_raw(key).map(|val| turn_into_const_value(tcx, val, key))

compiler/rustc_hir/src/hir.rs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4846,35 +4846,17 @@ impl<'hir> Node<'hir> {
48464846
match self {
48474847
Node::Item(Item {
48484848
owner_id,
4849-
kind:
4850-
ItemKind::Const(
4851-
..,
4852-
ConstArg { kind: ConstArgKind::Anon(AnonConst { body, .. }), .. },
4853-
)
4854-
| ItemKind::Static(.., body)
4855-
| ItemKind::Fn { body, .. },
4849+
kind: ItemKind::Static(.., body) | ItemKind::Fn { body, .. },
48564850
..
48574851
})
48584852
| Node::TraitItem(TraitItem {
48594853
owner_id,
4860-
kind:
4861-
TraitItemKind::Const(
4862-
_,
4863-
Some(ConstArg { kind: ConstArgKind::Anon(AnonConst { body, .. }), .. }),
4864-
)
4865-
| TraitItemKind::Fn(_, TraitFn::Provided(body)),
4854+
kind: TraitItemKind::Fn(_, TraitFn::Provided(body)),
48664855
..
48674856
})
4868-
| Node::ImplItem(ImplItem {
4869-
owner_id,
4870-
kind:
4871-
ImplItemKind::Const(
4872-
_,
4873-
ConstArg { kind: ConstArgKind::Anon(AnonConst { body, .. }), .. },
4874-
)
4875-
| ImplItemKind::Fn(_, body),
4876-
..
4877-
}) => Some((owner_id.def_id, *body)),
4857+
| Node::ImplItem(ImplItem { owner_id, kind: ImplItemKind::Fn(_, body), .. }) => {
4858+
Some((owner_id.def_id, *body))
4859+
}
48784860

48794861
Node::Item(Item {
48804862
owner_id, kind: ItemKind::GlobalAsm { asm: _, fake_body }, ..

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,6 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
203203
tcx.ensure_ok().eval_static_initializer(item_def_id);
204204
check::maybe_check_static_with_link_section(tcx, item_def_id);
205205
}
206-
DefKind::Const if tcx.generics_of(item_def_id).is_empty() => {
207-
let instance = ty::Instance::new_raw(item_def_id.into(), ty::GenericArgs::empty());
208-
let cid = GlobalId { instance, promoted: None };
209-
let typing_env = ty::TypingEnv::fully_monomorphized();
210-
tcx.ensure_ok().eval_to_const_value_raw(typing_env.as_query_input(cid));
211-
}
212206
_ => (),
213207
}
214208
// Skip `AnonConst`s because we feed their `type_of`.

compiler/rustc_middle/src/mir/interpret/queries.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,6 @@ impl<'tcx> TyCtxt<'tcx> {
7575
// FIXME: maybe have a separate version for resolving mir::UnevaluatedConst?
7676
match ty::Instance::try_resolve(self, typing_env, ct.def, ct.args) {
7777
Ok(Some(instance)) => {
78-
if let ty::InstanceKind::Item(def_id) = instance.def
79-
&& matches!(self.def_kind(def_id), DefKind::Const | DefKind::AssocConst)
80-
{
81-
let ct = self.const_of_item(def_id).instantiate(self, instance.args);
82-
match ct.kind() {
83-
ty::ConstKind::Unevaluated(_) => {
84-
return Err(ErrorHandled::TooGeneric(DUMMY_SP));
85-
}
86-
ty::ConstKind::Value(cv) => return Ok(self.valtree_to_const_val(cv)),
87-
ty::ConstKind::Error(guar) => {
88-
return Err(ErrorHandled::Reported(
89-
ReportedErrorInfo::const_eval_error(guar),
90-
DUMMY_SP,
91-
));
92-
}
93-
ty::ConstKind::Expr(_) => return Err(ErrorHandled::TooGeneric(DUMMY_SP)),
94-
ty::ConstKind::Param(_) | ty::ConstKind::Placeholder(_) => {
95-
return Err(ErrorHandled::TooGeneric(DUMMY_SP));
96-
}
97-
ty::ConstKind::Infer(_) | ty::ConstKind::Bound(..) => {
98-
bug!("unexpected constant {ct:?}")
99-
}
100-
}
101-
}
10278
let cid = GlobalId { instance, promoted: ct.promoted };
10379
self.const_eval_global_id(typing_env, cid, span)
10480
}

0 commit comments

Comments
 (0)