@@ -221,21 +221,21 @@ fn represent_type_uncached(cx: &mut CrateContext, t: ty::t) -> Repr {
221
221
/// For use in lint or similar, where being sound but slightly incomplete is acceptable.
222
222
pub fn is_ffi_safe ( tcx : ty:: ctxt , def_id : ast:: DefId ) -> bool {
223
223
match ty:: get ( ty:: lookup_item_type ( tcx, def_id) . ty ) . sty {
224
- ty:: ty_enum( def_id, ref substs ) => {
225
- let cases = get_cases ( tcx, def_id, substs ) ;
224
+ ty:: ty_enum( def_id, _ ) => {
225
+ let variants = ty :: enum_variants ( tcx, def_id) ;
226
226
// Univariant => like struct/tuple.
227
- if cases . len ( ) <= 2 {
227
+ if variants . len ( ) <= 1 {
228
228
return true ;
229
229
}
230
230
let hint = ty:: lookup_repr_hint ( tcx, def_id) ;
231
231
// Appropriate representation explicitly selected?
232
232
if hint. is_ffi_safe ( ) {
233
233
return true ;
234
234
}
235
- // Conservative approximation of nullable pointers, for Option<~T> etc.
236
- if cases . len ( ) == 2 && hint == attr :: ReprAny &&
237
- ( cases [ 0 ] . tys . is_empty ( ) && cases [ 1 ] . find_ptr ( ) . is_some ( ) ||
238
- cases [ 1 ] . tys . is_empty ( ) && cases [ 0 ] . find_ptr ( ) . is_some ( ) ) {
235
+ // Option<~T> and similar are used in FFI. Rather than try to resolve type parameters
236
+ // and recognize this case exactly, this overapproximates -- assuming that if a
237
+ // non-C-like enum is being used in FFI then the user knows what they're doing.
238
+ if variants . iter ( ) . any ( |vi| !vi . args . is_empty ( ) ) {
239
239
return true ;
240
240
}
241
241
false
0 commit comments