Skip to content

impl block on a type defined with type_alias_impl_trait can conflict with other unrelated impl #139583

@douglas-raillard-arm

Description

@douglas-raillard-arm

I tried this code:

#![feature(type_alias_impl_trait)] use std::any::TypeId; pub trait Trait {} impl<T: ?Sized> Trait for T {} pub trait Other {} macro_rules! mymac { () => {{ struct S; type Foo = impl Trait; let x: Foo = S; println!("{:?}", TypeId::of::<Foo>()); impl Foo { fn foo() -> () {} } impl Other for Foo {} }}; } fn main() { mymac!(); mymac!(); }

I expected to see this happen: compiles without error

Instead, this happened:

error[E0119]: conflicting implementations of trait `Other` for type `main::Foo` --> src/main.rs:19:9 | 19 | impl Other for Foo {} | ^^^^^^^^^^^^^^^^^^ | | | first implementation here | conflicting implementation for `main::Foo` ... 25 | mymac!(); | -------- in this macro invocation | = note: this error originates in the macro `mymac` (in Nightly builds, run with -Z macro-backtrace for more info) 

Meta

Rust nightly version on the playground as of 9th of April 2025.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-coherenceArea: CoherenceA-hygieneArea: Macro hygieneC-bugCategory: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types 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