Skip to content

Instantly share code, notes, and snippets.

Created July 23, 2015 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/34fae5ab507447e7b52d to your computer and use it in GitHub Desktop.
Save anonymous/34fae5ab507447e7b52d to your computer and use it in GitHub Desktop.
Shared via Rust Playground
#![
pub mod marker {
pub trait Marker: check::EligibleHelper {}
pub fn accepts_marker<T: Marker>(_t: T) {}
mod check {
pub trait Eligible: super::Marker {}
impl Eligible for .. {}
impl<'a, T> !Eligible for &'a T {}
impl<'a, T> !Eligible for &'a mut T {}
pub trait EligibleHelper {}
impl<T> EligibleHelper for T where T: Eligible {}
}
}
use marker::{Marker, accepts_marker};
struct A;
struct B;
struct C;
struct D(A, B);
struct E(A, B);
struct F(A, C);
impl Marker for A {}
impl Marker for B {}
impl Marker for D {}
// error: the trait `marker::Marker` is not implemented for the type `C`
// impl Marker for F {}
// error: the trait `marker::check::Eligible` is not implemented for the type `&'a A`
// impl<'a> Marker for &'a A {}
// error: the trait `marker::check::Eligible` is not implemented for the type `&'a mut A`
// impl<'a> Marker for &'a mut A {}
fn main() {
accepts_marker(A);
accepts_marker(B);
// error: the trait `marker::Marker` is not implemented for the type `C`
// accepts_marker(C);
accepts_marker(D(A, B));
// error: the trait `marker::Marker` is not implemented for the type `E`
// accepts_marker(E(A, B));
// error: the trait `marker::Marker` is not implemented for the type `F`
// accepts_marker(F(A, C));
// error: the trait `marker::Marker` is not implemented for the type `&A`
// accepts_marker(&A);
// error: the trait `marker::Marker` is not implemented for the type `&mut A`
// accepts_marker(&mut A);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment