Skip to content

Commit 1394eb9

Browse files
committed
---
yaml --- r: 166764 b: refs/heads/master c: 46e7376 h: refs/heads/master v: v3
1 parent 92a4717 commit 1394eb9

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 6d91419f27b25810f2cfcd263e0e20b62910f4ff
2+
refs/heads/master: 46e73764896316ef1384591656cfca01280c5e5c
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 023dfb0c898d851dee6ace2f8339b73b5287136b
55
refs/heads/try: f5d619caf9f32458680fae55526b99582ca682dd

trunk/src/librustc/middle/lang_items.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ lets_do_this! {
327327
NoSyncItem, "no_sync_bound", no_sync_bound;
328328
ManagedItem, "managed_bound", managed_bound;
329329

330+
NonZeroItem, "non_zero", non_zero;
331+
330332
IteratorItem, "iterator", iterator;
331333

332334
StackExhaustedLangItem, "stack_exhausted", stack_exhausted;

trunk/src/librustc_trans/trans/adt.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,19 @@ fn find_discr_field_candidate<'tcx>(tcx: &ty::ctxt<'tcx>, ty: Ty<'tcx>) -> Optio
357357
// Closures are a pair of pointers: the code and environment
358358
ty::ty_closure(..) => Some(vec![FAT_PTR_ADDR]),
359359

360-
// Perhaps one of the fields of this struct is non-null
360+
// Is this the NonZero lang item wrapping a pointer or integer type?
361+
ty::ty_struct(did, ref substs) if Some(did) == tcx.lang_items.non_zero() => {
362+
let nonzero_fields = ty::lookup_struct_fields(tcx, did);
363+
assert_eq!(nonzero_fields.len(), 1);
364+
let nonzero_field = ty::lookup_field_type(tcx, did, nonzero_fields[0].id, substs);
365+
match nonzero_field.sty {
366+
ty::ty_ptr(..) | ty::ty_int(..) |
367+
ty::ty_uint(..) => Some(vec![0]),
368+
_ => None
369+
}
370+
},
371+
372+
// Perhaps one of the fields of this struct is non-zero
361373
// let's recurse and find out
362374
ty::ty_struct(def_id, ref substs) => {
363375
let fields = ty::lookup_struct_fields(tcx, def_id);

0 commit comments

Comments
 (0)