Skip to content

Commit 22c1a0a

Browse files
committed
For now, accept all data for integer types when not in const mode
We'll try ruling out undef later
1 parent 9bb4bcd commit 22c1a0a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/librustc_mir/interpret/validity.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,18 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
162162
scalar_format(value), path, "a valid unicode codepoint");
163163
},
164164
ty::Float(_) | ty::Int(_) | ty::Uint(_) if const_mode => {
165-
// Integers/floats in CTFE: Must be scalar bits
165+
// Integers/floats in CTFE: Must be scalar bits, pointers are dangerous
166166
try_validation!(value.to_bits(size),
167167
scalar_format(value), path, "initialized plain bits");
168168
}
169169
ty::Float(_) | ty::Int(_) | ty::Uint(_) | ty::RawPtr(_) => {
170-
// Anything but undef goes
171-
try_validation!(value.not_undef(),
172-
scalar_format(value), path, "a raw pointer");
170+
if const_mode {
171+
// Anything but undef goes
172+
try_validation!(value.not_undef(),
173+
scalar_format(value), path, "a raw pointer");
174+
} else {
175+
// At run-time, for now, we accept *anything* for these types.
176+
}
173177
},
174178
ty::Ref(..) => {
175179
// This is checked by the recursive reference handling, nothing to do here.
@@ -182,10 +186,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
182186
scalar_format(value), path, "a function pointer");
183187
// FIXME: Check if the signature matches
184188
}
185-
ty::FnDef(..) => {
186-
// This is a zero-sized type with all relevant data sitting in the type.
187-
// There is nothing to validate.
188-
}
189+
// This should be all
190+
ty::Never => bug!("Uninhabited type should have been catched earlier"),
189191
_ => bug!("Unexpected primitive type {}", ty)
190192
}
191193
Ok(())

0 commit comments

Comments
 (0)