-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ICE with std::mem::size_of with repr(packed)
plus associated type
#58158
Comments
Slightly minimized (this can be reduced much more); the ICE in the following also occurs with use std::any::Any;
use std::fmt::Debug;
use std::marker::PhantomData;
#[repr(packed)]
struct Foo(Vector3<f32>);
fn main() {
// std::mem::size_of::<Foo>();
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct Matrix<N: Scalar, R: Dim, C: Dim, S> {
pub data: S,
_phantoms: PhantomData<(N, R, C)>,
}
type MatrixMN<N, R, C> = Matrix<N, R, C, Owned<N, R, C>>;
type VectorN<N, D> = MatrixMN<N, D, U1>;
type Vector3<N> = VectorN<N, U3>;
pub trait Dim: Any + Debug + Copy + PartialEq + Send + Sync {}
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct U1;
impl Dim for U1 {}
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct U3;
impl Dim for U3 {}
pub trait Scalar: Copy + PartialEq + Debug + Any {}
impl<T: Copy + PartialEq + Debug + Any> Scalar for T {}
pub unsafe trait Storage<N: Scalar, R: Dim, C: Dim = U1>: Debug + Sized {
type RStride: Dim;
type CStride: Dim;
}
pub unsafe trait StorageMut<N: Scalar, R: Dim, C: Dim = U1>: Storage<N, R, C> {}
pub unsafe trait ContiguousStorage<N: Scalar, R: Dim, C: Dim = U1>:
Storage<N, R, C>
{
}
pub unsafe trait ContiguousStorageMut<N: Scalar, R: Dim, C: Dim = U1>:
ContiguousStorage<N, R, C> + StorageMut<N, R, C>
{
}
pub trait Allocator<N: Scalar, R: Dim, C: Dim = U1>: Any + Sized {
type Buffer: ContiguousStorageMut<N, R, C> + Clone;
}
pub struct DefaultAllocator;
pub type Owned<N, R, C = U1> = <DefaultAllocator as Allocator<N, R, C>>::Buffer;
|
Minimized further: pub struct Matrix<S> {}
pub struct DefaultAllocator;
pub trait Allocator {
type Buffer;
}
#[repr(packed)]
struct Foo(Matrix<<DefaultAllocator as Allocator>::Buffer>); |
Even more: #[repr(packed)]
pub struct Foo(<Vec<u32> as IntoIterator>::Item); The ICE does not happen without the |
Also note, that this "never worked" (I went back to nightly-2018-03-01, and even there it panics). |
triage. Marking P-high mostly because 1. it is an ICE and 2. I want to ensure it is at the front of the T-compiler queue for next week's meeting. |
@hellow554 can you clarify what you meant by this parenthetical? Are you saying if I add |
triage: assigning to self. |
repr(packed)
plus associated type
repr(packed)
plus associated typerepr(packed)
plus associated type
There's other variations up above, but I thought this one was particularly illuminating: struct DefaultAllocator;
trait Allocator { type Buffer; }
// impl Allocator for DefaultAllocator { type Buffer = (); }
#[repr(packed)]
struct Foo(<DefaultAllocator as Allocator>::Buffer); note in particular that, at least in this variation, the concrete type here does not implement the trait in question. So its impossible to actually resolve the associated type when doing the (If you add back in the impl commented-out above, then the code compiles. And if you leave it out but remove |
when you use it as a regression test in https://github.com/rust-lang/rust/tree/master/src/test |
i find that ... surprising. Will investigate. |
Sorry @pnkfelix ! I don't mean that it doesn't crash when used as test, but if this issue will be fixed my code can be used as testcode because it doesn't emit any warnings or errors. |
@hellow554 ah, okay yes that makes more sense to me! |
…type-ice, r=petrochenkov delay_span_bug in wfcheck's ty.lift_to_tcx unwrap Fix rust-lang#58158
The compiler panics when there's a
std::mem::size_of
call for a struct withrepr(packed)
that contains a matrix type from nalgebra. I'm fairly new to rust and I'm not sure how to isolate what within the nalgebra crate might be causing this.src/main.rs:
Cargo.toml
Result of
RUST_BACKTRACE=1 cargo build --verbose
The text was updated successfully, but these errors were encountered: