Open
Description
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-nightly
—2021-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