Skip to content

Nullable field optimization does the Wrong Thing when faced with associated types #27532

Closed
@arielb1

Description

@arielb1

STR

use std::mem;
trait Mirror { type Image; }
impl<T> Mirror for T { type Image = T; }
struct S1<T>(<T as Mirror>::Image);
struct S2<T>(T);

fn main() {
    println!("with: {}", mem::size_of::<Option<S1<&u8>>>());
    println!("without: {}", mem::size_of::<Option<S2<&u8>>>());
}

Expected Result

Nullable field optimization should be triggered in both cases

Result

with: 8
without: 16

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions