Refactor compare_impl_method to use all bounds

Refactor compare_impl_method into its own file. Modify the
code to stop comparing individual parameter bounds.
Instead we now use the predicates list attached to the trait
and implementation generics. This ensures consistency even
when bounds are declared in different places (i.e on
a parameter vs. in a where clause).
This commit is contained in:
Jared Roesch 2015-01-14 13:43:17 -08:00
parent 896cb36eca
commit 6a66b32270
13 changed files with 571 additions and 574 deletions

View file

@ -20,8 +20,7 @@ struct X { data: u32 }
impl Something for X {
fn yay<T: Str>(_:Option<X>, thing: &[T]) {
//~^ ERROR in method `yay`, type parameter 0 requires bound `Str`, which is not required
//~^ ERROR the requirement `T : Str` appears on the impl method
}
}

View file

@ -20,7 +20,8 @@ struct E {
}
impl A for E {
fn b<F: Sync, G>(_x: F) -> F { panic!() } //~ ERROR type parameter 0 requires `Sync`
fn b<F: Sync, G>(_x: F) -> F { panic!() }
//~^ ERROR `F : core::marker::Sync` appears on the impl method
}
fn main() {}

View file

@ -16,15 +16,16 @@ struct Inv<'a> { // invariant w/r/t 'a
x: &'a mut &'a isize
}
pub trait Foo<'a> {
pub trait Foo<'a, 't> {
fn no_bound<'b>(self, b: Inv<'b>);
fn has_bound<'b:'a>(self, b: Inv<'b>);
fn wrong_bound1<'b,'c,'d:'a+'b>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>);
fn wrong_bound2<'b,'c,'d:'a+'b+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>);
fn okay_bound<'b,'c,'d:'a+'b+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>);
fn another_bound<'x: 'a>(self, x: Inv<'x>);
}
impl<'a> Foo<'a> for &'a isize {
impl<'a, 't> Foo<'a, 't> for &'a isize {
fn no_bound<'b:'a>(self, b: Inv<'b>) {
//~^ ERROR lifetime parameters or bounds on method `no_bound` do not match
}
@ -47,9 +48,10 @@ impl<'a> Foo<'a> for &'a isize {
// cases.
}
fn wrong_bound2<'b,'c,'e:'b+'c>(self, b: Inv<'b>, c: Inv<'c>, e: Inv<'e>) {
//~^ ERROR distinct set of bounds from its counterpart
fn okay_bound<'b,'c,'e:'b+'c>(self, b: Inv<'b>, c: Inv<'c>, e: Inv<'e>) {
}
fn another_bound<'x: 't>(self, x: Inv<'x>) {}
}
fn main() { }

View file

@ -32,15 +32,15 @@ trait Foo {
impl Foo for isize {
// invalid bound for T, was defined as Eq in trait
fn test_error1_fn<T: Ord>(&self) {}
//~^ ERROR in method `test_error1_fn`, type parameter 0 requires bound `core::cmp::Ord`
//~^ ERROR the requirement `T : core::cmp::Ord` appears on the impl
// invalid bound for T, was defined as Eq + Ord in trait
fn test_error2_fn<T: Eq + B>(&self) {}
//~^ ERROR in method `test_error2_fn`, type parameter 0 requires bound `B`
//~^ ERROR the requirement `T : B` appears on the impl
// invalid bound for T, was defined as Eq + Ord in trait
fn test_error3_fn<T: B + Eq>(&self) {}
//~^ ERROR in method `test_error3_fn`, type parameter 0 requires bound `B`
//~^ ERROR the requirement `T : B` appears on the impl
// multiple bounds, same order as in trait
fn test3_fn<T: Ord + Eq>(&self) {}
@ -50,16 +50,16 @@ impl Foo for isize {
// parameters in impls must be equal or more general than in the defining trait
fn test_error5_fn<T: B>(&self) {}
//~^ ERROR in method `test_error5_fn`, type parameter 0 requires bound `B`
//~^ ERROR the requirement `T : B` appears on the impl
// bound `std::cmp::Eq` not enforced by this implementation, but this is OK
fn test6_fn<T: A>(&self) {}
fn test_error7_fn<T: A + Eq>(&self) {}
//~^ ERROR in method `test_error7_fn`, type parameter 0 requires bound `core::cmp::Eq`
//~^ ERROR the requirement `T : core::cmp::Eq` appears on the impl
fn test_error8_fn<T: C>(&self) {}
//~^ ERROR in method `test_error8_fn`, type parameter 0 requires bound `C`
//~^ ERROR the requirement `T : C` appears on the impl
}
@ -71,8 +71,7 @@ trait Trait {
impl Trait for usize {
fn method<G: Getter<usize>>() {}
//~^ ERROR in method `method`, type parameter 0 requires bound `Getter<usize>`
//~^ G : Getter<usize>` appears on the impl method but not on the corresponding trait method
}
fn main() {}

View file

@ -20,7 +20,7 @@ trait IteratorUtil<A> {
impl<A, T: Iterator<A>> IteratorUtil<A> for T {
fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<T, U> {
//~^ ERROR in method `zip`, type parameter 1 requires bound `Iterator<B>`
//~^ ERROR the requirement `U : Iterator<B>` appears on the impl method
ZipIterator{a: self, b: other}
}
}

View file

@ -0,0 +1,28 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait Bound {}
trait Trait {
fn a<T>(&self, T) where T: Bound;
fn b<T>(&self, T) where T: Bound;
fn c<T: Bound>(&self, T);
fn d<T: Bound>(&self, T);
}
impl Trait for bool {
fn a<T: Bound>(&self, _: T) {}
//^~ This gets rejected but should be accepted
fn b<T>(&self, _: T) where T: Bound {}
fn c<T: Bound>(&self, _: T) {}
fn d<T>(&self, _: T) where T: Bound {}
}
fn main() {}