#[test]
fn test_transmute() {
- trait Foo {}
+ trait Foo { fn dummy(&self) { } }
impl Foo for int {}
let a = box 100 as Box<Foo>;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-pub trait TheTrait<T> {
+pub trait TheTrait<T> : ::std::marker::PhantomFn<T> {
fn the_fn(&self);
}
pub struct FakeHeap;
-pub struct FakeVec<T, A = FakeHeap>;
+pub struct FakeVec<T, A = FakeHeap> { pub f: Option<(T,A)> }
+
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-pub struct A<T>;
-pub struct B<T>;
+pub struct A<T> { pub v: T }
+pub struct B<T> { pub v: T }
pub mod test {
- pub struct A<T>;
+ pub struct A<T> { pub v: T }
impl<T> A<T> {
pub fn foo(&self) -> int {
}
pub fn foo() -> int {
- let a = A::<()>;
- let b = B::<()>;
- let c = test::A::<()>;
+ let a = A { v: () };
+ let b = B { v: () };
+ let c = test::A { v: () };
return a.foo() + a.bar() +
b.foo() + b.bar() +
c.foo() + c.bar();
#![crate_type="lib"]
#![deny(warnings)]
+#![allow(dead_code)]
pub use src::aliases::B;
pub use src::hidden_core::make;
pub mod hidden_core {
use super::aliases::B;
- pub struct A<T>;
+ pub struct A<T> { t: T }
- pub fn make() -> B { A }
+ pub fn make() -> B { A { t: 1.0 } }
impl<T> A<T> {
pub fn foo(&mut self) { println!("called foo"); }
#![crate_type = "lib"]
-pub struct TreeBuilder<H>;
+pub struct TreeBuilder<H> { pub h: H }
impl<H> TreeBuilder<H> {
pub fn process_token(&mut self) {
#![crate_type = "lib"]
pub trait Foo<'a, T> {
- fn foo(&self) -> T;
+ fn foo(&'a self) -> T;
}
pub fn foo<'a, T>(x: &'a Foo<'a, T>) -> T {
#![allow(unknown_features)]
#![feature(box_syntax)]
-pub trait i<T> { }
+pub trait i<T>
+{
+ fn dummy(&self, t: T) -> T { panic!() }
+}
pub fn f<T>() -> Box<i<T>+'static> {
impl<T> i<T> for () { }
#![feature(unsafe_destructor)]
+use std::marker;
+
struct arc_destruct<T> {
- _data: int,
+ _data: int,
+ _marker: marker::PhantomData<T>
}
#[unsafe_destructor]
fn arc_destruct<T: Sync>(data: int) -> arc_destruct<T> {
arc_destruct {
- _data: data
+ _data: data,
+ _marker: marker::PhantomData
}
}
pub trait T {
type C;
+ fn dummy(&self) { }
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-pub trait Foo {
+use std::marker::MarkerTrait;
+
+pub trait Foo : MarkerTrait {
fn bar();
}
use std::mem;
-trait A {}
+trait A {
+ fn dummy(&self) { }
+}
struct B;
impl A for B {}
fn f() { }
f();
}
+ fn dummy(&self) { }
}
#![no_std]
#![feature(lang_items)]
+#[lang="phantom_fn"]
+pub trait PhantomFn<A:?Sized,R:?Sized=()> { }
+impl<A:?Sized, R:?Sized, U:?Sized> PhantomFn<A,R> for U { }
+
#[lang="sized"]
-pub trait Sized {}
+pub trait Sized : PhantomFn<Self> {}
#[lang="panic"]
fn panic(_: &(&'static str, &'static str, uint)) -> ! { loop {} }
extern fn eh_personality() {}
#[lang="copy"]
-pub trait Copy {}
+pub trait Copy : PhantomFn<Self> {
+ // Empty.
+}
impl Trait for MethodTester {}
#[unstable(feature = "test_feature")]
-pub trait UnstableTrait {}
+pub trait UnstableTrait { fn dummy(&self) { } }
#[stable(feature = "test_feature", since = "1.0.0")]
#[deprecated(since = "1.0.0")]
}
// issue 8134
-pub struct Parser<T>;
+pub struct Parser<T>(T);
impl<T: std::iter::Iterator<Item=char>> Parser<T> {
fn in_doctype(&mut self) {
static DOCTYPEPattern: [char; 6] = ['O', 'C', 'T', 'Y', 'P', 'E'];
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-pub trait RemoteTrait {}
+pub trait RemoteTrait { fn dummy(&self) { } }
use std::ops::Deref;
struct DerefWithHelper<H, T> {
- pub helper: H
+ pub helper: H,
+ pub value: Option<T>
}
trait Helper<T> {
// Test cross-crate autoderef + vtable.
pub fn check<T: PartialEq>(x: T, y: T) -> bool {
- let d: DerefWithHelper<Option<T>, T> = DerefWithHelper { helper: Some(x) };
+ let d: DerefWithHelper<Option<T>, T> = DerefWithHelper { helper: Some(x), value: None };
d.eq(&y)
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait Foo {}
+trait Foo : ::std::marker::MarkerTrait {}
#![crate_name = "a"]
+use std::marker::MarkerTrait;
+
macro_rules! three {
() => { 3 }
}
-pub trait U {}
-pub trait V {}
+pub trait U : MarkerTrait {}
+pub trait V : MarkerTrait {}
impl U for () {}
impl V for () {}
#![crate_name = "a"]
+use std::marker::MarkerTrait;
+
macro_rules! three {
() => { 3 }
}
-pub trait U {}
-pub trait V {}
+pub trait U : MarkerTrait {}
+pub trait V : MarkerTrait {}
impl U for () {}
impl V for () {}
#![crate_name = "a"]
+use std::marker::MarkerTrait;
+
macro_rules! three {
() => { 3 }
}
-pub trait U {}
-pub trait V {}
+pub trait U : MarkerTrait {}
+pub trait V : MarkerTrait {}
impl U for () {}
impl V for () {}
#![crate_name = "a"]
+use std::marker::MarkerTrait;
+
macro_rules! three {
() => { 3 }
}
-pub trait U {}
-pub trait V {}
+pub trait U : MarkerTrait {}
+pub trait V : MarkerTrait {}
impl U for () {}
impl V for () {}
#![crate_name = "a"]
+use std::marker::MarkerTrait;
+
macro_rules! three {
() => { 3 }
}
-pub trait U {}
-pub trait V {}
+pub trait U : MarkerTrait {}
+pub trait V : MarkerTrait {}
impl U for () {}
impl V for () {}
#![crate_name = "a"]
+use std::marker::MarkerTrait;
+
macro_rules! three {
() => { 3 }
}
-pub trait U {}
-pub trait V {}
+pub trait U : MarkerTrait {}
+pub trait V : MarkerTrait {}
impl U for () {}
impl V for () {}
#![crate_name = "a"]
+use std::marker::MarkerTrait;
+
macro_rules! three {
() => { 3 }
}
-pub trait U {}
-pub trait V {}
+pub trait U : MarkerTrait {}
+pub trait V : MarkerTrait {}
impl U for () {}
impl V for () {}
#![crate_name = "a"]
+use std::marker::MarkerTrait;
+
macro_rules! three {
() => { 3 }
}
-pub trait U {}
-pub trait V {}
+pub trait U : MarkerTrait {}
+pub trait V : MarkerTrait {}
impl U for () {}
impl V for () {}
#![crate_name = "a"]
+use std::marker::MarkerTrait;
+
macro_rules! three {
() => { 3 }
}
-pub trait U {}
-pub trait V {}
+pub trait U : MarkerTrait {}
+pub trait V : MarkerTrait {}
impl U for () {}
impl V for () {}
#![crate_name = "a"]
+use std::marker::MarkerTrait;
+
macro_rules! three {
() => { 3 }
}
-pub trait U {}
-pub trait V {}
+pub trait U : MarkerTrait {}
+pub trait V : MarkerTrait {}
impl U for () {}
impl V for () {}
#![crate_name = "a"]
+use std::marker::MarkerTrait;
+
macro_rules! three {
() => { 3 }
}
-pub trait U {}
-pub trait V {}
+pub trait U : MarkerTrait {}
+pub trait V : MarkerTrait {}
impl U for () {}
impl V for () {}
#![crate_name = "a"]
+use std::marker::MarkerTrait;
+
macro_rules! three {
() => { 3 }
}
-pub trait U {}
-pub trait V {}
+pub trait U : MarkerTrait {}
+pub trait V : MarkerTrait {}
impl U for () {}
impl V for () {}
#![crate_name = "a"]
+use std::marker::MarkerTrait;
+
macro_rules! three {
() => { 3 }
}
-pub trait U {}
-pub trait V {}
+pub trait U : MarkerTrait {}
+pub trait V : MarkerTrait {}
impl U for () {}
impl V for () {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-pub trait Trait {}
+pub trait Trait {
+ fn dummy(&self) { }
+}
pub struct Foo<T:Trait> {
pub x: T,
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-pub trait Foo {
+pub trait Foo : ::std::marker::MarkerTrait {
}
impl Foo for int {
pub use self::sub::{Bar, Baz};
pub trait Trait {
- fn foo();
+ fn foo(&self);
}
struct Foo;
#![feature(no_std)]
#![no_std]
+#[lang="phantom_fn"]
+pub trait PhantomFn<A:?Sized,R:?Sized=()> { }
+impl<A:?Sized, R:?Sized, U:?Sized> PhantomFn<A,R> for U { }
+
#[lang="sized"]
-pub trait Sized {
+pub trait Sized : PhantomFn<Self> {
// Empty.
}
// Test that coherence detects overlap when some of the types in the
// impls are projections of associated type. Issue #20624.
+use std::marker::PhantomData;
use std::ops::Deref;
-pub struct Cow<'a, B: ?Sized>;
+pub struct Cow<'a, B: ?Sized>(PhantomData<(&'a (),B)>);
/// Trait for moving into a `Cow`
pub trait IntoCow<'a, B: ?Sized> {
// Check that an associated type cannot be bound in an expression path.
-trait Foo {
+trait Foo : ::std::marker::MarkerTrait {
type A;
fn bar() -> isize;
}
// Test that we do not ICE when an impl is missing an associated type (and that we report
// a useful error, of course).
-trait Trait {
+trait Trait : ::std::marker::MarkerTrait {
type Type;
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait Foo {
+trait Foo : ::std::marker::MarkerTrait {
type X;
type Y;
}
// Check that we get an error when you use `<Self as Get>::Value` in
// the trait definition but `Self` does not, in fact, implement `Get`.
-trait Get {
+trait Get : ::std::marker::MarkerTrait {
type Value;
}
pub trait Foo {
type A;
+
+ fn dummy(&self) { }
}
impl Foo for i32 {
// Check that an associated type cannot be bound in an expression path.
-trait Foo {
+trait Foo : ::std::marker::MarkerTrait {
type A;
fn bar() -> isize;
}
// ignore-tidy-linelength
-#![feature(no_std)]
-#![no_std]
-#![feature(lang_items)]
-
-#[lang="sized"]
-pub trait Sized {}
-
struct S<T> {
contents: T,
}
use std::cell::RefCell;
-trait Trait {}
+trait Trait : ::std::marker::MarkerTrait {}
pub fn main() {
let x: Vec<Trait + Sized> = Vec::new();
use std::fmt::Show;
use std::default::Default;
+use std::marker::MarkerTrait;
// Test that two blanket impls conflict (at least without negative
// bounds). After all, some other crate could implement Even or Odd
fn get(&self) -> usize;
}
-trait Even { }
+trait Even : MarkerTrait { }
-trait Odd { }
+trait Odd : MarkerTrait { }
impl Even for isize { }
fn get(&self) -> usize;
}
-trait Even { }
+trait Even : ::std::marker::MarkerTrait { }
-trait Odd { }
+trait Odd : ::std::marker::MarkerTrait { }
impl<T:Even> MyTrait for T { //~ ERROR E0119
fn get(&self) -> usize { 0 }
#![feature(optin_builtin_traits)]
-trait MyTrait {}
+trait MyTrait : ::std::marker::MarkerTrait {}
-struct TestType<T>;
+struct TestType<T>(::std::marker::PhantomData<T>);
-unsafe impl<T: MyTrait> Send for TestType<T> {}
+unsafe impl<T: MyTrait+'static> Send for TestType<T> {}
//~^ ERROR conflicting implementations for trait `core::marker::Send`
//~^^ ERROR conflicting implementations for trait `core::marker::Send`
impl<T: MyTrait> !Send for TestType<T> {}
//~^ ERROR conflicting implementations for trait `core::marker::Send`
-unsafe impl<T> Send for TestType<T> {}
+unsafe impl<T:'static> Send for TestType<T> {}
//~^ ERROR error: conflicting implementations for trait `core::marker::Send`
impl !Send for TestType<i32> {}
#![feature(box_syntax)]
struct Foo;
-trait Trait {}
+trait Trait : ::std::marker::MarkerTrait {}
impl Trait for Foo {}
pub fn main() {
#![feature(box_patterns)]
#![feature(box_syntax)]
-trait T {}
+trait T : ::std::marker::MarkerTrait {}
impl T for isize {}
fn main() {
}
struct Foo;
-trait Bar {}
+trait Bar : ::std::marker::MarkerTrait {}
pub fn main() {
// With a vec of isize.
}
struct Foo;
-trait Bar {}
+trait Bar : ::std::marker::MarkerTrait {}
impl Bar for Foo {}
pub fn main() {
}
struct Foo;
-trait Bar {}
+trait Bar : ::std::marker::MarkerTrait {}
impl Bar for Foo {}
fn baz<'a>() {
// Test implicit coercions involving DSTs and raw pointers.
+use std::marker::MarkerTrait;
+
struct S;
-trait T {}
+trait T : MarkerTrait {}
impl T for S {}
struct Foo<T: ?Sized> {
// Test that we cannot create objects from unsized types.
-trait Foo {}
+trait Foo : ::std::marker::MarkerTrait {}
impl Foo for str {}
fn test1<T: ?Sized + Foo>(t: &T) {
}
#[derive(Copy)] //~ ERROR the trait `Copy` may not be implemented
-struct Bar<T>;
+struct Bar<T>(::std::marker::PhantomData<T>);
#[unsafe_destructor]
impl<T> Drop for Bar<T> {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-struct Foo<A, B, C = (A, B)>;
+use std::marker;
+
+struct Foo<A, B, C = (A, B)>(
+ marker::PhantomData<(A,B,C)>);
impl<A, B, C = (A, B)> Foo<A, B, C> {
- fn new() -> Foo<A, B, C> {Foo}
+ fn new() -> Foo<A, B, C> {Foo(marker::PhantomData)}
}
fn main() {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::marker;
+
struct Heap;
-struct Vec<T, A = Heap>;
+struct Vec<T, A = Heap>(
+ marker::PhantomData<(T,A)>);
impl<T, A = Heap> Vec<T, A> {
- fn new() -> Vec<T, A> {Vec}
+ fn new() -> Vec<T, A> {Vec(marker::PhantomData)}
}
fn main() {
//
// Regression test for issue #16218.
-trait Bar<'a> {}
+trait Bar<'a> {
+ fn dummy(&'a self);
+}
trait Foo<'a> {
+ fn dummy(&'a self) { }
fn bar<'b, T: Bar<'b>>(self) -> &'b str;
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::marker;
+
struct Heap;
-struct Vec<T, A = Heap>;
+struct Vec<T, A = Heap>(
+ marker::PhantomData<(T,A)>);
fn main() {
let _: Vec; //~ ERROR wrong number of type arguments: expected at least 1, found 0
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::marker;
+
struct Heap;
-struct Vec<T, A = Heap>;
+struct Vec<T, A = Heap>(
+ marker::PhantomData<(T,A)>);
fn main() {
let _: Vec<isize, Heap, bool>;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::marker;
+
struct A;
struct B;
struct C;
-struct Foo<T = A, U = B, V = C>;
+struct Foo<T = A, U = B, V = C>(marker::PhantomData<(T,U,V)>);
-struct Hash<T>;
-struct HashMap<K, V, H = Hash<K>>;
+struct Hash<T>(marker::PhantomData<T>);
+struct HashMap<K, V, H = Hash<K>>(marker::PhantomData<(K,V,H)>);
fn main() {
// Ensure that the printed type doesn't include the default type params...
#![feature(box_syntax)]
-struct Test<'s> {
+struct Test {
func: Box<FnMut()+'static>
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait FromStructReader<'a> { }
+use std::marker::PhantomFn;
+
+trait FromStructReader<'a> : PhantomFn<(Self,&'a ())> { }
trait ResponseHook {
fn get<'a, T: FromStructReader<'a>>(&'a self);
}
#![crate_type = "lib"]
+use std::marker::PhantomData;
+
enum NodeContents<'a> {
Children(Vec<Node<'a>>),
}
struct Node<'a> {
contents: NodeContents<'a>,
+ marker: PhantomData<&'a ()>,
}
impl<'a> Node<'a> {
fn noName(contents: NodeContents<'a>) -> Node<'a> {
- Node{ contents: contents,}
+ Node { contents: contents, marker: PhantomData }
}
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait Node {
+use std::marker::MarkerTrait;
+
+trait Node : MarkerTrait {
fn zomg();
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait Foo {}
+trait Foo {
+ fn dummy(&self) { }
+}
struct A;
// except according to those terms.
use std::fmt::Debug;
+use std::marker::MarkerTrait;
-trait Str {}
+trait Str : MarkerTrait {}
trait Something {
fn yay<T: Debug>(_: Option<Self>, thing: &[T]);
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait ListItem<'a> {
+use std::marker::MarkerTrait;
+
+trait ListItem<'a> : MarkerTrait {
fn list_name() -> &'a str;
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-struct Foo<T> { foo: Option<Option<Foo<T>>> }
+use std::marker;
+
+struct Foo<T> { foo: Option<Option<Foo<T>>>, marker: marker::PhantomData<T> }
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
impl<T> Foo<T> { fn bar(&self) {} }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::marker;
+
struct Foo { foo: Bar<Foo> }
-struct Bar<T> { x: Bar<Foo> }
+struct Bar<T> { x: Bar<Foo> , marker: marker::PhantomData<T> }
//~^ ERROR illegal recursive struct type; wrap the inner value in a box to make it representable
impl Foo { fn foo(&self) {} }
#![feature(unboxed_closures)]
-struct B<T>;
+use std::marker;
+
+struct B<T>(marker::PhantomData<T>);
fn main() {
- let foo = B; //~ ERROR: unable to infer enough type information
+ let foo = B(marker::PhantomData); //~ ERROR unable to infer enough type information
let closure = || foo;
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::marker::MarkerTrait;
-
-pub trait AbstractRenderer {}
+pub trait AbstractRenderer : MarkerTrait {}
fn _create_render(_: &()) ->
AbstractRenderer
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::marker::MarkerTrait;
+
fn add_state(op: <isize as HasState>::State) {
//~^ ERROR the trait `HasState` is not implemented for the type `isize`
}
-trait HasState {
+trait HasState : MarkerTrait {
type State;
}
Push::push(&c, box || y = 0);
Push::push(&c, box || y = 0);
+//~^ ERROR cannot borrow `y` as mutable more than once at a time
}
trait Push<'c> {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait Foo {
+use std::marker::MarkerTrait;
+
+trait Foo : MarkerTrait {
type Item;
}
#![feature(lang_items, start, no_std)]
#![no_std]
+#[lang="phantom_fn"]
+trait PhantomFn<A:?Sized,R:?Sized=()> { }
+impl<A:?Sized, R:?Sized, U:?Sized> PhantomFn<A,R> for U { }
+
#[lang = "sized"]
-trait Sized {}
+trait Sized : PhantomFn<Self> {}
#[start]
fn main(_: int, _: *const *const u8) -> int {
// cause compiler to loop. Note that no instances
// of such a type could ever be constructed.
+use std::marker::MarkerTrait;
struct t(Box<t>); //~ ERROR this type cannot be instantiated
-trait to_str_2 {
+trait to_str_2 : MarkerTrait {
fn my_to_string() -> String;
}
// below. Note that changing to a named lifetime made the problem go
// away.
-use std::ops::{Shl, Shr};
use std::cell::RefCell;
+use std::marker::MarkerTrait;
+use std::ops::{Shl, Shr};
-pub trait Subscriber {
+pub trait Subscriber : MarkerTrait {
type Input;
}
// than the trait method it's implementing
trait A {
- fn b<C,D>(x: C) -> C;
+ fn b<C,D>(&self, x: C) -> C;
}
struct E {
}
impl A for E {
- fn b<F: Sync, G>(_x: F) -> F { panic!() }
+ fn b<F: Sync, G>(&self, _x: F) -> F { panic!() }
//~^ ERROR `F : core::marker::Sync` appears on the impl method
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::marker;
+
enum E1 { V1(E2<E1>), }
-enum E2<T> { V2(E2<E1>), }
+enum E2<T> { V2(E2<E1>, marker::PhantomData<T>), }
//~^ ERROR illegal recursive enum type; wrap the inner value in a box to make it representable
impl E1 { fn foo(&self) {} }
#![feature(box_patterns)]
#![feature(box_syntax)]
-trait MyTrait { }
+trait MyTrait {
+ fn dummy(&self) {}
+}
pub enum TraitWrapper {
A(Box<MyTrait+'static>),
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait I {}
+use std::marker::MarkerTrait;
+
+trait I : MarkerTrait {}
type K = I+'static;
fn foo(_x: K) {} //~ ERROR: the trait `core::marker::Sized` is not implemented
#![feature(box_syntax)]
-trait Foo {}
+use std::marker::MarkerTrait;
+
+trait Foo : MarkerTrait {}
impl Foo for u8 {}
fn main() {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait A {}
+use std::marker::MarkerTrait;
+
+trait A : MarkerTrait {}
struct Struct {
r: A+'static
Struct { r: r }
}
-trait Curve {}
+trait Curve : MarkerTrait {}
enum E {X(Curve+'static)}
fn main() {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-pub struct TypeWithState<State>;
+use std::marker;
+
+pub struct TypeWithState<State>(marker::PhantomData<State>);
pub struct MyState;
pub fn foo<State>(_: TypeWithState<State>) {}
pub fn bar() {
- foo(TypeWithState); //~ ERROR type annotations required
+ foo(TypeWithState(marker::PhantomData)); //~ ERROR type annotations required
}
fn main() {
// Test the mechanism for warning about possible missing `self` declarations.
+use std::marker::MarkerTrait;
+
trait CtxtFn {
fn f8(self, usize) -> usize;
fn f9(usize) -> usize; //~ NOTE candidate
}
-trait OtherTrait {
+trait OtherTrait : MarkerTrait {
fn f9(usize) -> usize; //~ NOTE candidate
}
// declaration to match against, so we wind up prisizeing it as a
// candidate. This seems not unreasonable -- perhaps the user meant to
// implement it, after all.
-trait UnusedTrait {
+trait UnusedTrait : MarkerTrait {
fn f9(usize) -> usize; //~ NOTE candidate
}
}
}
-trait ManyImplTrait {
+trait ManyImplTrait : MarkerTrait {
fn is_str() -> bool { //~ NOTE candidate
false
}
// Verify the compiler fails with an error on infinite function
// recursions.
-struct Data(Box<Option<Data>>);
-
-fn generic<T>( _ : Vec<(Data,T)> ) {
- let rec : Vec<(Data,(bool,T))> = Vec::new();
- generic( rec );
+fn generic<T>() {
+ generic::<Option<T>>();
}
fn main () {
// Use generic<T> at least once to trigger instantiation.
- let input : Vec<(Data,())> = Vec::new();
- generic(input);
+ generic::<i32>();
}
// Test which of the builtin types are considered POD.
-
+use std::marker::MarkerTrait;
use std::rc::Rc;
fn assert_copy<T:Copy>() { }
-trait Dummy { }
+trait Dummy : MarkerTrait { }
#[derive(Copy)]
struct MyStruct {
#![feature(box_syntax)]
-trait Foo {
+use std::marker::MarkerTrait;
+
+trait Foo : MarkerTrait {
}
impl<T:Copy> Foo for T {
#![feature(box_syntax)]
-struct S<T>;
+use std::marker;
-trait Gettable<T> {}
+struct S<T>(marker::PhantomData<T>);
+
+trait Gettable<T> {
+ fn get(&self) -> T { panic!() }
+}
impl<T: Send + Copy + 'static> Gettable<T> for S<T> {}
fn f<T>(val: T) {
- let t: S<T> = S;
+ let t: S<T> = S(marker::PhantomData);
let a = &t as &Gettable<T>;
//~^ ERROR the trait `core::marker::Send` is not implemented
//~^^ ERROR the trait `core::marker::Copy` is not implemented
}
fn g<T>(val: T) {
- let t: S<T> = S;
+ let t: S<T> = S(marker::PhantomData);
let a: &Gettable<T> = &t;
//~^ ERROR the trait `core::marker::Send` is not implemented
//~^^ ERROR the trait `core::marker::Copy` is not implemented
}
fn foo<'a>() {
- let t: S<&'a isize> = S;
+ let t: S<&'a isize> = S(marker::PhantomData);
let a = &t as &Gettable<&'a isize>;
- //~^ ERROR the type `&'a isize` does not fulfill the required lifetime
+ //~^ ERROR cannot infer
}
fn foo2<'a>() {
- let t: Box<S<String>> = box S;
+ let t: Box<S<String>> = box S(marker::PhantomData);
let a = t as Box<Gettable<String>>;
//~^ ERROR the trait `core::marker::Copy` is not implemented
}
fn foo3<'a>() {
- let t: Box<S<String>> = box S;
+ let t: Box<S<String>> = box S(marker::PhantomData);
let a: Box<Gettable<String>> = t;
//~^ ERROR the trait `core::marker::Copy` is not implemented
}
// in this file all test the "kind" violates detected during kindck.
// See all `regions-bounded-by-send.rs`
+use std::marker::MarkerTrait;
+
fn assert_send<T:Send>() { }
-trait Dummy { }
+trait Dummy : MarkerTrait { }
trait Message : Send { }
// careful with object types, who knows what they close over...
// is broken into two parts because some errors occur in distinct
// phases in the compiler. See kindck-send-object2.rs as well!
+use std::marker::MarkerTrait;
+
fn assert_send<T:Send+'static>() { }
-trait Dummy { }
+trait Dummy : MarkerTrait { }
// careful with object types, who knows what they close over...
fn test51<'a>() {
// Continue kindck-send-object1.rs.
+use std::marker::MarkerTrait;
+
fn assert_send<T:Send>() { }
-trait Dummy { }
+trait Dummy : MarkerTrait { }
fn test50() {
assert_send::<&'static Dummy>(); //~ ERROR the trait `core::marker::Sync` is not implemented
// ignore-tidy-linelength
-struct Bar<'x, 'y, 'z> { bar: &'y i32, baz: i32 }
+use std::marker::PhantomData;
+
+struct Bar<'x, 'y, 'z> { bar: &'y i32, baz: i32, marker: PhantomData<(&'x(),&'y(),&'z())> }
fn bar1<'a>(x: &Bar) -> (&'a i32, &'a i32, &'a i32) {
//~^ HELP: consider using an explicit lifetime parameter as shown: fn bar1<'b, 'c, 'a>(x: &'a Bar<'b, 'a, 'c>) -> (&'a i32, &'a i32, &'a i32)
(x.bar, &x.baz, &x.baz)
// ignore-tidy-linelength
-struct Foo<'x> { bar: isize }
+use std::marker::PhantomData;
+
+struct Foo<'x> { bar: isize, marker: PhantomData<&'x ()> }
fn foo1<'a>(x: &Foo) -> &'a isize {
//~^ HELP: consider using an explicit lifetime parameter as shown: fn foo1<'a>(x: &'a Foo) -> &'a isize
&x.bar //~ ERROR: cannot infer
/// dox
pub trait A {
/// dox
- fn foo();
+ fn foo(&self);
/// dox
- fn foo_with_impl() {}
+ fn foo_with_impl(&self) {}
}
+
#[allow(missing_docs)]
trait B {
- fn foo();
- fn foo_with_impl() {}
+ fn foo(&self);
+ fn foo_with_impl(&self) {}
}
+
pub trait C { //~ ERROR: missing documentation
- fn foo(); //~ ERROR: missing documentation
- fn foo_with_impl() {} //~ ERROR: missing documentation
+ fn foo(&self); //~ ERROR: missing documentation
+ fn foo_with_impl(&self) {} //~ ERROR: missing documentation
+}
+
+#[allow(missing_docs)]
+pub trait D {
+ fn dummy(&self) { }
}
-#[allow(missing_docs)] pub trait D {}
impl Foo {
pub fn foo() {}
}
trait foo6 { //~ ERROR trait `foo6` should have a camel case name such as `Foo6`
+ fn dummy(&self) { }
}
fn f<ty>(_: ty) {} //~ ERROR type parameter `ty` should have a camel case name such as `Ty`
#[unstable(feature = "test_feature")]
#[deprecated(since = "1.0.0")]
- pub trait DeprecatedTrait {}
+ pub trait DeprecatedTrait {
+ fn dummy(&self) { }
+ }
struct S;
#![allow(dead_code)]
#![crate_type="lib"]
-struct Private<T>;
-pub struct Public<T>;
+use std::marker;
+
+struct Private<T>(marker::PhantomData<T>);
+pub struct Public<T>(marker::PhantomData<T>);
impl Private<Public<isize>> {
pub fn a(&self) -> Private<isize> { panic!() }
fn bar(&self) -> Private<isize> { panic!() }
}
-pub trait ParamTrait<T> {
+pub trait ParamTrait<T> : marker::MarkerTrait {
fn foo() -> T;
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::marker;
+
fn send<T:Send + std::fmt::Debug>(ch: _chan<T>, data: T) {
println!("{:?}", ch);
println!("{:?}", data);
}
#[derive(Debug)]
-struct _chan<T>(isize);
+struct _chan<T>(isize, marker::PhantomData<T>);
// Tests that "log(debug, message);" is flagged as using
// message after the send deinitializes it
use std::collections::HashMap;
-trait Map<K, V> {}
+trait Map<K, V>
+{
+ fn get(&self, k: K) -> V { panic!() }
+}
impl<K, V> Map<K, V> for HashMap<K, V> {}
+++ /dev/null
-// Copyright 2012 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.
-
-// Test that when we pick a trait based on coercion, versus subtyping,
-// we consider all possible coercions equivalent and don't try to pick
-// a best one.
-
-trait Object { }
-
-trait foo {
- fn foo(self) -> isize;
-}
-
-impl foo for Box<Object+'static> {
- fn foo(self) -> isize {1}
-}
-
-impl foo for Box<Object+Send> {
- fn foo(self) -> isize {2}
-}
-
-fn test1(x: Box<Object+Send+Sync>) {
- // FIXME(#18737) -- we ought to consider this to be ambiguous,
- // since we could coerce to either impl. However, what actually
- // happens is that we consider both impls applicable because of
- // incorrect subtyping relation. We then decide to call this a
- // call to the `foo` trait, leading to the following error
- // message.
-
- x.foo(); //~ ERROR `foo` is not implemented
-}
-
-fn test2(x: Box<Object+Send>) {
- // Not ambiguous because it is a precise match:
- x.foo();
-}
-
-fn test3(x: Box<Object+'static>) {
- // Not ambiguous because it is a precise match:
- x.foo();
-}
-
-fn main() { }
// Test that an object type `Box<Foo>` is not considered to implement the
// trait `Foo`. Issue #5087.
+use std::marker::MarkerTrait;
-trait Foo {}
+trait Foo : MarkerTrait {}
fn take_foo<F:Foo>(f: F) {}
fn take_object(f: Box<Foo>) { take_foo(f); }
//~^ ERROR the trait `Foo` is not implemented
a
//~^ ERROR cannot infer
//~| ERROR mismatched types
- //~| ERROR mismatched types
}
fn main() {
// Check that we correctly prevent users from making trait objects
// from traits with static methods.
-trait Foo {
+trait Foo : ::std::marker::MarkerTrait {
fn foo();
}
#![allow(unused)]
+use std::marker;
+
#[rustc_on_unimplemented = "test error `{Self}` with `{Bar}` `{Baz}` `{Quux}`"]
-trait Foo<Bar, Baz, Quux>{}
+trait Foo<Bar, Baz, Quux>
+ : marker::PhantomFn<(Self,Bar,Baz,Quux)>
+{}
#[rustc_on_unimplemented="a collection of type `{Self}` cannot be built from an iterator over elements of type `{A}`"]
trait MyFromIterator<A> {
}
#[rustc_on_unimplemented] //~ ERROR this attribute must have a value
-trait BadAnnotation1 {}
+trait BadAnnotation1
+ : marker::MarkerTrait
+{}
#[rustc_on_unimplemented = "Unimplemented trait error on `{Self}` with params `<{A},{B},{C}>`"]
//~^ ERROR there is no type parameter C on trait BadAnnotation2
-trait BadAnnotation2<A,B> {}
+trait BadAnnotation2<A,B>
+ : marker::PhantomFn<(Self,A,B)>
+{}
#[rustc_on_unimplemented = "Unimplemented trait error on `{Self}` with params `<{A},{B},{}>`"]
//~^ only named substitution parameters are allowed
-trait BadAnnotation3<A,B> {}
+trait BadAnnotation3<A,B>
+ : marker::PhantomFn<(Self,A,B)>
+{}
pub fn main() {
}
#![feature(on_unimplemented)]
+use std::marker;
+
#[rustc_on_unimplemented = "test error `{Self}` with `{Bar}` `{Baz}` `{Quux}`"]
-trait Foo<Bar, Baz, Quux>{}
+trait Foo<Bar, Baz, Quux>
+ : marker::PhantomFn<(Self,Bar,Baz,Quux)>
+{}
fn foobar<U: Clone, T: Foo<u8, U, u32>>() -> T {
use orphan_check_diagnostics::RemoteTrait;
-trait LocalTrait {}
+trait LocalTrait { fn dummy(&self) { } }
impl<T> RemoteTrait for T where T: LocalTrait {}
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
}
trait A {
- fn foo() {}
+ fn foo(&self) {}
}
struct B;
pub impl B {} //~ ERROR: unnecessary visibility
pub impl A for B { //~ ERROR: unnecessary visibility
- pub fn foo() {} //~ ERROR: unnecessary visibility
+ pub fn foo(&self) {} //~ ERROR: unnecessary visibility
}
pub fn main() {}
// public type, private value
pub mod foo1 {
- pub trait Bar {
+ use std::marker::MarkerTrait;
+
+ pub trait Bar : MarkerTrait {
}
pub struct Baz;
// private type, public value
pub mod foo2 {
- trait Bar {
+ trait Bar : ::std::marker::MarkerTrait {
}
pub struct Baz;
// neither public
pub mod foo3 {
- trait Bar {
+ trait Bar : ::std::marker::MarkerTrait {
}
pub struct Baz;
#![feature(lang_items, start, no_std)]
#![no_std] // makes debugging this test *a lot* easier (during resolve)
+#[lang="phantom_fn"]
+pub trait PhantomFn<A:?Sized,R:?Sized=()> { }
+impl<A:?Sized, R:?Sized, U:?Sized> PhantomFn<A,R> for U { }
+
#[lang="sized"]
-pub trait Sized {}
+pub trait Sized : PhantomFn<Self> {}
#[lang="copy"]
-pub trait Copy {}
+pub trait Copy : PhantomFn<Self> {}
mod bar {
// shouldn't bring in too much
#![feature(lang_items, start, no_std)]
#![no_std] // makes debugging this test *a lot* easier (during resolve)
-#[lang = "sized"] pub trait Sized {}
-#[lang="copy"] pub trait Copy {}
+#[lang="phantom_fn"]
+pub trait PhantomFn<A:?Sized,R:?Sized=()> { }
+impl<A:?Sized, R:?Sized, U:?Sized> PhantomFn<A,R> for U { }
+
+#[lang = "sized"] pub trait Sized : PhantomFn<Self> {}
+#[lang="copy"] pub trait Copy : PhantomFn<Self> {}
// Test to make sure that private items imported through globs remain private
// when they're used.
#![feature(box_syntax)]
-trait Foo {}
+trait Foo : ::std::marker::MarkerTrait {}
impl<'a> Foo for &'a [u8] {}
fn a(v: &[u8]) -> Box<Foo + 'static> {
// Test that the compiler checks that arbitrary region bounds declared
// in the trait must be satisfied on the impl. Issue #20890.
-trait Foo<'a> { type Value: 'a; }
+trait Foo<'a> {
+ type Value: 'a;
+ fn dummy(&'a self) { }
+}
impl<'a> Foo<'a> for &'a i16 {
// OK.
// Test that the compiler checks that the 'static bound declared in
// the trait must be satisfied on the impl. Issue #20890.
-trait Foo { type Value: 'static; }
+trait Foo {
+ type Value: 'static;
+ fn dummy(&self) { }
+}
impl<'a> Foo for &'a i32 {
//~^ ERROR cannot infer
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 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>);
+ fn another_bound<'x: 'a>(self, x: Inv<'x>, y: Inv<'t>);
}
-
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
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 another_bound<'x: 't>(self, x: Inv<'x>, y: Inv<'t>) {}
}
fn main() { }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-#![feature(lang_items, no_std)]
-#![no_std]
-
// Check that explicit region bounds are allowed on the various
// nominal types (but not on other types) and that they are type
// checked.
-#[lang="sized"]
-trait Sized { }
-
struct Inv<'a> { // invariant w/r/t 'a
x: &'a mut &'a isize
}
#![feature(box_syntax)]
-trait X {}
+use std::marker::MarkerTrait;
+
+trait X : MarkerTrait {}
trait Iter {
type Item: X;
#![feature(box_syntax)]
#![allow(warnings)]
-trait A<T> {}
+use std::marker::PhantomFn;
+
+trait A<T> : PhantomFn<(Self,T)> { }
struct B<'a, T>(&'a (A<T>+'a));
-trait X {}
+trait X : ::std::marker::MarkerTrait {}
+
impl<'a, T> X for B<'a, T> {}
-fn f<'a, T, U>(v: Box<A<T>+'static>) -> Box<X+'static> {
+fn f<'a, T:'static, U>(v: Box<A<T>+'static>) -> Box<X+'static> {
box B(&*v) as Box<X> //~ ERROR `*v` does not live long enough
}
#![feature(box_syntax)]
-trait A<T> {}
+use std::marker::PhantomFn;
+
+trait A<T> : PhantomFn<(Self,T)> { }
struct B<'a, T>(&'a (A<T>+'a));
-trait X {}
+trait X : PhantomFn<Self> {}
impl<'a, T> X for B<'a, T> {}
fn g<'a, T: 'static>(v: Box<A<T>+'a>) -> Box<X+'static> {
#![feature(box_syntax)]
#![allow(warnings)]
-trait A<T> {}
+use std::marker::PhantomFn;
+
+trait A<T> : PhantomFn<(Self,T)> {}
struct B<'a, T>(&'a (A<T>+'a));
-trait X {}
+trait X : PhantomFn<Self> {}
impl<'a, T> X for B<'a, T> {}
fn h<'a, T, U>(v: Box<A<U>+'static>) -> Box<X+'static> {
#![feature(box_syntax)]
-trait A<T> {}
+use std::marker::PhantomFn;
+
+trait A<T> : PhantomFn<(Self,T)> {}
struct B<'a, T>(&'a (A<T>+'a));
-trait X {}
+trait X : PhantomFn<Self> {}
impl<'a, T> X for B<'a, T> {}
fn i<'a, T, U>(v: Box<A<U>+'a>) -> Box<X+'static> {
#![feature(box_syntax)]
-trait Foo { }
+use std::marker::MarkerTrait;
+
+trait Foo : MarkerTrait { }
impl<'a> Foo for &'a isize { }
#![feature(box_syntax)]
-trait X {}
+trait X : ::std::marker::MarkerTrait {}
fn p1<T>(v: T) -> Box<X+'static>
where T : X
// Contravariant<'foo> <: Contravariant<'static> because
// 'foo <= 'static
struct Contravariant<'a> {
- marker: marker::ContravariantLifetime<'a>
+ marker: marker::PhantomData<&'a()>
}
fn use_<'short,'long>(c: Contravariant<'short>,
use std::marker;
struct Covariant<'a> {
- marker: marker::CovariantLifetime<'a>
+ marker: marker::PhantomData<fn(&'a ())>
}
fn use_<'short,'long>(c: Covariant<'long>,
use std::marker;
struct invariant<'a> {
- marker: marker::InvariantLifetime<'a>
+ marker: marker::PhantomData<*mut &'a()>
}
fn to_same_lifetime<'r>(bi: invariant<'r>) {
#![feature(lang_items, no_std)]
#![no_std]
-#[lang="sized"] pub trait Sized {}
+#[lang="phantom_fn"]
+pub trait PhantomFn<T:?Sized> { }
+impl<T:?Sized, U:?Sized> PhantomFn<T> for U { }
+
+#[lang="sized"] pub trait Sized : PhantomFn<Self> {}
// error-pattern:requires `start` lang_item
#![feature(box_syntax)]
-struct Foo<T>;
+struct Foo<T>(T);
impl<T> Foo<T> {
fn shadow_in_method<T>(&self) {}
//~^ ERROR type parameter `T` shadows another type parameter
fn not_shadow_in_item<U>(&self) {
- struct Bar<T, U>; // not a shadow, separate item
+ struct Bar<T, U>(T,U); // not a shadow, separate item
fn foo<T, U>() {} // same
}
}
trait Bar<T> {
+ fn dummy(&self) -> T;
+
fn shadow_in_required<T>(&self);
//~^ ERROR type parameter `T` shadows another type parameter
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-struct Foo<T,U>(T);
+use std::marker;
+
+struct Foo<T,U>(T, marker::PhantomData<U>);
fn main() {
- match Foo(1.1) {
+ match Foo(1.1, marker::PhantomData) {
1 => {}
//~^ ERROR mismatched types
//~| expected `Foo<_, _>`
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-
trait foo {
+ fn dummy(&self) { }
fn bar();
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait TraitNotAStruct { }
+trait TraitNotAStruct : ::std::marker::MarkerTrait { }
fn main() {
TraitNotAStruct{ value: 0 };
trait Foo {
+ fn dummy(&self) { }
}
fn a(_x: Box<Foo+Send>) {
// Make sure rustc checks the type parameter bounds in implementations of traits,
// see #2687
-trait A {}
+use std::marker;
+
+trait A : marker::PhantomFn<Self> {
+}
trait B: A {}
//~^ ERROR the requirement `T : C` appears on the impl
}
-
-trait Getter<T> { }
+trait Getter<T> {
+ fn get(&self) -> T { loop { } }
+}
trait Trait {
- fn method<G:Getter<isize>>();
+ fn method<G:Getter<isize>>(&self);
}
impl Trait for usize {
- fn method<G: Getter<usize>>() {}
+ fn method<G: Getter<usize>>(&self) {}
//~^ G : Getter<usize>` appears on the impl method but not on the corresponding trait method
}
fn next(&mut self) -> Option<A>;
}
-trait IteratorUtil<A> {
+trait IteratorUtil<A>
+ : ::std::marker::PhantomFn<(),A>
+{
fn zip<B, U: Iterator<U>>(self, other: U) -> ZipIterator<Self, U>;
}
// except according to those terms.
trait Foo {
+ fn dummy(&self) { }
}
// This should emit the less confusing error, not the more confusing one.
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait Trait {}
+trait Trait {
+ fn dummy(&self) { }
+}
struct Foo<T:Trait> {
x: T,
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait Trait {}
+trait Trait {
+ fn dummy(&self) { }
+}
struct Foo<T:Trait> {
x: T,
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait Trait {}
+use std::marker::MarkerTrait;
+
+trait Trait : MarkerTrait {}
struct Foo<T:Trait> {
x: T,
EvenMoreBadness(Bar<V>),
}
-trait PolyTrait<T> {
- fn whatever() {}
+trait PolyTrait<T>
+{
+ fn whatever(&self, t: T) {}
}
struct Struct;
impl PolyTrait<Foo<usize>> for Struct {
//~^ ERROR not implemented
- fn whatever() {}
}
fn main() {
// Tests for "default" bounds inferred for traits with no bounds list.
+use std::marker::MarkerTrait;
-trait Foo {}
+trait Foo : MarkerTrait {}
fn a(_x: Box<Foo+Send>) {
}
// trait impl is only applied to a trait object, not concrete types which implement
// the trait.
-trait T {}
+use std::marker::MarkerTrait;
+
+trait T : MarkerTrait {}
impl<'a> T+'a {
fn foo(&self) {}
trait Tr {
fn foo();
+ fn bar(&self) { }
}
struct St;
mod base {
pub trait HasNew<T> {
fn new() -> T;
+ fn dummy(&self) { }
}
pub struct Foo {
struct TestType;
-trait TestTrait {}
+trait TestTrait {
+ fn dummy(&self) { }
+}
impl !TestTrait for TestType {}
//~^ ERROR negative impls are currently allowed just for `Send` and `Sync`
// This test checks that genuine type errors with partial
// type hints are understandable.
-struct Foo<T>;
-struct Bar<U>;
+use std::marker::PhantomData;
+
+struct Foo<T>(PhantomData<T>);
+struct Bar<U>(PhantomData<U>);
pub fn main() {
}
fn test1() {
- let x: Foo<_> = Bar::<usize>;
+ let x: Foo<_> = Bar::<usize>(PhantomData);
//~^ ERROR mismatched types
//~| expected `Foo<_>`
//~| found `Bar<usize>`
}
fn test2() {
- let x: Foo<_> = Bar::<usize>;
+ let x: Foo<_> = Bar::<usize>(PhantomData);
//~^ ERROR mismatched types
//~| expected `Foo<_>`
//~| found `Bar<usize>`
// Check that parenthetical notation is feature-gated except with the
// `Fn` traits.
+use std::marker;
+
trait Foo<A> {
type Output;
+
+ fn dummy(&self, a: A) { }
}
fn main() {
fn dummy(&self, t: T, v: V);
}
-trait Eq<X: ?Sized> { }
+trait Eq<X: ?Sized> { fn same_types(&self, x: &X) -> bool { true } }
impl<X: ?Sized> Eq<X> for X { }
fn eq<A: ?Sized,B: ?Sized>() where A : Eq<B> { }
#![feature(unboxed_closures)]
#![allow(dead_code)]
+use std::marker::PhantomFn;
+
trait Foo<T> {
type Output;
fn dummy(&self, t: T, u: Self::Output);
}
-trait Eq<X: ?Sized> { }
+trait Eq<X: ?Sized> : PhantomFn<(Self,X)> { }
impl<X: ?Sized> Eq<X> for X { }
fn eq<A: ?Sized,B: ?Sized +Eq<A>>() { }
#![feature(unboxed_closures)]
#![allow(dead_code)]
+use std::marker;
+
trait Foo<T> {
type Output;
fn dummy(&self, t: T);
}
-trait Eq<X: ?Sized> { }
+trait Eq<X: ?Sized> : marker::PhantomFn<(Self, X)> { }
impl<X: ?Sized> Eq<X> for X { }
fn eq<A: ?Sized,B: ?Sized +Eq<A>>() { }
fn dummy(&'a self) -> &'a (T,Self::Output);
}
-trait Eq<X: ?Sized> { }
+trait Eq<X: ?Sized> { fn is_of_eq_type(&self, x: &X) -> bool { true } }
impl<X: ?Sized> Eq<X> for X { }
fn eq<A: ?Sized,B: ?Sized +Eq<A>>() { }
#![feature(core,unboxed_closures)]
-use std::marker::CovariantType;
+use std::marker::PhantomData;
// A erroneous variant of `run-pass/unboxed_closures-infer-recursive-fn.rs`
// where we attempt to perform mutation in the recursive function. This fails to compile
struct YCombinator<F,A,R> {
func: F,
- marker: CovariantType<(A,R)>,
+ marker: PhantomData<(A,R)>,
}
impl<F,A,R> YCombinator<F,A,R> {
fn new(f: F) -> YCombinator<F,A,R> {
- YCombinator { func: f, marker: CovariantType }
+ YCombinator { func: f, marker: PhantomData }
}
}
pub struct A; //~ ERROR: visibility has no effect
pub enum B {} //~ ERROR: visibility has no effect
pub trait C { //~ ERROR: visibility has no effect
- pub fn foo() {} //~ ERROR: visibility has no effect
+ pub fn foo(&self) {} //~ ERROR: visibility has no effect
}
impl A {
- pub fn foo() {} //~ ERROR: visibility has no effect
+ pub fn foo(&self) {} //~ ERROR: visibility has no effect
}
struct D {
// impl - struct
-struct S5<Y>;
+struct S5<Y>(Y);
impl<X: ?Sized> S5<X> { //~ ERROR not implemented
}
// impl - struct
trait T3<Z: ?Sized> {
+ fn foo(&self, z: &Z);
}
-struct S5<Y>;
+struct S5<Y>(Y);
impl<X: ?Sized> T3<X> for S5<X> { //~ ERROR not implemented
}
// impl - unbounded
trait T2<Z> {
+ fn foo(&self, z: Z);
}
-struct S4<Y: ?Sized>;
+struct S4<Y: ?Sized>(Box<Y>);
impl<X: ?Sized> T2<X> for S4<X> {
//~^ ERROR `core::marker::Sized` is not implemented for the type `X`
}
// Test sized-ness checking in substitution within fn bodies..
+use std::marker;
// Unbounded.
fn f1<X: ?Sized>(x: &X) {
}
// Bounded.
-trait T {}
+trait T {
+ fn foo(&self) { }
+}
fn f3<X: ?Sized + T>(x: &X) {
f4::<X>(x);
//~^ ERROR the trait `core::marker::Sized` is not implemented
// Test `?Sized` local variables.
+use std::marker;
-trait T {}
+trait T : marker::MarkerTrait { }
fn f1<X: ?Sized>(x: &X) {
let _: X; // <-- this is OK, no bindings created, no initializer.
// Test sized-ness checking in substitution in impls.
-trait T {}
+use std::marker::MarkerTrait;
+
+trait T : MarkerTrait {}
// I would like these to fail eventually.
// impl - bounded
trait T1<Z: T> {
+ fn dummy(&self) -> Z;
}
-struct S3<Y: ?Sized>;
+
+struct S3<Y: ?Sized>(Box<Y>);
impl<X: ?Sized + T> T1<X> for S3<X> {
//~^ ERROR `core::marker::Sized` is not implemented for the type `X`
}
#[foo] //~ ERROR unused attribute
trait Baz {
#[foo] //~ ERROR unused attribute
- fn blah();
+ fn blah(&self);
#[foo] //~ ERROR unused attribute
- fn blah2() {}
+ fn blah2(&self) {}
}
fn main() {}
pub enum C { pub Variant } //~ ERROR: unnecessary `pub`
pub trait E {
- pub fn foo() {} //~ ERROR: unnecessary visibility
+ pub fn foo(&self) {} //~ ERROR: unnecessary visibility
+}
+trait F {
+ pub fn foo(&self) {} //~ ERROR: unnecessary visibility
}
-trait F { pub fn foo() {} } //~ ERROR: unnecessary visibility
impl E for A {
- pub fn foo() {} //~ ERROR: unnecessary visibility
+ pub fn foo(&self) {} //~ ERROR: unnecessary visibility
}
fn main() {}
// except according to those terms.
pub trait E {
- pub fn foo(); //~ ERROR: unnecessary visibility
+ pub fn foo(&self); //~ ERROR: unnecessary visibility
+}
+trait F {
+ pub fn foo(&self); //~ ERROR: unnecessary visibility
}
-trait F { pub fn foo(); } //~ ERROR: unnecessary visibility
fn main() {}
#[rustc_variance]
struct Test7<'a> { //~ ERROR regions=[[*];[];[]]
+ //~^ ERROR parameter `'a` is never used
x: isize
}
#[rustc_variance]
enum Base<'a, 'b, 'c:'b, 'd> { //~ ERROR regions=[[+, -, o, *];[];[]]
+ //~^ ERROR parameter `'d` is never used
Test8A(extern "Rust" fn(&'a isize)),
Test8B(&'b [isize]),
Test8C(&'b mut &'c str),
#[rustc_variance]
struct Derived1<'w, 'x:'y, 'y, 'z> { //~ ERROR regions=[[*, o, -, +];[];[]]
+ //~^ ERROR parameter `'w` is never used
f: Base<'z, 'y, 'x, 'w>
}
#[rustc_variance] // Combine - and + to yield o
struct Derived2<'a, 'b:'a, 'c> { //~ ERROR regions=[[o, o, *];[];[]]
+ //~^ ERROR parameter `'c` is never used
f: Base<'a, 'a, 'b, 'c>
}
#[rustc_variance] // Combine + and o to yield o (just pay attention to 'a here)
struct Derived3<'a:'b, 'b, 'c> { //~ ERROR regions=[[o, -, *];[];[]]
+ //~^ ERROR parameter `'c` is never used
f: Base<'a, 'b, 'a, 'c>
}
use std::mem;
-trait T { fn foo(); }
+trait T { fn foo(&self); }
#[rustc_variance]
struct TOption<'a> { //~ ERROR regions=[[-];[];[]]
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait Foo {}
+trait Foo {
+ fn dummy(&self) { }
+}
pub fn f<
T
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait Foo {}
+trait Foo {
+ fn dummy(&self) { }
+}
pub trait Bar : Foo {} //~ ERROR private trait in exported type
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait Foo<T> {}
+trait Foo<T> {
+ fn dummy(&self, t: T) { }
+}
trait Bar<A> {
fn method<B>(&self) where A: Foo<B>;
#[derive(PartialEq)]
//~^ ERROR cannot bound type `isize`, where clause bounds
-enum Foo<T> where isize : Eq { MkFoo }
+enum Foo<T> where isize : Eq { MkFoo(T) }
//~^ ERROR cannot bound type `isize`, where clause bounds
fn test3<T: Eq>() -> bool where Option<Foo<T>> : Eq {}
trait Baz<T> where isize : Eq {
//~^ ERROR cannot bound type `isize`, where clause bounds may only
- fn baz() where String : Eq; //~ ERROR cannot bound type `collections::string::String`
+ fn baz(&self, t: T) where String : Eq; //~ ERROR cannot bound type `collections::string::String`
//~^ ERROR cannot bound type `isize`, where clause
}
#![omit_gdb_pretty_printer_section]
use self::Enum1::{Variant1_1, Variant1_2};
+use std::marker::PhantomData;
use std::ptr;
struct Struct1;
-struct GenericStruct<T1, T2>;
+struct GenericStruct<T1, T2>(PhantomData<(T1,T2)>);
enum Enum1 {
Variant1_1,
}
}
-trait Trait1 { }
-trait Trait2<T1, T2> { }
+trait Trait1 { fn dummy(&self) { } }
+trait Trait2<T1, T2> { fn dummy(&self, _: T1, _:T2) { } }
impl Trait1 for isize {}
impl<T1, T2> Trait2<T1, T2> for isize {}
// Structs
let simple_struct = Struct1;
- let generic_struct1: GenericStruct<Mod1::Struct2, Mod1::Mod2::Struct3> = GenericStruct;
- let generic_struct2: GenericStruct<Struct1, extern "fastcall" fn(isize) -> usize> = GenericStruct;
+ let generic_struct1: GenericStruct<Mod1::Struct2, Mod1::Mod2::Struct3> =
+ GenericStruct(PhantomData);
+ let generic_struct2: GenericStruct<Struct1, extern "fastcall" fn(isize) -> usize> =
+ GenericStruct(PhantomData);
let mod_struct = Mod1::Struct2;
// Enums
// References
let ref1 = (&Struct1, 0i32);
- let ref2 = (&GenericStruct::<char, Struct1>, 0i32);
+ let ref2 = (&GenericStruct::<char, Struct1>(PhantomData), 0i32);
let mut mut_struct1 = Struct1;
- let mut mut_generic_struct = GenericStruct::<Mod1::Enum2, f64>;
+ let mut mut_generic_struct = GenericStruct::<Mod1::Enum2, f64>(PhantomData);
let mut_ref1 = (&mut mut_struct1, 0i32);
let mut_ref2 = (&mut mut_generic_struct, 0i32);
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait X { }
+trait X { fn dummy(&self) { } }
impl X for uint { }
-trait Y { }
+trait Y { fn dummy(&self) { } }
impl Y for uint { }
// pp-exact
-trait Tr { }
+trait Tr {
+ fn dummy(&self) { }
+}
impl Tr for int { }
fn foo<'a>(x: Box<Tr+ Sync + 'a>) -> Box<Tr+ Sync + 'a> { x }
// except according to those terms.
// error-pattern:quux
+
+use std::marker::PhantomData;
+
fn test00_start(ch: chan_t<int>, message: int) { send(ch, message); }
type task_id = int;
struct chan_t<T> {
task: task_id,
port: port_id,
+ marker: PhantomData<*mut T>,
}
fn send<T:Send>(_ch: chan_t<T>, _data: T) { panic!(); }
}
/// *wow*
- pub trait Doge { }
+ pub trait Doge { fn dummy(&self) { } }
}
// @matches foo/struct.Alpha.html '//pre' "pub struct Alpha"
pub struct Alpha;
// @matches foo/struct.Bravo.html '//pre' "pub struct Bravo<B>"
-pub struct Bravo<B>;
+pub struct Bravo<B>(B);
// @matches foo/struct.Alpha.html '//*[@class="impl"]//code' "impl !Send for Alpha"
impl !Send for Alpha {}
}
pub trait PrivateTrait {
- fn trait_method() {} // @!has - priv_method
+ fn trait_method(&self) {} // @!has - priv_method
}
}
/// *wow*
// @has foo/bar/trait.Doge.html
- pub trait Doge { }
+ pub trait Doge { fn dummy(&self) { } }
// @has foo/bar/struct.Foo.html
pub struct Foo { x: int, y: uint }
// except according to those terms.
pub mod io {
- pub trait Reader { }
+ pub trait Reader { fn dummy(&self) { } }
}
pub enum Maybe<A> {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-pub trait MyTrait {}
+pub trait MyTrait { fn dummy(&self) { } }
// @has foo/struct.Alpha.html '//pre' "pub struct Alpha<A> where A: MyTrait"
-pub struct Alpha<A> where A: MyTrait;
+pub struct Alpha<A>(A) where A: MyTrait;
// @has foo/trait.Bravo.html '//pre' "pub trait Bravo<B> where B: MyTrait"
-pub trait Bravo<B> where B: MyTrait {}
+pub trait Bravo<B> where B: MyTrait { fn get(&self, B: B); }
// @has foo/fn.charlie.html '//pre' "pub fn charlie<C>() where C: MyTrait"
pub fn charlie<C>() where C: MyTrait {}
-pub struct Delta<D>;
+pub struct Delta<D>(D);
+
// @has foo/struct.Delta.html '//*[@class="impl"]//code' \
// "impl<D> Delta<D> where D: MyTrait"
impl<D> Delta<D> where D: MyTrait {
pub fn delta() {}
}
-pub struct Echo<E>;
+pub struct Echo<E>(E);
+
// @has foo/struct.Echo.html '//*[@class="impl"]//code' \
// "impl<E> MyTrait for Echo<E> where E: MyTrait"
// @has foo/trait.MyTrait.html '//*[@id="implementors-list"]//code' \
// "impl<E> MyTrait for Echo<E> where E: MyTrait"
impl<E> MyTrait for Echo<E> where E: MyTrait {}
-pub enum Foxtrot<F> {}
+pub enum Foxtrot<F> { Foxtrot1(F) }
+
// @has foo/enum.Foxtrot.html '//*[@class="impl"]//code' \
// "impl<F> MyTrait for Foxtrot<F> where F: MyTrait"
// @has foo/trait.MyTrait.html '//*[@id="implementors-list"]//code' \
type SF = some_fields;
trait SuperTrait {
+ fn dummy(&self) { }
}
trait SomeTrait: SuperTrait {
}
#[lang = "sized"]
-trait Sized {}
+pub trait Sized : PhantomFn<Self> {}
#[lang = "copy"]
-trait Copy {}
+pub trait Copy : PhantomFn<Self> {}
+
+#[lang="phantom_fn"]
+pub trait PhantomFn<A:?Sized,R:?Sized=()> { }
+impl<A:?Sized, R:?Sized, U:?Sized> PhantomFn<A,R> for U { }
mod core {
pub mod marker {
pub static X: &'static str = "foobarbaz";
pub static Y: &'static [u8] = include_bytes!("lib.rs");
-trait Foo {}
+trait Foo { fn dummy(&self) { } }
impl Foo for uint {}
pub fn dummy() {
#![feature(lang_items, no_std)]
#![no_std]
+#[lang="phantom_fn"]
+trait PhantomFn<A:?Sized,R:?Sized=()> { }
+impl<A:?Sized, R:?Sized, U:?Sized> PhantomFn<A,R> for U { }
+
#[lang="copy"]
-trait Copy { }
+trait Copy : PhantomFn<Self> { }
#[lang="sized"]
-trait Sized { }
+trait Sized : PhantomFn<Self> { }
#[lang="start"]
fn start(_main: *const u8, _argc: int, _argv: *const *const u8) -> int { 0 }
}
-trait Trait {}
+trait Trait { fn dummy(&self) { } }
impl Trait for Foo {}
pub fn main() {
}
}
-trait Trait {}
+trait Trait { fn dummy(&self) { } }
impl Trait for Foo {}
struct Fat<T: ?Sized> {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait Foo {
+use std::marker::MarkerTrait;
+
+trait Foo : MarkerTrait {
type T;
}
// `Target=[A]`, then the impl marked with `(*)` is seen to conflict
// with all the others.
+use std::marker::PhantomData;
use std::ops::Deref;
pub trait MyEq<U: ?Sized=Self> {
}
struct DerefWithHelper<H, T> {
- pub helper: H
+ pub helper: H,
+ pub marker: PhantomData<T>,
}
trait Helper<T> {
}
pub fn check<T: MyEq>(x: T, y: T) -> bool {
- let d: DerefWithHelper<Option<T>, T> = DerefWithHelper { helper: Some(x) };
+ let d: DerefWithHelper<Option<T>, T> = DerefWithHelper { helper: Some(x),
+ marker: PhantomData };
d.eq(&y)
}
// Test that we are able to have an impl that defines an associated type
// before the actual trait.
+use std::marker::MarkerTrait;
+
impl X for f64 { type Y = int; }
-trait X {type Y; }
+trait X : MarkerTrait { type Y; }
fn main() {}
panic!()
}
}
-impl <P> Parser for P {
+
+impl <P> Parser for P {
type Input = ();
}
// Test that we can resolve nested projection types. Issue #20666.
+use std::marker::MarkerTrait;
use std::slice;
-trait Bound {}
+trait Bound : MarkerTrait {}
-impl<'a> Bound for &'a int {}
+impl<'a> Bound for &'a i32 {}
trait IntoIterator {
type Iter: Iterator;
#![allow(dead_code)]
-pub trait Integral {
+use std::marker::MarkerTrait;
+
+pub trait Integral : MarkerTrait {
type Opposite;
}
pub trait FnLike<A> {
type R;
+
+ fn dummy(&self, a: A) -> Self::R { loop { } }
}
fn foo<T>()
// Test that we normalize associated types that appear in bounds; if
// we didn't, the call to `self.split2()` fails to type check.
-struct Splits<'a, T, P>;
-struct SplitsN<I>;
+use std::marker::PhantomData;
+
+struct Splits<'a, T:'a, P>(PhantomData<(&'a T, P)>);
+struct SplitsN<I>(PhantomData<I>);
trait SliceExt2 {
type Item;
fn split2<'a, P>(&'a self, pred: P) -> Splits<'a, Self::Item, P>
where P: FnMut(&Self::Item) -> bool;
- fn splitn2<'a, P>(&'a self, n: uint, pred: P) -> SplitsN<Splits<'a, Self::Item, P>>
+ fn splitn2<'a, P>(&'a self, n: u32, pred: P) -> SplitsN<Splits<'a, Self::Item, P>>
where P: FnMut(&Self::Item) -> bool;
}
loop {}
}
- fn splitn2<P>(&self, n: uint, pred: P) -> SplitsN<Splits<T, P>> where P: FnMut(&T) -> bool {
+ fn splitn2<P>(&self, n: u32, pred: P) -> SplitsN<Splits<T, P>> where P: FnMut(&T) -> bool {
SliceExt2::split2(self, pred);
loop {}
}
// Test that we normalize associated types that appear in bounds; if
// we didn't, the call to `self.split2()` fails to type check.
-struct Splits<'a, T, P>;
-struct SplitsN<I>;
+use std::marker::PhantomData;
+
+struct Splits<'a, T, P>(PhantomData<(&'a(),T,P)>);
+struct SplitsN<I>(PhantomData<I>);
trait SliceExt2 {
type Item;
fn split2<'a, P>(&'a self, pred: P) -> Splits<'a, Self::Item, P>
where P: FnMut(&Self::Item) -> bool;
- fn splitn2<'a, P>(&'a self, n: uint, pred: P) -> SplitsN<Splits<'a, Self::Item, P>>
+ fn splitn2<'a, P>(&'a self, n: usize, pred: P) -> SplitsN<Splits<'a, Self::Item, P>>
where P: FnMut(&Self::Item) -> bool;
}
loop {}
}
- fn splitn2<P>(&self, n: uint, pred: P) -> SplitsN<Splits<T, P>> where P: FnMut(&T) -> bool {
+ fn splitn2<P>(&self, n: usize, pred: P) -> SplitsN<Splits<T, P>> where P: FnMut(&T) -> bool {
self.split2(pred);
loop {}
}
pub trait OffsetState: Sized {}
-pub trait Offset { type State: OffsetState; }
+pub trait Offset {
+ type State: OffsetState;
+ fn dummy(&self) { }
+}
#[derive(Copy)] pub struct X;
impl Offset for X { type State = Y; }
trait Int
{
type T;
+
+ fn dummy(&self) { }
}
trait NonZero
pub trait Subscriber {
type Input;
+
+ fn dummy(&self) { }
}
pub trait Publisher<'a> {
trait A
{
type TA;
+
+ fn dummy(&self) { }
}
trait B<TB>
trait Int
{
type T;
+
+ fn dummy(&self) { }
}
trait NonZero
pub trait Foo {
type Bar;
+
+ fn dummy(&self) { }
}
impl Foo for int {
trait Trait<'a> {
type T: 'static;
type U: Get<&'a int>;
+
+ fn dummy(&'a self) { }
}
fn main() {}
pub trait UnifyKey {
type Value;
+
+ fn dummy(&self) { }
}
pub struct Node<K:UnifyKey> {
pub trait UnifyKey {
type Value;
+
+ fn dummy(&self) { }
}
pub struct Node<K:UnifyKey>(K, K::Value);
// Using a type via an impl.
trait C {
fn f();
+ fn g(&self) { }
}
-struct B<X>;
+struct B<X>(X);
impl<T: Foo> C for B<T> {
fn f() {
let x: T::A = panic!();
// to the same lifetime on a trait succeeds. See issue #10766.
#![allow(dead_code)]
+
+use std::marker;
+
fn main() {
- trait T {}
+ trait T : marker::MarkerTrait {}
fn f<'a, V: T>(v: &'a V) -> &'a T {
v as &'a T
// except according to those terms.
pub trait Foo<T> {
- fn func1<U>(&self, t: U);
+ fn func1<U>(&self, t: U, w: T);
- fn func2<U>(&self, t: U) {
- self.func1(t);
+ fn func2<U>(&self, t: U, w: T) {
+ self.func1(t, w);
}
}
extern crate trait_superkinds_in_metadata;
use trait_superkinds_in_metadata::{RequiresRequiresShareAndSend, RequiresShare};
use trait_superkinds_in_metadata::{RequiresCopy};
+use std::marker;
#[derive(Copy)]
struct X<T>(T);
// super-builtin-kind of a trait, if the type parameter is never used,
// the type can implement the trait anyway.
+use std::marker;
+
trait Foo : Send { }
-struct X<T>(());
+struct X<T> { marker: marker::PhantomData<T> }
-impl <T> Foo for X<T> { }
+impl<T:Send> Foo for X<T> { }
pub fn main() { }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::marker::PhantomData;
+
struct cat<U> {
meows : uint,
-
how_hungry : int,
+ m: PhantomData<U>
}
impl<U> cat<U> {
fn cat<U>(in_x : uint, in_y : int) -> cat<U> {
cat {
meows: in_x,
- how_hungry: in_y
+ how_hungry: in_y,
+ m: PhantomData
}
}
// Test coercions involving DST and/or raw pointers
struct S;
-trait T {}
+trait T { fn dummy(&self) { } }
impl T for S {}
pub fn main() {
use std::rc::Rc;
use std::sync::Arc;
-trait Trait {}
+trait Trait { fn dummy(&self) { } }
fn main() {
// Functions
struct LM { resize_at: uint, size: uint }
enum HashMap<K,V> {
- HashMap_(LM)
+ HashMap_(LM, Vec<(K,V)>)
}
-impl<K,V> Copy for HashMap<K,V> {}
-
fn linear_map<K,V>() -> HashMap<K,V> {
HashMap::HashMap_(LM{
resize_at: 32,
- size: 0})
+ size: 0}, Vec::new())
}
impl<K,V> HashMap<K,V> {
pub fn len(&mut self) -> uint {
match *self {
- HashMap::HashMap_(l) => l.size
+ HashMap::HashMap_(ref l, _) => l.size
}
}
}
+++ /dev/null
-// Copyright 2012 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.
-
-
-enum list_cell<T> { cons(Box<list_cell<T>>), nil }
-
-pub fn main() { }
extern crate default_type_params_xc;
-struct Vec<T, A = default_type_params_xc::Heap>;
+struct Vec<T, A = default_type_params_xc::Heap>(Option<(T,A)>);
struct Foo;
fn main() {
- let _a = Vec::<int>;
- let _b = Vec::<int, default_type_params_xc::FakeHeap>;
- let _c = default_type_params_xc::FakeVec::<int>;
- let _d = default_type_params_xc::FakeVec::<int, Foo>;
+ let _a = Vec::<int>(None);
+ let _b = Vec::<int, default_type_params_xc::FakeHeap>(None);
+ let _c = default_type_params_xc::FakeVec::<int> { f: None };
+ let _d = default_type_params_xc::FakeVec::<int, Foo> { f: None };
}
#![allow(dead_code)]
-use std::marker;
+use std::marker::PhantomData;
#[derive(Copy)]
struct Foo<T> { x: T }
type Ty<'tcx> = &'tcx TyS<'tcx>;
enum TyS<'tcx> {
- Boop(marker::InvariantLifetime<'tcx>)
+ Boop(PhantomData<*mut &'tcx ()>)
}
#[derive(Copy)]
extern crate inner_static;
pub fn main() {
- let a = inner_static::A::<()>;
- let b = inner_static::B::<()>;
- let c = inner_static::test::A::<()>;
+ let a = inner_static::A::<()> { v: () };
+ let b = inner_static::B::<()> { v: () };
+ let c = inner_static::test::A::<()> { v: () };
assert_eq!(a.bar(), 2);
assert_eq!(b.bar(), 4);
assert_eq!(c.bar(), 6);
fn bar(&self);
}
-pub trait Baz {}
+pub trait Baz {
+ fn baz(&self) { }
+}
impl<T: Baz> Bar for T {
fn bar(&self) {}
}
}
-trait MyTrait { }
+trait MyTrait { fn dummy(&self) { } }
impl MyTrait for Box<DroppableStruct> {}
impl MyTrait for Box<DroppableEnum> {}
// except according to those terms.
pub mod two_tuple {
- pub trait T {}
+ pub trait T { fn dummy(&self) { } }
pub struct P<'a>(&'a (T + 'a), &'a (T + 'a));
pub fn f<'a>(car: &'a T, cdr: &'a T) -> P<'a> {
P(car, cdr)
}
pub mod two_fields {
- pub trait T {}
+ pub trait T { fn dummy(&self) { } }
pub struct P<'a> { car: &'a (T + 'a), cdr: &'a (T + 'a) }
pub fn f<'a>(car: &'a T, cdr: &'a T) -> P<'a> {
P{ car: car, cdr: cdr }
#![allow(unknown_features)]
#![feature(box_syntax)]
-trait Foo {}
+trait Foo { fn dummy(&self) { } }
impl Foo for int {}
fn foo(_: [&Foo; 2]) {}
fn foos(_: &[&Foo]) {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait Common {}
+trait Common { fn dummy(&self) { } }
impl<'t, T> Common for (T, &'t T) {}
// We weren't updating the auto adjustments with all the resolved
// type information after type check.
-trait A {}
+trait A { fn dummy(&self) { } }
struct B<'a, T:'a> {
f: &'a T
// this code used to cause an ICE
-trait X<T> {}
+use std::marker;
+
+trait X<T> {
+ fn dummy(&self) -> T { panic!() }
+}
struct S<T> {f: Box<X<T>+'static>,
g: Box<X<T>+'static>}
struct F;
-impl X<int> for F {}
+impl X<int> for F {
+}
fn main() {
S {f: box F, g: box F};
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait Foo {
+use std::marker::MarkerTrait;
+
+trait Foo : MarkerTrait {
fn quux(u8) {}
}
#[derive(Clone)]
struct B1;
-trait A {}
+trait A : std::marker::MarkerTrait {}
impl A for B1 {}
fn main() {
fn main() {
send::<Box<Foo>>(box Output(0));
Test::<Box<Foo>>::foo(box Output(0));
- Test::<Box<Foo>>.send(box Output(0));
+ Test::<Box<Foo>>::new().send(box Output(0));
}
fn send<T>(_: T) {}
-struct Test<T>;
+struct Test<T> { marker: std::marker::PhantomData<T> }
impl<T> Test<T> {
+ fn new() -> Test<T> { Test { marker: ::std::marker::PhantomData } }
fn foo(_: T) {}
fn send(&self, _: T) {}
}
-trait Foo {}
+trait Foo { fn dummy(&self) { }}
struct Output(int);
impl Foo for Output {}
#![feature(unboxed_closures)]
-trait Foo {}
+trait Foo { fn dummy(&self) { }}
struct Bar;
use std::ops::Fn;
-trait Response {}
-trait Request {}
+trait Response { fn dummy(&self) { } }
+trait Request { fn dummy(&self) { } }
trait Ingot<R, S> {
fn enter(&mut self, _: &mut R, _: &mut S, a: &mut Alloy) -> Status;
}
#[allow(dead_code)]
struct HelloWorld;
-struct SendFile<'a>;
+struct SendFile;
struct Alloy;
enum Status {
Continue
}
}
-impl<'a, 'b> Fn<(&'b mut (Response+'b),)> for SendFile<'a> {
+impl<'b> Fn<(&'b mut (Response+'b),)> for SendFile {
type Output = ();
extern "rust-call" fn call(&self, (_res,): (&'b mut (Response+'b),)) {}
static mut DROP_RAN: bool = false;
-trait Bar<'b> {
+trait Bar {
fn do_something(&mut self);
}
-struct BarImpl<'b>;
+struct BarImpl;
-impl<'b> Bar<'b> for BarImpl<'b> {
+impl Bar for BarImpl {
fn do_something(&mut self) {}
}
-struct Foo<B>;
+struct Foo<B>(B);
#[unsafe_destructor]
-impl<'b, B: Bar<'b>> Drop for Foo<B> {
+impl<B: Bar> Drop for Foo<B> {
fn drop(&mut self) {
unsafe {
DROP_RAN = true;
fn main() {
{
- let _x: Foo<BarImpl> = Foo;
+ let _x: Foo<BarImpl> = Foo(BarImpl);
}
unsafe {
assert_eq!(DROP_RAN, true);
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait MatrixRow {}
+trait MatrixRow { fn dummy(&self) { }}
struct Mat;
extern crate "issue-16643" as i;
pub fn main() {
- i::TreeBuilder::<uint>.process_token();
+ i::TreeBuilder { h: 3u }.process_token();
}
extern crate "issue-17662" as i;
-struct Bar<'a>;
+use std::marker;
+
+struct Bar<'a> { m: marker::PhantomData<&'a ()> }
impl<'a> i::Foo<'a, uint> for Bar<'a> {
fn foo(&self) -> uint { 5u }
}
pub fn main() {
- assert_eq!(i::foo(&Bar), 5);
+ assert_eq!(i::foo(&Bar { m: marker::PhantomData }), 5);
}
trait Person {
type string;
+ fn dummy(&self) { }
}
-struct Someone<P: Person>;
+struct Someone<P: Person>(std::marker::PhantomData<P>);
fn main() {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait Aaa {}
+trait Aaa { fn dummy(&self) { } }
impl<'a> Aaa for &'a mut (Aaa + 'a) {}
#![feature(unboxed_closures)]
+use std::marker::PhantomData;
+
fn main() {
- struct Symbol<'a, F: Fn(Vec<&'a str>) -> &'a str> { function: F }
+ struct Symbol<'a, F: Fn(Vec<&'a str>) -> &'a str> { function: F, marker: PhantomData<&'a ()> }
let f = |x: Vec<&str>| -> &str "foobar";
- let sym = Symbol { function: f };
+ let sym = Symbol { function: f, marker: PhantomData };
(sym.function)(vec![]);
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-struct Foo<T> where T: Copy;
+// Test that we can parse where clauses on various forms of tuple
+// structs.
+
struct Bar<T>(T) where T: Copy;
struct Bleh<T, U>(T, U) where T: Copy, U: Sized;
struct Baz<T> where T: Copy {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-struct Cursor<'a>;
+struct Cursor<'a>(::std::marker::PhantomData<&'a ()>);
trait CursorNavigator {
fn init_cursor<'a, 'b:'a>(&'a self, cursor: &mut Cursor<'b>) -> bool;
}
fn main() {
- let mut c = Cursor;
+ let mut c = Cursor(::std::marker::PhantomData);
let n = SimpleNavigator;
n.init_cursor(&mut c);
}
q.foo(k.borrow())
}
-struct MyTree<K>;
+struct MyTree<K>(K);
impl<K> MyTree<K> {
// This caused a failure in #18906
trait Foo {
type A;
+
+ fn dummy(&self) { }
}
fn bar(x: &Foo) {}
trait Trait<Input> {
type Output;
- fn method() -> bool { false }
+ fn method(&self, i: Input) -> bool { false }
}
fn main() {}
#![feature(unboxed_closures)]
+use std::marker::PhantomData;
+
#[derive(Debug)]
-struct LifetimeStruct<'a>;
+struct LifetimeStruct<'a>(PhantomData<&'a ()>);
fn main() {
takes_hrtb_closure(|lts| println!("{:?}", lts));
}
fn takes_hrtb_closure<F: for<'a>FnMut(LifetimeStruct<'a>)>(mut f: F) {
- f(LifetimeStruct);
+ f(LifetimeStruct(PhantomData));
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait Trait {}
+trait Trait { fn dummy(&self) { } }
#[derive(Debug)]
struct Foo<T: Trait> {
// except according to those terms.
trait T {
- unsafe extern "Rust" fn foo();
+ unsafe extern "Rust" fn foo(&self);
}
impl T for () {
- unsafe extern "Rust" fn foo() {}
+ unsafe extern "Rust" fn foo(&self) {}
}
fn main() {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait Base {}
+trait Base {
+ fn dummy(&self) { }
+}
trait AssocA {
type X: Base;
+ fn dummy(&self) { }
}
trait AssocB {
type Y: Base;
+ fn dummy(&self) { }
}
impl<T: AssocA> AssocB for T {
type Y = <T as AssocA>::X;
trait PoolManager {
type C;
+ fn dummy(&self) { }
}
struct InnerPool<M> {
trait PoolManager {
type C;
+ fn dummy(&self) { }
}
struct InnerPool<M: PoolManager> {
// whichever arm is run, and subsequently dropped at the end of the
// statement surrounding the `match`.
-trait Boo { }
+trait Boo {
+ fn dummy(&self) { }
+}
impl Boo for [i8; 1] { }
impl Boo for [i8; 2] { }
struct C;
struct D;
-trait T<A> {}
+trait T<A> { fn dummy(&self, a: A) { } }
impl<A> T<A> for () {}
impl B {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait T0 { type O; }
+trait T0 {
+ type O;
+ fn dummy(&self) { }
+}
struct S<A>(A);
impl<A> T0 for S<A> { type O = A; }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait T0 { type O; }
+trait T0 {
+ type O;
+ fn dummy(&self) { }
+}
struct S<A>(A);
impl<A> T0 for S<A> { type O = A; }
trait Iterator {
type Item;
+ fn dummy(&self) { }
}
impl<'a, T> Iterator for &'a mut (Iterator<Item=T> + 'a) {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait A<X> {}
+trait A<X> {
+ fn dummy(&self, arg: X);
+}
trait B {
type X;
type Y: A<Self::X>;
+
+ fn dummy(&self);
}
fn main () { }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait clam<A> { }
+trait clam<A> {
+ fn get(self) -> A;
+}
+
struct foo<A> {
x: A,
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait clam<A> { }
+trait clam<A> { fn get(self) -> A; }
trait foo<A> {
fn bar<B,C:clam<A>>(&self, c: C) -> B;
}
// Testing that the B's are resolved
-trait clam<A> { }
+trait clam<A> { fn get(self) -> A; }
struct foo(int);
// than the traits require.
trait A {
- fn b<C:Sync,D>(x: C) -> C;
+ fn b<C:Sync,D>(&self, x: C) -> C;
}
struct E {
}
impl A for E {
- fn b<F,G>(_x: F) -> F { panic!() }
+ fn b<F,G>(&self, _x: F) -> F { panic!() }
//~^ ERROR in method `b`, type parameter 0 has 1 bound, but
}
#![allow(unknown_features)]
#![feature(box_syntax)]
-trait hax { }
+trait hax {
+ fn dummy(&self) { }
+}
impl<A> hax for A { }
fn perform_hax<T: 'static>(x: Box<T>) -> Box<hax+'static> {
#![allow(unknown_features)]
#![feature(box_syntax)]
-trait hax { }
+trait hax {
+ fn dummy(&self) { }
+}
impl<A> hax for A { }
fn perform_hax<T: 'static>(x: Box<T>) -> Box<hax+'static> {
// except according to those terms.
pub fn main() {
- let _id: &Mat2<f64> = &Matrix::identity();
+ let _id: &Mat2<f64> = &Matrix::identity(1.0);
}
-pub trait Index<Index,Result> { }
+pub trait Index<Index,Result> { fn get(&self, Index) -> Result { panic!() } }
pub trait Dimensional<T>: Index<uint, T> { }
-pub struct Mat2<T> { x: () }
-pub struct Vec2<T> { x: () }
+pub struct Mat2<T> { x: T }
+pub struct Vec2<T> { x: T }
impl<T> Dimensional<Vec2<T>> for Mat2<T> { }
impl<T> Index<uint, Vec2<T>> for Mat2<T> { }
impl<T> Index<uint, T> for Vec2<T> { }
pub trait Matrix<T,V>: Dimensional<V> {
- fn identity() -> Self;
+ fn identity(t:T) -> Self;
}
impl<T> Matrix<T, Vec2<T>> for Mat2<T> {
- fn identity() -> Mat2<T> { Mat2{ x: () } }
+ fn identity(t:T) -> Mat2<T> { Mat2{ x: t } }
}
#![feature(box_syntax)]
pub trait EventLoop {
+ fn dummy(&self) { }
}
pub struct UvEventLoop {
// minimal
-pub trait MyTrait<T> { }
+pub trait MyTrait<T> {
+ fn dummy(&self, t: T) -> T { panic!() }
+}
pub struct MyContainer<'a, T> {
foos: Vec<&'a (MyTrait<T>+'a)> ,
trait Graph<Node, Edge> {
fn f(&self, Edge);
+ fn g(&self, Node);
}
fn f(&self, _e: E) {
panic!();
}
+ fn g(&self, _e: int) {
+ panic!();
+ }
}
pub fn main() {
A(Box<Foo+'static>)
}
-pub trait Foo {}
+pub trait Foo {
+ fn dummy(&self) { }
+}
pub struct Struct;
trait Foo {
fn new() -> bool { false }
+ fn dummy(&self) { }
}
trait Bar {
pub fn main() {}
-trait A {}
+trait A {
+ fn dummy(&self) { }
+}
+
impl<T: 'static> A for T {}
fn owned2<T: 'static>(a: Box<T>) { a as Box<A>; }
// with different mutability in macro in two methods
#![allow(unused_variable)] // unused foobar_immut + foobar_mut
-trait FooBar {}
+trait FooBar {
+ fn dummy(&self) { }
+}
struct Bar(i32);
struct Foo { bar: Bar }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait A {}
+trait A {
+ fn dummy(&self) { }
+}
struct B;
impl A for B {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait A {}
+trait A {
+ fn dummy(&self) { }
+}
struct B;
impl A for B {}
A(T),
}
- pub trait X {}
+ pub trait X {
+ fn dummy(&self) { }
+ }
impl X for int {}
pub struct Z<'a>(Enum<&'a (X+'a)>);
}
mod b {
- trait X {}
+ trait X {
+ fn dummy(&self) { }
+ }
impl X for int {}
struct Y<'a>{
x:Option<&'a (X+'a)>,
}
trait A {
- fn foo() {
+ fn foo(&self) {
unsafe {
rust_get_test_int();
}
#![allow(dead_code)]
-struct Cursor<'a>;
+use std::marker;
+
+struct Cursor<'a> {
+ m: marker::PhantomData<&'a ()>
+}
trait CursorNavigator {
fn init_cursor<'a, 'b:'a>(&'a self, cursor: &mut Cursor<'b>) -> bool;
}
fn main() {
- let mut c = Cursor;
+ let mut c = Cursor { m: marker::PhantomData };
let n = SimpleNavigator;
n.init_cursor(&mut c);
}
// Note: this must be generic for the problem to show up
trait Foo<A> {
- fn foo(&self);
+ fn foo(&self, a: A);
}
impl Foo<u8> for [u8] {
- fn foo(&self) {}
+ fn foo(&self, a: u8) {}
}
impl<'a, A, T> Foo<A> for &'a T where T: Foo<A> {
- fn foo(&self) {
- Foo::foo(*self)
+ fn foo(&self, a: A) {
+ Foo::foo(*self, a)
}
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+use std::marker::MarkerTrait;
-trait Serializer {
+trait Serializer : MarkerTrait {
}
trait Serializable {
use std::ops::Deref;
struct DerefWithHelper<H, T> {
- helper: H
+ helper: H,
+ value: T
}
trait Helper<T> {
}
pub fn main() {
- let x: DerefWithHelper<Option<Foo>, Foo> = DerefWithHelper { helper: Some(Foo {x: 5}) };
+ let x: DerefWithHelper<Option<Foo>, Foo> =
+ DerefWithHelper { helper: Some(Foo {x: 5}), value: Foo { x: 2 } };
assert!(x.foo() == 5);
}
#![feature(unboxed_closures)]
+use std::marker::PhantomData;
use std::ops::Fn;
use std::ops::Add;
-struct G<A>;
+struct G<A>(PhantomData<A>);
impl<'a, A: Add<i32, Output=i32>> Fn<(A,)> for G<A> {
type Output = i32;
fn main() {
// ICE trigger
- G(1_i32);
+ (G(PhantomData))(1_i32);
}
#![allow(dead_code)]
-trait A<T> {}
-trait B<T, U> {}
-trait C<'a, U> {}
+trait A<T> { fn get(self) -> T; }
+trait B<T, U> { fn get(self) -> (T,U); }
+trait C<'a, U> { fn get(self) -> &'a U; }
mod foo {
- pub trait D<'a, T> {}
+ pub trait D<'a, T> { fn get(self) -> &'a T; }
}
fn foo1<T>(_: &(A<T> + Send)) {}
// public type, private value
pub mod foo1 {
pub trait Bar {
+ fn dummy(&self) { }
}
pub struct Baz;
// private type, public value
pub mod foo2 {
trait Bar {
+ fn dummy(&self) { }
}
pub struct Baz;
// public type, public value
pub mod foo3 {
pub trait Bar {
+ fn dummy(&self) { }
}
pub struct Baz;
// Test that the compiler considers the 'static bound declared in the
// trait. Issue #20890.
-trait Foo { type Value: 'static; }
+trait Foo {
+ type Value: 'static;
+ fn dummy(&self) { }
+}
fn require_static<T: 'static>() {}
#![feature(issue_5723_bootstrap)]
-trait Foo { }
+trait Foo {
+ fn dummy(&self) { }
+}
fn foo<'a, 'b, 'c:'a+'b, 'd>() {
}
#![feature(issue_5723_bootstrap)]
-
-trait Foo { }
+trait Foo {
+ fn dummy(&self) { }
+}
fn foo<'a>(x: Box<Foo + 'a>) {
}
// lifetime parameters must be early bound in the type of the
// associated item.
+use std::marker;
+
pub enum Value<'v> {
A(&'v str),
B,
fn read(&mut self) -> Value<'v>;
}
-pub trait Decodable<'v, D: Decoder<'v>> {
+pub trait Decodable<'v, D: Decoder<'v>>
+ : marker::PhantomFn<(), &'v int>
+{
fn decode(d: &mut D) -> Self;
}
x.f.short()
}
-trait MakerTrait<'o> {
+trait MakerTrait {
fn mk() -> Self;
}
-fn make_val<'p, T:MakerTrait<'p>>() -> T {
+fn make_val<T:MakerTrait>() -> T {
MakerTrait::mk()
}
}
}
-impl<'t> MakerTrait<'t> for Box<Trait<'t>+'static> {
+impl<'t> MakerTrait for Box<Trait<'t>+'static> {
fn mk() -> Box<Trait<'t>+'static> { box() (4,5) as Box<Trait> }
}
+++ /dev/null
-// Copyright 2012 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.
-
-// Test that a type whose lifetime parameters is never used is
-// inferred to be bivariant.
-
-use std::marker;
-
-struct Bivariant<'a>;
-
-fn use1<'short,'long>(c: Bivariant<'short>,
- _where:Option<&'short &'long ()>) {
- let _: Bivariant<'long> = c;
-}
-
-fn use2<'short,'long>(c: Bivariant<'long>,
- _where:Option<&'short &'long ()>) {
- let _: Bivariant<'short> = c;
-}
-
-pub fn main() {}
#![feature(unsafe_destructor)]
-pub struct Foo<T>;
+use std::marker;
+
+pub struct Foo<T>(marker::PhantomData<T>);
impl<T> Iterator for Foo<T> {
type Item = T;
// should not upset the variance inference for actual occurrences of
// that lifetime in type expressions.
-pub trait HasLife<'a> { }
+pub trait HasLife<'a> {
+ fn dummy(&'a self) { } // just to induce a variance on 'a
+}
trait UseLife01 {
fn refs<'a, H: HasLife<'a>>(&'a self) -> H;
}
-pub trait HasType<T> { }
+pub trait HasType<T>
+{
+ fn dummy(&self, t: T) -> T { panic!() }
+}
+
trait UseLife03<T> {
fn refs<'a, H: HasType<&'a T>>(&'a self) -> H;
trait Bar<X> {
fn bar(x: Self, y: &Self, z: Box<Self>) -> Self;
+ fn dummy(&self, x: X) { }
}
impl Bar<int> for Box<Baz<int>> {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-
-
-enum opt<T> { none, }
+enum opt<T> { none, some(T) }
pub fn main() {
let x = opt::none::<int>;
- match x { opt::none::<int> => { println!("hello world"); } }
+ match x {
+ opt::none::<int> => { println!("hello world"); }
+ opt::some(_) => { }
+ }
}
#![feature(optin_builtin_traits)]
-use std::marker::Send;
+use std::marker::{MarkerTrait, Send};
struct TestType;
impl TestType {}
-trait TestTrait {}
+trait TestTrait : MarkerTrait {}
impl !Send for TestType {}
-struct TestType2<T>;
+struct TestType2<T>(T);
impl<T> TestType2<T> {}
fn f<T,>(_: T,) {}
-struct Foo<T,>;
+struct Foo<T,>(T);
struct Bar;
let [_, _, .., _,] = [1, 1, 1, 1,];
let [_, _, _.., _,] = [1, 1, 1, 1,];
- let x: Foo<int,> = Foo::<int,>;
+ let x: Foo<int,> = Foo::<int,>(1);
Bar::f(0,);
Bar.g(0,);
// except according to those terms.
-trait Foo {
+trait Foo : ::std::marker::MarkerTrait {
}
fn b(_x: Box<Foo+Send>) {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait U {}
-trait T<X: U> {}
+trait U : ::std::marker::MarkerTrait {}
+trait T<X: U> { fn get(self) -> X; }
-trait S2<Y: U> {
+trait S2<Y: U> : ::std::marker::MarkerTrait {
fn m(x: Box<T<Y>+'static>) {}
}
trait I { fn i(&self) -> Self; }
-trait A<T:I> {
+trait A<T:I> : ::std::marker::MarkerTrait {
fn id(x:T) -> T { x.i() }
}
-trait J<T> { fn j(&self) -> Self; }
+trait J<T> { fn j(&self) -> T; }
-trait B<T:J<T>> {
+trait B<T:J<T>> : ::std::marker::MarkerTrait {
fn id(x:T) -> T { x.j() }
}
-trait C {
+trait C : ::std::marker::MarkerTrait {
fn id<T:J<T>>(x:T) -> T { x.j() }
}
trait A<T> {
fn g(&self, x: uint) -> uint { x }
+ fn h(&self, x: T) { }
}
impl<T> A<T> for int { }
static mut COUNT: uint = 1;
-trait T {}
+trait T : ::std::marker::MarkerTrait {
+}
impl<'a> T+'a {
fn foo(&self) {
use std::cmp::{PartialEq, PartialOrd};
use std::num::NumCast;
-pub trait TypeExt {}
-
+pub trait TypeExt : ::std::marker::MarkerTrait { }
impl TypeExt for u8 {}
impl TypeExt for u16 {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-pub trait MyEq { }
+pub trait MyEq : ::std::marker::MarkerTrait { }
-pub trait MyNum {
+pub trait MyNum : ::std::marker::MarkerTrait {
fn from_int(int) -> Self;
}
#![allow(unknown_features)]
#![feature(box_syntax)]
+use std::marker;
+
pub trait Trait2<A> {
- fn doit(&self);
+ fn doit(&self) -> A;
}
pub struct Impl<A1, A2, A3> {
+ m1: marker::PhantomData<(A1,A2,A3)>,
/*
* With A2 we get the ICE:
* task <unnamed> failed at 'index out of bounds: the len is 1 but the index is 1',
impl<A1, A2, A3> Impl<A1, A2, A3> {
pub fn step(&self) {
- self.t.doit()
+ self.t.doit();
}
}
// test for #8601
-enum Type<T> { Constant }
+enum Type<T> { Constant(T) }
trait Trait<K,V> {
fn method(&self,Type<(K,V)>) -> int;
pub fn main() {
let a = box() () as Box<Trait<u8, u8>>;
- assert_eq!(a.method(Type::Constant), 0);
+ assert_eq!(a.method(Type::Constant((1u8, 2u8))), 0);
}
// except according to those terms.
mod base {
- pub trait HasNew<T> {
+ pub trait HasNew {
fn new() -> Self;
}
dummy: (),
}
- impl ::base::HasNew<Foo> for Foo {
+ impl ::base::HasNew for Foo {
fn new() -> Foo {
println!("Foo");
Foo { dummy: () }
dummy: (),
}
- impl ::base::HasNew<Bar> for Bar {
+ impl ::base::HasNew for Bar {
fn new() -> Bar {
println!("Bar");
Bar { dummy: () }
}
pub fn main() {
- let _f: base::Foo = base::HasNew::<base::Foo>::new();
- let _b: base::Bar = base::HasNew::<base::Bar>::new();
+ let _f: base::Foo = base::HasNew::new();
+ let _b: base::Bar = base::HasNew::new();
}
#![feature(core,unboxed_closures)]
-use std::marker::CovariantType;
+use std::marker::PhantomData;
// Test that we are able to infer a suitable kind for a "recursive"
// closure. As far as I can tell, coding up a recursive closure
struct YCombinator<F,A,R> {
func: F,
- marker: CovariantType<(A,R)>,
+ marker: PhantomData<(A,R)>,
}
impl<F,A,R> YCombinator<F,A,R> {
fn new(f: F) -> YCombinator<F,A,R> {
- YCombinator { func: f, marker: CovariantType }
+ YCombinator { func: f, marker: PhantomData }
}
}
#![allow(unknown_features)]
#![feature(box_syntax)]
-pub trait EventLoop { }
+pub trait EventLoop : ::std::marker::MarkerTrait { }
pub struct UvEventLoop {
uvio: int
// Test syntax checks for `?Sized` syntax.
-trait T1 {}
-pub trait T2 {}
-trait T3<X: T1> : T2 {}
-trait T4<X: ?Sized> {}
-trait T5<X: ?Sized, Y> {}
-trait T6<Y, X: ?Sized> {}
-trait T7<X: ?Sized, Y: ?Sized> {}
-trait T8<X: ?Sized+T2> {}
-trait T9<X: T2 + ?Sized> {}
-struct S1<X: ?Sized>;
-enum E<X: ?Sized> {}
+use std::marker::{PhantomData, PhantomFn};
+
+trait T1 : PhantomFn<Self> { }
+pub trait T2 : PhantomFn<Self> { }
+trait T3<X: T1> : T2 + PhantomFn<X> { }
+trait T4<X: ?Sized> : PhantomFn<(Self,X)> {}
+trait T5<X: ?Sized, Y> : PhantomFn<(Self,X,Y)> {}
+trait T6<Y, X: ?Sized> : PhantomFn<(Self,X,Y)> {}
+trait T7<X: ?Sized, Y: ?Sized> : PhantomFn<(Self,X,Y)> {}
+trait T8<X: ?Sized+T2> : PhantomFn<(Self,X)> {}
+trait T9<X: T2 + ?Sized> : PhantomFn<(Self,X)> {}
+struct S1<X: ?Sized>(PhantomData<X>);
+enum E<X: ?Sized> { E1(PhantomData<X>) }
impl <X: ?Sized> T1 for S1<X> {}
fn f<X: ?Sized>() {}
type TT<T: ?Sized> = T;
// Test sized-ness checking in substitution.
+use std::marker;
+
// Unbounded.
fn f1<X: ?Sized>(x: &X) {
f1::<X>(x);
}
// Bounded.
-trait T {}
+trait T { fn dummy(&self) { } }
fn f3<X: T+?Sized>(x: &X) {
f3::<X>(x);
}
}
trait T4<X> {
- fn m1(x: &T4<X>);
- fn m2(x: &T5<X>);
+ fn dummy(&self) { }
+ fn m1(x: &T4<X>, y: X);
+ fn m2(x: &T5<X>, y: X);
}
trait T5<X: ?Sized> {
+ fn dummy(&self) { }
// not an error (for now)
fn m1(x: &T4<X>);
fn m2(x: &T5<X>);
}
trait T6<X: T> {
+ fn dummy(&self) { }
fn m1(x: &T4<X>);
fn m2(x: &T5<X>);
}
trait T7<X: ?Sized+T> {
+ fn dummy(&self) { }
// not an error (for now)
fn m1(x: &T4<X>);
fn m2(x: &T5<X>);
#![feature(visible_private_types)]
-trait Foo {}
+trait Foo { fn dummy(&self) { } }
pub trait Bar : Foo {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait Bound {}
+trait Bound {
+ fn dummy(&self) { }
+}
trait Trait {
fn a<T>(&self, T) where T: Bound;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait TheTrait { }
+trait TheTrait { fn dummy(&self) { } }
impl TheTrait for &'static int { }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-trait Foo<T> {}
+trait Foo<T> { fn dummy(&self, arg: T) { } }
trait Bar<A> {
fn method<B>(&self) where A: Foo<B>;
impl Foo<S> for X {}
-impl Bar<X> for int {
+impl Bar<X> for i32 {
fn method<U>(&self) where X: Foo<U> {
}
}
// Test that we can quantify lifetimes outside a constraint (i.e., including
// the self type) in a where clause.
+use std::marker::PhantomFn;
+
static mut COUNT: u32 = 1;
-trait Bar<'a> {
+trait Bar<'a>
+ : PhantomFn<&'a ()>
+{
fn bar(&self);
}
-trait Baz<'a> {
+trait Baz<'a>
+ : PhantomFn<&'a ()>
+{
fn baz(&self);
}