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

Bounds seem to be ignored in negative impls #23072

Closed
japaric opened this issue Mar 5, 2015 · 4 comments
Closed

Bounds seem to be ignored in negative impls #23072

japaric opened this issue Mar 5, 2015 · 4 comments
Assignees
Labels
A-traits Area: Trait system

Comments

@japaric
Copy link
Member

japaric commented Mar 5, 2015

#![feature(optin_builtin_traits)]

use std::marker::MarkerTrait;

unsafe trait Pod: MarkerTrait {}
unsafe impl Pod for .. {}

trait Bound: MarkerTrait {}

// it seems that the bound is ignored here, i.e. this gets treated as `impl<T> !Pod for T {}`
impl<T: Bound> !Pod for T {}

fn is_pod<T: Pod>(_: T) {}

fn main() {
    is_pod(0i32);  // `i32` doesn't implement `Bound`, so it should be `Pod`
    is_pod(&0i32);  // likewise here
}
rustc 1.0.0-nightly (3b3bb0e68 2015-03-04) (built 2015-03-05)

cc @nikomatsakis @flaper87

@nikomatsakis
Copy link
Contributor

Yeah, hmm, this is caused by the way that trait dispatch picks a concrete impl if its the only thing available without recursively evaluating the bounds. Hmm. It makes sense for positive impls but for negative impls doesn't seem quite right. 

Niko

-------- Original message --------
From: Jorge Aparicio notifications@github.com
Date:03/05/2015 09:57 (GMT-05:00)
To: rust-lang/rust rust@noreply.github.com
Cc: Niko Matsakis niko@alum.mit.edu
Subject: [rust] Bounds seem to be ignored in negative impls (#23072)

#![feature(optin_builtin_traits)]

use std::marker::MarkerTrait;

unsafe trait Pod: MarkerTrait {}
unsafe impl Pod for .. {}

trait Bound: MarkerTrait {}

// it seems that the bound is ignored here, i.e. this gets treated as impl<T> !Pod for T {}
impl<T: Bound> !Pod for T {}

fn is_pod<T: Pod>(_: T) {}

fn main() {
is_pod(0); // i32 doesn't implement Bound, so it should be Pod
is_pod(&0); // likewise here
}
rustc 1.0.0-nightly (3b3bb0e 2015-03-04) (built 2015-03-05)
cc @nikomatsakis @flaper87


Reply to this email directly or view it on GitHub.

@nikomatsakis
Copy link
Contributor

This turns out to be a deeper issue. We should hold off on removing feature-gate for negative impls until it is resolved. The core issue that that negative impls with extra bounds become effectively negative bounds:

trait NegFoo : MarkerTrait { }
impl NegFoo for .. { }
impl<T:!Foo> !NegFoo for T { }

Now T:NegFoo is effectively T:!Foo from rust-lang/rfcs#586. I am very nervous about introducing such unbounded negativity into the trait system (see e.g. #23086). I would like to (for now) limit negative impls in OIBIT so that they can't carry where-clauses -- or at least not more where-clauses than are needed for their types to be well-formed.

@kdeeee
Copy link

kdeeee commented Sep 30, 2016

error still persist in rustc 1.11.0 (9b21dcd6a 2016-08-15)
error message

default trait implementations are experimental and possibly buggy
negative trait bounds are not yet fully implemented; use marker types for now

@Manishearth
Copy link
Member

triage: OIBITs cannot have bounds anymore. yay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-traits Area: Trait system
Projects
None yet
Development

No branches or pull requests

6 participants