Skip to content

Commit 8cea658

Browse files
committed
Rollup merge of #56059 - alexcrichton:fix-tests, r=sfackler
Increase `Duration` approximate equal threshold to 1us Previously this threshold when testing was 100ns, but the Windows documentation states: > which is a high resolution (<1us) time stamp which presumably means that we could have up to 1us resolution, which means that 100ns doesn't capture "equivalent" time intervals due to various bits of rounding here and there. It's hoped that this.. Closes #56034
2 parents 10565c4 + 8607325 commit 8cea658

File tree

4 files changed

+54
-5
lines changed

4 files changed

+54
-5
lines changed

src/librustc_mir/interpret/eval_context.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,21 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
340340
// the last field). Can't have foreign types here, how would we
341341
// adjust alignment and size for them?
342342
let field = layout.field(self, layout.fields.count() - 1)?;
343-
let (unsized_size, unsized_align) = self.size_and_align_of(metadata, field)?
344-
.expect("Fields cannot be extern types");
343+
let (unsized_size, unsized_align) = match self.size_and_align_of(metadata, field)? {
344+
Some(size_and_align) => size_and_align,
345+
None => {
346+
// A field with extern type. If this field is at offset 0, we behave
347+
// like the underlying extern type.
348+
// FIXME: Once we have made decisions for how to handle size and alignment
349+
// of `extern type`, this should be adapted. It is just a temporary hack
350+
// to get some code to work that probably ought to work.
351+
if sized_size == Size::ZERO {
352+
return Ok(None)
353+
} else {
354+
bug!("Fields cannot be extern types, unless they are at offset 0")
355+
}
356+
}
357+
};
345358

346359
// FIXME (#26403, #27023): We should be adding padding
347360
// to `sized_size` (to accommodate the `unsized_align`

src/librustc_mir/interpret/place.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,17 @@ where
351351
// Offset may need adjustment for unsized fields
352352
let (meta, offset) = if field_layout.is_unsized() {
353353
// re-use parent metadata to determine dynamic field layout
354-
let (_, align) = self.size_and_align_of(base.meta, field_layout)?
355-
.expect("Fields cannot be extern types");
354+
let align = match self.size_and_align_of(base.meta, field_layout)? {
355+
Some((_, align)) => align,
356+
None if offset == Size::ZERO =>
357+
// An extern type at offset 0, we fall back to its static alignment.
358+
// FIXME: Once we have made decisions for how to handle size and alignment
359+
// of `extern type`, this should be adapted. It is just a temporary hack
360+
// to get some code to work that probably ought to work.
361+
field_layout.align,
362+
None =>
363+
bug!("Cannot compute offset for extern type field at non-0 offset"),
364+
};
356365
(base.meta, offset.abi_align(align))
357366
} else {
358367
// base.meta could be present; we might be accessing a sized field of an unsized

src/libstd/time.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ mod tests {
481481
let (a, b) = ($a, $b);
482482
if a != b {
483483
let (a, b) = if a > b {(a, b)} else {(b, a)};
484-
assert!(a - Duration::new(0, 100) <= b,
484+
assert!(a - Duration::new(0, 1000) <= b,
485485
"{:?} is not almost equal to {:?}", a, b);
486486
}
487487
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// compile-pass
2+
3+
// Test that we can handle newtypes wrapping extern types
4+
5+
#![feature(extern_types, const_transmute)]
6+
7+
use std::marker::PhantomData;
8+
9+
extern "C" {
10+
pub type ExternType;
11+
}
12+
unsafe impl Sync for ExternType {}
13+
static MAGIC_FFI_STATIC: u8 = 42;
14+
15+
#[repr(transparent)]
16+
pub struct Wrapper(ExternType);
17+
pub static MAGIC_FFI_REF: &'static Wrapper = unsafe {
18+
std::mem::transmute(&MAGIC_FFI_STATIC)
19+
};
20+
21+
#[repr(transparent)]
22+
pub struct Wrapper2(PhantomData<Vec<i32>>, ExternType);
23+
pub static MAGIC_FFI_REF2: &'static Wrapper2 = unsafe {
24+
std::mem::transmute(&MAGIC_FFI_STATIC)
25+
};
26+
27+
fn main() {}

0 commit comments

Comments
 (0)