rustc_typeck: support functions in variance computation.

This commit is contained in:
Eduard-Mihai Burtescu 2017-06-02 22:05:41 +03:00
parent 33ecf72e8e
commit a9d4069975
9 changed files with 316 additions and 504 deletions

View file

@ -1,25 +0,0 @@
// 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.
// Check that `T:'a` is contravariant in T.
#![feature(rustc_attrs)]
#[rustc_variance]
trait Foo: 'static { //~ ERROR [o]
}
#[rustc_variance]
trait Bar<T> { //~ ERROR [o, o]
fn do_it(&self)
where T: 'static;
}
fn main() { }

View file

@ -14,13 +14,11 @@
// Check that bounds on type parameters (other than `Self`) do not
// influence variance.
#[rustc_variance]
trait Getter<T> { //~ ERROR [o, o]
trait Getter<T> {
fn get(&self) -> T;
}
#[rustc_variance]
trait Setter<T> { //~ ERROR [o, o]
trait Setter<T> {
fn get(&self, T);
}
@ -34,20 +32,6 @@ enum TestEnum<U,T:Setter<U>> { //~ ERROR [*, +]
Foo(T)
}
#[rustc_variance]
trait TestTrait<U,T:Setter<U>> { //~ ERROR [o, o, o]
fn getter(&self, u: U) -> T;
}
#[rustc_variance]
trait TestTrait2<U> : Getter<U> { //~ ERROR [o, o]
}
#[rustc_variance]
trait TestTrait3<U> { //~ ERROR [o, o]
fn getter<T:Getter<U>>(&self);
}
#[rustc_variance]
struct TestContraStruct<U,T:Setter<U>> { //~ ERROR [*, +]
t: T

View file

@ -36,37 +36,14 @@ struct TestIndirect2<A:'static, B:'static> { //~ ERROR [o, o]
m: TestMut<B, A>
}
#[rustc_variance]
trait Getter<A> { //~ ERROR [o, o]
trait Getter<A> {
fn get(&self) -> A;
}
#[rustc_variance]
trait Setter<A> { //~ ERROR [o, o]
trait Setter<A> {
fn set(&mut self, a: A);
}
#[rustc_variance]
trait GetterSetter<A> { //~ ERROR [o, o]
fn get(&self) -> A;
fn set(&mut self, a: A);
}
#[rustc_variance]
trait GetterInTypeBound<A> { //~ ERROR [o, o]
// Here, the use of `A` in the method bound *does* affect
// variance. Think of it as if the method requested a dictionary
// for `T:Getter<A>`. Since this dictionary is an input, it is
// contravariant, and the Getter is covariant w/r/t A, yielding an
// overall contravariant result.
fn do_it<T:Getter<A>>(&self);
}
#[rustc_variance]
trait SetterInTypeBound<A> { //~ ERROR [o, o]
fn do_it<T:Setter<A>>(&self);
}
#[rustc_variance]
struct TestObject<A, R> { //~ ERROR [o, o]
n: Box<Setter<A>+Send>,