Skip to content

Commit e907a0e

Browse files
committed
const eval of FRTs (they are uninhabited, so not really much to do)
1 parent 14f4d3e commit e907a0e

File tree

6 files changed

+33
-3
lines changed

6 files changed

+33
-3
lines changed

compiler/rustc_const_eval/src/const_eval/valtrees.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ fn const_to_valtree_inner<'tcx>(
161161
branches(ecx, place, def.variant(variant).fields.len(), def.is_enum().then_some(variant), num_nodes)
162162
}
163163

164-
ty::Never
164+
ty::Field(..)
165+
| ty::Never
165166
| ty::Error(_)
166167
| ty::Foreign(..)
167168
| ty::Infer(ty::FreshIntTy(_))
@@ -323,7 +324,9 @@ pub fn valtree_to_const_value<'tcx>(
323324

324325
op_to_const(&ecx, &place.into(), /* for diagnostics */ false)
325326
}
326-
ty::Never
327+
328+
ty::Field(..)
329+
| ty::Never
327330
| ty::Error(_)
328331
| ty::Foreign(..)
329332
| ty::Infer(ty::FreshIntTy(_))

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
188188
| ty::CoroutineWitness(..)
189189
| ty::UnsafeBinder(_)
190190
| ty::Never
191+
| ty::Field(..)
191192
| ty::Tuple(_)
192193
| ty::Error(_) => ConstValue::from_target_usize(0u64, &tcx),
193194
};

compiler/rustc_const_eval/src/interpret/stack.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
507507
| ty::Closure(..)
508508
| ty::CoroutineClosure(..)
509509
| ty::Never
510+
| ty::Field(..)
510511
| ty::Error(_) => true,
511512

512513
ty::Str | ty::Slice(_) | ty::Dynamic(_, _, ty::Dyn) | ty::Foreign(..) => false,

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
771771
interp_ok(true)
772772
}
773773
ty::Never => throw_validation_failure!(self.path, NeverVal),
774+
ty::Field(..) => throw_validation_failure!(self.path, NeverVal),
774775
ty::Foreign(..) | ty::FnDef(..) => {
775776
// Nothing to check.
776777
interp_ok(true)

compiler/rustc_const_eval/src/util/type_name.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::fmt::Write;
2+
use std::ops::ControlFlow;
23

34
use rustc_data_structures::intern::Interned;
45
use rustc_hir::def_id::{CrateNum, DefId};
@@ -58,6 +59,29 @@ impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> {
5859
| ty::CoroutineClosure(def_id, args)
5960
| ty::Coroutine(def_id, args) => self.print_def_path(def_id, args),
6061
ty::Foreign(def_id) => self.print_def_path(def_id, &[]),
62+
ty::Field(container, field_path) => {
63+
write!(self, "field_of!(")?;
64+
self.print_type(container)?;
65+
write!(self, ", ")?;
66+
field_path
67+
.walk(self.tcx, container, |_, name, _, last| {
68+
match write!(self, "{name}") {
69+
Ok(()) => ControlFlow::Continue(()),
70+
Err(err) => ControlFlow::Break(Err(err)),
71+
}?;
72+
if !last {
73+
match write!(self, ".") {
74+
Ok(()) => ControlFlow::Continue(()),
75+
Err(err) => ControlFlow::Break(Err(err)),
76+
}
77+
} else {
78+
ControlFlow::Continue(())
79+
}
80+
})
81+
.unwrap_or(Ok(()))?;
82+
write!(self, ")")?;
83+
Ok(())
84+
}
6185

6286
ty::Alias(ty::Free, _) => bug!("type_name: unexpected free alias"),
6387
ty::Alias(ty::Inherent, _) => bug!("type_name: unexpected inherent projection"),

tests/debuginfo/function-names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
// Const generic parameter
3939
// gdb-command:info functions -q function_names::const_generic_fn.*
4040
// gdb-check:[...]static fn function_names::const_generic_fn_bool<false>();
41-
// gdb-check:[...]static fn function_names::const_generic_fn_non_int<{CONST#ffa3db4ca1d52dce}>();
41+
// gdb-check:[...]static fn function_names::const_generic_fn_non_int<{CONST#5177fe61e1757625}>();
4242
// gdb-check:[...]static fn function_names::const_generic_fn_signed_int<-7>();
4343
// gdb-check:[...]static fn function_names::const_generic_fn_unsigned_int<14>();
4444

0 commit comments

Comments
 (0)