Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
danielhenrymantilla opened this issue Oct 4, 2021 · 2 comments
Open

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

danielhenrymantilla opened this issue Oct 4, 2021 · 2 comments
Labels
A-lifetimes Area: Lifetimes / regions A-trait-system Area: Trait system C-bug Category: This is a bug. F-marker_trait_attr `#![feature(marker_trait_attr)]` requires-nightly This issue requires a nightly compiler in some way. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@danielhenrymantilla
Copy link
Contributor

danielhenrymantilla commented Oct 4, 2021

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

@danielhenrymantilla danielhenrymantilla added the C-bug Category: This is a bug. label Oct 4, 2021
@rustbot
Copy link
Collaborator

rustbot commented Oct 4, 2021

Error: Label B-unstable can only be set by Rust team members

Please let @rust-lang/release know if you're having trouble with this bot.

@rustbot rustbot added A-lifetimes Area: Lifetimes / regions A-trait-system Area: Trait system F-marker_trait_attr `#![feature(marker_trait_attr)]` requires-nightly This issue requires a nightly compiler in some way. labels Oct 4, 2021
@crlf0710 crlf0710 added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Sep 8, 2022
@crlf0710
Copy link
Member

crlf0710 commented Sep 8, 2022

Seems this is just a diagnostics issue? Better error message is needed here, and "type annotations needed" is not actually correct.

Edit: No, sorry.

@crlf0710 crlf0710 added A-diagnostics Area: Messages for errors, warnings, and lints and removed A-diagnostics Area: Messages for errors, warnings, and lints labels Sep 8, 2022
@jackh726 jackh726 added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions A-trait-system Area: Trait system C-bug Category: This is a bug. F-marker_trait_attr `#![feature(marker_trait_attr)]` requires-nightly This issue requires a nightly compiler in some way. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants