Skip to content

An associated type magically adds a destructor? #29821

Closed
@alevy

Description

@alevy

These two code snippets should functionally be doing the same thing, but the type checker seems to think one has a destructor. The difference seems to be in the reliance on an associated type.

rustc complains that myfoo cannot be declared a mutable static because it has a desctructor:

pub trait Foo {
    type FooAssoc;
}

pub struct Bar<F: Foo> {
    id: F::FooAssoc
}

pub struct Baz;

impl Foo for Baz {
    type FooAssoc = usize;
}

static mut myfoo : Bar<Baz> = Bar { id: 0 };

While this, unsurprisingly, works:

pub struct Bar<A> {
    id: A
}

static mut myfoo : Bar<usize> = Bar { id: 0 };

Here are links to non-compiling/compiling examples on play.rust-lang:

Metadata

Metadata

Assignees

Labels

A-trait-systemArea: Trait systemC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions