Skip to content

Inference failure when a trait is changed to a marker trait #61651

Closed
@scottmcm

Description

@scottmcm
#![feature(marker_trait_attr)]

#[marker] // Remove this line and it works?!?
trait Foo<T> {}
impl Foo<u16> for u8 {}
impl Foo<[u8; 1]> for u8 {}
fn foo<T: Foo<U>, U>(_: T) -> U { unimplemented!() }

fn main() {
    let _: u16 = foo(0_u8);
}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=120bf7cdd44e52d7a6d2280cdcdc6de6

It works if I remove the #[marker], but when it's a #[marker] trait it fails with

error[E0308]: mismatched types
  --> src/lib.rs:10:18
   |
10 |     let _: u16 = foo(0_u8);
   |                  ^^^^^^^^^ expected u16, found array of 1 elements
   |
   = note: expected type `u16`
              found type `[u8; 1]`

(I didn't think this property of a trait affected inference at all, so I'm very confused by this...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inferenceArea: Type inferenceC-bugCategory: This is a bug.F-marker_trait_attr`#![feature(marker_trait_attr)]`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