}
}
-/////////////////
-
fn foo() { }
fn foo3(_: i32, _: (), _: ()) { }
fn qux(_: i32) { }
fn chip_paint(&self, c: Self::Color) { }
}
-///////////////////////////////////////////////////////////////////////////
-
struct Black;
struct ModelT;
impl Vehicle for ModelT { type Color = Black; }
impl Car for ModelT { }
-///////////////////////////////////////////////////////////////////////////
-
struct Blue;
struct ModelU;
impl Vehicle for ModelU { type Color = Blue; }
impl Car for ModelU { }
-///////////////////////////////////////////////////////////////////////////
-
fn dent<C:Car>(c: C, color: C::Color) { c.chip_paint(color) }
fn a() { dent(ModelT, Black); }
fn b() { dent(ModelT, Blue); } //~ ERROR mismatched types
fn c() { dent(ModelU, Black); } //~ ERROR mismatched types
fn d() { dent(ModelU, Blue); }
-///////////////////////////////////////////////////////////////////////////
-
fn e() { ModelT.chip_paint(Black); }
fn f() { ModelT.chip_paint(Blue); } //~ ERROR mismatched types
fn g() { ModelU.chip_paint(Black); } //~ ERROR mismatched types
fn honk(&self) { }
}
-///////////////////////////////////////////////////////////////////////////
-
struct Black;
struct ModelT;
impl Vehicle for ModelT { type Color = Black; }
impl Car for ModelT { }
-///////////////////////////////////////////////////////////////////////////
-
struct Blue;
struct ModelU;
impl Vehicle for ModelU { type Color = Blue; }
impl Car for ModelU { }
-///////////////////////////////////////////////////////////////////////////
-
fn black_car<C:Car<Color=Black>>(c: C) {
}
fn test(&self, value: &Self::V) -> bool;
}
-///////////////////////////////////////////////////////////////////////////
-
struct TesterPair<T:Test> {
tester: T,
value: T::V,
}
}
-///////////////////////////////////////////////////////////////////////////
-
struct EqU32(u32);
impl Test for EqU32 {
type V = u32;
{
}
-///////////////////////////////////////////////////////////////////////////
// Expressed as a where clause
struct SomeStruct<X> {
want_foo::<SomeStruct<usize>>();
}
-///////////////////////////////////////////////////////////////////////////
// Expressed as shorthand
struct AnotherStruct<X> {
{
}
-///////////////////////////////////////////////////////////////////////////
// Expressed as a where clause
struct SomeStruct;
// See issue 60414
-/////////////////////////////////////////////
// Reduction to `impl Trait`
struct Foo<T>(T);
}
}
-/////////////////////////////////////////////
// Same with lifetimes in the trait
mod lifetimes {
// See issue 60414
-/////////////////////////////////////////////
// Reduction to `impl Trait`
struct Foo<T>(T);
}
}
-/////////////////////////////////////////////
// Same with lifetimes in the trait
mod lifetimes {
}
}
-/////////////////////////////////////////////
// Reduction using `impl Trait` in bindings
mod impl_trait_in_bindings {
}
}
-/////////////////////////////////////////////
// The same applied to `type Foo = impl Bar`s
mod opaque_types {
fn stream(&self) -> Self::S;
}
-//////////////////////////////////////////////////////////////////////////////
-
trait StreamHash<H: StreamHasher>: Hash<H> {
fn input_stream(&self, stream: &mut H::S);
}
extern "rust-call" fn call_once(mut self, _: ()) -> u32 { self.call_mut(()) }
}
-/////////////////////////////////////////////////////////////////////////
-
impl FnMut<(u32,)> for Foo {
extern "rust-call" fn call_mut(&mut self, (x,): (u32,)) -> u32 { self.foo + x }
}
extern "rust-call" fn call_once(mut self, args: (u32,)) -> u32 { self.call_mut(args) }
}
-/////////////////////////////////////////////////////////////////////////
-
impl FnMut<(u32,u32)> for Foo {
extern "rust-call" fn call_mut(&mut self, (x, y): (u32, u32)) -> u32 { self.foo + x + y }
}
// Test that we can use method notation to call methods based on a
// projection bound from a trait. Issue #20469.
-///////////////////////////////////////////////////////////////////////////
-
-
trait MakeString {
fn make_string(&self) -> String;
}
}
}
-///////////////////////////////////////////////////////////////////////////
-
trait Foo {
type F: MakeString;
f.get().make_string()
}
-///////////////////////////////////////////////////////////////////////////
-
struct SomeStruct {
field: isize,
}
}
}
-///////////////////////////////////////////////////////////////////////////
-
struct SomeOtherStruct {
field: usize,
}
#![allow(dead_code)]
-
-///////////////////////////////////////////////////////////////////////////
-
pub trait TheTrait<'b> {
type TheAssocType;
}
type TheAssocType = &'b ();
}
-///////////////////////////////////////////////////////////////////////////
-
pub struct WithHrAssoc<T>
where for<'a> T : TheTrait<'a>
{
//[nll]~^^ ERROR lifetime may not live long enough
}
-///////////////////////////////////////////////////////////////////////////
-
pub trait TheSubTrait : for<'a> TheTrait<'a> {
}
#![allow(dead_code)]
-///////////////////////////////////////////////////////////////////////////
-
pub trait TheTrait {
type TheAssocType;
}
type TheAssocType = &'b ();
}
-///////////////////////////////////////////////////////////////////////////
-
pub struct WithAssoc<T> where T : TheTrait {
m: [T; 0]
}
#![allow(dead_code)]
#![feature(rustc_attrs)]
-///////////////////////////////////////////////////////////////////////////
-
pub trait TheTrait {
type TheAssocType;
}
type TheAssocType = &'b ();
}
-///////////////////////////////////////////////////////////////////////////
-
pub struct WithAssoc<T:TheTrait> {
m: [T; 0]
}
// Check a number of scenarios in which one impl tries to override another,
// without correctly using `default`.
-////////////////////////////////////////////////////////////////////////////////
// Test 1: one layer of specialization, multiple methods, missing `default`
-////////////////////////////////////////////////////////////////////////////////
trait Foo {
fn foo(&self);
fn bar(&self) {} //~ ERROR E0520
}
-////////////////////////////////////////////////////////////////////////////////
// Test 2: one layer of specialization, missing `default` on associated type
-////////////////////////////////////////////////////////////////////////////////
trait Bar {
type T;
type T = (); //~ ERROR E0520
}
-////////////////////////////////////////////////////////////////////////////////
// Test 3a: multiple layers of specialization, missing interior `default`
-////////////////////////////////////////////////////////////////////////////////
trait Baz {
fn baz(&self);
fn baz(&self) {} //~ ERROR E0520
}
-////////////////////////////////////////////////////////////////////////////////
// Test 3b: multiple layers of specialization, missing interior `default`,
// redundant `default` in bottom layer.
-////////////////////////////////////////////////////////////////////////////////
trait Redundant {
fn redundant(&self);
// Check a number of scenarios in which one impl tries to override another,
// without correctly using `default`.
-////////////////////////////////////////////////////////////////////////////////
// Test 1: one layer of specialization, multiple methods, missing `default`
-////////////////////////////////////////////////////////////////////////////////
trait Foo {
fn foo(&self);
fn bar(&self) {} //~ ERROR E0520
}
-////////////////////////////////////////////////////////////////////////////////
// Test 2: one layer of specialization, missing `default` on associated type
-////////////////////////////////////////////////////////////////////////////////
trait Bar {
type T;
type T = (); //~ ERROR E0520
}
-////////////////////////////////////////////////////////////////////////////////
// Test 3a: multiple layers of specialization, missing interior `default`
-////////////////////////////////////////////////////////////////////////////////
trait Baz {
fn baz(&self);
fn baz(&self) {} //~ ERROR E0520
}
-////////////////////////////////////////////////////////////////////////////////
// Test 3b: multiple layers of specialization, missing interior `default`,
// redundant `default` in bottom layer.
-////////////////////////////////////////////////////////////////////////////////
trait Redundant {
fn redundant(&self);
use std::rc::Rc;
use std::cell::Cell;
-///////////////////////////////////////////////////////////////////////////
-
struct SomeGoableThing {
counter: Rc<Cell<isize>>
}
}
}
-///////////////////////////////////////////////////////////////////////////
-
struct SomeGoOnceableThing {
counter: Rc<Cell<isize>>
}
}
}
-///////////////////////////////////////////////////////////////////////////
-
fn main() {
let counter = Rc::new(Cell::new(0));
let mut x = SomeGoableThing { counter: counter.clone() };