Skip to content

Chalk HasInterner derive macro doesn't work because it expands to named constant #9562

Closed
@flodiebold

Description

@flodiebold

Reproduction:

use std::marker::PhantomData;

use chalk_ir::interner::{HasInterner, Interner};
use chalk_derive::HasInterner;

#[derive(HasInterner)]
struct WithInterner<I: Interner> {
    _phantom: PhantomData<I>,
}

fn test<I: Interner>(i: I) {
    let x: <WithInterner<I> as HasInterner>::Interner = i;
}

With chalk_ir and chalk_derive dependencies. x should be type I, which works if I write the HasInterner impl by hand, but not in the above code.

It turns out that the synstructure derive macro expands to an impl in a named constant:

#[allow(non_upper_case_globals)]
#[doc(hidden)]
const _DERIVE_chalk_ir_interner_HasInterner_FOR_WithInterner: () = {
    impl<I: Interner> ::chalk_ir::interner::HasInterner for WithInterner<I> {
        type Interner = I;
    }
};

Which we don't support. Maybe we can change synstructure to use unnamed consts, or build a hack to treat _DERIVE consts like unnamed ones 😬

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macromacro expansionS-actionableSomeone could pick this issue up and work on it right now

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions