Skip to content

#[marker]: overlapping impls misinteract with lifetimes #89515

Open
@danielhenrymantilla

Description

@danielhenrymantilla

I tried this code:

#![feature(marker_trait_attr)]

#[marker] trait Marker {}

impl Marker for &'_ () {}
impl Marker for &'_ () {}

I expected to see this happen:

  • Code compiles fine, and for any 'lt, &'lt () : Marker does hold.

Instead, this happened:

  • error[E0283]: type annotations needed
     --> src/lib.rs:5:6
      |
    5 | impl Marker for &'_ () {}
      |      ^^^^^^ cannot infer type for reference `&()`
      |
      = note: cannot satisfy `&(): Marker`
    note: required by a bound in `Marker`
     --> src/lib.rs:3:11
      |
    3 | #[marker] trait Marker {}
      |           ^^^^^^^^^^^^ required by this bound in `Marker`
    
    error[E0283]: type annotations needed
     --> src/lib.rs:6:6
      |
    6 | impl Marker for &'_ () {}
      |      ^^^^^^ cannot infer type for reference `&()`
      |
      = note: cannot satisfy `&(): Marker`
    note: required by a bound in `Marker`
     --> src/lib.rs:3:11
      |
    3 | #[marker] trait Marker {}
      |           ^^^^^^^^^^^^ required by this bound in `Marker`
    
    For more information about this error, try `rustc --explain E0283`.
    • FWIW, here is the one-sentence description of that error code:

      An implementation cannot be chosen unambiguously because of lack of information.

Meta

Happens as of the latest nightly available on the Playground:

  • 1.57.0-nightly2021-10-03

Context

This comes from #89357 (review), once reduced to:

trait A {}
trait B {}

impl A for &'_ () {}
impl B for &'_ () {}

/// `A ∪ B`
#[marker]
trait Marker {}

impl<T : A> Marker for T {}
impl<T : B> Marker for T {}

const _: () = {
    fn assert_impls_Marker<T : Marker> ()
    {}
    
    let _ = assert_impls_Marker::<&()>; // Fails
    let _ = assert_impls_Marker::<&'static ()>; // Fails as well
};

which was then further reduced to the initial snippet.


@rustbot modify labels +requires-nightly +F-marker_trait_attr +A-traits +A-lifetimes

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsA-trait-systemArea: Trait systemC-bugCategory: This is a bug.F-marker_trait_attr`#![feature(marker_trait_attr)]`S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-typesRelevant to the types team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions