Normalize when computing offset_of for slice tail
This commit is contained in:
parent
85b5e42d5e
commit
d9dd5509dc
2 changed files with 48 additions and 2 deletions
|
@ -404,8 +404,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
code: traits::ObligationCauseCode<'tcx>,
|
code: traits::ObligationCauseCode<'tcx>,
|
||||||
) {
|
) {
|
||||||
if !ty.references_error() {
|
if !ty.references_error() {
|
||||||
let tail =
|
let tail = self.tcx.struct_tail_with_normalize(
|
||||||
self.tcx.struct_tail_with_normalize(ty, |ty| self.normalize(span, ty), || {});
|
ty,
|
||||||
|
|ty| {
|
||||||
|
if self.next_trait_solver() {
|
||||||
|
self.try_structurally_resolve_type(span, ty)
|
||||||
|
} else {
|
||||||
|
self.normalize(span, ty)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|| {},
|
||||||
|
);
|
||||||
// Sized types have static alignment, and so do slices.
|
// Sized types have static alignment, and so do slices.
|
||||||
if tail.is_trivially_sized(self.tcx) || matches!(tail.kind(), ty::Slice(..)) {
|
if tail.is_trivially_sized(self.tcx) || matches!(tail.kind(), ty::Slice(..)) {
|
||||||
// Nothing else is required here.
|
// Nothing else is required here.
|
||||||
|
|
37
tests/ui/offset-of/offset-of-slice-normalized.rs
Normal file
37
tests/ui/offset-of/offset-of-slice-normalized.rs
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
//@ revisions: current next
|
||||||
|
//@ ignore-compare-mode-next-solver (explicit revisions)
|
||||||
|
//@[next] compile-flags: -Znext-solver
|
||||||
|
//@ run-pass
|
||||||
|
|
||||||
|
#![feature(offset_of_slice)]
|
||||||
|
|
||||||
|
use std::mem::offset_of;
|
||||||
|
|
||||||
|
trait Mirror {
|
||||||
|
type Assoc: ?Sized;
|
||||||
|
}
|
||||||
|
impl<T: ?Sized> Mirror for T {
|
||||||
|
type Assoc = T;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
struct S {
|
||||||
|
a: u8,
|
||||||
|
b: (u8, u8),
|
||||||
|
c: <[i32] as Mirror>::Assoc,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
struct T {
|
||||||
|
x: i8,
|
||||||
|
y: S,
|
||||||
|
}
|
||||||
|
|
||||||
|
type Tup = (i16, <[i32] as Mirror>::Assoc);
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
assert_eq!(offset_of!(S, c), 4);
|
||||||
|
assert_eq!(offset_of!(T, y), 4);
|
||||||
|
assert_eq!(offset_of!(T, y.c), 8);
|
||||||
|
assert_eq!(offset_of!(Tup, 1), 4);
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue