--- /dev/null
+#![feature(trait_alias)]
+
+mod inner {
+ pub trait A { fn foo(&self); }
+ pub trait B { fn foo(&self); }
+
+ impl A for u8 {
+ fn foo(&self) {}
+ }
+ impl B for u8 {
+ fn foo(&self) {}
+ }
+
+ pub trait C = A + B;
+}
+
+use inner::C;
+
+fn main() {
+ let t = 1u8;
+ t.foo(); //~ ERROR E0034
+
+ inner::A::foo(&t); // ok
+}
--- /dev/null
+error[E0034]: multiple applicable items in scope
+ --> $DIR/ambiguous.rs:21:7
+ |
+LL | t.foo();
+ | ^^^ multiple `foo` found
+ |
+note: candidate #1 is defined in an impl of the trait `A` for the type `u8`
+ --> $DIR/ambiguous.rs:8:9
+ |
+LL | fn foo(&self) {}
+ | ^^^^^^^^^^^^^
+note: candidate #2 is defined in an impl of the trait `B` for the type `u8`
+ --> $DIR/ambiguous.rs:11:9
+ |
+LL | fn foo(&self) {}
+ | ^^^^^^^^^^^^^
+help: disambiguate the associated function for candidate #1
+ |
+LL | A::foo(&t);
+ | ^^^^^^^^^^
+help: disambiguate the associated function for candidate #2
+ |
+LL | B::foo(&t);
+ | ^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0034`.
--- /dev/null
+#![feature(trait_alias)]
+
+pub trait Hello {
+ fn hello(&self);
+}
+
+pub struct Hi;
+
+impl Hello for Hi {
+ fn hello(&self) {}
+}
+
+pub trait Greet = Hello;
--- /dev/null
+#![feature(trait_alias)]
+
+pub trait SendSync = Send + Sync;
--- /dev/null
+// run-pass
+
+#![feature(trait_alias)]
+
+pub trait Foo {}
+pub trait FooAlias = Foo;
+
+fn main() {}
--- /dev/null
+// run-pass
+
+#![feature(trait_alias)]
+
+use std::marker::PhantomData;
+
+trait Empty {}
+trait EmptyAlias = Empty;
+trait CloneDefault = Clone + Default;
+trait SendSyncAlias = Send + Sync;
+trait WhereSendAlias = where Self: Send;
+trait SendEqAlias<T> = Send where T: PartialEq<Self>;
+trait I32Iterator = Iterator<Item = i32>;
+
+#[allow(dead_code)]
+struct Foo<T: SendSyncAlias>(PhantomData<T>);
+#[allow(dead_code)]
+struct Bar<T>(PhantomData<T>) where T: SendSyncAlias;
+
+impl dyn EmptyAlias {}
+
+impl<T: SendSyncAlias> Empty for T {}
+
+fn a<T: CloneDefault>() -> (T, T) {
+ let one = T::default();
+ let two = one.clone();
+ (one, two)
+}
+
+fn b(x: &impl SendEqAlias<i32>) -> bool {
+ 22_i32 == *x
+}
+
+fn c<T: I32Iterator>(x: &mut T) -> Option<i32> {
+ x.next()
+}
+
+fn d<T: SendSyncAlias>() {
+ is_send_and_sync::<T>();
+}
+
+fn is_send_and_sync<T: Send + Sync>() {}
+
+fn main() {
+ let both = a::<i32>();
+ assert_eq!(both.0, 0);
+ assert_eq!(both.1, 0);
+ let both: (i32, i32) = a();
+ assert_eq!(both.0, 0);
+ assert_eq!(both.1, 0);
+
+ assert!(b(&22));
+
+ assert_eq!(c(&mut vec![22].into_iter()), Some(22));
+
+ d::<i32>();
+}
--- /dev/null
+// aux-build:send_sync.rs
+
+#![feature(trait_alias)]
+
+extern crate send_sync;
+
+use std::rc::Rc;
+use send_sync::SendSync;
+
+fn use_alias<T: SendSync>() {}
+
+fn main() {
+ use_alias::<u32>();
+ use_alias::<Rc<u32>>();
+ //~^ ERROR `Rc<u32>` cannot be sent between threads safely [E0277]
+ //~^^ ERROR `Rc<u32>` cannot be shared between threads safely [E0277]
+}
--- /dev/null
+error[E0277]: `Rc<u32>` cannot be sent between threads safely
+ --> $DIR/cross-crate.rs:14:17
+ |
+LL | fn use_alias<T: SendSync>() {}
+ | -------- required by this bound in `use_alias`
+...
+LL | use_alias::<Rc<u32>>();
+ | ^^^^^^^ `Rc<u32>` cannot be sent between threads safely
+ |
+ = help: the trait `Send` is not implemented for `Rc<u32>`
+
+error[E0277]: `Rc<u32>` cannot be shared between threads safely
+ --> $DIR/cross-crate.rs:14:17
+ |
+LL | fn use_alias<T: SendSync>() {}
+ | -------- required by this bound in `use_alias`
+...
+LL | use_alias::<Rc<u32>>();
+ | ^^^^^^^ `Rc<u32>` cannot be shared between threads safely
+ |
+ = help: the trait `Sync` is not implemented for `Rc<u32>`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+#![feature(trait_alias)]
+
+trait DefaultAlias = Default;
+
+impl DefaultAlias for () {} //~ ERROR expected trait, found trait alias
+
+fn main() {}
--- /dev/null
+error[E0404]: expected trait, found trait alias `DefaultAlias`
+ --> $DIR/impl.rs:5:6
+ |
+LL | impl DefaultAlias for () {}
+ | ^^^^^^^^^^^^ not a trait
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0404`.
--- /dev/null
+// run-pass
+// aux-build:greeter.rs
+
+#![feature(trait_alias)]
+
+extern crate greeter;
+
+// Import only the alias, not the real trait.
+use greeter::{Greet, Hi};
+
+fn main() {
+ let hi = Hi;
+ hi.hello(); // From `Hello`, via `Greet` alias.
+}
--- /dev/null
+// run-pass
+
+#![feature(trait_alias)]
+
+mod inner {
+ pub trait Foo {
+ fn foo(&self);
+ }
+
+ pub struct Qux;
+
+ impl Foo for Qux {
+ fn foo(&self) {}
+ }
+
+ pub trait Bar = Foo;
+}
+
+mod two {
+ pub trait A {
+ fn foo();
+ }
+
+ impl A for u8 {
+ fn foo() {}
+ }
+}
+
+// Import only the alias, not the `Foo` trait.
+use inner::{Bar, Qux};
+
+// Declaring an alias also brings in aliased methods.
+trait Two = two::A;
+
+fn main() {
+ let q = Qux;
+ q.foo(); // From Bar.
+
+ u8::foo(); // From A.
+}
--- /dev/null
+// check-pass
+
+#![feature(trait_alias)]
+
+trait SomeTrait {
+ fn map(&self) {}
+}
+
+impl<T> SomeTrait for Option<T> {}
+
+trait SomeAlias = SomeTrait;
+
+fn main() {
+ let x = Some(123);
+ // This should resolve to the trait impl for Option
+ Option::map(x, |z| z);
+ // This should resolve to the trait impl for SomeTrait
+ SomeTrait::map(&x);
+}
--- /dev/null
+// check-pass
+
+#![feature(trait_alias)]
+
+trait Bounded { const MAX: Self; }
+
+impl Bounded for u32 {
+ // This should correctly resolve to the associated const in the inherent impl of u32.
+ const MAX: Self = u32::MAX;
+}
+
+trait Num = Bounded + Copy;
+
+fn main() {}
--- /dev/null
+// check-pass
+
+#![feature(trait_alias)]
+
+struct Bar;
+trait Foo {}
+impl Foo for Bar {}
+
+trait Baz = Foo where Bar: Foo;
+
+fn new() -> impl Baz {
+ Bar
+}
+
+fn main() {
+ let _ = new();
+}
--- /dev/null
+// build-pass (FIXME(62277): could be check-pass?)
+
+// Test that `dyn ... + ?Sized + ...` resulting from the expansion of trait aliases is okay.
+
+#![feature(trait_alias)]
+
+trait Foo {}
+
+trait S = ?Sized;
+
+// Nest a couple of levels deep:
+trait _0 = S;
+trait _1 = _0;
+
+// Straight list expansion:
+type _T0 = dyn _1 + Foo;
+
+// In second position:
+type _T1 = dyn Foo + _1;
+
+// ... and with an auto trait:
+type _T2 = dyn Foo + Send + _1;
+
+// Twice:
+trait _2 = _1 + _1;
+
+type _T3 = dyn _2 + Foo;
+
+fn main() {}
--- /dev/null
+// The purpose of this test is to demonstrate that duplicating object safe traits
+// that are not auto traits is rejected with trait aliases even though one could
+// reasonably accept this.
+
+#![feature(trait_alias)]
+
+use std::marker::Unpin;
+
+// Some arbitrary object-safe trait:
+trait Obj {}
+
+// Nest a few levels deep:
+trait _0 = Obj;
+trait _1 = _0;
+
+type _T00 = dyn _0 + _0;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T01 = dyn _1 + _0;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T02 = dyn _1 + _1;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T03 = dyn Obj + _1;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T04 = dyn _1 + Obj;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+// Nest some more and in weird ways:
+
+trait _2 = _0 + _1;
+trait _3 = Obj;
+trait _4 = _3;
+
+type _T10 = dyn _2 + _3;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T11 = dyn _3 + _2;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T12 = dyn Obj + _2;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T13 = dyn _2 + Obj;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T14 = dyn _1 + _3;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T15 = dyn _3 + _1;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T16 = dyn _1 + _4;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T17 = dyn _4 + _1;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+// Include auto traits:
+
+trait _5 = Obj + Send;
+
+type _T20 = dyn _5 + _5;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T21 = dyn Obj + _5;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T22 = dyn _5 + Obj;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T23 = dyn _5 + Send + Sync + Obj;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+// Also nest:
+
+trait _6 = _5 + _5; // ==> Obj + Send + Obj + Send
+
+type _T30 = dyn _6;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T31 = dyn _6 + Send;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T32 = dyn Send + _6;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+// Nest some more:
+
+trait _7 = _5 + Sync;
+trait _8 = Unpin + _7;
+
+type _T40 = dyn _8 + Obj;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T41 = dyn Obj + _8;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T42 = dyn _8 + _4;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T43 = dyn _4 + _8;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T44 = dyn _4 + Send + Sync + _8;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+// Take higher ranked types into account.
+
+// Note that `'a` and `'b` are intentionally different to make sure we consider
+// them semantically the same.
+trait ObjL<'l> {}
+trait _9 = for<'a> ObjL<'a>;
+trait _10 = for<'b> ObjL<'b>;
+type _T50 = dyn _9 + _10;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+trait ObjT<T> {}
+trait _11 = ObjT<for<'a> fn(&'a u8)>;
+trait _12 = ObjT<for<'b> fn(&'b u8)>;
+type _T60 = dyn _11 + _12;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+fn main() {}
--- /dev/null
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:16:22
+ |
+LL | trait _0 = Obj;
+ | ---
+ | |
+ | additional non-auto trait
+ | first non-auto trait
+...
+LL | type _T00 = dyn _0 + _0;
+ | -- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:19:22
+ |
+LL | trait _0 = Obj;
+ | ---
+ | |
+ | additional non-auto trait
+ | first non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (first use)
+...
+LL | type _T01 = dyn _1 + _0;
+ | -- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:22:22
+ |
+LL | trait _0 = Obj;
+ | ---
+ | |
+ | additional non-auto trait
+ | first non-auto trait
+LL | trait _1 = _0;
+ | --
+ | |
+ | referenced here (additional use)
+ | referenced here (first use)
+...
+LL | type _T02 = dyn _1 + _1;
+ | -- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:25:23
+ |
+LL | trait _0 = Obj;
+ | --- additional non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (additional use)
+...
+LL | type _T03 = dyn Obj + _1;
+ | --- ^^ trait alias used in trait object type (additional use)
+ | |
+ | first non-auto trait
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:28:22
+ |
+LL | trait _0 = Obj;
+ | --- first non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (first use)
+...
+LL | type _T04 = dyn _1 + Obj;
+ | -- ^^^ additional non-auto trait
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:37:17
+ |
+LL | trait _0 = Obj;
+ | ---
+ | |
+ | additional non-auto trait
+ | first non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (additional use)
+...
+LL | trait _2 = _0 + _1;
+ | -- -- referenced here (additional use)
+ | |
+ | referenced here (first use)
+...
+LL | type _T10 = dyn _2 + _3;
+ | ^^
+ | |
+ | trait alias used in trait object type (additional use)
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:40:22
+ |
+LL | trait _0 = Obj;
+ | --- additional non-auto trait
+...
+LL | trait _2 = _0 + _1;
+ | -- referenced here (additional use)
+LL | trait _3 = Obj;
+ | --- first non-auto trait
+...
+LL | type _T11 = dyn _3 + _2;
+ | -- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:43:23
+ |
+LL | trait _0 = Obj;
+ | --- additional non-auto trait
+...
+LL | trait _2 = _0 + _1;
+ | -- referenced here (additional use)
+...
+LL | type _T12 = dyn Obj + _2;
+ | --- ^^ trait alias used in trait object type (additional use)
+ | |
+ | first non-auto trait
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:46:17
+ |
+LL | trait _0 = Obj;
+ | ---
+ | |
+ | additional non-auto trait
+ | first non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (additional use)
+...
+LL | trait _2 = _0 + _1;
+ | -- -- referenced here (additional use)
+ | |
+ | referenced here (first use)
+...
+LL | type _T13 = dyn _2 + Obj;
+ | ^^
+ | |
+ | trait alias used in trait object type (additional use)
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:49:22
+ |
+LL | trait _0 = Obj;
+ | --- first non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (first use)
+...
+LL | trait _3 = Obj;
+ | --- additional non-auto trait
+...
+LL | type _T14 = dyn _1 + _3;
+ | -- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:52:22
+ |
+LL | trait _0 = Obj;
+ | --- additional non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (additional use)
+...
+LL | trait _3 = Obj;
+ | --- first non-auto trait
+...
+LL | type _T15 = dyn _3 + _1;
+ | -- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:55:22
+ |
+LL | trait _0 = Obj;
+ | --- first non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (first use)
+...
+LL | trait _3 = Obj;
+ | --- additional non-auto trait
+LL | trait _4 = _3;
+ | -- referenced here (additional use)
+...
+LL | type _T16 = dyn _1 + _4;
+ | -- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:58:22
+ |
+LL | trait _0 = Obj;
+ | --- additional non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (additional use)
+...
+LL | trait _3 = Obj;
+ | --- first non-auto trait
+LL | trait _4 = _3;
+ | -- referenced here (first use)
+...
+LL | type _T17 = dyn _4 + _1;
+ | -- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:65:22
+ |
+LL | trait _5 = Obj + Send;
+ | ---
+ | |
+ | additional non-auto trait
+ | first non-auto trait
+LL |
+LL | type _T20 = dyn _5 + _5;
+ | -- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:68:23
+ |
+LL | trait _5 = Obj + Send;
+ | --- additional non-auto trait
+...
+LL | type _T21 = dyn Obj + _5;
+ | --- ^^ trait alias used in trait object type (additional use)
+ | |
+ | first non-auto trait
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:71:22
+ |
+LL | trait _5 = Obj + Send;
+ | --- first non-auto trait
+...
+LL | type _T22 = dyn _5 + Obj;
+ | -- ^^^ additional non-auto trait
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:74:36
+ |
+LL | trait _5 = Obj + Send;
+ | --- first non-auto trait
+...
+LL | type _T23 = dyn _5 + Send + Sync + Obj;
+ | -- ^^^ additional non-auto trait
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:81:17
+ |
+LL | trait _5 = Obj + Send;
+ | ---
+ | |
+ | additional non-auto trait
+ | first non-auto trait
+...
+LL | trait _6 = _5 + _5; // ==> Obj + Send + Obj + Send
+ | -- -- referenced here (additional use)
+ | |
+ | referenced here (first use)
+LL |
+LL | type _T30 = dyn _6;
+ | ^^
+ | |
+ | trait alias used in trait object type (additional use)
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:84:17
+ |
+LL | trait _5 = Obj + Send;
+ | ---
+ | |
+ | additional non-auto trait
+ | first non-auto trait
+...
+LL | trait _6 = _5 + _5; // ==> Obj + Send + Obj + Send
+ | -- -- referenced here (additional use)
+ | |
+ | referenced here (first use)
+...
+LL | type _T31 = dyn _6 + Send;
+ | ^^
+ | |
+ | trait alias used in trait object type (additional use)
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:87:24
+ |
+LL | trait _5 = Obj + Send;
+ | ---
+ | |
+ | additional non-auto trait
+ | first non-auto trait
+...
+LL | trait _6 = _5 + _5; // ==> Obj + Send + Obj + Send
+ | -- -- referenced here (additional use)
+ | |
+ | referenced here (first use)
+...
+LL | type _T32 = dyn Send + _6;
+ | ^^
+ | |
+ | trait alias used in trait object type (additional use)
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:95:22
+ |
+LL | trait _5 = Obj + Send;
+ | --- first non-auto trait
+...
+LL | trait _7 = _5 + Sync;
+ | -- referenced here (first use)
+LL | trait _8 = Unpin + _7;
+ | -- referenced here (first use)
+LL |
+LL | type _T40 = dyn _8 + Obj;
+ | -- ^^^ additional non-auto trait
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:98:23
+ |
+LL | trait _5 = Obj + Send;
+ | --- additional non-auto trait
+...
+LL | trait _7 = _5 + Sync;
+ | -- referenced here (additional use)
+LL | trait _8 = Unpin + _7;
+ | -- referenced here (additional use)
+...
+LL | type _T41 = dyn Obj + _8;
+ | --- ^^ trait alias used in trait object type (additional use)
+ | |
+ | first non-auto trait
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:101:22
+ |
+LL | trait _3 = Obj;
+ | --- additional non-auto trait
+LL | trait _4 = _3;
+ | -- referenced here (additional use)
+...
+LL | trait _5 = Obj + Send;
+ | --- first non-auto trait
+...
+LL | trait _7 = _5 + Sync;
+ | -- referenced here (first use)
+LL | trait _8 = Unpin + _7;
+ | -- referenced here (first use)
+...
+LL | type _T42 = dyn _8 + _4;
+ | -- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:104:22
+ |
+LL | trait _3 = Obj;
+ | --- first non-auto trait
+LL | trait _4 = _3;
+ | -- referenced here (first use)
+...
+LL | trait _5 = Obj + Send;
+ | --- additional non-auto trait
+...
+LL | trait _7 = _5 + Sync;
+ | -- referenced here (additional use)
+LL | trait _8 = Unpin + _7;
+ | -- referenced here (additional use)
+...
+LL | type _T43 = dyn _4 + _8;
+ | -- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:107:36
+ |
+LL | trait _3 = Obj;
+ | --- first non-auto trait
+LL | trait _4 = _3;
+ | -- referenced here (first use)
+...
+LL | trait _5 = Obj + Send;
+ | --- additional non-auto trait
+...
+LL | trait _7 = _5 + Sync;
+ | -- referenced here (additional use)
+LL | trait _8 = Unpin + _7;
+ | -- referenced here (additional use)
+...
+LL | type _T44 = dyn _4 + Send + Sync + _8;
+ | -- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:117:22
+ |
+LL | trait _9 = for<'a> ObjL<'a>;
+ | ---------------- first non-auto trait
+LL | trait _10 = for<'b> ObjL<'b>;
+ | ---------------- additional non-auto trait
+LL | type _T50 = dyn _9 + _10;
+ | -- ^^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: for<'a> ObjL<'a> + for<'b> ObjL<'b> {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:123:23
+ |
+LL | trait _11 = ObjT<for<'a> fn(&'a u8)>;
+ | ------------------------ first non-auto trait
+LL | trait _12 = ObjT<for<'b> fn(&'b u8)>;
+ | ------------------------ additional non-auto trait
+LL | type _T60 = dyn _11 + _12;
+ | --- ^^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjT<for<'a> fn(&'a u8)> + ObjT<for<'b> fn(&'b u8)> {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error: aborting due to 27 previous errors
+
+For more information about this error, try `rustc --explain E0225`.
--- /dev/null
+// The purpose of this test is to demonstrate that trait alias expansion
+// preserves the rule that `dyn Trait` may only reference one non-auto trait.
+
+#![feature(trait_alias)]
+
+use std::marker::Unpin;
+
+// Some arbitrary object-safe traits:
+trait ObjA {}
+trait ObjB {}
+
+// Nest a few levels deep:
+trait _0 = ObjA;
+trait _1 = _0;
+
+type _T00 = dyn _0 + ObjB;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T01 = dyn ObjB + _0;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T02 = dyn ObjB + _1;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T03 = dyn _1 + ObjB;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+// Nest some more and in weird ways:
+
+trait _2 = ObjB;
+trait _3 = _2;
+trait _4 = _3;
+
+type _T10 = dyn _2 + _3;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T11 = dyn _3 + _2;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T12 = dyn _2 + _4;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T13 = dyn _4 + _2;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+// Include auto traits:
+
+trait _5 = Sync + ObjB + Send;
+
+type _T20 = dyn _5 + _1;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T21 = dyn _1 + _5;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T22 = dyn _5 + ObjA;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T23 = dyn ObjA + _5;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T24 = dyn Send + _5 + _1 + Sync;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T25 = dyn _1 + Sync + _5 + Send;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T26 = dyn Sync + Send + _5 + ObjA;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T27 = dyn Send + Sync + ObjA + _5;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+// Also nest:
+
+trait _6 = _1 + _5;
+trait _7 = _6;
+trait _8 = _7;
+
+type _T30 = dyn _6;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T31 = dyn _6 + Send;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T32 = dyn Send + _6;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T33 = dyn _8;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T34 = dyn _8 + Send;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T35 = dyn Send + _8;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+// Nest some more:
+
+trait _9 = _5 + Sync;
+trait _10 = Unpin + _9;
+
+type _T40 = dyn _10 + ObjA;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T41 = dyn ObjA + _10;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T42 = dyn _10 + _1;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T43 = dyn Send + _10 + Sync + ObjA;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T44 = dyn ObjA + _10 + Send + Sync;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _T45 = dyn Sync + Send + _10 + _1;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+fn main() {}
--- /dev/null
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:16:22
+ |
+LL | trait _0 = ObjA;
+ | ---- first non-auto trait
+...
+LL | type _T00 = dyn _0 + ObjB;
+ | -- ^^^^ additional non-auto trait
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:19:24
+ |
+LL | trait _0 = ObjA;
+ | ---- additional non-auto trait
+...
+LL | type _T01 = dyn ObjB + _0;
+ | ---- ^^ trait alias used in trait object type (additional use)
+ | |
+ | first non-auto trait
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjA {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:22:24
+ |
+LL | trait _0 = ObjA;
+ | ---- additional non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (additional use)
+...
+LL | type _T02 = dyn ObjB + _1;
+ | ---- ^^ trait alias used in trait object type (additional use)
+ | |
+ | first non-auto trait
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjA {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:25:22
+ |
+LL | trait _0 = ObjA;
+ | ---- first non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (first use)
+...
+LL | type _T03 = dyn _1 + ObjB;
+ | -- ^^^^ additional non-auto trait
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:34:22
+ |
+LL | trait _2 = ObjB;
+ | ----
+ | |
+ | additional non-auto trait
+ | first non-auto trait
+LL | trait _3 = _2;
+ | -- referenced here (additional use)
+...
+LL | type _T10 = dyn _2 + _3;
+ | -- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjB {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:37:22
+ |
+LL | trait _2 = ObjB;
+ | ----
+ | |
+ | additional non-auto trait
+ | first non-auto trait
+LL | trait _3 = _2;
+ | -- referenced here (first use)
+...
+LL | type _T11 = dyn _3 + _2;
+ | -- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjB {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:40:22
+ |
+LL | trait _2 = ObjB;
+ | ----
+ | |
+ | additional non-auto trait
+ | first non-auto trait
+LL | trait _3 = _2;
+ | -- referenced here (additional use)
+LL | trait _4 = _3;
+ | -- referenced here (additional use)
+...
+LL | type _T12 = dyn _2 + _4;
+ | -- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjB {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:43:22
+ |
+LL | trait _2 = ObjB;
+ | ----
+ | |
+ | additional non-auto trait
+ | first non-auto trait
+LL | trait _3 = _2;
+ | -- referenced here (first use)
+LL | trait _4 = _3;
+ | -- referenced here (first use)
+...
+LL | type _T13 = dyn _4 + _2;
+ | -- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjB {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:50:22
+ |
+LL | trait _0 = ObjA;
+ | ---- additional non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (additional use)
+...
+LL | trait _5 = Sync + ObjB + Send;
+ | ---- first non-auto trait
+LL |
+LL | type _T20 = dyn _5 + _1;
+ | -- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjA {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:53:22
+ |
+LL | trait _0 = ObjA;
+ | ---- first non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (first use)
+...
+LL | trait _5 = Sync + ObjB + Send;
+ | ---- additional non-auto trait
+...
+LL | type _T21 = dyn _1 + _5;
+ | -- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:56:22
+ |
+LL | trait _5 = Sync + ObjB + Send;
+ | ---- first non-auto trait
+...
+LL | type _T22 = dyn _5 + ObjA;
+ | -- ^^^^ additional non-auto trait
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjA {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:59:24
+ |
+LL | trait _5 = Sync + ObjB + Send;
+ | ---- additional non-auto trait
+...
+LL | type _T23 = dyn ObjA + _5;
+ | ---- ^^ trait alias used in trait object type (additional use)
+ | |
+ | first non-auto trait
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:62:29
+ |
+LL | trait _0 = ObjA;
+ | ---- additional non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (additional use)
+...
+LL | trait _5 = Sync + ObjB + Send;
+ | ---- first non-auto trait
+...
+LL | type _T24 = dyn Send + _5 + _1 + Sync;
+ | -- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjA {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:65:29
+ |
+LL | trait _0 = ObjA;
+ | ---- first non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (first use)
+...
+LL | trait _5 = Sync + ObjB + Send;
+ | ---- additional non-auto trait
+...
+LL | type _T25 = dyn _1 + Sync + _5 + Send;
+ | -- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:68:36
+ |
+LL | trait _5 = Sync + ObjB + Send;
+ | ---- first non-auto trait
+...
+LL | type _T26 = dyn Sync + Send + _5 + ObjA;
+ | -- ^^^^ additional non-auto trait
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjA {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:71:38
+ |
+LL | trait _5 = Sync + ObjB + Send;
+ | ---- additional non-auto trait
+...
+LL | type _T27 = dyn Send + Sync + ObjA + _5;
+ | ---- ^^ trait alias used in trait object type (additional use)
+ | |
+ | first non-auto trait
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:80:17
+ |
+LL | trait _0 = ObjA;
+ | ---- first non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (first use)
+...
+LL | trait _5 = Sync + ObjB + Send;
+ | ---- additional non-auto trait
+...
+LL | trait _6 = _1 + _5;
+ | -- -- referenced here (additional use)
+ | |
+ | referenced here (first use)
+...
+LL | type _T30 = dyn _6;
+ | ^^
+ | |
+ | trait alias used in trait object type (additional use)
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:83:17
+ |
+LL | trait _0 = ObjA;
+ | ---- first non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (first use)
+...
+LL | trait _5 = Sync + ObjB + Send;
+ | ---- additional non-auto trait
+...
+LL | trait _6 = _1 + _5;
+ | -- -- referenced here (additional use)
+ | |
+ | referenced here (first use)
+...
+LL | type _T31 = dyn _6 + Send;
+ | ^^
+ | |
+ | trait alias used in trait object type (additional use)
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:86:24
+ |
+LL | trait _0 = ObjA;
+ | ---- first non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (first use)
+...
+LL | trait _5 = Sync + ObjB + Send;
+ | ---- additional non-auto trait
+...
+LL | trait _6 = _1 + _5;
+ | -- -- referenced here (additional use)
+ | |
+ | referenced here (first use)
+...
+LL | type _T32 = dyn Send + _6;
+ | ^^
+ | |
+ | trait alias used in trait object type (additional use)
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:89:17
+ |
+LL | trait _0 = ObjA;
+ | ---- first non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (first use)
+...
+LL | trait _5 = Sync + ObjB + Send;
+ | ---- additional non-auto trait
+...
+LL | trait _6 = _1 + _5;
+ | -- -- referenced here (additional use)
+ | |
+ | referenced here (first use)
+LL | trait _7 = _6;
+ | --
+ | |
+ | referenced here (additional use)
+ | referenced here (first use)
+LL | trait _8 = _7;
+ | --
+ | |
+ | referenced here (additional use)
+ | referenced here (first use)
+...
+LL | type _T33 = dyn _8;
+ | ^^
+ | |
+ | trait alias used in trait object type (additional use)
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:92:17
+ |
+LL | trait _0 = ObjA;
+ | ---- first non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (first use)
+...
+LL | trait _5 = Sync + ObjB + Send;
+ | ---- additional non-auto trait
+...
+LL | trait _6 = _1 + _5;
+ | -- -- referenced here (additional use)
+ | |
+ | referenced here (first use)
+LL | trait _7 = _6;
+ | --
+ | |
+ | referenced here (additional use)
+ | referenced here (first use)
+LL | trait _8 = _7;
+ | --
+ | |
+ | referenced here (additional use)
+ | referenced here (first use)
+...
+LL | type _T34 = dyn _8 + Send;
+ | ^^
+ | |
+ | trait alias used in trait object type (additional use)
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:95:24
+ |
+LL | trait _0 = ObjA;
+ | ---- first non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (first use)
+...
+LL | trait _5 = Sync + ObjB + Send;
+ | ---- additional non-auto trait
+...
+LL | trait _6 = _1 + _5;
+ | -- -- referenced here (additional use)
+ | |
+ | referenced here (first use)
+LL | trait _7 = _6;
+ | --
+ | |
+ | referenced here (additional use)
+ | referenced here (first use)
+LL | trait _8 = _7;
+ | --
+ | |
+ | referenced here (additional use)
+ | referenced here (first use)
+...
+LL | type _T35 = dyn Send + _8;
+ | ^^
+ | |
+ | trait alias used in trait object type (additional use)
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:103:23
+ |
+LL | trait _5 = Sync + ObjB + Send;
+ | ---- first non-auto trait
+...
+LL | trait _9 = _5 + Sync;
+ | -- referenced here (first use)
+LL | trait _10 = Unpin + _9;
+ | -- referenced here (first use)
+LL |
+LL | type _T40 = dyn _10 + ObjA;
+ | --- ^^^^ additional non-auto trait
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjA {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:106:24
+ |
+LL | trait _5 = Sync + ObjB + Send;
+ | ---- additional non-auto trait
+...
+LL | trait _9 = _5 + Sync;
+ | -- referenced here (additional use)
+LL | trait _10 = Unpin + _9;
+ | -- referenced here (additional use)
+...
+LL | type _T41 = dyn ObjA + _10;
+ | ---- ^^^ trait alias used in trait object type (additional use)
+ | |
+ | first non-auto trait
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:109:23
+ |
+LL | trait _0 = ObjA;
+ | ---- additional non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (additional use)
+...
+LL | trait _5 = Sync + ObjB + Send;
+ | ---- first non-auto trait
+...
+LL | trait _9 = _5 + Sync;
+ | -- referenced here (first use)
+LL | trait _10 = Unpin + _9;
+ | -- referenced here (first use)
+...
+LL | type _T42 = dyn _10 + _1;
+ | --- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjA {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:112:37
+ |
+LL | trait _5 = Sync + ObjB + Send;
+ | ---- first non-auto trait
+...
+LL | trait _9 = _5 + Sync;
+ | -- referenced here (first use)
+LL | trait _10 = Unpin + _9;
+ | -- referenced here (first use)
+...
+LL | type _T43 = dyn Send + _10 + Sync + ObjA;
+ | --- ^^^^ additional non-auto trait
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjA {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:115:24
+ |
+LL | trait _5 = Sync + ObjB + Send;
+ | ---- additional non-auto trait
+...
+LL | trait _9 = _5 + Sync;
+ | -- referenced here (additional use)
+LL | trait _10 = Unpin + _9;
+ | -- referenced here (additional use)
+...
+LL | type _T44 = dyn ObjA + _10 + Send + Sync;
+ | ---- ^^^ trait alias used in trait object type (additional use)
+ | |
+ | first non-auto trait
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-extra-traits.rs:118:37
+ |
+LL | trait _0 = ObjA;
+ | ---- additional non-auto trait
+LL | trait _1 = _0;
+ | -- referenced here (additional use)
+...
+LL | trait _5 = Sync + ObjB + Send;
+ | ---- first non-auto trait
+...
+LL | trait _9 = _5 + Sync;
+ | -- referenced here (first use)
+LL | trait _10 = Unpin + _9;
+ | -- referenced here (first use)
+...
+LL | type _T45 = dyn Sync + Send + _10 + _1;
+ | --- ^^ trait alias used in trait object type (additional use)
+ | |
+ | trait alias used in trait object type (first use)
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjA {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error: aborting due to 28 previous errors
+
+For more information about this error, try `rustc --explain E0225`.
--- /dev/null
+#![feature(trait_alias)]
+
+trait EqAlias = Eq;
+trait IteratorAlias = Iterator;
+
+fn main() {
+ let _: &dyn EqAlias = &123;
+ //~^ ERROR the trait `Eq` cannot be made into an object [E0038]
+ let _: &dyn IteratorAlias = &vec![123].into_iter();
+ //~^ ERROR must be specified
+}
--- /dev/null
+error[E0038]: the trait `Eq` cannot be made into an object
+ --> $DIR/object-fail.rs:7:13
+ |
+LL | let _: &dyn EqAlias = &123;
+ | ^^^^^^^^^^^ `Eq` cannot be made into an object
+ |
+note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
+ --> $SRC_DIR/core/src/cmp.rs:LL:COL
+ |
+LL | pub trait Eq: PartialEq<Self> {
+ | ^^^^^^^^^^^^^^^ the trait cannot be made into an object because it uses `Self` as a type parameter
+
+error[E0191]: the value of the associated type `Item` (from trait `Iterator`) must be specified
+ --> $DIR/object-fail.rs:9:17
+ |
+LL | let _: &dyn IteratorAlias = &vec![123].into_iter();
+ | ^^^^^^^^^^^^^ help: specify the associated type: `IteratorAlias<Item = Type>`
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0038, E0191.
+For more information about an error, try `rustc --explain E0038`.
--- /dev/null
+// check-pass
+
+// This test checks that trait objects involving trait aliases are well-formed.
+
+#![feature(trait_alias)]
+
+trait Obj {}
+
+trait _0 = Send + Sync;
+
+// Just auto traits:
+
+trait _1 = _0 + Send + Sync;
+
+use std::marker::Unpin;
+
+fn _f0() {
+ let _: Box<dyn _0>;
+ let _: Box<dyn _1>;
+ let _: Box<dyn Unpin + _1 + Send + Sync>;
+}
+
+// Include object safe traits:
+
+fn _f1() {
+ let _: Box<dyn Obj + _0>;
+ let _: Box<dyn Obj + _1>;
+ let _: Box<dyn Obj + _1 + _0>;
+}
+
+// And when the object safe trait is in a trait alias:
+
+trait _2 = Obj;
+
+fn _f2() {
+ let _: Box<dyn _2 + _0>;
+ let _: Box<dyn _2 + _1>;
+ let _: Box<dyn _2 + _1 + _0>;
+}
+
+// And it should also work when that trait is has auto traits to the right of it.
+
+trait _3 = Obj + Unpin;
+
+fn _f3() {
+ let _: Box<dyn _3 + _0>;
+ let _: Box<dyn _3 + _1>;
+ let _: Box<dyn _3 + _1 + _0>;
+}
+
+// Nest the trait deeply:
+
+trait _4 = _3;
+trait _5 = _4 + Sync + _0 + Send;
+trait _6 = _5 + Send + _1 + Sync;
+
+fn _f4() {
+ let _: Box<dyn _6 + _0>;
+ let _: Box<dyn _6 + _1>;
+ let _: Box<dyn _6 + _1 + _0>;
+}
+
+// Just nest the trait alone:
+
+trait _7 = _2;
+trait _8 = _7;
+trait _9 = _8;
+
+fn _f5() {
+ let _: Box<dyn _9>;
+}
+
+// First bound is auto trait:
+
+trait _10 = Send + Obj;
+trait _11 = Obj + Send;
+trait _12 = Sync + _11;
+trait _13 = Send + _12;
+
+fn f6() {
+ let _: Box<dyn _10>;
+ let _: Box<dyn _13>;
+}
+
+fn main() {}
--- /dev/null
+// run-pass
+
+#![feature(trait_alias)]
+
+trait Foo = PartialEq<i32> + Send;
+trait Bar = Foo + Sync;
+
+trait I32Iterator = Iterator<Item = i32>;
+
+pub fn main() {
+ let a: &dyn Bar = &123;
+ assert!(*a == 123);
+ let b = Box::new(456) as Box<dyn Foo>;
+ assert!(*b == 456);
+
+ let c: &mut dyn I32Iterator = &mut vec![123].into_iter();
+ assert_eq!(c.next(), Some(123));
+}
--- /dev/null
+// Test that `dyn ?Sized` (i.e., a trait object with only a maybe buond) is not allowed, when just
+// `?Sized` results from trait alias expansion.
+
+#![feature(trait_alias)]
+
+trait S = ?Sized;
+
+// Nest a couple of levels deep:
+trait _0 = S;
+trait _1 = _0;
+
+// Straight list expansion:
+type _T0 = dyn _1;
+//~^ ERROR at least one trait is required for an object type [E0224]
+
+// Twice:
+trait _2 = _1 + _1;
+
+type _T1 = dyn _2;
+//~^ ERROR at least one trait is required for an object type [E0224]
+
+fn main() {}
--- /dev/null
+error[E0224]: at least one trait is required for an object type
+ --> $DIR/only-maybe-bound.rs:13:12
+ |
+LL | type _T0 = dyn _1;
+ | ^^^^^^
+
+error[E0224]: at least one trait is required for an object type
+ --> $DIR/only-maybe-bound.rs:19:12
+ |
+LL | type _T1 = dyn _2;
+ | ^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0224`.
--- /dev/null
+#![feature(trait_alias)]
+
+trait Foo {}
+auto trait A = Foo; //~ ERROR trait aliases cannot be `auto`
+unsafe trait B = Foo; //~ ERROR trait aliases cannot be `unsafe`
+
+trait C: Ord = Eq; //~ ERROR bounds are not allowed on trait aliases
+trait D: = Eq; //~ ERROR bounds are not allowed on trait aliases
+
+fn main() {}
--- /dev/null
+error: trait aliases cannot be `auto`
+ --> $DIR/syntax-fail.rs:4:1
+ |
+LL | auto trait A = Foo;
+ | ^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `auto`
+
+error: trait aliases cannot be `unsafe`
+ --> $DIR/syntax-fail.rs:5:1
+ |
+LL | unsafe trait B = Foo;
+ | ^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `unsafe`
+
+error: bounds are not allowed on trait aliases
+ --> $DIR/syntax-fail.rs:7:8
+ |
+LL | trait C: Ord = Eq;
+ | ^^^^^
+
+error: bounds are not allowed on trait aliases
+ --> $DIR/syntax-fail.rs:8:8
+ |
+LL | trait D: = Eq;
+ | ^
+
+error: aborting due to 4 previous errors
+
--- /dev/null
+// run-pass
+
+#![feature(trait_alias)]
+
+trait SimpleAlias = Default;
+trait GenericAlias<T> = Iterator<Item = T>;
+trait Partial<T> = IntoIterator<Item = T>;
+trait SpecificAlias = GenericAlias<i32>;
+trait PartialEqRef<'a, T: 'a> = PartialEq<&'a T>;
+trait StaticAlias = 'static;
+
+trait Things<T> {}
+trait Romeo {}
+#[allow(dead_code)]
+struct The<T>(T);
+#[allow(dead_code)]
+struct Fore<T>(T);
+impl<T, U> Things<T> for The<U> {}
+impl<T> Romeo for Fore<T> {}
+
+trait WithWhere<Art, Thou> = Romeo + Romeo where Fore<(Art, Thou)>: Romeo;
+trait BareWhere<Wild, Are> = where The<Wild>: Things<Are>;
+
+fn main() {}
--- /dev/null
+#![feature(trait_alias)]
+
+trait Foo {}
+trait A<T: Foo> {}
+trait B<T> = A<T>; //~ ERROR `T: Foo` is not satisfied
+
+fn main() {}
--- /dev/null
+error[E0277]: the trait bound `T: Foo` is not satisfied
+ --> $DIR/wf.rs:5:14
+ |
+LL | trait A<T: Foo> {}
+ | --- required by this bound in `A`
+LL | trait B<T> = A<T>;
+ | ^^^^ the trait `Foo` is not implemented for `T`
+ |
+help: consider restricting type parameter `T`
+ |
+LL | trait B<T: Foo> = A<T>;
+ | ^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+// run-pass
+struct Foo {
+ x: isize
+}
+
+impl Foo {
+ pub fn new() -> Foo {
+ Foo { x: 3 }
+ }
+}
+
+pub fn main() {
+ let x = Foo::new();
+ println!("{}", x.x);
+}
+++ /dev/null
-// run-pass
-struct Foo {
- x: isize
-}
-
-impl Foo {
- pub fn new() -> Foo {
- Foo { x: 3 }
- }
-}
-
-pub fn main() {
- let x = Foo::new();
- println!("{}", x.x);
-}
--- /dev/null
+trait TraitNotAStruct {}
+
+fn main() {
+ TraitNotAStruct{ value: 0 };
+ //~^ ERROR expected struct, variant or union type, found trait `TraitNotAStruct`
+}
--- /dev/null
+error[E0574]: expected struct, variant or union type, found trait `TraitNotAStruct`
+ --> $DIR/as-struct-constructor.rs:4:5
+ |
+LL | TraitNotAStruct{ value: 0 };
+ | ^^^^^^^^^^^^^^^ not a struct, variant or union type
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0574`.
--- /dev/null
+// Test case where an associated type is referenced from within the
+// supertrait definition, and the impl makes the wrong
+// associations. Issue #20220.
+
+use std::vec::IntoIter;
+
+pub trait Foo: Iterator<Item=<Self as Foo>::Key> {
+ type Key;
+}
+
+impl Foo for IntoIter<i32> {
+ type Key = u32; //~ ERROR type mismatch
+}
+
+fn main() {
+}
--- /dev/null
+error[E0271]: type mismatch resolving `<std::vec::IntoIter<i32> as Iterator>::Item == u32`
+ --> $DIR/assoc-type-in-superbad.rs:12:16
+ |
+LL | type Key = u32;
+ | ^^^ expected `i32`, found `u32`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0271`.
--- /dev/null
+// run-pass
+// Test case where an associated type is referenced from within the
+// supertrait definition. Issue #20220.
+
+
+use std::vec::IntoIter;
+
+pub trait Foo: Iterator<Item=<Self as Foo>::Key> {
+ type Key;
+}
+
+impl Foo for IntoIter<i32> {
+ type Key = i32;
+}
+
+fn sum_foo<F:Foo<Key=i32>>(f: F) -> i32 {
+ f.fold(0, |a,b| a + b)
+}
+
+fn main() {
+ let x = sum_foo(vec![11, 10, 1].into_iter());
+ assert_eq!(x, 22);
+}
+++ /dev/null
-trait Bar {
- type Baz;
-}
-
-struct Foo<T> where T: Bar, <T as Bar>::Baz: String { //~ ERROR expected trait, found struct
- t: T,
-}
-
-struct Qux<'a, T> where T: Bar, <&'a T as Bar>::Baz: String { //~ ERROR expected trait, found struct
- t: &'a T,
-}
-
-fn foo<T: Bar>(_: T) where <T as Bar>::Baz: String { //~ ERROR expected trait, found struct
-}
-
-fn qux<'a, T: Bar>(_: &'a T) where <&'a T as Bar>::Baz: String { //~ ERROR expected trait, found
-}
-
-fn main() {}
+++ /dev/null
-error[E0404]: expected trait, found struct `String`
- --> $DIR/assoc_type_bound_with_struct.rs:5:46
- |
-LL | struct Foo<T> where T: Bar, <T as Bar>::Baz: String {
- | ^^^^^^ not a trait
- |
- ::: $SRC_DIR/alloc/src/string.rs:LL:COL
- |
-LL | pub trait ToString {
- | ------------------ similarly named trait `ToString` defined here
- |
-help: constrain the associated type to `String`
- |
-LL | struct Foo<T> where T: Bar, T: Bar<Baz = String> {
- | ^^^^^^^^^^^^^^^^^^^^
-help: a trait with a similar name exists
- |
-LL | struct Foo<T> where T: Bar, <T as Bar>::Baz: ToString {
- | ^^^^^^^^
-
-error[E0404]: expected trait, found struct `String`
- --> $DIR/assoc_type_bound_with_struct.rs:9:54
- |
-LL | struct Qux<'a, T> where T: Bar, <&'a T as Bar>::Baz: String {
- | ^^^^^^ not a trait
- |
- ::: $SRC_DIR/alloc/src/string.rs:LL:COL
- |
-LL | pub trait ToString {
- | ------------------ similarly named trait `ToString` defined here
- |
-help: constrain the associated type to `String`
- |
-LL | struct Qux<'a, T> where T: Bar, &'a T: Bar<Baz = String> {
- | ^^^^^^^^^^^^^^^^^^^^^^^^
-help: a trait with a similar name exists
- |
-LL | struct Qux<'a, T> where T: Bar, <&'a T as Bar>::Baz: ToString {
- | ^^^^^^^^
-
-error[E0404]: expected trait, found struct `String`
- --> $DIR/assoc_type_bound_with_struct.rs:13:45
- |
-LL | fn foo<T: Bar>(_: T) where <T as Bar>::Baz: String {
- | ^^^^^^ not a trait
- |
- ::: $SRC_DIR/alloc/src/string.rs:LL:COL
- |
-LL | pub trait ToString {
- | ------------------ similarly named trait `ToString` defined here
- |
-help: constrain the associated type to `String`
- |
-LL | fn foo<T: Bar>(_: T) where T: Bar<Baz = String> {
- | ^^^^^^^^^^^^^^^^^^^^
-help: a trait with a similar name exists
- |
-LL | fn foo<T: Bar>(_: T) where <T as Bar>::Baz: ToString {
- | ^^^^^^^^
-
-error[E0404]: expected trait, found struct `String`
- --> $DIR/assoc_type_bound_with_struct.rs:16:57
- |
-LL | fn qux<'a, T: Bar>(_: &'a T) where <&'a T as Bar>::Baz: String {
- | ^^^^^^ not a trait
- |
- ::: $SRC_DIR/alloc/src/string.rs:LL:COL
- |
-LL | pub trait ToString {
- | ------------------ similarly named trait `ToString` defined here
- |
-help: constrain the associated type to `String`
- |
-LL | fn qux<'a, T: Bar>(_: &'a T) where &'a T: Bar<Baz = String> {
- | ^^^^^^^^^^^^^^^^^^^^^^^^
-help: a trait with a similar name exists
- |
-LL | fn qux<'a, T: Bar>(_: &'a T) where <&'a T as Bar>::Baz: ToString {
- | ^^^^^^^^
-
-error: aborting due to 4 previous errors
-
-For more information about this error, try `rustc --explain E0404`.
--- /dev/null
+trait Bar {
+ type Baz;
+}
+
+struct Foo<T> where T: Bar, <T as Bar>::Baz: String { //~ ERROR expected trait, found struct
+ t: T,
+}
+
+struct Qux<'a, T> where T: Bar, <&'a T as Bar>::Baz: String { //~ ERROR expected trait, found struct
+ t: &'a T,
+}
+
+fn foo<T: Bar>(_: T) where <T as Bar>::Baz: String { //~ ERROR expected trait, found struct
+}
+
+fn qux<'a, T: Bar>(_: &'a T) where <&'a T as Bar>::Baz: String { //~ ERROR expected trait, found
+}
+
+fn main() {}
--- /dev/null
+error[E0404]: expected trait, found struct `String`
+ --> $DIR/assoc_type_bound_with_struct.rs:5:46
+ |
+LL | struct Foo<T> where T: Bar, <T as Bar>::Baz: String {
+ | ^^^^^^ not a trait
+ |
+ ::: $SRC_DIR/alloc/src/string.rs:LL:COL
+ |
+LL | pub trait ToString {
+ | ------------------ similarly named trait `ToString` defined here
+ |
+help: constrain the associated type to `String`
+ |
+LL | struct Foo<T> where T: Bar, T: Bar<Baz = String> {
+ | ^^^^^^^^^^^^^^^^^^^^
+help: a trait with a similar name exists
+ |
+LL | struct Foo<T> where T: Bar, <T as Bar>::Baz: ToString {
+ | ^^^^^^^^
+
+error[E0404]: expected trait, found struct `String`
+ --> $DIR/assoc_type_bound_with_struct.rs:9:54
+ |
+LL | struct Qux<'a, T> where T: Bar, <&'a T as Bar>::Baz: String {
+ | ^^^^^^ not a trait
+ |
+ ::: $SRC_DIR/alloc/src/string.rs:LL:COL
+ |
+LL | pub trait ToString {
+ | ------------------ similarly named trait `ToString` defined here
+ |
+help: constrain the associated type to `String`
+ |
+LL | struct Qux<'a, T> where T: Bar, &'a T: Bar<Baz = String> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+help: a trait with a similar name exists
+ |
+LL | struct Qux<'a, T> where T: Bar, <&'a T as Bar>::Baz: ToString {
+ | ^^^^^^^^
+
+error[E0404]: expected trait, found struct `String`
+ --> $DIR/assoc_type_bound_with_struct.rs:13:45
+ |
+LL | fn foo<T: Bar>(_: T) where <T as Bar>::Baz: String {
+ | ^^^^^^ not a trait
+ |
+ ::: $SRC_DIR/alloc/src/string.rs:LL:COL
+ |
+LL | pub trait ToString {
+ | ------------------ similarly named trait `ToString` defined here
+ |
+help: constrain the associated type to `String`
+ |
+LL | fn foo<T: Bar>(_: T) where T: Bar<Baz = String> {
+ | ^^^^^^^^^^^^^^^^^^^^
+help: a trait with a similar name exists
+ |
+LL | fn foo<T: Bar>(_: T) where <T as Bar>::Baz: ToString {
+ | ^^^^^^^^
+
+error[E0404]: expected trait, found struct `String`
+ --> $DIR/assoc_type_bound_with_struct.rs:16:57
+ |
+LL | fn qux<'a, T: Bar>(_: &'a T) where <&'a T as Bar>::Baz: String {
+ | ^^^^^^ not a trait
+ |
+ ::: $SRC_DIR/alloc/src/string.rs:LL:COL
+ |
+LL | pub trait ToString {
+ | ------------------ similarly named trait `ToString` defined here
+ |
+help: constrain the associated type to `String`
+ |
+LL | fn qux<'a, T: Bar>(_: &'a T) where &'a T: Bar<Baz = String> {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+help: a trait with a similar name exists
+ |
+LL | fn qux<'a, T: Bar>(_: &'a T) where <&'a T as Bar>::Baz: ToString {
+ | ^^^^^^^^
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0404`.
--- /dev/null
+// Check that we validate associated type bounds for trait objects
+
+trait X {
+ type Y: Clone;
+}
+
+fn f<T: X + ?Sized>() {
+ None::<T::Y>.clone();
+}
+
+fn main() {
+ f::<dyn X<Y = str>>();
+ //~^ ERROR the trait bound `str: Clone` is not satisfied
+}
--- /dev/null
+error[E0277]: the trait bound `str: Clone` is not satisfied
+ --> $DIR/check-trait-object-bounds-1.rs:12:5
+ |
+LL | fn f<T: X + ?Sized>() {
+ | - required by this bound in `f`
+...
+LL | f::<dyn X<Y = str>>();
+ | ^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `str`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+// Make sure that we're handling bound lifetimes correctly when validating trait
+// bounds.
+// run-pass
+
+trait X<'a> {
+ type F: FnOnce(&i32) -> &'a i32;
+}
+
+fn f<T: for<'r> X<'r> + ?Sized>() {
+ None::<T::F>.map(|f| f(&0));
+}
+
+fn main() {
+ f::<dyn for<'x> X<'x, F = fn(&i32) -> &'x i32>>();
+}
--- /dev/null
+// Check that we validate associated type bounds for trait objects when they
+// have bound lifetimes
+
+trait X<'a> {
+ type F: FnOnce(&i32) -> &'a i32;
+}
+
+fn f<T: for<'r> X<'r> + ?Sized>() {
+ None::<T::F>.map(|f| f(&0));
+}
+
+fn main() {
+ f::<dyn for<'x> X<'x, F = i32>>();
+ //~^ expected a `FnOnce<(&i32,)>` closure, found `i32`
+}
--- /dev/null
+error[E0277]: expected a `FnOnce<(&i32,)>` closure, found `i32`
+ --> $DIR/check-trait-object-bounds-2.rs:13:5
+ |
+LL | fn f<T: for<'r> X<'r> + ?Sized>() {
+ | ------------- required by this bound in `f`
+...
+LL | f::<dyn for<'x> X<'x, F = i32>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an `FnOnce<(&i32,)>` closure, found `i32`
+ |
+ = help: the trait `for<'r> FnOnce<(&'r i32,)>` is not implemented for `i32`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+// Check that we validate associated type bounds for trait objects
+
+trait X<'a> {
+ type Y: Into<&'static str> + From<&'a str>;
+}
+
+fn f<'a, T: X<'a> + ?Sized>(s: &'a str) -> &'static str {
+ T::Y::from(s).into()
+}
+
+pub fn main() {
+ let z;
+ {
+ let s = String::from("abcdef");
+ z = f::<dyn X<Y = &str>>(&s);
+ //~^ ERROR `s` does not live long enough
+ }
+
+ println!("{}", z)
+}
--- /dev/null
+error[E0597]: `s` does not live long enough
+ --> $DIR/check-trait-object-bounds-3.rs:15:34
+ |
+LL | z = f::<dyn X<Y = &str>>(&s);
+ | ---------------------^^-
+ | | |
+ | | borrowed value does not live long enough
+ | argument requires that `s` is borrowed for `'static`
+LL |
+LL | }
+ | - `s` dropped here while still borrowed
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0597`.
--- /dev/null
+// Check that we validate associated type bounds on super traits for trait
+// objects
+
+trait Super {
+ type Y: Clone;
+}
+
+trait X: Super {}
+
+fn f<T: X + ?Sized>() {
+ None::<T::Y>.clone();
+}
+
+fn main() {
+ f::<dyn X<Y = str>>();
+ //~^ ERROR the trait bound `str: Clone` is not satisfied
+}
--- /dev/null
+error[E0277]: the trait bound `str: Clone` is not satisfied
+ --> $DIR/check-trait-object-bounds-4.rs:15:5
+ |
+LL | fn f<T: X + ?Sized>() {
+ | - required by this bound in `f`
+...
+LL | f::<dyn X<Y = str>>();
+ | ^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `str`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+// Check that we validate associated type bounds on super traits for trait
+// objects
+
+trait Is {
+ type T;
+}
+
+impl<U> Is for U {
+ type T = U;
+}
+
+trait Super {
+ type V;
+}
+
+trait Obj: Super {
+ type U: Is<T = Self::V>;
+}
+
+fn is_obj<T: ?Sized + Obj>(_: &T) {}
+
+fn f(x: &dyn Obj<U = i32, V = i64>) {
+ is_obj(x)
+ //~^ type mismatch resolving `<i32 as Is>::T == i64`
+}
+
+fn main() {}
--- /dev/null
+error[E0271]: type mismatch resolving `<i32 as Is>::T == i64`
+ --> $DIR/check-trait-object-bounds-5.rs:23:5
+ |
+LL | fn is_obj<T: ?Sized + Obj>(_: &T) {}
+ | --- required by this bound in `is_obj`
+...
+LL | is_obj(x)
+ | ^^^^^^ expected `i64`, found `i32`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0271`.
--- /dev/null
+// Check that we validate associated type bounds on super traits for trait
+// objects
+
+trait Is {
+ type T;
+}
+
+impl<U> Is for U {
+ type T = U;
+}
+
+trait Obj {
+ type U: Is<T = Self::V>;
+ type V;
+}
+
+fn is_obj<T: ?Sized + Obj>(_: &T) {}
+
+fn f(x: &dyn Obj<U = i32, V = i64>) {
+ is_obj(x)
+ //~^ ERROR type mismatch resolving `<i32 as Is>::T == i64`
+}
+
+fn main() {}
--- /dev/null
+error[E0271]: type mismatch resolving `<i32 as Is>::T == i64`
+ --> $DIR/check-trait-object-bounds-6.rs:20:5
+ |
+LL | fn is_obj<T: ?Sized + Obj>(_: &T) {}
+ | --- required by this bound in `is_obj`
+...
+LL | is_obj(x)
+ | ^^^^^^ expected `i64`, found `i32`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0271`.
--- /dev/null
+// run-pass
+// Test that we are able to successfully compile a setup where a trait
+// (`Trait1`) references a struct (`SomeType<u32>`) which in turn
+// carries a predicate that references the trait (`u32 : Trait1`,
+// substituted).
+
+// pretty-expanded FIXME #23616
+
+#![allow(dead_code)]
+
+trait Trait1 : Trait2<SomeType<u32>> {
+ fn dumb(&self) { }
+}
+
+trait Trait2<A> {
+ fn dumber(&self, _: A) { }
+}
+
+struct SomeType<A>
+ where A : Trait1
+{
+ a: A
+}
+
+impl Trait1 for u32 { }
+
+impl Trait2<SomeType<u32>> for u32 { }
+
+fn main() { }
+++ /dev/null
-// run-pass
-// Test that we are able to successfully compile a setup where a trait
-// (`Trait1`) references a struct (`SomeType<u32>`) which in turn
-// carries a predicate that references the trait (`u32 : Trait1`,
-// substituted).
-
-// pretty-expanded FIXME #23616
-
-#![allow(dead_code)]
-
-trait Trait1 : Trait2<SomeType<u32>> {
- fn dumb(&self) { }
-}
-
-trait Trait2<A> {
- fn dumber(&self, _: A) { }
-}
-
-struct SomeType<A>
- where A : Trait1
-{
- a: A
-}
-
-impl Trait1 for u32 { }
-
-impl Trait2<SomeType<u32>> for u32 { }
-
-fn main() { }
+++ /dev/null
-pub trait Bar {}
-
-pub fn try_foo(x: impl Bar) {}
-
-pub struct ImplementsTraitForUsize<T> {
- _marker: std::marker::PhantomData<T>,
-}
-
-impl Bar for ImplementsTraitForUsize<usize> {}
+++ /dev/null
-pub struct Foo;
-
-pub trait Bar {}
-
-impl Bar for Foo {}
-
-pub struct DoesNotImplementTrait;
-
-pub struct ImplementsWrongTraitConditionally<T> {
- _marker: std::marker::PhantomData<T>,
-}
-
-impl Bar for ImplementsWrongTraitConditionally<isize> {}
+++ /dev/null
-#![feature(trait_alias)]
-
-pub trait Hello {
- fn hello(&self);
-}
-
-pub struct Hi;
-
-impl Hello for Hi {
- fn hello(&self) {}
-}
-
-pub trait Greet = Hello;
+++ /dev/null
-pub trait Trait {
- fn dummy(&self) { }
-}
-
-pub struct Foo<T:Trait> {
- pub x: T,
-}
-
-pub enum Bar<T:Trait> {
- ABar(isize),
- BBar(T),
- CBar(usize),
-}
+++ /dev/null
-pub struct Something { pub x: isize }
-
-pub trait A {
- fn f(&self) -> isize;
- fn g(&self) -> isize { 10 }
- fn h(&self) -> isize { 11 }
- fn lurr(x: &Self, y: &Self) -> isize { x.g() + y.h() }
-}
-
-
-impl A for isize {
- fn f(&self) -> isize { 10 }
-}
-
-impl A for Something {
- fn f(&self) -> isize { 10 }
-}
-
-pub trait B<T> {
- fn thing<U>(&self, x: T, y: U) -> (T, U) { (x, y) }
- fn staticthing<U>(_z: &Self, x: T, y: U) -> (T, U) { (x, y) }
-}
-
-impl<T> B<T> for isize { }
-impl B<f64> for bool { }
-
-
-
-pub trait TestEquality {
- fn test_eq(&self, rhs: &Self) -> bool;
- fn test_neq(&self, rhs: &Self) -> bool {
- !self.test_eq(rhs)
- }
-}
-
-impl TestEquality for isize {
- fn test_eq(&self, rhs: &isize) -> bool {
- *self == *rhs
- }
-}
+++ /dev/null
-// aux-build:trait_default_method_xc_aux.rs
-
-extern crate trait_default_method_xc_aux as aux;
-use aux::A;
-
-pub struct a_struct { pub x: isize }
-
-impl A for a_struct {
- fn f(&self) -> isize { 10 }
-}
-
-// This function will need to get inlined, and badness may result.
-pub fn welp<A>(x: A) -> A {
- let a = a_struct { x: 0 };
- a.g();
- x
-}
+++ /dev/null
-pub trait Foo { fn f(&self) -> isize; }
-pub trait Bar { fn g(&self) -> isize; }
-pub trait Baz { fn h(&self) -> isize; }
-
-pub struct A { pub x: isize }
-
-impl Foo for A { fn f(&self) -> isize { 10 } }
-impl Bar for A { fn g(&self) -> isize { 20 } }
-impl Baz for A { fn h(&self) -> isize { 30 } }
+++ /dev/null
-pub trait Foo { fn f(&self) -> isize; }
-pub trait Bar { fn g(&self) -> isize; }
-pub trait Baz { fn h(&self) -> isize; }
-
-pub trait Quux: Foo + Bar + Baz { }
-
-impl<T:Foo + Bar + Baz> Quux for T { }
+++ /dev/null
-use std::cmp::PartialEq;
-use std::ops::{Add, Sub, Mul};
-
-pub trait MyNum : Add<Output=Self> + Sub<Output=Self> + Mul<Output=Self> + PartialEq + Clone {
-}
-
-#[derive(Clone, Debug)]
-pub struct MyInt {
- pub val: isize
-}
-
-impl Add for MyInt {
- type Output = MyInt;
-
- fn add(self, other: MyInt) -> MyInt { mi(self.val + other.val) }
-}
-
-impl Sub for MyInt {
- type Output = MyInt;
-
- fn sub(self, other: MyInt) -> MyInt { mi(self.val - other.val) }
-}
-
-impl Mul for MyInt {
- type Output = MyInt;
-
- fn mul(self, other: MyInt) -> MyInt { mi(self.val * other.val) }
-}
-
-impl PartialEq for MyInt {
- fn eq(&self, other: &MyInt) -> bool { self.val == other.val }
-
- fn ne(&self, other: &MyInt) -> bool { !self.eq(other) }
-}
-
-impl MyNum for MyInt {}
-
-fn mi(v: isize) -> MyInt { MyInt { val: v } }
+++ /dev/null
-pub trait Foo {
- fn f(&self) -> isize;
-}
-
-pub struct A {
- pub x: isize
-}
-
-impl Foo for A {
- fn f(&self) -> isize { 10 }
-}
--- /dev/null
+pub trait Bar {}
+
+pub fn try_foo(x: impl Bar) {}
+
+pub struct ImplementsTraitForUsize<T> {
+ _marker: std::marker::PhantomData<T>,
+}
+
+impl Bar for ImplementsTraitForUsize<usize> {}
--- /dev/null
+pub struct Foo;
+
+pub trait Bar {}
+
+impl Bar for Foo {}
+
+pub struct DoesNotImplementTrait;
+
+pub struct ImplementsWrongTraitConditionally<T> {
+ _marker: std::marker::PhantomData<T>,
+}
+
+impl Bar for ImplementsWrongTraitConditionally<isize> {}
--- /dev/null
+pub trait Trait {
+ fn dummy(&self) { }
+}
+
+pub struct Foo<T:Trait> {
+ pub x: T,
+}
+
+pub enum Bar<T:Trait> {
+ ABar(isize),
+ BBar(T),
+ CBar(usize),
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+#![allow(unconditional_recursion)]
+
+// pretty-expanded FIXME #23616
+
+trait Foo {
+}
+
+fn b(_x: Box<dyn Foo+Send>) {
+}
+
+fn c(x: Box<dyn Foo+Sync+Send>) {
+ e(x);
+}
+
+fn d(x: Box<dyn Foo+Send>) {
+ e(x);
+}
+
+fn e(x: Box<dyn Foo>) {
+ e(x);
+}
+
+pub fn main() { }
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+#![allow(non_camel_case_types)]
+#![allow(non_snake_case)]
+
+trait connection {
+ fn read(&self) -> isize;
+}
+
+trait connection_factory<C:connection> {
+ fn create(&self) -> C;
+}
+
+type my_connection = ();
+type my_connection_factory = ();
+
+impl connection for () {
+ fn read(&self) -> isize { 43 }
+}
+
+impl connection_factory<my_connection> for my_connection_factory {
+ fn create(&self) -> my_connection { () }
+}
+
+pub fn main() {
+ let factory = ();
+ let connection = factory.create();
+ let result = connection.read();
+ assert_eq!(result, 43);
+}
--- /dev/null
+// run-pass
+// Tests that type parameter bounds on an implementation need not match the
+// trait exactly, as long as the implementation doesn't demand *more* bounds
+// than the trait.
+
+// pretty-expanded FIXME #23616
+
+trait A {
+ fn foo<T: Eq + Ord>(&self);
+}
+
+impl A for isize {
+ fn foo<T: Ord>(&self) {} // Ord implies Eq, so this is ok.
+}
+
+fn main() {}
--- /dev/null
+// run-pass
+#![allow(unused_must_use)]
+// Tests that a heterogeneous list of existential `dyn` types can be put inside an Arc
+// and shared between threads as long as all types fulfill Send.
+
+// ignore-emscripten no threads support
+
+#![feature(box_syntax)]
+
+use std::sync::Arc;
+use std::sync::mpsc::channel;
+use std::thread;
+
+trait Pet {
+ fn name(&self, blk: Box<dyn FnMut(&str)>);
+ fn num_legs(&self) -> usize;
+ fn of_good_pedigree(&self) -> bool;
+}
+
+struct Catte {
+ num_whiskers: usize,
+ name: String,
+}
+
+struct Dogge {
+ bark_decibels: usize,
+ tricks_known: usize,
+ name: String,
+}
+
+struct Goldfyshe {
+ swim_speed: usize,
+ name: String,
+}
+
+impl Pet for Catte {
+ fn name(&self, mut blk: Box<dyn FnMut(&str)>) { blk(&self.name) }
+ fn num_legs(&self) -> usize { 4 }
+ fn of_good_pedigree(&self) -> bool { self.num_whiskers >= 4 }
+}
+impl Pet for Dogge {
+ fn name(&self, mut blk: Box<dyn FnMut(&str)>) { blk(&self.name) }
+ fn num_legs(&self) -> usize { 4 }
+ fn of_good_pedigree(&self) -> bool {
+ self.bark_decibels < 70 || self.tricks_known > 20
+ }
+}
+impl Pet for Goldfyshe {
+ fn name(&self, mut blk: Box<dyn FnMut(&str)>) { blk(&self.name) }
+ fn num_legs(&self) -> usize { 0 }
+ fn of_good_pedigree(&self) -> bool { self.swim_speed >= 500 }
+}
+
+pub fn main() {
+ let catte = Catte { num_whiskers: 7, name: "alonzo_church".to_string() };
+ let dogge1 = Dogge {
+ bark_decibels: 100,
+ tricks_known: 42,
+ name: "alan_turing".to_string(),
+ };
+ let dogge2 = Dogge {
+ bark_decibels: 55,
+ tricks_known: 11,
+ name: "albert_einstein".to_string(),
+ };
+ let fishe = Goldfyshe {
+ swim_speed: 998,
+ name: "alec_guinness".to_string(),
+ };
+ let arc = Arc::new(vec![box catte as Box<dyn Pet+Sync+Send>,
+ box dogge1 as Box<dyn Pet+Sync+Send>,
+ box fishe as Box<dyn Pet+Sync+Send>,
+ box dogge2 as Box<dyn Pet+Sync+Send>]);
+ let (tx1, rx1) = channel();
+ let arc1 = arc.clone();
+ let t1 = thread::spawn(move|| { check_legs(arc1); tx1.send(()); });
+ let (tx2, rx2) = channel();
+ let arc2 = arc.clone();
+ let t2 = thread::spawn(move|| { check_names(arc2); tx2.send(()); });
+ let (tx3, rx3) = channel();
+ let arc3 = arc.clone();
+ let t3 = thread::spawn(move|| { check_pedigree(arc3); tx3.send(()); });
+ rx1.recv();
+ rx2.recv();
+ rx3.recv();
+ t1.join();
+ t2.join();
+ t3.join();
+}
+
+fn check_legs(arc: Arc<Vec<Box<dyn Pet+Sync+Send>>>) {
+ let mut legs = 0;
+ for pet in arc.iter() {
+ legs += pet.num_legs();
+ }
+ assert!(legs == 12);
+}
+fn check_names(arc: Arc<Vec<Box<dyn Pet+Sync+Send>>>) {
+ for pet in arc.iter() {
+ pet.name(Box::new(|name| {
+ assert!(name.as_bytes()[0] == 'a' as u8 && name.as_bytes()[1] == 'l' as u8);
+ }))
+ }
+}
+fn check_pedigree(arc: Arc<Vec<Box<dyn Pet+Sync+Send>>>) {
+ for pet in arc.iter() {
+ assert!(pet.of_good_pedigree());
+ }
+}
--- /dev/null
+// run-pass
+// pretty-expanded FIXME #23616
+
+fn f<T:PartialEq + PartialOrd>(_: T) {
+}
+
+pub fn main() {
+ f(3);
+}
--- /dev/null
+trait Foo {
+ fn dummy(&self) { }
+}
+
+// This should emit the less confusing error, not the more confusing one.
+
+fn foo(_x: Foo + Send) {
+ //~^ ERROR the size for values of type
+ //~| WARN trait objects without an explicit `dyn` are deprecated
+}
+
+fn main() { }
--- /dev/null
+warning: trait objects without an explicit `dyn` are deprecated
+ --> $DIR/not-on-bare-trait.rs:7:12
+ |
+LL | fn foo(_x: Foo + Send) {
+ | ^^^^^^^^^^ help: use `dyn`: `dyn Foo + Send`
+ |
+ = note: `#[warn(bare_trait_objects)]` on by default
+
+error[E0277]: the size for values of type `(dyn Foo + Send + 'static)` cannot be known at compilation time
+ --> $DIR/not-on-bare-trait.rs:7:8
+ |
+LL | fn foo(_x: Foo + Send) {
+ | ^^ doesn't have a size known at compile-time
+ |
+ = help: the trait `Sized` is not implemented for `(dyn Foo + Send + 'static)`
+ = help: unsized fn params are gated as an unstable feature
+help: function arguments must have a statically known size, borrowed types always have a known size
+ |
+LL | fn foo(&_x: Foo + Send) {
+ | ^
+
+error: aborting due to previous error; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+// We don't need those errors. Ideally we would silence them, but to do so we need to move the
+// lint from being an early-lint during parsing to a late-lint, because it needs to be aware of
+// the types involved.
+#![allow(bare_trait_objects)]
+
+struct Foo;
+
+fn foo(_x: Box<Foo + Send>) { } //~ ERROR expected trait, found struct `Foo`
+
+type TypeAlias<T> = Box<dyn Vec<T>>; //~ ERROR expected trait, found struct `Vec`
+
+struct A;
+fn a() -> A + 'static { //~ ERROR expected trait, found
+ A
+}
+fn b<'a,T,E>(iter: Iterator<Item=Result<T,E> + 'a>) { //~ ERROR expected trait, found
+ panic!()
+}
+fn c() -> 'static + A { //~ ERROR expected trait, found
+ A
+}
+fn d<'a,T,E>(iter: Iterator<Item='a + Result<T,E>>) { //~ ERROR expected trait, found
+ panic!()
+}
+fn e() -> 'static + A + 'static { //~ ERROR expected trait, found
+//~^ ERROR only a single explicit lifetime bound is permitted
+ A
+}
+fn f<'a,T,E>(iter: Iterator<Item='a + Result<T,E> + 'a>) { //~ ERROR expected trait, found
+//~^ ERROR only a single explicit lifetime bound is permitted
+ panic!()
+}
+struct Traitor;
+trait Trait {}
+fn g() -> Traitor + 'static { //~ ERROR expected trait, found struct `Traitor`
+ A
+}
+fn main() {}
--- /dev/null
+error[E0226]: only a single explicit lifetime bound is permitted
+ --> $DIR/not-on-struct.rs:25:25
+ |
+LL | fn e() -> 'static + A + 'static {
+ | ^^^^^^^
+
+error[E0226]: only a single explicit lifetime bound is permitted
+ --> $DIR/not-on-struct.rs:29:53
+ |
+LL | fn f<'a,T,E>(iter: Iterator<Item='a + Result<T,E> + 'a>) {
+ | ^^
+
+error[E0404]: expected trait, found struct `Foo`
+ --> $DIR/not-on-struct.rs:8:16
+ |
+LL | fn foo(_x: Box<Foo + Send>) { }
+ | ^^^ not a trait
+ |
+help: `+` is used to constrain a "trait object" type with lifetimes or auto-traits; structs and enums can't be bound in that way
+ --> $DIR/not-on-struct.rs:8:22
+ |
+LL | fn foo(_x: Box<Foo + Send>) { }
+ | --- ^^^^ ...because of this bound
+ | |
+ | expected this type to be a trait...
+
+error[E0404]: expected trait, found struct `Vec`
+ --> $DIR/not-on-struct.rs:10:29
+ |
+LL | type TypeAlias<T> = Box<dyn Vec<T>>;
+ | ^^^^^^ not a trait
+
+error[E0404]: expected trait, found struct `A`
+ --> $DIR/not-on-struct.rs:13:11
+ |
+LL | fn a() -> A + 'static {
+ | ^ not a trait
+ |
+help: `+` is used to constrain a "trait object" type with lifetimes or auto-traits; structs and enums can't be bound in that way
+ --> $DIR/not-on-struct.rs:13:15
+ |
+LL | fn a() -> A + 'static {
+ | - ^^^^^^^ ...because of this bound
+ | |
+ | expected this type to be a trait...
+help: if you meant to use a type and not a trait here, remove the bounds
+ |
+LL | fn a() -> A {
+ | --
+
+error[E0404]: expected trait, found enum `Result`
+ --> $DIR/not-on-struct.rs:16:34
+ |
+LL | fn b<'a,T,E>(iter: Iterator<Item=Result<T,E> + 'a>) {
+ | ^^^^^^^^^^^ not a trait
+ |
+help: `+` is used to constrain a "trait object" type with lifetimes or auto-traits; structs and enums can't be bound in that way
+ --> $DIR/not-on-struct.rs:16:48
+ |
+LL | fn b<'a,T,E>(iter: Iterator<Item=Result<T,E> + 'a>) {
+ | ----------- ^^ ...because of this bound
+ | |
+ | expected this type to be a trait...
+help: if you meant to use a type and not a trait here, remove the bounds
+ |
+LL | fn b<'a,T,E>(iter: Iterator<Item=Result<T,E>>) {
+ | --
+
+error[E0404]: expected trait, found struct `A`
+ --> $DIR/not-on-struct.rs:19:21
+ |
+LL | fn c() -> 'static + A {
+ | ^ not a trait
+ |
+help: `+` is used to constrain a "trait object" type with lifetimes or auto-traits; structs and enums can't be bound in that way
+ --> $DIR/not-on-struct.rs:19:11
+ |
+LL | fn c() -> 'static + A {
+ | ^^^^^^^ - expected this type to be a trait...
+ | |
+ | ...because of this bound
+help: if you meant to use a type and not a trait here, remove the bounds
+ |
+LL | fn c() -> A {
+ | --
+
+error[E0404]: expected trait, found enum `Result`
+ --> $DIR/not-on-struct.rs:22:39
+ |
+LL | fn d<'a,T,E>(iter: Iterator<Item='a + Result<T,E>>) {
+ | ^^^^^^^^^^^ not a trait
+ |
+help: `+` is used to constrain a "trait object" type with lifetimes or auto-traits; structs and enums can't be bound in that way
+ --> $DIR/not-on-struct.rs:22:34
+ |
+LL | fn d<'a,T,E>(iter: Iterator<Item='a + Result<T,E>>) {
+ | ^^ ----------- expected this type to be a trait...
+ | |
+ | ...because of this bound
+help: if you meant to use a type and not a trait here, remove the bounds
+ |
+LL | fn d<'a,T,E>(iter: Iterator<Item=Result<T,E>>) {
+ | --
+
+error[E0404]: expected trait, found struct `A`
+ --> $DIR/not-on-struct.rs:25:21
+ |
+LL | fn e() -> 'static + A + 'static {
+ | ^ not a trait
+ |
+help: `+` is used to constrain a "trait object" type with lifetimes or auto-traits; structs and enums can't be bound in that way
+ --> $DIR/not-on-struct.rs:25:11
+ |
+LL | fn e() -> 'static + A + 'static {
+ | ^^^^^^^ - ^^^^^^^ ...because of these bounds
+ | |
+ | expected this type to be a trait...
+help: if you meant to use a type and not a trait here, remove the bounds
+ |
+LL | fn e() -> A {
+ | ---
+
+error[E0404]: expected trait, found enum `Result`
+ --> $DIR/not-on-struct.rs:29:39
+ |
+LL | fn f<'a,T,E>(iter: Iterator<Item='a + Result<T,E> + 'a>) {
+ | ^^^^^^^^^^^ not a trait
+ |
+help: `+` is used to constrain a "trait object" type with lifetimes or auto-traits; structs and enums can't be bound in that way
+ --> $DIR/not-on-struct.rs:29:34
+ |
+LL | fn f<'a,T,E>(iter: Iterator<Item='a + Result<T,E> + 'a>) {
+ | ^^ ----------- ^^ ...because of these bounds
+ | |
+ | expected this type to be a trait...
+help: if you meant to use a type and not a trait here, remove the bounds
+ |
+LL | fn f<'a,T,E>(iter: Iterator<Item=Result<T,E>>) {
+ | -- --
+
+error[E0404]: expected trait, found struct `Traitor`
+ --> $DIR/not-on-struct.rs:35:11
+ |
+LL | trait Trait {}
+ | ----------- similarly named trait `Trait` defined here
+LL | fn g() -> Traitor + 'static {
+ | ^^^^^^^ not a trait
+ |
+help: `+` is used to constrain a "trait object" type with lifetimes or auto-traits; structs and enums can't be bound in that way
+ --> $DIR/not-on-struct.rs:35:21
+ |
+LL | fn g() -> Traitor + 'static {
+ | ------- ^^^^^^^ ...because of this bound
+ | |
+ | expected this type to be a trait...
+help: if you meant to use a type and not a trait here, remove the bounds
+ |
+LL | fn g() -> Traitor {
+ | --
+help: a trait with a similar name exists
+ |
+LL | fn g() -> Trait + 'static {
+ | ^^^^^
+
+error: aborting due to 11 previous errors
+
+Some errors have detailed explanations: E0226, E0404.
+For more information about an error, try `rustc --explain E0226`.
--- /dev/null
+trait Trait {}
+
+struct Foo<T:Trait> {
+ x: T,
+}
+
+enum Bar<T:Trait> {
+ ABar(isize),
+ BBar(T),
+ CBar(usize),
+}
+
+fn explode(x: Foo<u32>) {}
+//~^ ERROR E0277
+
+fn kaboom(y: Bar<f32>) {}
+//~^ ERROR E0277
+
+fn main() {
+}
--- /dev/null
+error[E0277]: the trait bound `u32: Trait` is not satisfied
+ --> $DIR/on-structs-and-enums-in-fns.rs:13:15
+ |
+LL | struct Foo<T:Trait> {
+ | ----- required by this bound in `Foo`
+...
+LL | fn explode(x: Foo<u32>) {}
+ | ^^^^^^^^ the trait `Trait` is not implemented for `u32`
+
+error[E0277]: the trait bound `f32: Trait` is not satisfied
+ --> $DIR/on-structs-and-enums-in-fns.rs:16:14
+ |
+LL | enum Bar<T:Trait> {
+ | ----- required by this bound in `Bar`
+...
+LL | fn kaboom(y: Bar<f32>) {}
+ | ^^^^^^^^ the trait `Trait` is not implemented for `f32`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+trait Trait {}
+
+struct Foo<T:Trait> {
+ x: T,
+}
+
+enum Bar<T:Trait> {
+ ABar(isize),
+ BBar(T),
+ CBar(usize),
+}
+
+trait PolyTrait<T>
+{
+ fn whatever(&self, t: T) {}
+}
+
+struct Struct;
+
+impl PolyTrait<Foo<u16>> for Struct {
+//~^ ERROR E0277
+}
+
+fn main() {
+}
--- /dev/null
+error[E0277]: the trait bound `u16: Trait` is not satisfied
+ --> $DIR/on-structs-and-enums-in-impls.rs:20:6
+ |
+LL | struct Foo<T:Trait> {
+ | ----- required by this bound in `Foo`
+...
+LL | impl PolyTrait<Foo<u16>> for Struct {
+ | ^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `u16`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+trait Trait {
+ fn dummy(&self) { }
+}
+
+struct Foo<T:Trait> {
+ x: T,
+}
+
+fn main() {
+ let foo = Foo {
+ //~^ ERROR E0277
+ x: 3
+ };
+
+ let baz: Foo<usize> = loop { };
+ //~^ ERROR E0277
+}
--- /dev/null
+error[E0277]: the trait bound `usize: Trait` is not satisfied
+ --> $DIR/on-structs-and-enums-locals.rs:15:14
+ |
+LL | struct Foo<T:Trait> {
+ | ----- required by this bound in `Foo`
+...
+LL | let baz: Foo<usize> = loop { };
+ | ^^^^^^^^^^ the trait `Trait` is not implemented for `usize`
+
+error[E0277]: the trait bound `{integer}: Trait` is not satisfied
+ --> $DIR/on-structs-and-enums-locals.rs:10:15
+ |
+LL | struct Foo<T:Trait> {
+ | ------------------- required by `Foo`
+...
+LL | let foo = Foo {
+ | ^^^ the trait `Trait` is not implemented for `{integer}`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+#![allow(unused_variables)]
+// pretty-expanded FIXME #23616
+
+trait U {}
+trait T<X: U> { fn get(self) -> X; }
+
+trait S2<Y: U> {
+ fn m(x: Box<dyn T<Y>+'static>) {}
+}
+
+struct St<X: U> {
+ f: Box<dyn T<X>+'static>,
+}
+
+impl<X: U> St<X> {
+ fn blah() {}
+}
+
+fn main() {}
--- /dev/null
+trait Trait {
+ fn dummy(&self) { }
+}
+
+struct Foo<T:Trait> {
+ x: T,
+}
+
+static X: Foo<usize> = Foo {
+//~^ ERROR E0277
+ x: 1,
+};
+
+fn main() {
+}
--- /dev/null
+error[E0277]: the trait bound `usize: Trait` is not satisfied
+ --> $DIR/on-structs-and-enums-static.rs:9:11
+ |
+LL | struct Foo<T:Trait> {
+ | ----- required by this bound in `Foo`
+...
+LL | static X: Foo<usize> = Foo {
+ | ^^^^^^^^^^ the trait `Trait` is not implemented for `usize`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+// aux-build:on_structs_and_enums_xc.rs
+
+extern crate on_structs_and_enums_xc;
+
+use on_structs_and_enums_xc::{Bar, Foo, Trait};
+
+fn explode(x: Foo<usize>) {}
+//~^ ERROR E0277
+
+fn kaboom(y: Bar<f32>) {}
+//~^ ERROR E0277
+
+fn main() {
+}
--- /dev/null
+error[E0277]: the trait bound `usize: Trait` is not satisfied
+ --> $DIR/on-structs-and-enums-xc.rs:7:15
+ |
+LL | fn explode(x: Foo<usize>) {}
+ | ^^^^^^^^^^ the trait `Trait` is not implemented for `usize`
+ |
+ ::: $DIR/auxiliary/on_structs_and_enums_xc.rs:5:18
+ |
+LL | pub struct Foo<T:Trait> {
+ | ----- required by this bound in `Foo`
+
+error[E0277]: the trait bound `f32: Trait` is not satisfied
+ --> $DIR/on-structs-and-enums-xc.rs:10:14
+ |
+LL | fn kaboom(y: Bar<f32>) {}
+ | ^^^^^^^^ the trait `Trait` is not implemented for `f32`
+ |
+ ::: $DIR/auxiliary/on_structs_and_enums_xc.rs:9:16
+ |
+LL | pub enum Bar<T:Trait> {
+ | ----- required by this bound in `Bar`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+// aux-build:on_structs_and_enums_xc.rs
+
+extern crate on_structs_and_enums_xc;
+
+use on_structs_and_enums_xc::{Bar, Foo, Trait};
+
+fn main() {
+ let foo = Foo {
+ //~^ ERROR E0277
+ x: 3
+ };
+ let bar: Bar<f64> = return;
+ //~^ ERROR E0277
+ let _ = bar;
+}
--- /dev/null
+error[E0277]: the trait bound `f64: Trait` is not satisfied
+ --> $DIR/on-structs-and-enums-xc1.rs:12:14
+ |
+LL | let bar: Bar<f64> = return;
+ | ^^^^^^^^ the trait `Trait` is not implemented for `f64`
+ |
+ ::: $DIR/auxiliary/on_structs_and_enums_xc.rs:9:16
+ |
+LL | pub enum Bar<T:Trait> {
+ | ----- required by this bound in `Bar`
+
+error[E0277]: the trait bound `{integer}: Trait` is not satisfied
+ --> $DIR/on-structs-and-enums-xc1.rs:8:15
+ |
+LL | let foo = Foo {
+ | ^^^ the trait `Trait` is not implemented for `{integer}`
+ |
+ = note: required by `Foo`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+trait Trait {}
+
+struct Foo<T:Trait> {
+ x: T,
+}
+
+enum Bar<T:Trait> {
+ ABar(isize),
+ BBar(T),
+ CBar(usize),
+}
+
+impl<T> Foo<T> {
+//~^ ERROR `T: Trait` is not satisfied
+ fn uhoh() {}
+}
+
+struct Baz {
+ a: Foo<isize>, //~ ERROR E0277
+}
+
+enum Boo {
+ Quux(Bar<usize>), //~ ERROR E0277
+}
+
+struct Badness<U> {
+ b: Foo<U>, //~ ERROR E0277
+}
+
+enum MoreBadness<V> {
+ EvenMoreBadness(Bar<V>), //~ ERROR E0277
+}
+
+struct TupleLike(
+ Foo<i32>, //~ ERROR E0277
+);
+
+enum Enum {
+ DictionaryLike { field: Bar<u8> }, //~ ERROR E0277
+}
+
+fn main() {
+}
--- /dev/null
+error[E0277]: the trait bound `T: Trait` is not satisfied
+ --> $DIR/on-structs-and-enums.rs:13:9
+ |
+LL | struct Foo<T:Trait> {
+ | ----- required by this bound in `Foo`
+...
+LL | impl<T> Foo<T> {
+ | ^^^^^^ the trait `Trait` is not implemented for `T`
+ |
+help: consider restricting type parameter `T`
+ |
+LL | impl<T: Trait> Foo<T> {
+ | ^^^^^^^
+
+error[E0277]: the trait bound `isize: Trait` is not satisfied
+ --> $DIR/on-structs-and-enums.rs:19:8
+ |
+LL | struct Foo<T:Trait> {
+ | ----- required by this bound in `Foo`
+...
+LL | a: Foo<isize>,
+ | ^^^^^^^^^^ the trait `Trait` is not implemented for `isize`
+
+error[E0277]: the trait bound `usize: Trait` is not satisfied
+ --> $DIR/on-structs-and-enums.rs:23:10
+ |
+LL | enum Bar<T:Trait> {
+ | ----- required by this bound in `Bar`
+...
+LL | Quux(Bar<usize>),
+ | ^^^^^^^^^^ the trait `Trait` is not implemented for `usize`
+
+error[E0277]: the trait bound `U: Trait` is not satisfied
+ --> $DIR/on-structs-and-enums.rs:27:8
+ |
+LL | struct Foo<T:Trait> {
+ | ----- required by this bound in `Foo`
+...
+LL | b: Foo<U>,
+ | ^^^^^^ the trait `Trait` is not implemented for `U`
+ |
+help: consider restricting type parameter `U`
+ |
+LL | struct Badness<U: Trait> {
+ | ^^^^^^^
+
+error[E0277]: the trait bound `V: Trait` is not satisfied
+ --> $DIR/on-structs-and-enums.rs:31:21
+ |
+LL | enum Bar<T:Trait> {
+ | ----- required by this bound in `Bar`
+...
+LL | EvenMoreBadness(Bar<V>),
+ | ^^^^^^ the trait `Trait` is not implemented for `V`
+ |
+help: consider restricting type parameter `V`
+ |
+LL | enum MoreBadness<V: Trait> {
+ | ^^^^^^^
+
+error[E0277]: the trait bound `i32: Trait` is not satisfied
+ --> $DIR/on-structs-and-enums.rs:35:5
+ |
+LL | struct Foo<T:Trait> {
+ | ----- required by this bound in `Foo`
+...
+LL | Foo<i32>,
+ | ^^^^^^^^ the trait `Trait` is not implemented for `i32`
+
+error[E0277]: the trait bound `u8: Trait` is not satisfied
+ --> $DIR/on-structs-and-enums.rs:39:29
+ |
+LL | enum Bar<T:Trait> {
+ | ----- required by this bound in `Bar`
+...
+LL | DictionaryLike { field: Bar<u8> },
+ | ^^^^^^^ the trait `Trait` is not implemented for `u8`
+
+error: aborting due to 7 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+// run-pass
+// pretty-expanded FIXME #23616
+
+trait I { fn i(&self) -> Self; }
+
+trait A<T:I> {
+ fn id(x:T) -> T { x.i() }
+}
+
+trait J<T> { fn j(&self) -> T; }
+
+trait B<T:J<T>> {
+ fn id(x:T) -> T { x.j() }
+}
+
+trait C {
+ fn id<T:J<T>>(x:T) -> T { x.j() }
+}
+
+pub fn main() { }
--- /dev/null
+// aux-build:crate_a1.rs
+// aux-build:crate_a2.rs
+
+// Issue 22750
+// This tests the extra help message reported when a trait bound
+// is not met but the struct implements a trait with the same path.
+
+fn main() {
+ let foo = {
+ extern crate crate_a2 as a;
+ a::Foo
+ };
+
+ let implements_no_traits = {
+ extern crate crate_a2 as a;
+ a::DoesNotImplementTrait
+ };
+
+ let other_variant_implements_mismatched_trait = {
+ extern crate crate_a2 as a;
+ a::ImplementsWrongTraitConditionally { _marker: std::marker::PhantomData::<isize> }
+ };
+
+ let other_variant_implements_correct_trait = {
+ extern crate crate_a1 as a;
+ a::ImplementsTraitForUsize { _marker: std::marker::PhantomData::<isize> }
+ };
+
+ {
+ extern crate crate_a1 as a;
+ a::try_foo(foo);
+ //~^ ERROR E0277
+ //~| trait impl with same name found
+ //~| perhaps two different versions of crate `crate_a2`
+
+ // We don't want to see the "version mismatch" help message here
+ // because `implements_no_traits` has no impl for `Foo`
+ a::try_foo(implements_no_traits);
+ //~^ ERROR E0277
+
+ // We don't want to see the "version mismatch" help message here
+ // because `other_variant_implements_mismatched_trait`
+ // does not have an impl for its `<isize>` variant,
+ // only for its `<usize>` variant.
+ a::try_foo(other_variant_implements_mismatched_trait);
+ //~^ ERROR E0277
+
+ // We don't want to see the "version mismatch" help message here
+ // because `ImplementsTraitForUsize` only has
+ // impls for the correct trait where the path is not misleading.
+ a::try_foo(other_variant_implements_correct_trait);
+ //~^ ERROR E0277
+ //~| the following implementations were found:
+ }
+}
--- /dev/null
+error[E0277]: the trait bound `Foo: main::a::Bar` is not satisfied
+ --> $DIR/same-crate-name.rs:31:20
+ |
+LL | a::try_foo(foo);
+ | ^^^ the trait `main::a::Bar` is not implemented for `Foo`
+ |
+ ::: $DIR/auxiliary/crate_a1.rs:3:24
+ |
+LL | pub fn try_foo(x: impl Bar) {}
+ | --- required by this bound in `try_foo`
+ |
+help: trait impl with same name found
+ --> $DIR/auxiliary/crate_a2.rs:5:1
+ |
+LL | impl Bar for Foo {}
+ | ^^^^^^^^^^^^^^^^^^^
+ = note: perhaps two different versions of crate `crate_a2` are being used?
+
+error[E0277]: the trait bound `DoesNotImplementTrait: main::a::Bar` is not satisfied
+ --> $DIR/same-crate-name.rs:38:20
+ |
+LL | a::try_foo(implements_no_traits);
+ | ^^^^^^^^^^^^^^^^^^^^ the trait `main::a::Bar` is not implemented for `DoesNotImplementTrait`
+ |
+ ::: $DIR/auxiliary/crate_a1.rs:3:24
+ |
+LL | pub fn try_foo(x: impl Bar) {}
+ | --- required by this bound in `try_foo`
+
+error[E0277]: the trait bound `ImplementsWrongTraitConditionally<isize>: main::a::Bar` is not satisfied
+ --> $DIR/same-crate-name.rs:45:20
+ |
+LL | a::try_foo(other_variant_implements_mismatched_trait);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `main::a::Bar` is not implemented for `ImplementsWrongTraitConditionally<isize>`
+ |
+ ::: $DIR/auxiliary/crate_a1.rs:3:24
+ |
+LL | pub fn try_foo(x: impl Bar) {}
+ | --- required by this bound in `try_foo`
+ |
+help: trait impl with same name found
+ --> $DIR/auxiliary/crate_a2.rs:13:1
+ |
+LL | impl Bar for ImplementsWrongTraitConditionally<isize> {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = note: perhaps two different versions of crate `crate_a2` are being used?
+
+error[E0277]: the trait bound `ImplementsTraitForUsize<isize>: main::a::Bar` is not satisfied
+ --> $DIR/same-crate-name.rs:51:20
+ |
+LL | a::try_foo(other_variant_implements_correct_trait);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `main::a::Bar` is not implemented for `ImplementsTraitForUsize<isize>`
+ |
+ ::: $DIR/auxiliary/crate_a1.rs:3:24
+ |
+LL | pub fn try_foo(x: impl Bar) {}
+ | --- required by this bound in `try_foo`
+ |
+ = help: the following implementations were found:
+ <ImplementsTraitForUsize<usize> as main::a::Bar>
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+// Tests for "default" bounds inferred for traits with no bounds list.
+
+trait Foo {}
+
+fn a(_x: Box<dyn Foo + Send>) {
+}
+
+fn b(_x: &'static (dyn Foo + 'static)) {
+}
+
+fn c(x: Box<dyn Foo + Sync>) {
+ a(x); //~ ERROR mismatched types
+}
+
+fn d(x: &'static (dyn Foo + Sync)) {
+ b(x);
+}
+
+fn main() {}
--- /dev/null
+error[E0308]: mismatched types
+ --> $DIR/sugar.rs:12:7
+ |
+LL | a(x);
+ | ^ expected trait `Foo + Send`, found trait `Foo + Sync`
+ |
+ = note: expected struct `Box<(dyn Foo + Send + 'static)>`
+ found struct `Box<(dyn Foo + Sync + 'static)>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
--- /dev/null
+// run-pass
+// Test that the cache results from the default method do not pollute
+// the cache for the later call in `load()`.
+//
+// See issue #18209.
+
+// pretty-expanded FIXME #23616
+
+pub trait Foo {
+ fn load_from() -> Box<Self>;
+ fn load() -> Box<Self> {
+ Foo::load_from()
+ }
+}
+
+pub fn load<M: Foo>() -> Box<M> {
+ Foo::load()
+}
+
+fn main() { }
+++ /dev/null
-// Check that we validate associated type bounds for trait objects
-
-trait X {
- type Y: Clone;
-}
-
-fn f<T: X + ?Sized>() {
- None::<T::Y>.clone();
-}
-
-fn main() {
- f::<dyn X<Y = str>>();
- //~^ ERROR the trait bound `str: Clone` is not satisfied
-}
+++ /dev/null
-error[E0277]: the trait bound `str: Clone` is not satisfied
- --> $DIR/check-trait-object-bounds-1.rs:12:5
- |
-LL | fn f<T: X + ?Sized>() {
- | - required by this bound in `f`
-...
-LL | f::<dyn X<Y = str>>();
- | ^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `str`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-// Make sure that we're handling bound lifetimes correctly when validating trait
-// bounds.
-// run-pass
-
-trait X<'a> {
- type F: FnOnce(&i32) -> &'a i32;
-}
-
-fn f<T: for<'r> X<'r> + ?Sized>() {
- None::<T::F>.map(|f| f(&0));
-}
-
-fn main() {
- f::<dyn for<'x> X<'x, F = fn(&i32) -> &'x i32>>();
-}
+++ /dev/null
-// Check that we validate associated type bounds for trait objects when they
-// have bound lifetimes
-
-trait X<'a> {
- type F: FnOnce(&i32) -> &'a i32;
-}
-
-fn f<T: for<'r> X<'r> + ?Sized>() {
- None::<T::F>.map(|f| f(&0));
-}
-
-fn main() {
- f::<dyn for<'x> X<'x, F = i32>>();
- //~^ expected a `FnOnce<(&i32,)>` closure, found `i32`
-}
+++ /dev/null
-error[E0277]: expected a `FnOnce<(&i32,)>` closure, found `i32`
- --> $DIR/check-trait-object-bounds-2.rs:13:5
- |
-LL | fn f<T: for<'r> X<'r> + ?Sized>() {
- | ------------- required by this bound in `f`
-...
-LL | f::<dyn for<'x> X<'x, F = i32>>();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an `FnOnce<(&i32,)>` closure, found `i32`
- |
- = help: the trait `for<'r> FnOnce<(&'r i32,)>` is not implemented for `i32`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-// Check that we validate associated type bounds for trait objects
-
-trait X<'a> {
- type Y: Into<&'static str> + From<&'a str>;
-}
-
-fn f<'a, T: X<'a> + ?Sized>(s: &'a str) -> &'static str {
- T::Y::from(s).into()
-}
-
-pub fn main() {
- let z;
- {
- let s = String::from("abcdef");
- z = f::<dyn X<Y = &str>>(&s);
- //~^ ERROR `s` does not live long enough
- }
-
- println!("{}", z)
-}
+++ /dev/null
-error[E0597]: `s` does not live long enough
- --> $DIR/check-trait-object-bounds-3.rs:15:34
- |
-LL | z = f::<dyn X<Y = &str>>(&s);
- | ---------------------^^-
- | | |
- | | borrowed value does not live long enough
- | argument requires that `s` is borrowed for `'static`
-LL |
-LL | }
- | - `s` dropped here while still borrowed
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0597`.
+++ /dev/null
-// Check that we validate associated type bounds on super traits for trait
-// objects
-
-trait Super {
- type Y: Clone;
-}
-
-trait X: Super {}
-
-fn f<T: X + ?Sized>() {
- None::<T::Y>.clone();
-}
-
-fn main() {
- f::<dyn X<Y = str>>();
- //~^ ERROR the trait bound `str: Clone` is not satisfied
-}
+++ /dev/null
-error[E0277]: the trait bound `str: Clone` is not satisfied
- --> $DIR/check-trait-object-bounds-4.rs:15:5
- |
-LL | fn f<T: X + ?Sized>() {
- | - required by this bound in `f`
-...
-LL | f::<dyn X<Y = str>>();
- | ^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `str`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-// Check that we validate associated type bounds on super traits for trait
-// objects
-
-trait Is {
- type T;
-}
-
-impl<U> Is for U {
- type T = U;
-}
-
-trait Super {
- type V;
-}
-
-trait Obj: Super {
- type U: Is<T = Self::V>;
-}
-
-fn is_obj<T: ?Sized + Obj>(_: &T) {}
-
-fn f(x: &dyn Obj<U = i32, V = i64>) {
- is_obj(x)
- //~^ type mismatch resolving `<i32 as Is>::T == i64`
-}
-
-fn main() {}
+++ /dev/null
-error[E0271]: type mismatch resolving `<i32 as Is>::T == i64`
- --> $DIR/check-trait-object-bounds-5.rs:23:5
- |
-LL | fn is_obj<T: ?Sized + Obj>(_: &T) {}
- | --- required by this bound in `is_obj`
-...
-LL | is_obj(x)
- | ^^^^^^ expected `i64`, found `i32`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0271`.
+++ /dev/null
-// Check that we validate associated type bounds on super traits for trait
-// objects
-
-trait Is {
- type T;
-}
-
-impl<U> Is for U {
- type T = U;
-}
-
-trait Obj {
- type U: Is<T = Self::V>;
- type V;
-}
-
-fn is_obj<T: ?Sized + Obj>(_: &T) {}
-
-fn f(x: &dyn Obj<U = i32, V = i64>) {
- is_obj(x)
- //~^ ERROR type mismatch resolving `<i32 as Is>::T == i64`
-}
-
-fn main() {}
+++ /dev/null
-error[E0271]: type mismatch resolving `<i32 as Is>::T == i64`
- --> $DIR/check-trait-object-bounds-6.rs:20:5
- |
-LL | fn is_obj<T: ?Sized + Obj>(_: &T) {}
- | --- required by this bound in `is_obj`
-...
-LL | is_obj(x)
- | ^^^^^^ expected `i64`, found `i32`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0271`.
--- /dev/null
+struct Struct {
+ person: &'static str
+}
+
+trait Trait<T> {
+ fn f(&self, x: T);
+}
+
+impl Trait<&'static str> for Struct {
+ fn f(&self, x: &'static str) {
+ println!("Hello, {}!", x);
+ }
+}
+
+fn main() {
+ let s: Box<dyn Trait<isize>> = Box::new(Struct { person: "Fred" });
+ //~^ ERROR `Struct: Trait<isize>` is not satisfied
+ s.f(1);
+}
--- /dev/null
+error[E0277]: the trait bound `Struct: Trait<isize>` is not satisfied
+ --> $DIR/coercion-generic-bad.rs:16:36
+ |
+LL | let s: Box<dyn Trait<isize>> = Box::new(Struct { person: "Fred" });
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait<isize>` is not implemented for `Struct`
+ |
+ = help: the following implementations were found:
+ <Struct as Trait<&'static str>>
+ = note: required for the cast to the object type `dyn Trait<isize>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+struct Struct {
+ person: &'static str
+}
+
+trait Trait<T> {
+ fn f(&self, x: T);
+}
+
+impl Trait<&'static str> for Struct {
+ fn f(&self, x: &'static str) {
+ println!("Hello, {}!", x);
+ }
+}
+
+fn main() {
+ let person = "Fred".to_string();
+ let person: &str = &person; //~ ERROR `person` does not live long enough
+ let s: Box<dyn Trait<&'static str>> = Box::new(Struct { person: person });
+}
--- /dev/null
+error[E0597]: `person` does not live long enough
+ --> $DIR/coercion-generic-regions.rs:17:24
+ |
+LL | let person: &str = &person;
+ | ^^^^^^^
+ | |
+ | borrowed value does not live long enough
+ | assignment requires that `person` is borrowed for `'static`
+LL | let s: Box<dyn Trait<&'static str>> = Box::new(Struct { person: person });
+LL | }
+ | - `person` dropped here while still borrowed
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0597`.
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+trait Trait<T> {
+ fn f(&self, x: T);
+}
+
+#[derive(Copy, Clone)]
+struct Struct {
+ x: isize,
+ y: isize,
+}
+
+impl Trait<&'static str> for Struct {
+ fn f(&self, x: &'static str) {
+ println!("Hi, {}!", x);
+ }
+}
+
+pub fn main() {
+ let a = Struct { x: 1, y: 2 };
+ let b: Box<dyn Trait<&'static str>> = Box::new(a);
+ b.f("Mary");
+ let c: &dyn Trait<&'static str> = &a;
+ c.f("Joe");
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+#![allow(unused_mut)]
+#![allow(unused_variables)]
+#![feature(box_syntax)]
+
+use std::io::{self, Write};
+
+trait Trait {
+ fn f(&self);
+}
+
+#[derive(Copy, Clone)]
+struct Struct {
+ x: isize,
+ y: isize,
+}
+
+impl Trait for Struct {
+ fn f(&self) {
+ println!("Hi!");
+ }
+}
+
+fn foo(mut a: Box<dyn Write>) {}
+
+pub fn main() {
+ let a = Struct { x: 1, y: 2 };
+ let b: Box<dyn Trait> = Box::new(a);
+ b.f();
+ let c: &dyn Trait = &a;
+ c.f();
+
+ let out = io::stdout();
+ foo(Box::new(out));
+}
--- /dev/null
+// run-pass
+// pretty-expanded FIXME #23616
+
+trait Foo {
+ fn foo(&self);
+}
+
+trait Bar : Foo {
+ fn bar(&self);
+}
+
+pub fn main() {}
--- /dev/null
+// run-pass
+// Test that we are able to resolve conditional dispatch. Here, the
+// blanket impl for T:Copy coexists with an impl for Box<T>, because
+// Box does not impl Copy.
+
+#![feature(box_syntax)]
+
+trait Get {
+ fn get(&self) -> Self;
+}
+
+trait MyCopy { fn copy(&self) -> Self; }
+impl MyCopy for u16 { fn copy(&self) -> Self { *self } }
+impl MyCopy for u32 { fn copy(&self) -> Self { *self } }
+impl MyCopy for i32 { fn copy(&self) -> Self { *self } }
+impl<T:Copy> MyCopy for Option<T> { fn copy(&self) -> Self { *self } }
+
+impl<T:MyCopy> Get for T {
+ fn get(&self) -> T { self.copy() }
+}
+
+impl Get for Box<i32> {
+ fn get(&self) -> Box<i32> { box get_it(&**self) }
+}
+
+fn get_it<T:Get>(t: &T) -> T {
+ (*t).get()
+}
+
+fn main() {
+ assert_eq!(get_it(&1_u32), 1_u32);
+ assert_eq!(get_it(&1_u16), 1_u16);
+ assert_eq!(get_it(&Some(1_u16)), Some(1_u16));
+ assert_eq!(get_it(&Box::new(1)), Box::new(1));
+}
--- /dev/null
+// run-pass
+#![allow(unused_imports)]
+// A model for how the `Fn` traits could work. You can implement at
+// most one of `Go`, `GoMut`, or `GoOnce`, and then the others follow
+// automatically.
+
+// aux-build:go_trait.rs
+
+extern crate go_trait;
+
+use go_trait::{Go, GoMut, GoOnce, go, go_mut, go_once};
+
+use std::rc::Rc;
+use std::cell::Cell;
+
+struct SomeGoableThing {
+ counter: Rc<Cell<isize>>
+}
+
+impl Go for SomeGoableThing {
+ fn go(&self, arg: isize) {
+ self.counter.set(self.counter.get() + arg);
+ }
+}
+
+struct SomeGoOnceableThing {
+ counter: Rc<Cell<isize>>
+}
+
+impl GoOnce for SomeGoOnceableThing {
+ fn go_once(self, arg: isize) {
+ self.counter.set(self.counter.get() + arg);
+ }
+}
+
+fn main() {
+ let counter = Rc::new(Cell::new(0));
+ let mut x = SomeGoableThing { counter: counter.clone() };
+
+ go(&x, 10);
+ assert_eq!(counter.get(), 10);
+
+ go_mut(&mut x, 100);
+ assert_eq!(counter.get(), 110);
+
+ go_once(x, 1_000);
+ assert_eq!(counter.get(), 1_110);
+
+ let x = SomeGoOnceableThing { counter: counter.clone() };
+
+ go_once(x, 10_000);
+ assert_eq!(counter.get(), 11_110);
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+// "guessing" in trait selection can affect `copy_or_move`. Check that this
+// is correctly handled. I am not sure what is the "correct" behaviour,
+// but we should at least not ICE.
+
+use std::mem;
+
+struct U([u8; 1337]);
+
+struct S<'a,T:'a>(&'a T);
+impl<'a, T> Clone for S<'a, T> { fn clone(&self) -> Self { S(self.0) } }
+/// This impl triggers inference "guessing" - S<_>: Copy => _ = U
+impl<'a> Copy for S<'a, Option<U>> {}
+
+fn assert_impls_fn<R,T: Fn()->R>(_: &T){}
+
+fn main() {
+ let n = None;
+ let e = S(&n);
+ let f = || {
+ // S being copy is critical for this to work
+ drop(e);
+ mem::size_of_val(e.0)
+ };
+ assert_impls_fn(&f);
+ assert_eq!(f(), 1337+1);
+
+ assert_eq!((|| {
+ // S being Copy is not critical here, but
+ // we check it anyway.
+ let n = None;
+ let e = S(&n);
+ let ret = mem::size_of_val(e.0);
+ drop(e);
+ ret
+ })(), 1337+1);
+}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-// Test a case where a supertrait references a type that references
-// the original trait. This poses no problem at the moment.
-
-// pretty-expanded FIXME #23616
-
-trait Chromosome: Get<Struct<i32>> {
-}
-
-trait Get<A> {
- fn get(&self) -> A;
-}
-
-struct Struct<C:Chromosome> { c: C }
-
-impl Chromosome for i32 { }
-
-impl Get<Struct<i32>> for i32 {
- fn get(&self) -> Struct<i32> {
- Struct { c: *self }
- }
-}
-
-fn main() { }
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+// Test a case where a supertrait references a type that references
+// the original trait. This poses no problem at the moment.
+
+// pretty-expanded FIXME #23616
+
+trait Chromosome: Get<Struct<i32>> {
+}
+
+trait Get<A> {
+ fn get(&self) -> A;
+}
+
+struct Struct<C:Chromosome> { c: C }
+
+impl Chromosome for i32 { }
+
+impl Get<Struct<i32>> for i32 {
+ fn get(&self) -> Struct<i32> {
+ Struct { c: *self }
+ }
+}
+
+fn main() { }
+++ /dev/null
-// run-pass
-
-
-// Tests that we can call a function bounded over a supertrait from
-// a default method
-
-fn require_y<T: Y>(x: T) -> isize { x.y() }
-
-trait Y {
- fn y(self) -> isize;
-}
-
-
-trait Z: Y + Sized {
- fn x(self) -> isize {
- require_y(self)
- }
-}
-
-impl Y for isize {
- fn y(self) -> isize { self }
-}
-
-impl Z for isize {}
-
-pub fn main() {
- assert_eq!(12.x(), 12);
-}
--- /dev/null
+pub struct Something { pub x: isize }
+
+pub trait A {
+ fn f(&self) -> isize;
+ fn g(&self) -> isize { 10 }
+ fn h(&self) -> isize { 11 }
+ fn lurr(x: &Self, y: &Self) -> isize { x.g() + y.h() }
+}
+
+
+impl A for isize {
+ fn f(&self) -> isize { 10 }
+}
+
+impl A for Something {
+ fn f(&self) -> isize { 10 }
+}
+
+pub trait B<T> {
+ fn thing<U>(&self, x: T, y: U) -> (T, U) { (x, y) }
+ fn staticthing<U>(_z: &Self, x: T, y: U) -> (T, U) { (x, y) }
+}
+
+impl<T> B<T> for isize { }
+impl B<f64> for bool { }
+
+
+
+pub trait TestEquality {
+ fn test_eq(&self, rhs: &Self) -> bool;
+ fn test_neq(&self, rhs: &Self) -> bool {
+ !self.test_eq(rhs)
+ }
+}
+
+impl TestEquality for isize {
+ fn test_eq(&self, rhs: &isize) -> bool {
+ *self == *rhs
+ }
+}
--- /dev/null
+// aux-build:xc.rs
+
+extern crate xc as aux;
+use aux::A;
+
+pub struct a_struct { pub x: isize }
+
+impl A for a_struct {
+ fn f(&self) -> isize { 10 }
+}
+
+// This function will need to get inlined, and badness may result.
+pub fn welp<A>(x: A) -> A {
+ let a = a_struct { x: 0 };
+ a.g();
+ x
+}
--- /dev/null
+// run-pass
+
+
+trait A<T> {
+ fn g<U>(&self, x: T, y: U) -> (T, U) { (x, y) }
+}
+
+impl A<i32> for i32 { }
+impl<T> A<T> for u32 { }
+
+fn f<T, U, V: A<T>>(i: V, j: T, k: U) -> (T, U) {
+ i.g(j, k)
+}
+
+pub fn main () {
+ assert_eq!(f(0, 1, 2), (1, 2));
+ assert_eq!(f(0, 1, 2), (1, 2));
+}
--- /dev/null
+// run-pass
+
+
+trait A<T> {
+ fn g(&self, x: T) -> T { x }
+}
+
+impl A<isize> for isize { }
+
+fn f<T, V: A<T>>(i: V, j: T) -> T {
+ i.g(j)
+}
+
+pub fn main () {
+ assert_eq!(f(0, 2), 2);
+}
--- /dev/null
+// run-pass
+
+
+trait A {
+ fn g<T>(&self, x: T, y: T) -> (T, T) { (x, y) }
+}
+
+impl A for isize { }
+
+fn f<T, V: A>(i: V, j: T, k: T) -> (T, T) {
+ i.g(j, k)
+}
+
+pub fn main () {
+ assert_eq!(f(0, 1, 2), (1, 2));
+ assert_eq!(f(0, 1u8, 2u8), (1u8, 2u8));
+}
--- /dev/null
+// run-pass
+#![allow(unused_variables)]
+
+
+trait A<T> {
+ fn g(&self, x: usize) -> usize { x }
+ fn h(&self, x: T) { }
+}
+
+impl<T> A<T> for isize { }
+
+fn f<T, V: A<T>>(i: V, j: usize) -> usize {
+ i.g(j)
+}
+
+pub fn main () {
+ assert_eq!(f::<f64, isize>(0, 2), 2);
+ assert_eq!(f::<usize, isize>(0, 2), 2);
+}
--- /dev/null
+// run-pass
+
+
+trait A {
+ fn g(&self) -> isize { 10 }
+}
+
+impl A for isize { }
+
+fn f<T:A>(i: T) {
+ assert_eq!(i.g(), 10);
+}
+
+pub fn main () {
+ f(0);
+}
--- /dev/null
+// run-pass
+
+
+trait Foo {
+ fn bar(&self) -> String {
+ format!("test")
+ }
+}
+
+enum Baz {
+ Quux
+}
+
+impl Foo for Baz {
+}
+
+pub fn main() {
+ let q = Baz::Quux;
+ assert_eq!(q.bar(), "test".to_string());
+}
--- /dev/null
+// run-pass
+#![allow(unused_assignments)]
+// pretty-expanded FIXME #23616
+
+#![allow(unused_variables)]
+
+trait Foo {
+ fn foo(&self, mut v: isize) { v = 1; }
+}
+
+pub fn main() {}
--- /dev/null
+// run-pass
+
+
+trait Cat {
+ fn meow(&self) -> bool;
+ fn scratch(&self) -> bool { self.purr() }
+ fn purr(&self) -> bool { true }
+}
+
+impl Cat for isize {
+ fn meow(&self) -> bool {
+ self.scratch()
+ }
+}
+
+pub fn main() {
+ assert!(5.meow());
+}
--- /dev/null
+// run-pass
+
+
+// Tests that we can call a function bounded over a supertrait from
+// a default method
+
+fn require_y<T: Y>(x: T) -> isize { x.y() }
+
+trait Y {
+ fn y(self) -> isize;
+}
+
+
+trait Z: Y + Sized {
+ fn x(self) -> isize {
+ require_y(self)
+ }
+}
+
+impl Y for isize {
+ fn y(self) -> isize { self }
+}
+
+impl Z for isize {}
+
+pub fn main() {
+ assert_eq!(12.x(), 12);
+}
--- /dev/null
+// run-pass
+
+
+trait Cat {
+ fn meow(&self) -> bool;
+ fn scratch(&self) -> bool;
+ fn purr(&self) -> bool { true }
+}
+
+impl Cat for isize {
+ fn meow(&self) -> bool {
+ self.scratch()
+ }
+ fn scratch(&self) -> bool {
+ self.purr()
+ }
+}
+
+pub fn main() {
+ assert!(5.meow());
+}
--- /dev/null
+// run-pass
+// aux-build:xc.rs
+// aux-build:xc_2.rs
+
+
+
+extern crate xc as aux;
+extern crate xc_2 as aux2;
+use aux::A;
+use aux2::{a_struct, welp};
+
+
+pub fn main () {
+
+ let a = a_struct { x: 0 };
+ let b = a_struct { x: 1 };
+
+ assert_eq!(0.g(), 10);
+ assert_eq!(a.g(), 10);
+ assert_eq!(a.h(), 11);
+ assert_eq!(b.g(), 10);
+ assert_eq!(b.h(), 11);
+ assert_eq!(A::lurr(&a, &b), 21);
+
+ welp(&0);
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+#![allow(non_camel_case_types)]
+
+// aux-build:xc.rs
+
+
+extern crate xc as aux;
+use aux::{A, TestEquality, Something};
+use aux::B;
+
+fn f<T: aux::A>(i: T) {
+ assert_eq!(i.g(), 10);
+}
+
+fn welp<T>(i: isize, _x: &T) -> isize {
+ i.g()
+}
+
+mod stuff {
+ pub struct thing { pub x: isize }
+}
+
+impl A for stuff::thing {
+ fn f(&self) -> isize { 10 }
+}
+
+fn g<T, U, V: B<T>>(i: V, j: T, k: U) -> (T, U) {
+ i.thing(j, k)
+}
+
+fn eq<T: TestEquality>(lhs: &T, rhs: &T) -> bool {
+ lhs.test_eq(rhs)
+}
+fn neq<T: TestEquality>(lhs: &T, rhs: &T) -> bool {
+ lhs.test_neq(rhs)
+}
+
+
+impl TestEquality for stuff::thing {
+ fn test_eq(&self, rhs: &stuff::thing) -> bool {
+ //self.x.test_eq(&rhs.x)
+ eq(&self.x, &rhs.x)
+ }
+}
+
+
+pub fn main() {
+ // Some tests of random things
+ f(0);
+
+ assert_eq!(A::lurr(&0, &1), 21);
+
+ let a = stuff::thing { x: 0 };
+ let b = stuff::thing { x: 1 };
+ let c = Something { x: 1 };
+
+ assert_eq!(0.g(), 10);
+ assert_eq!(a.g(), 10);
+ assert_eq!(a.h(), 11);
+ assert_eq!(c.h(), 11);
+
+ assert_eq!(0.thing(3.14f64, 1), (3.14f64, 1));
+ assert_eq!(B::staticthing(&0, 3.14f64, 1), (3.14f64, 1));
+ assert_eq!(B::<f64>::staticthing::<isize>(&0, 3.14, 1), (3.14, 1));
+
+ assert_eq!(g(0, 3.14f64, 1), (3.14f64, 1));
+ assert_eq!(g(false, 3.14f64, 1), (3.14, 1));
+
+
+ // Trying out a real one
+ assert!(12.test_neq(&10));
+ assert!(!10.test_neq(&10));
+ assert!(a.test_neq(&b));
+ assert!(!a.test_neq(&a));
+
+ assert!(neq(&12, &10));
+ assert!(!neq(&10, &10));
+ assert!(neq(&a, &b));
+ assert!(!neq(&a, &a));
+}
--- /dev/null
+trait Foo {
+ fn orange(&self);
+ fn orange(&self); //~ ERROR the name `orange` is defined multiple times
+}
+
+fn main() {}
--- /dev/null
+error[E0428]: the name `orange` is defined multiple times
+ --> $DIR/duplicate-methods.rs:3:5
+ |
+LL | fn orange(&self);
+ | ----------------- previous definition of the value `orange` here
+LL | fn orange(&self);
+ | ^^^^^^^^^^^^^^^^^ `orange` redefined here
+ |
+ = note: `orange` must be defined only once in the value namespace of this trait
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0428`.
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+
+// Test that we elaborate `Type: 'region` constraints and infer various important things.
+
+trait Master<'a, T: ?Sized> {
+ fn foo() where T: 'a;
+}
+
+// [U]: 'a => U: 'a
+impl<'a, U> Master<'a, [U]> for () {
+ fn foo() where U: 'a { }
+}
+
+// &'b U: 'a => 'b: 'a, U: 'a
+impl<'a, 'b, U> Master<'a, &'b U> for () {
+ fn foo() where 'b: 'a, U: 'a { }
+}
+
+// &'b [U]: 'a => 'b: 'a, U: 'a
+impl<'a, 'b, U> Master<'a, &'b [U]> for () {
+ fn foo() where 'b: 'a, U: 'a { }
+}
+
+// Foo<'b>: 'a => 'b: 'a
+struct Foo<'a> { x: &'a () }
+impl<'a, 'b> Master<'a, Foo<'b>> for () {
+ fn foo() where 'b: 'a { }
+}
+
+// Bar<'b, T>: 'a => 'b: 'a, T: 'a
+struct Bar<'a, T: 'a> { x: &'a T }
+impl<'a, 'b, T> Master<'a, Bar<'b, T>> for () {
+ fn foo() where 'b: 'a, T: 'a { }
+}
+
+// fn(T): 'a => T: 'a
+impl<'a, T> Master<'a, fn(T)> for () {
+ fn foo() where T: 'a { }
+}
+
+// fn() -> T: 'a => T: 'a
+impl<'a, T> Master<'a, fn() -> T> for () {
+ fn foo() where T: 'a { }
+}
+
+fn main() {
+ println!("Hello, world!");
+}
--- /dev/null
+// run-pass
+// Test that we do not error out because of a (False) ambiguity
+// between the builtin rules for Sized and the where clause. Issue
+// #20959.
+
+// pretty-expanded FIXME #23616
+
+fn foo<K>(x: Option<K>)
+ where Option<K> : Sized
+{
+ let _y = x;
+}
+
+fn main() {
+ foo(Some(22));
+}
--- /dev/null
+// run-pass
+#![allow(non_camel_case_types)]
+
+
+
+trait to_str {
+ fn to_string_(&self) -> String;
+}
+impl to_str for isize {
+ fn to_string_(&self) -> String { self.to_string() }
+}
+impl to_str for String {
+ fn to_string_(&self) -> String { self.clone() }
+}
+impl to_str for () {
+ fn to_string_(&self) -> String { "()".to_string() }
+}
+
+trait map<T> {
+ fn map<U, F>(&self, f: F) -> Vec<U> where F: FnMut(&T) -> U;
+}
+impl<T> map<T> for Vec<T> {
+ fn map<U, F>(&self, mut f: F) -> Vec<U> where F: FnMut(&T) -> U {
+ let mut r = Vec::new();
+ for i in self {
+ r.push(f(i));
+ }
+ r
+ }
+}
+
+fn foo<U, T: map<U>>(x: T) -> Vec<String> {
+ x.map(|_e| "hi".to_string() )
+}
+fn bar<U:to_str,T:map<U>>(x: T) -> Vec<String> {
+ x.map(|_e| _e.to_string_() )
+}
+
+pub fn main() {
+ assert_eq!(foo(vec![1]), ["hi".to_string()]);
+ assert_eq!(bar::<isize, Vec<isize> >(vec![4, 5]), ["4".to_string(), "5".to_string()]);
+ assert_eq!(bar::<String, Vec<String> >(vec!["x".to_string(), "y".to_string()]),
+ ["x".to_string(), "y".to_string()]);
+ assert_eq!(bar::<(), Vec<()>>(vec![()]), ["()".to_string()]);
+}
--- /dev/null
+// Test calling methods on an impl for a bare trait. This test checks that the
+// trait impl is only applied to a trait object, not concrete types which implement
+// the trait.
+
+trait T {}
+
+impl<'a> dyn T + 'a {
+ fn foo(&self) {}
+}
+
+impl T for i32 {}
+
+fn main() {
+ let x = &42i32;
+ x.foo(); //~ERROR: no method named `foo` found
+}
--- /dev/null
+error[E0599]: no method named `foo` found for reference `&i32` in the current scope
+ --> $DIR/impl-1.rs:15:7
+ |
+LL | x.foo();
+ | ^^^ method not found in `&i32`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0599`.
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+#![allow(non_snake_case)]
+
+// pretty-expanded FIXME #23616
+
+pub mod Foo {
+ pub trait Trait {
+ fn foo(&self);
+ }
+}
+
+mod Bar {
+ impl<'a> dyn (::Foo::Trait) + 'a {
+ fn bar(&self) { self.foo() }
+ }
+}
+
+fn main() {}
--- /dev/null
+trait A { }
+
+impl A for isize {
+ const BAR: () = (); //~ ERROR const `BAR` is not a member of trait `A`
+ type Baz = (); //~ ERROR type `Baz` is not a member of trait `A`
+ fn foo(&self) { } //~ ERROR method `foo` is not a member of trait `A`
+}
+
+fn main() { }
--- /dev/null
+error[E0438]: const `BAR` is not a member of trait `A`
+ --> $DIR/impl-can-not-have-untraitful-items.rs:4:5
+ |
+LL | const BAR: () = ();
+ | ^^^^^^^^^^^^^^^^^^^ not a member of trait `A`
+
+error[E0437]: type `Baz` is not a member of trait `A`
+ --> $DIR/impl-can-not-have-untraitful-items.rs:5:5
+ |
+LL | type Baz = ();
+ | ^^^^^^^^^^^^^^ not a member of trait `A`
+
+error[E0407]: method `foo` is not a member of trait `A`
+ --> $DIR/impl-can-not-have-untraitful-items.rs:6:5
+ |
+LL | fn foo(&self) { }
+ | ^^^^^^^^^^^^^^^^^ not a member of trait `A`
+
+error: aborting due to 3 previous errors
+
+Some errors have detailed explanations: E0407, E0437, E0438.
+For more information about an error, try `rustc --explain E0407`.
--- /dev/null
+trait Foo {
+ fn bar(&self, x: usize) -> Self;
+}
+impl Foo for isize {
+ fn bar(&self) -> isize {
+ //~^ ERROR method `bar` has 1 parameter but the declaration in trait `Foo::bar` has 2
+ *self
+ }
+}
+
+fn main() {
+}
--- /dev/null
+error[E0050]: method `bar` has 1 parameter but the declaration in trait `Foo::bar` has 2
+ --> $DIR/impl-different-num-params.rs:5:12
+ |
+LL | fn bar(&self, x: usize) -> Self;
+ | --------------- trait requires 2 parameters
+...
+LL | fn bar(&self) -> isize {
+ | ^^^^^ expected 2 parameters, found 1
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0050`.
--- /dev/null
+mod a {
+}
+
+trait A {
+}
+
+impl A for a { //~ ERROR expected type, found module
+}
+
+fn main() {
+}
--- /dev/null
+error[E0573]: expected type, found module `a`
+ --> $DIR/impl-for-module.rs:7:12
+ |
+LL | trait A {
+ | ------- similarly named trait `A` defined here
+...
+LL | impl A for a {
+ | ^ help: a trait with a similar name exists: `A`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0573`.
--- /dev/null
+trait Mumbo {
+ fn jumbo(&self, x: &usize) -> usize;
+}
+
+impl Mumbo for usize {
+ // Cannot have a larger effect than the trait:
+ unsafe fn jumbo(&self, x: &usize) { *self + *x; }
+ //~^ ERROR method `jumbo` has an incompatible type for trait
+ //~| expected fn pointer `fn
+ //~| found fn pointer `unsafe fn
+}
+
+fn main() {}
--- /dev/null
+error[E0053]: method `jumbo` has an incompatible type for trait
+ --> $DIR/impl-method-mismatch.rs:7:5
+ |
+LL | fn jumbo(&self, x: &usize) -> usize;
+ | ------------------------------------ type in trait
+...
+LL | unsafe fn jumbo(&self, x: &usize) { *self + *x; }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected normal fn, found unsafe fn
+ |
+ = note: expected fn pointer `fn(&usize, &usize) -> usize`
+ found fn pointer `unsafe fn(&usize, &usize)`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0053`.
--- /dev/null
+// run-pass
+// Test that we are able to compile the case where both a blanket impl
+// and the object type itself supply the required trait obligation.
+// In this case, the blanket impl for `Foo` applies to any type,
+// including `Bar`, but the object type `Bar` also implicitly supplies
+// this context.
+
+trait Foo { fn dummy(&self) { } }
+
+trait Bar: Foo { }
+
+impl<T:?Sized> Foo for T { }
+
+fn want_foo<B:?Sized+Foo>() { }
+
+fn main() {
+ want_foo::<dyn Bar>();
+}
--- /dev/null
+// Check that when we test the supertrait we ensure consistent use of
+// lifetime parameters. In this case, implementing T2<'a,'b> requires
+// an impl of T1<'a>, but we have an impl of T1<'b>.
+
+trait T1<'x> {
+ fn x(&self) -> &'x isize;
+}
+
+trait T2<'x, 'y> : T1<'x> {
+ fn y(&self) -> &'y isize;
+}
+
+struct S<'a, 'b> {
+ a: &'a isize,
+ b: &'b isize
+}
+
+impl<'a,'b> T1<'b> for S<'a, 'b> {
+ fn x(&self) -> &'b isize {
+ self.b
+ }
+}
+
+impl<'a,'b> T2<'a, 'b> for S<'a, 'b> { //~ ERROR cannot infer an appropriate lifetime
+ fn y(&self) -> &'b isize {
+ self.b
+ }
+}
+
+pub fn main() {
+}
--- /dev/null
+error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'b` due to conflicting requirements
+ --> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:13
+ |
+LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> {
+ | ^^^^^^^^^^
+ |
+note: first, the lifetime cannot outlive the lifetime `'a` as defined on the impl at 24:6...
+ --> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:6
+ |
+LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> {
+ | ^^
+note: ...but the lifetime must also be valid for the lifetime `'b` as defined on the impl at 24:9...
+ --> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:9
+ |
+LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> {
+ | ^^
+note: ...so that the types are compatible
+ --> $DIR/impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:13
+ |
+LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> {
+ | ^^^^^^^^^^
+ = note: expected `T1<'a>`
+ found `T1<'_>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0495`.
--- /dev/null
+// run-pass
+// Test calling methods on an impl for a bare trait.
+
+// aux-build:traitimpl.rs
+
+extern crate traitimpl;
+use traitimpl::Bar;
+
+static mut COUNT: usize = 1;
+
+trait T {
+ fn t(&self) {}
+}
+
+impl<'a> dyn T+'a {
+ fn foo(&self) {
+ unsafe { COUNT *= 2; }
+ }
+ fn bar() {
+ unsafe { COUNT *= 3; }
+ }
+}
+
+impl T for isize {}
+
+struct Foo;
+impl<'a> Bar<'a> for Foo {}
+
+fn main() {
+ let x: &dyn T = &42;
+
+ x.foo();
+ T::foo(x);
+ T::bar();
+
+ unsafe { assert_eq!(COUNT, 12); }
+
+ // Cross-crait case
+ let x: &dyn Bar = &Foo;
+ x.bar();
+}
--- /dev/null
+// Test that we don't hit the recursion limit for short cycles involving lifetimes.
+
+// Shouldn't hit this, we should realize that we're in a cycle sooner.
+#![recursion_limit="20"]
+
+trait NotAuto {}
+trait Y {
+ type P;
+}
+
+impl<'a> Y for C<'a> {
+ type P = Box<X<C<'a>>>;
+}
+
+struct C<'a>(&'a ());
+struct X<T: Y>(T::P);
+
+impl<T: NotAuto> NotAuto for Box<T> {}
+impl<T: Y> NotAuto for X<T> where T::P: NotAuto {}
+impl<'a> NotAuto for C<'a> {}
+
+fn is_send<S: NotAuto>() {}
+//~^ NOTE: required
+
+fn main() {
+ // Should only be a few notes.
+ is_send::<X<C<'static>>>();
+ //~^ ERROR overflow evaluating
+ //~| NOTE: required
+}
--- /dev/null
+error[E0275]: overflow evaluating the requirement `Box<X<C<'_>>>: NotAuto`
+ --> $DIR/lifetime.rs:27:5
+ |
+LL | fn is_send<S: NotAuto>() {}
+ | ------- required by this bound in `is_send`
+...
+LL | is_send::<X<C<'static>>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: required because of the requirements on the impl of `NotAuto` for `X<C<'static>>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0275`.
--- /dev/null
+// Regression test for #33344, initial version. This example allowed
+// arbitrary trait bounds to be synthesized.
+
+trait Tweedledum: IntoIterator {}
+trait Tweedledee: IntoIterator {}
+
+impl<T: Tweedledum> Tweedledee for T {}
+impl<T: Tweedledee> Tweedledum for T {}
+
+trait Combo: IntoIterator {}
+impl<T: Tweedledee + Tweedledum> Combo for T {}
+
+fn is_ee<T: Combo>(t: T) {
+ t.into_iter();
+}
+
+fn main() {
+ is_ee(4);
+ //~^ ERROR overflow evaluating the requirement `{integer}: Tweedle
+}
--- /dev/null
+error[E0275]: overflow evaluating the requirement `{integer}: Tweedledum`
+ --> $DIR/simultaneous.rs:18:5
+ |
+LL | fn is_ee<T: Combo>(t: T) {
+ | ----- required by this bound in `is_ee`
+...
+LL | is_ee(4);
+ | ^^^^^
+ |
+ = note: required because of the requirements on the impl of `Combo` for `{integer}`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0275`.
--- /dev/null
+// Auto-trait-based version of #29859, supertrait version. Test that using
+// a simple auto trait `..` impl alone still doesn't allow arbitrary bounds
+// to be synthesized.
+
+#![feature(auto_traits)]
+#![feature(negative_impls)]
+
+auto trait Magic: Copy {} //~ ERROR E0568
+
+fn copy<T: Magic>(x: T) -> (T, T) { (x, x) }
+
+#[derive(Debug)]
+struct NoClone;
+
+fn main() {
+ let (a, b) = copy(NoClone); //~ ERROR
+ println!("{:?} {:?}", a, b);
+}
--- /dev/null
+error[E0568]: auto traits cannot have super traits
+ --> $DIR/supertrait-auto-trait.rs:8:19
+ |
+LL | auto trait Magic: Copy {}
+ | ----- ^^^^ help: remove the super traits
+ | |
+ | auto trait cannot have super traits
+
+error[E0277]: the trait bound `NoClone: Copy` is not satisfied
+ --> $DIR/supertrait-auto-trait.rs:16:23
+ |
+LL | fn copy<T: Magic>(x: T) -> (T, T) { (x, x) }
+ | ----- required by this bound in `copy`
+...
+LL | let (a, b) = copy(NoClone);
+ | ^^^^^^^ the trait `Copy` is not implemented for `NoClone`
+ |
+ = note: required because of the requirements on the impl of `Magic` for `NoClone`
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0277, E0568.
+For more information about an error, try `rustc --explain E0277`.
--- /dev/null
+// Regression test for #29859, supertrait version. This example
+// allowed arbitrary trait bounds to be synthesized.
+
+trait Magic: Copy {}
+impl<T: Magic> Magic for T {}
+
+fn copy<T: Magic>(x: T) -> (T, T) { (x, x) }
+
+#[derive(Debug)]
+struct NoClone;
+
+fn main() {
+ let (a, b) = copy(NoClone); //~ ERROR E0275
+ println!("{:?} {:?}", a, b);
+}
--- /dev/null
+error[E0275]: overflow evaluating the requirement `NoClone: Magic`
+ --> $DIR/supertrait.rs:13:18
+ |
+LL | fn copy<T: Magic>(x: T) -> (T, T) { (x, x) }
+ | ----- required by this bound in `copy`
+...
+LL | let (a, b) = copy(NoClone);
+ | ^^^^
+ |
+ = note: required because of the requirements on the impl of `Magic` for `NoClone`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0275`.
--- /dev/null
+// Regression test for #29859, initial version. This example allowed
+// arbitrary trait bounds to be synthesized.
+
+// Trait that you want all types to implement.
+use std::marker::{Sync as Trait};
+
+pub trait Magic {
+ type X: Trait;
+}
+impl<T: Magic> Magic for T {
+ type X = Self;
+ //~^ ERROR E0277
+}
+
+fn check<T: Trait>() {}
+
+fn wizard<T: Magic>() { check::<<T as Magic>::X>(); }
+
+fn main() {
+ wizard::<*mut ()>(); //~ ERROR E0275
+ // check::<*mut ()>();
+}
--- /dev/null
+error[E0277]: `T` cannot be shared between threads safely
+ --> $DIR/two-traits.rs:11:5
+ |
+LL | type X: Trait;
+ | ----- required by this bound in `Magic::X`
+...
+LL | type X = Self;
+ | ^^^^^^^^^^^^^^ `T` cannot be shared between threads safely
+ |
+help: consider further restricting this bound
+ |
+LL | impl<T: Magic + Sync> Magic for T {
+ | ^^^^^^
+
+error[E0275]: overflow evaluating the requirement `*mut (): Magic`
+ --> $DIR/two-traits.rs:20:5
+ |
+LL | fn wizard<T: Magic>() { check::<<T as Magic>::X>(); }
+ | ----- required by this bound in `wizard`
+...
+LL | wizard::<*mut ()>();
+ | ^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0275, E0277.
+For more information about an error, try `rustc --explain E0275`.
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+#![allow(unused_variables)]
+// Test that when we match a trait reference like `Foo<A>: Foo<_#0t>`,
+// we unify with `_#0t` with `A`. In this code, if we failed to do
+// that, then you get an unconstrained type-variable in `call`.
+//
+// Also serves as a regression test for issue #26952, though the test
+// was derived from another reported regression with the same cause.
+
+use std::marker::PhantomData;
+
+trait Trait<A> { fn foo(&self); }
+
+struct Type<A> { a: PhantomData<A> }
+
+fn as_trait<A>(t: &Type<A>) -> &dyn Trait<A> { loop { } }
+
+fn want<A,T:Trait<A>+?Sized>(t: &T) { }
+
+fn call<A>(p: Type<A>) {
+ let q = as_trait(&p);
+ want(q); // parameter A to `want` *would* be unconstrained
+}
+
+fn main() { }
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-#![allow(unused_variables)]
-// Test that when we match a trait reference like `Foo<A>: Foo<_#0t>`,
-// we unify with `_#0t` with `A`. In this code, if we failed to do
-// that, then you get an unconstrained type-variable in `call`.
-//
-// Also serves as a regression test for issue #26952, though the test
-// was derived from another reported regression with the same cause.
-
-use std::marker::PhantomData;
-
-trait Trait<A> { fn foo(&self); }
-
-struct Type<A> { a: PhantomData<A> }
-
-fn as_trait<A>(t: &Type<A>) -> &dyn Trait<A> { loop { } }
-
-fn want<A,T:Trait<A>+?Sized>(t: &T) { }
-
-fn call<A>(p: Type<A>) {
- let q = as_trait(&p);
- want(q); // parameter A to `want` *would* be unconstrained
-}
-
-fn main() { }
--- /dev/null
+// run-pass
+
+struct Foo;
+
+impl Foo {
+ #[allow(dead_code)]
+ fn foo(self) {
+ panic!("wrong method!")
+ }
+}
+
+trait Trait {
+ fn foo(self);
+}
+
+impl<'a,'b,'c> Trait for &'a &'b &'c Foo {
+ fn foo(self) {
+ // ok
+ }
+}
+
+fn main() {
+ let x = &(&(&Foo));
+ x.foo();
+}
+++ /dev/null
-// run-pass
-
-struct Foo;
-
-impl Foo {
- #[allow(dead_code)]
- fn foo(self) {
- panic!("wrong method!")
- }
-}
-
-trait Trait {
- fn foo(self);
-}
-
-impl<'a,'b,'c> Trait for &'a &'b &'c Foo {
- fn foo(self) {
- // ok
- }
-}
-
-fn main() {
- let x = &(&(&Foo));
- x.foo();
-}
--- /dev/null
+// run-pass
+// aux-build:auto_xc_2.rs
+
+
+extern crate auto_xc_2 as aux;
+
+// aux defines impls of Foo, Bar and Baz for A
+use aux::{Foo, Bar, Baz, A};
+
+// We want to extend all Foo, Bar, Bazes to Quuxes
+pub trait Quux: Foo + Bar + Baz { }
+impl<T:Foo + Bar + Baz> Quux for T { }
+
+fn f<T:Quux>(a: &T) {
+ assert_eq!(a.f(), 10);
+ assert_eq!(a.g(), 20);
+ assert_eq!(a.h(), 30);
+}
+
+pub fn main() {
+ let a = &A { x: 3 };
+ f(a);
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+// aux-build:auto_xc.rs
+
+
+extern crate auto_xc as aux;
+
+use aux::{Foo, Bar, Baz, Quux};
+
+struct A { x: isize }
+
+impl Foo for A { fn f(&self) -> isize { 10 } }
+impl Bar for A { fn g(&self) -> isize { 20 } }
+impl Baz for A { fn h(&self) -> isize { 30 } }
+
+fn f<T:Quux>(a: &T) {
+ assert_eq!(a.f(), 10);
+ assert_eq!(a.g(), 20);
+ assert_eq!(a.h(), 30);
+}
+
+pub fn main() {
+ let a = &A { x: 3 };
+ f(a);
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+// Testing that this impl turns A into a Quux, because
+// A is already a Foo Bar Baz
+
+impl<T:Foo + Bar + Baz> Quux for T { }
+
+trait Foo { fn f(&self) -> isize; }
+trait Bar { fn g(&self) -> isize; }
+trait Baz { fn h(&self) -> isize; }
+
+trait Quux: Foo + Bar + Baz { }
+
+struct A { x: isize }
+
+impl Foo for A { fn f(&self) -> isize { 10 } }
+impl Bar for A { fn g(&self) -> isize { 20 } }
+impl Baz for A { fn h(&self) -> isize { 30 } }
+
+fn f<T:Quux>(a: &T) {
+ assert_eq!(a.f(), 10);
+ assert_eq!(a.g(), 20);
+ assert_eq!(a.h(), 30);
+}
+
+pub fn main() {
+ let a = &A { x: 3 };
+ f(a);
+}
--- /dev/null
+pub trait Foo { fn f(&self) -> isize; }
+pub trait Bar { fn g(&self) -> isize; }
+pub trait Baz { fn h(&self) -> isize; }
+
+pub trait Quux: Foo + Bar + Baz { }
+
+impl<T:Foo + Bar + Baz> Quux for T { }
--- /dev/null
+pub trait Foo { fn f(&self) -> isize; }
+pub trait Bar { fn g(&self) -> isize; }
+pub trait Baz { fn h(&self) -> isize; }
+
+pub struct A { pub x: isize }
+
+impl Foo for A { fn f(&self) -> isize { 10 } }
+impl Bar for A { fn g(&self) -> isize { 20 } }
+impl Baz for A { fn h(&self) -> isize { 30 } }
--- /dev/null
+use std::cmp::PartialEq;
+use std::ops::{Add, Sub, Mul};
+
+pub trait MyNum : Add<Output=Self> + Sub<Output=Self> + Mul<Output=Self> + PartialEq + Clone {
+}
+
+#[derive(Clone, Debug)]
+pub struct MyInt {
+ pub val: isize
+}
+
+impl Add for MyInt {
+ type Output = MyInt;
+
+ fn add(self, other: MyInt) -> MyInt { mi(self.val + other.val) }
+}
+
+impl Sub for MyInt {
+ type Output = MyInt;
+
+ fn sub(self, other: MyInt) -> MyInt { mi(self.val - other.val) }
+}
+
+impl Mul for MyInt {
+ type Output = MyInt;
+
+ fn mul(self, other: MyInt) -> MyInt { mi(self.val * other.val) }
+}
+
+impl PartialEq for MyInt {
+ fn eq(&self, other: &MyInt) -> bool { self.val == other.val }
+
+ fn ne(&self, other: &MyInt) -> bool { !self.eq(other) }
+}
+
+impl MyNum for MyInt {}
+
+fn mi(v: isize) -> MyInt { MyInt { val: v } }
--- /dev/null
+pub trait Foo {
+ fn f(&self) -> isize;
+}
+
+pub struct A {
+ pub x: isize
+}
+
+impl Foo for A {
+ fn f(&self) -> isize { 10 }
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+
+trait Foo { fn f(&self) -> isize; }
+trait Bar { fn g(&self) -> isize; }
+trait Baz { fn h(&self) -> isize; }
+
+trait Quux: Foo + Bar + Baz { }
+
+struct A { x: isize }
+
+impl Foo for A { fn f(&self) -> isize { 10 } }
+impl Bar for A { fn g(&self) -> isize { 20 } }
+impl Baz for A { fn h(&self) -> isize { 30 } }
+impl Quux for A {}
+
+fn f<T:Quux + Foo + Bar + Baz>(a: &T) {
+ assert_eq!(a.f(), 10);
+ assert_eq!(a.g(), 20);
+ assert_eq!(a.h(), 30);
+}
+
+pub fn main() {
+ let a = &A { x: 3 };
+ f(a);
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+
+trait Foo { fn f(&self) -> isize; }
+trait Bar : Foo { fn g(&self) -> isize; }
+
+struct A { x: isize }
+
+impl Foo for A { fn f(&self) -> isize { 10 } }
+impl Bar for A { fn g(&self) -> isize { 20 } }
+
+// Call a function on Foo, given a T: Bar
+fn gg<T:Bar>(a: &T) -> isize {
+ a.f()
+}
+
+pub fn main() {
+ let a = &A { x: 3 };
+ assert_eq!(gg(a), 10);
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+
+trait Foo { fn f(&self) -> isize; }
+trait Bar : Foo { fn g(&self) -> isize; }
+trait Baz : Bar { fn h(&self) -> isize; }
+
+struct A { x: isize }
+
+impl Foo for A { fn f(&self) -> isize { 10 } }
+impl Bar for A { fn g(&self) -> isize { 20 } }
+impl Baz for A { fn h(&self) -> isize { 30 } }
+
+// Call a function on Foo, given a T: Baz,
+// which is inherited via Bar
+fn gg<T:Baz>(a: &T) -> isize {
+ a.f()
+}
+
+pub fn main() {
+ let a = &A { x: 3 };
+ assert_eq!(gg(a), 10);
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+// Testing that we can cast to a subtrait and call subtrait
+// methods. Not testing supertrait methods
+
+
+trait Foo {
+ fn f(&self) -> isize;
+}
+
+trait Bar : Foo {
+ fn g(&self) -> isize;
+}
+
+struct A {
+ x: isize
+}
+
+impl Foo for A {
+ fn f(&self) -> isize { 10 }
+}
+
+impl Bar for A {
+ fn g(&self) -> isize { 20 }
+}
+
+pub fn main() {
+ let a = &A { x: 3 };
+ let afoo = a as &dyn Foo;
+ let abar = a as &dyn Bar;
+ assert_eq!(afoo.f(), 10);
+ assert_eq!(abar.g(), 20);
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+// Testing that supertrait methods can be called on subtrait object types
+
+
+trait Foo {
+ fn f(&self) -> isize;
+}
+
+trait Bar : Foo {
+ fn g(&self) -> isize;
+}
+
+struct A {
+ x: isize
+}
+
+impl Foo for A {
+ fn f(&self) -> isize { 10 }
+}
+
+impl Bar for A {
+ fn g(&self) -> isize { 20 }
+}
+
+pub fn main() {
+ let a = &A { x: 3 };
+ let afoo = a as &dyn Foo;
+ let abar = a as &dyn Bar;
+ assert_eq!(afoo.f(), 10);
+ assert_eq!(abar.g(), 20);
+ assert_eq!(abar.f(), 10);
+}
--- /dev/null
+// run-pass
+// aux-build:xc_call.rs
+
+
+extern crate xc_call as aux;
+
+use aux::Foo;
+
+trait Bar : Foo {
+ fn g(&self) -> isize;
+}
+
+impl Bar for aux::A {
+ fn g(&self) -> isize { self.f() }
+}
+
+pub fn main() {
+ let a = &aux::A { x: 3 };
+ assert_eq!(a.g(), 10);
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+
+trait Foo { fn f(&self) -> isize; }
+trait Bar : Foo { fn g(&self) -> isize; }
+
+struct A { x: isize }
+
+impl Foo for A { fn f(&self) -> isize { 10 } }
+
+impl Bar for A {
+ // Testing that this impl can call the impl of Foo
+ fn g(&self) -> isize { self.f() }
+}
+
+pub fn main() {
+ let a = &A { x: 3 };
+ assert_eq!(a.g(), 10);
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+// B and C both require A, so D does as well, twice, but that's just fine
+
+
+trait A { fn a(&self) -> isize; }
+trait B: A { fn b(&self) -> isize; }
+trait C: A { fn c(&self) -> isize; }
+trait D: B + C { fn d(&self) -> isize; }
+
+struct S { bogus: () }
+
+impl A for S { fn a(&self) -> isize { 10 } }
+impl B for S { fn b(&self) -> isize { 20 } }
+impl C for S { fn c(&self) -> isize { 30 } }
+impl D for S { fn d(&self) -> isize { 40 } }
+
+fn f<T:D>(x: &T) {
+ assert_eq!(x.a(), 10);
+ assert_eq!(x.b(), 20);
+ assert_eq!(x.c(), 30);
+ assert_eq!(x.d(), 40);
+}
+
+pub fn main() {
+ let value = &S { bogus: () };
+ f(value);
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+
+trait A { fn a(&self) -> isize; }
+trait B: A { fn b(&self) -> isize; }
+trait C: A { fn c(&self) -> isize; }
+
+struct S { bogus: () }
+
+impl A for S { fn a(&self) -> isize { 10 } }
+impl B for S { fn b(&self) -> isize { 20 } }
+impl C for S { fn c(&self) -> isize { 30 } }
+
+// Both B and C inherit from A
+fn f<T:B + C>(x: &T) {
+ assert_eq!(x.a(), 10);
+ assert_eq!(x.b(), 20);
+ assert_eq!(x.c(), 30);
+}
+
+pub fn main() {
+ f(&S { bogus: () })
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+
+trait A { fn a(&self) -> isize; }
+trait B: A { fn b(&self) -> isize; }
+trait C: A { fn c(&self) -> isize; }
+
+struct S { bogus: () }
+
+impl A for S { fn a(&self) -> isize { 10 } }
+impl B for S { fn b(&self) -> isize { 20 } }
+impl C for S { fn c(&self) -> isize { 30 } }
+
+// Multiple type params, multiple levels of inheritance
+fn f<X:A,Y:B,Z:C>(x: &X, y: &Y, z: &Z) {
+ assert_eq!(x.a(), 10);
+ assert_eq!(y.a(), 10);
+ assert_eq!(y.b(), 20);
+ assert_eq!(z.a(), 10);
+ assert_eq!(z.c(), 30);
+}
+
+pub fn main() {
+ let s = &S { bogus: () };
+ f(s, s, s);
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+#![allow(unused_variables)]
+// pretty-expanded FIXME #23616
+
+pub trait NumExt: PartialEq + PartialOrd {}
+
+pub trait FloatExt: NumExt {}
+
+fn greater_than_one<T: NumExt>(n: &T) -> bool { loop {} }
+fn greater_than_one_float<T: FloatExt>(n: &T) -> bool { loop {} }
+
+pub fn main() {}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+// Extending Num and using inherited static methods
+
+// pretty-expanded FIXME #23616
+
+use std::cmp::PartialOrd;
+
+pub trait NumCast: Sized {
+ fn from(i: i32) -> Option<Self>;
+}
+
+pub trait Num {
+ fn from_int(i: isize) -> Self;
+ fn gt(&self, other: &Self) -> bool;
+}
+
+pub trait NumExt: NumCast + PartialOrd { }
+
+fn greater_than_one<T:NumExt>(n: &T) -> bool {
+ n.gt(&NumCast::from(1).unwrap())
+}
+
+pub fn main() {}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+// pretty-expanded FIXME #23616
+
+pub trait NumCast: Sized {
+ fn from(i: i32) -> Option<Self>;
+}
+
+pub trait NumExt: NumCast + PartialOrd { }
+
+fn greater_than_one<T:NumExt>(n: &T) -> bool {
+ *n > NumCast::from(1).unwrap()
+}
+
+pub fn main() {}
--- /dev/null
+// run-pass
+// A more complex example of numeric extensions
+
+pub trait TypeExt {}
+
+impl TypeExt for u8 {}
+impl TypeExt for u16 {}
+impl TypeExt for u32 {}
+impl TypeExt for u64 {}
+impl TypeExt for usize {}
+
+impl TypeExt for i8 {}
+impl TypeExt for i16 {}
+impl TypeExt for i32 {}
+impl TypeExt for i64 {}
+impl TypeExt for isize {}
+
+impl TypeExt for f32 {}
+impl TypeExt for f64 {}
+
+
+pub trait NumExt: TypeExt + PartialEq + PartialOrd {}
+
+impl NumExt for u8 {}
+impl NumExt for u16 {}
+impl NumExt for u32 {}
+impl NumExt for u64 {}
+impl NumExt for usize {}
+
+impl NumExt for i8 {}
+impl NumExt for i16 {}
+impl NumExt for i32 {}
+impl NumExt for i64 {}
+impl NumExt for isize {}
+
+impl NumExt for f32 {}
+impl NumExt for f64 {}
+
+
+pub trait UnSignedExt: NumExt {}
+
+impl UnSignedExt for u8 {}
+impl UnSignedExt for u16 {}
+impl UnSignedExt for u32 {}
+impl UnSignedExt for u64 {}
+impl UnSignedExt for usize {}
+
+
+pub trait SignedExt: NumExt {}
+
+impl SignedExt for i8 {}
+impl SignedExt for i16 {}
+impl SignedExt for i32 {}
+impl SignedExt for i64 {}
+impl SignedExt for isize {}
+
+impl SignedExt for f32 {}
+impl SignedExt for f64 {}
+
+
+pub trait IntegerExt: NumExt {}
+
+impl IntegerExt for u8 {}
+impl IntegerExt for u16 {}
+impl IntegerExt for u32 {}
+impl IntegerExt for u64 {}
+impl IntegerExt for usize {}
+
+impl IntegerExt for i8 {}
+impl IntegerExt for i16 {}
+impl IntegerExt for i32 {}
+impl IntegerExt for i64 {}
+impl IntegerExt for isize {}
+
+
+pub trait FloatExt: NumExt {}
+
+impl FloatExt for f32 {}
+impl FloatExt for f64 {}
+
+
+fn test_float_ext<T:FloatExt>(n: T) { println!("{}", n < n) }
+
+pub fn main() {
+ test_float_ext(1f32);
+}
--- /dev/null
+// run-pass
+pub trait NumCast: Sized {
+ fn from(i: i32) -> Option<Self>;
+}
+
+pub trait NumExt: PartialEq + PartialOrd + NumCast {}
+
+impl NumExt for f32 {}
+impl NumCast for f32 {
+ fn from(i: i32) -> Option<f32> { Some(i as f32) }
+}
+
+fn num_eq_one<T: NumExt>(n: T) {
+ println!("{}", n == NumCast::from(1).unwrap())
+}
+
+pub fn main() {
+ num_eq_one(1f32); // you need to actually use the function to trigger the ICE
+}
--- /dev/null
+// run-pass
+// pretty-expanded FIXME #23616
+
+pub trait NumCast: Sized {
+ fn from(i: i32) -> Option<Self>;
+}
+
+pub trait NumExt: PartialEq + NumCast {}
+
+impl NumExt for f32 {}
+impl NumExt for isize {}
+
+impl NumCast for f32 {
+ fn from(i: i32) -> Option<f32> { Some(i as f32) }
+}
+impl NumCast for isize {
+ fn from(i: i32) -> Option<isize> { Some(i as isize) }
+}
+
+fn num_eq_one<T:NumExt>() -> T {
+ NumCast::from(1).unwrap()
+}
+
+pub fn main() {
+ num_eq_one::<isize>(); // you need to actually use the function to trigger the ICE
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+use std::cmp::PartialEq;
+
+trait MyNum : PartialEq { }
+
+#[derive(Debug)]
+struct MyInt { val: isize }
+
+impl PartialEq for MyInt {
+ fn eq(&self, other: &MyInt) -> bool { self.val == other.val }
+ fn ne(&self, other: &MyInt) -> bool { !self.eq(other) }
+}
+
+impl MyNum for MyInt {}
+
+fn f<T:MyNum>(x: T, y: T) -> bool {
+ return x == y;
+}
+
+fn mi(v: isize) -> MyInt { MyInt { val: v } }
+
+pub fn main() {
+ let (x, y, z) = (mi(3), mi(5), mi(3));
+ assert!(x != y);
+ assert_eq!(x, z);
+}
--- /dev/null
+// run-pass
+// aux-build:overloading_xc.rs
+
+
+extern crate overloading_xc;
+use overloading_xc::{MyNum, MyInt};
+
+fn f<T:MyNum>(x: T, y: T) -> (T, T, T) {
+ return (x.clone() + y.clone(), x.clone() - y.clone(), x * y);
+}
+
+fn mi(v: isize) -> MyInt { MyInt { val: v } }
+
+pub fn main() {
+ let (x, y) = (mi(3), mi(5));
+ let (a, b, c) = f(x, y);
+ assert_eq!(a, mi(8));
+ assert_eq!(b, mi(-2));
+ assert_eq!(c, mi(15));
+}
--- /dev/null
+// run-pass
+use std::cmp::PartialEq;
+use std::ops::{Add, Sub, Mul};
+
+trait MyNum : Add<Output=Self> + Sub<Output=Self> + Mul<Output=Self> + PartialEq + Clone { }
+
+#[derive(Clone, Debug)]
+struct MyInt { val: isize }
+
+impl Add for MyInt {
+ type Output = MyInt;
+
+ fn add(self, other: MyInt) -> MyInt { mi(self.val + other.val) }
+}
+
+impl Sub for MyInt {
+ type Output = MyInt;
+
+ fn sub(self, other: MyInt) -> MyInt { mi(self.val - other.val) }
+}
+
+impl Mul for MyInt {
+ type Output = MyInt;
+
+ fn mul(self, other: MyInt) -> MyInt { mi(self.val * other.val) }
+}
+
+impl PartialEq for MyInt {
+ fn eq(&self, other: &MyInt) -> bool { self.val == other.val }
+ fn ne(&self, other: &MyInt) -> bool { !self.eq(other) }
+}
+
+impl MyNum for MyInt {}
+
+fn f<T:MyNum>(x: T, y: T) -> (T, T, T) {
+ return (x.clone() + y.clone(), x.clone() - y.clone(), x * y);
+}
+
+fn mi(v: isize) -> MyInt { MyInt { val: v } }
+
+pub fn main() {
+ let (x, y) = (mi(3), mi(5));
+ let (a, b, c) = f(x, y);
+ assert_eq!(a, mi(8));
+ assert_eq!(b, mi(-2));
+ assert_eq!(c, mi(15));
+}
--- /dev/null
+// Test a case of a trait which extends the same supertrait twice, but
+// with difference type parameters. Test then that when we don't give
+// enough information to pick between these, no selection is made. In
+// this particular case, the two choices are i64/u64 -- so when we use
+// an integer literal, we wind up falling this literal back to i32.
+// See also `run-pass/trait-repeated-supertrait.rs`.
+
+trait CompareTo<T> {
+ fn same_as(&self, t: T) -> bool;
+}
+
+trait CompareToInts : CompareTo<i64> + CompareTo<u64> {
+}
+
+impl CompareTo<i64> for i64 {
+ fn same_as(&self, t: i64) -> bool { *self == t }
+}
+
+impl CompareTo<u64> for i64 {
+ fn same_as(&self, t: u64) -> bool { *self == (t as i64) }
+}
+
+impl CompareToInts for i64 { }
+
+fn with_obj(c: &dyn CompareToInts) -> bool {
+ c.same_as(22) //~ ERROR `dyn CompareToInts: CompareTo<i32>` is not satisfied
+}
+
+fn with_trait<C:CompareToInts>(c: &C) -> bool {
+ c.same_as(22) //~ ERROR `C: CompareTo<i32>` is not satisfied
+}
+
+fn with_ufcs1<C:CompareToInts>(c: &C) -> bool {
+ CompareToInts::same_as(c, 22) //~ ERROR `dyn CompareToInts: CompareTo<i32>` is not satisfied
+}
+
+fn with_ufcs2<C:CompareToInts>(c: &C) -> bool {
+ CompareTo::same_as(c, 22) //~ ERROR `C: CompareTo<i32>` is not satisfied
+}
+
+fn main() {
+ assert_eq!(22_i64.same_as(22), true); //~ ERROR `i64: CompareTo<i32>` is not satisfied
+}
--- /dev/null
+error[E0277]: the trait bound `dyn CompareToInts: CompareTo<i32>` is not satisfied
+ --> $DIR/repeated-supertrait-ambig.rs:26:7
+ |
+LL | c.same_as(22)
+ | ^^^^^^^ the trait `CompareTo<i32>` is not implemented for `dyn CompareToInts`
+
+error[E0277]: the trait bound `C: CompareTo<i32>` is not satisfied
+ --> $DIR/repeated-supertrait-ambig.rs:30:7
+ |
+LL | c.same_as(22)
+ | ^^^^^^^ the trait `CompareTo<i32>` is not implemented for `C`
+ |
+help: consider further restricting this bound
+ |
+LL | fn with_trait<C:CompareToInts + CompareTo<i32>>(c: &C) -> bool {
+ | ^^^^^^^^^^^^^^^^
+
+error[E0277]: the trait bound `dyn CompareToInts: CompareTo<i32>` is not satisfied
+ --> $DIR/repeated-supertrait-ambig.rs:34:5
+ |
+LL | fn same_as(&self, t: T) -> bool;
+ | -------------------------------- required by `CompareTo::same_as`
+...
+LL | CompareToInts::same_as(c, 22)
+ | ^^^^^^^^^^^^^^^^^^^^^^ the trait `CompareTo<i32>` is not implemented for `dyn CompareToInts`
+
+error[E0277]: the trait bound `C: CompareTo<i32>` is not satisfied
+ --> $DIR/repeated-supertrait-ambig.rs:38:5
+ |
+LL | fn same_as(&self, t: T) -> bool;
+ | -------------------------------- required by `CompareTo::same_as`
+...
+LL | CompareTo::same_as(c, 22)
+ | ^^^^^^^^^^^^^^^^^^ the trait `CompareTo<i32>` is not implemented for `C`
+ |
+help: consider further restricting this bound
+ |
+LL | fn with_ufcs2<C:CompareToInts + CompareTo<i32>>(c: &C) -> bool {
+ | ^^^^^^^^^^^^^^^^
+
+error[E0277]: the trait bound `i64: CompareTo<i32>` is not satisfied
+ --> $DIR/repeated-supertrait-ambig.rs:42:23
+ |
+LL | assert_eq!(22_i64.same_as(22), true);
+ | ^^^^^^^ the trait `CompareTo<i32>` is not implemented for `i64`
+ |
+ = help: the following implementations were found:
+ <i64 as CompareTo<i64>>
+ <i64 as CompareTo<u64>>
+
+error: aborting due to 5 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+// run-pass
+// Test a case of a trait which extends the same supertrait twice, but
+// with difference type parameters. Test that we can invoke the
+// various methods in various ways successfully.
+// See also `ui/traits/trait-repeated-supertrait-ambig.rs`.
+
+
+trait CompareTo<T> {
+ fn same_as(&self, t: T) -> bool;
+}
+
+trait CompareToInts : CompareTo<i64> + CompareTo<u64> {
+}
+
+impl CompareTo<i64> for i64 {
+ fn same_as(&self, t: i64) -> bool { *self == t }
+}
+
+impl CompareTo<u64> for i64 {
+ fn same_as(&self, t: u64) -> bool { *self == (t as i64) }
+}
+
+impl CompareToInts for i64 { }
+
+fn with_obj(c: &dyn CompareToInts) -> bool {
+ c.same_as(22_i64) && c.same_as(22_u64)
+}
+
+fn with_trait<C:CompareToInts>(c: &C) -> bool {
+ c.same_as(22_i64) && c.same_as(22_u64)
+}
+
+fn with_ufcs1<C:CompareToInts>(c: &C) -> bool {
+ CompareToInts::same_as(c, 22_i64) && CompareToInts::same_as(c, 22_u64)
+}
+
+fn with_ufcs2<C:CompareToInts>(c: &C) -> bool {
+ CompareTo::same_as(c, 22_i64) && CompareTo::same_as(c, 22_u64)
+}
+
+fn main() {
+ assert_eq!(22_i64.same_as(22_i64), true);
+ assert_eq!(22_i64.same_as(22_u64), true);
+ assert_eq!(with_trait(&22), true);
+ assert_eq!(with_obj(&22), true);
+ assert_eq!(with_ufcs1(&22), true);
+ assert_eq!(with_ufcs2(&22), true);
+}
--- /dev/null
+// run-pass
+// Test for issue #4183: use of Self in supertraits.
+
+pub static FUZZY_EPSILON: f64 = 0.1;
+
+pub trait FuzzyEq<Eps> {
+ fn fuzzy_eq(&self, other: &Self) -> bool;
+ fn fuzzy_eq_eps(&self, other: &Self, epsilon: &Eps) -> bool;
+}
+
+trait Float: Sized+FuzzyEq<Self> {
+ fn two_pi() -> Self;
+}
+
+impl FuzzyEq<f32> for f32 {
+ fn fuzzy_eq(&self, other: &f32) -> bool {
+ self.fuzzy_eq_eps(other, &(FUZZY_EPSILON as f32))
+ }
+
+ fn fuzzy_eq_eps(&self, other: &f32, epsilon: &f32) -> bool {
+ (*self - *other).abs() < *epsilon
+ }
+}
+
+impl Float for f32 {
+ fn two_pi() -> f32 { 6.28318530717958647692528676655900576_f32 }
+}
+
+impl FuzzyEq<f64> for f64 {
+ fn fuzzy_eq(&self, other: &f64) -> bool {
+ self.fuzzy_eq_eps(other, &(FUZZY_EPSILON as f64))
+ }
+
+ fn fuzzy_eq_eps(&self, other: &f64, epsilon: &f64) -> bool {
+ (*self - *other).abs() < *epsilon
+ }
+}
+
+impl Float for f64 {
+ fn two_pi() -> f64 { 6.28318530717958647692528676655900576_f64 }
+}
+
+fn compare<F:Float>(f1: F) -> bool {
+ let f2 = Float::two_pi();
+ f1.fuzzy_eq(&f2)
+}
+
+pub fn main() {
+ assert!(compare::<f32>(6.28318530717958647692528676655900576));
+ assert!(compare::<f32>(6.29));
+ assert!(compare::<f32>(6.3));
+ assert!(compare::<f32>(6.19));
+ assert!(!compare::<f32>(7.28318530717958647692528676655900576));
+ assert!(!compare::<f32>(6.18));
+
+ assert!(compare::<f64>(6.28318530717958647692528676655900576));
+ assert!(compare::<f64>(6.29));
+ assert!(compare::<f64>(6.3));
+ assert!(compare::<f64>(6.19));
+ assert!(!compare::<f64>(7.28318530717958647692528676655900576));
+ assert!(!compare::<f64>(6.18));
+}
--- /dev/null
+// run-pass
+trait Foo<T> {
+ fn f(&self, x: &T);
+}
+
+trait Bar : Sized + Foo<Self> {
+ fn g(&self);
+}
+
+struct S {
+ x: isize
+}
+
+impl Foo<S> for S {
+ fn f(&self, x: &S) {
+ println!("{}", x.x);
+ }
+}
+
+impl Bar for S {
+ fn g(&self) {
+ self.f(self);
+ }
+}
+
+pub fn main() {
+ let s = S { x: 1 };
+ s.g();
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+
+trait Foo { fn f(&self) -> isize; }
+trait Bar : Foo { fn g(&self) -> isize; }
+
+struct A { x: isize }
+
+impl Foo for A { fn f(&self) -> isize { 10 } }
+impl Bar for A { fn g(&self) -> isize { 20 } }
+
+fn ff<T:Foo>(a: &T) -> isize {
+ a.f()
+}
+
+fn gg<T:Bar>(a: &T) -> isize {
+ a.g()
+}
+
+pub fn main() {
+ let a = &A { x: 3 };
+ assert_eq!(ff(a), 10);
+ assert_eq!(gg(a), 20);
+}
--- /dev/null
+// run-pass
+
+pub trait MyNum {
+ fn from_int(_: isize) -> Self;
+}
+
+pub trait NumExt: MyNum { }
+
+struct S { v: isize }
+
+impl MyNum for S {
+ fn from_int(i: isize) -> S {
+ S {
+ v: i
+ }
+ }
+}
+
+impl NumExt for S { }
+
+fn greater_than_one<T:NumExt>() -> T { MyNum::from_int(1) }
+
+pub fn main() {
+ let v: S = greater_than_one();
+ assert_eq!(v.v, 1);
+}
--- /dev/null
+// run-pass
+pub trait MyEq {}
+
+pub trait MyNum {
+ fn from_int(_: isize) -> Self;
+}
+
+pub trait NumExt: MyEq + MyNum { }
+
+struct S { v: isize }
+
+impl MyEq for S { }
+
+impl MyNum for S {
+ fn from_int(i: isize) -> S {
+ S {
+ v: i
+ }
+ }
+}
+
+impl NumExt for S { }
+
+fn greater_than_one<T:NumExt>() -> T { MyNum::from_int(1) }
+
+pub fn main() {
+ let v: S = greater_than_one();
+ assert_eq!(v.v, 1);
+}
--- /dev/null
+// run-pass
+
+pub trait Add<RHS,Result> {
+ fn add(&self, rhs: &RHS) -> Result;
+}
+
+trait MyNum : Sized + Add<Self,Self> { }
+
+struct MyInt { val: isize }
+
+impl Add<MyInt, MyInt> for MyInt {
+ fn add(&self, other: &MyInt) -> MyInt { mi(self.val + other.val) }
+}
+
+impl MyNum for MyInt {}
+
+fn f<T:MyNum>(x: T, y: T) -> T {
+ return x.add(&y);
+}
+
+fn mi(v: isize) -> MyInt { MyInt { val: v } }
+
+pub fn main() {
+ let (x, y) = (mi(3), mi(5));
+ let z = f(x, y);
+ assert_eq!(z.val, 8)
+}
--- /dev/null
+// run-pass
+
+trait Panda<T> {
+ fn chomp(&self, bamboo: &T) -> T;
+}
+
+trait Add<RHS,Result>: Panda<RHS> {
+ fn add(&self, rhs: &RHS) -> Result;
+}
+
+trait MyNum : Sized + Add<Self,Self> { }
+
+struct MyInt { val: isize }
+
+impl Panda<MyInt> for MyInt {
+ fn chomp(&self, bamboo: &MyInt) -> MyInt {
+ mi(self.val + bamboo.val)
+ }
+}
+
+impl Add<MyInt, MyInt> for MyInt {
+ fn add(&self, other: &MyInt) -> MyInt { self.chomp(other) }
+}
+
+impl MyNum for MyInt {}
+
+fn f<T:MyNum>(x: T, y: T) -> T {
+ return x.add(&y).chomp(&y);
+}
+
+fn mi(v: isize) -> MyInt { MyInt { val: v } }
+
+pub fn main() {
+ let (x, y) = (mi(3), mi(5));
+ let z = f(x, y);
+ assert_eq!(z.val, 13);
+}
--- /dev/null
+// run-pass
+
+mod traits {
+ pub trait Foo { fn f(&self) -> isize; }
+
+ impl Foo for isize { fn f(&self) -> isize { 10 } }
+}
+
+trait Quux: traits::Foo { }
+impl<T:traits::Foo> Quux for T { }
+
+// Foo is not in scope but because Quux is we can still access
+// Foo's methods on a Quux bound typaram
+fn f<T:Quux>(x: &T) {
+ assert_eq!(x.f(), 10);
+}
+
+pub fn main() {
+ f(&0)
+}
--- /dev/null
+// run-pass
+// Test an issue where global caching was causing free regions from
+// distinct scopes to be compared (`'g` and `'h`). The only important
+// thing is that compilation succeeds here.
+
+// pretty-expanded FIXME #23616
+
+#![allow(missing_copy_implementations)]
+#![allow(unused_variables)]
+
+use std::borrow::ToOwned;
+
+pub struct CFGNode;
+
+pub type Node<'a> = &'a CFGNode;
+
+pub trait GraphWalk<'c, N> {
+ /// Returns all the nodes in this graph.
+ fn nodes(&'c self) where [N]:ToOwned<Owned=Vec<N>>;
+}
+
+impl<'g> GraphWalk<'g, Node<'g>> for u32
+{
+ fn nodes(&'g self) where [Node<'g>]:ToOwned<Owned=Vec<Node<'g>>>
+ { loop { } }
+}
+
+impl<'h> GraphWalk<'h, Node<'h>> for u64
+{
+ fn nodes(&'h self) where [Node<'h>]:ToOwned<Owned=Vec<Node<'h>>>
+ { loop { } }
+}
+
+fn main() { }
--- /dev/null
+// run-pass
+// Test an issue where we reported ambiguity between the where-clause
+// and the blanket impl. The only important thing is that compilation
+// succeeds here. Issue #22110.
+
+// pretty-expanded FIXME #23616
+
+#![allow(dead_code)]
+
+trait Foo<A> {
+ fn foo(&self, a: A);
+}
+
+impl<A,F:Fn(A)> Foo<A> for F {
+ fn foo(&self, _: A) { }
+}
+
+fn baz<A,F:for<'a> Foo<(&'a A,)>>(_: F) { }
+
+fn components<T,A>(t: fn(&A))
+ where fn(&A) : for<'a> Foo<(&'a A,)>,
+{
+ baz(t)
+}
+
+fn main() {
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+// Regression test for issue #22655: This test should not lead to
+// infinite recursion.
+
+// pretty-expanded FIXME #23616
+
+unsafe impl<T: Send + ?Sized> Send for Unique<T> { }
+
+pub struct Unique<T:?Sized> {
+ pointer: *const T,
+}
+
+pub struct Node<V> {
+ vals: V,
+ edges: Unique<Node<V>>,
+}
+
+fn is_send<T: Send>() {}
+
+fn main() {
+ is_send::<Node<&'static ()>>();
+}
--- /dev/null
+// A variant of traits-issue-23003 in which an infinite series of
+// types are required. This test now just compiles fine, since the
+// relevant rules that triggered the overflow were removed.
+
+// check-pass
+#![allow(dead_code)]
+
+use std::marker::PhantomData;
+
+trait Async {
+ type Cancel;
+}
+
+struct Receipt<A:Async> {
+ marker: PhantomData<A>,
+}
+
+struct Complete<B> {
+ core: Option<B>,
+}
+
+impl<B> Async for Complete<B> {
+ type Cancel = Receipt<Complete<Option<B>>>;
+}
+
+fn foo(_: Receipt<Complete<()>>) { }
+
+
+fn main() { }
--- /dev/null
+// run-pass
+// Test stack overflow triggered by evaluating the implications. To be
+// WF, the type `Receipt<Complete>` would require that `<Complete as
+// Async>::Cancel` be WF. This normalizes to `Receipt<Complete>`
+// again, leading to an infinite cycle. Issue #23003.
+
+// pretty-expanded FIXME #23616
+
+#![allow(dead_code)]
+#![allow(unused_variables)]
+
+use std::marker::PhantomData;
+
+trait Async {
+ type Cancel;
+}
+
+struct Receipt<A:Async> {
+ marker: PhantomData<A>,
+}
+
+struct Complete {
+ core: Option<()>,
+}
+
+impl Async for Complete {
+ type Cancel = Receipt<Complete>;
+}
+
+fn foo(r: Receipt<Complete>) { }
+
+fn main() { }
--- /dev/null
+// run-pass
+// Test that the right implementation is called through a trait
+// object when supertraits include multiple references to the
+// same trait, with different type parameters.
+
+trait A: PartialEq<Foo> + PartialEq<Bar> { }
+
+struct Foo;
+struct Bar;
+
+struct Aimpl;
+
+impl PartialEq<Foo> for Aimpl {
+ fn eq(&self, _rhs: &Foo) -> bool {
+ true
+ }
+}
+
+impl PartialEq<Bar> for Aimpl {
+ fn eq(&self, _rhs: &Bar) -> bool {
+ false
+ }
+}
+
+impl A for Aimpl { }
+
+fn main() {
+ let a = &Aimpl as &dyn A;
+
+ assert!(*a == Foo);
+}
--- /dev/null
+struct Foo(u8);
+
+#[derive(Clone)]
+struct FooHolster {
+ the_foos: Vec<Foo>, //~ERROR Clone
+}
+
+fn main() {}
--- /dev/null
+error[E0277]: the trait bound `Foo: Clone` is not satisfied
+ --> $DIR/issue-71136.rs:5:5
+ |
+LL | the_foos: Vec<Foo>,
+ | ^^^^^^^^^^^^^^^^^^ expected an implementor of trait `Clone`
+ |
+ = note: required because of the requirements on the impl of `Clone` for `Vec<Foo>`
+ = note: required by `clone`
+ = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+// run-pass
+
+trait Base: Base2 + Base3{
+ fn foo(&self) -> String;
+ fn foo1(&self) -> String;
+ fn foo2(&self) -> String{
+ "base foo2".to_string()
+ }
+}
+
+trait Base2: Base3{
+ fn baz(&self) -> String;
+}
+
+trait Base3{
+ fn root(&self) -> String;
+}
+
+trait Super: Base{
+ fn bar(&self) -> String;
+}
+
+struct X;
+
+impl Base for X {
+ fn foo(&self) -> String{
+ "base foo".to_string()
+ }
+ fn foo1(&self) -> String{
+ "base foo1".to_string()
+ }
+
+}
+
+impl Base2 for X {
+ fn baz(&self) -> String{
+ "base2 baz".to_string()
+ }
+}
+
+impl Base3 for X {
+ fn root(&self) -> String{
+ "base3 root".to_string()
+ }
+}
+
+impl Super for X {
+ fn bar(&self) -> String{
+ "super bar".to_string()
+ }
+}
+
+pub fn main() {
+ let n = X;
+ let s = &n as &dyn Super;
+ assert_eq!(s.bar(),"super bar".to_string());
+ assert_eq!(s.foo(),"base foo".to_string());
+ assert_eq!(s.foo1(),"base foo1".to_string());
+ assert_eq!(s.foo2(),"base foo2".to_string());
+ assert_eq!(s.baz(),"base2 baz".to_string());
+ assert_eq!(s.root(),"base3 root".to_string());
+}
+++ /dev/null
-// run-pass
-
-trait Base: Base2 + Base3{
- fn foo(&self) -> String;
- fn foo1(&self) -> String;
- fn foo2(&self) -> String{
- "base foo2".to_string()
- }
-}
-
-trait Base2: Base3{
- fn baz(&self) -> String;
-}
-
-trait Base3{
- fn root(&self) -> String;
-}
-
-trait Super: Base{
- fn bar(&self) -> String;
-}
-
-struct X;
-
-impl Base for X {
- fn foo(&self) -> String{
- "base foo".to_string()
- }
- fn foo1(&self) -> String{
- "base foo1".to_string()
- }
-
-}
-
-impl Base2 for X {
- fn baz(&self) -> String{
- "base2 baz".to_string()
- }
-}
-
-impl Base3 for X {
- fn root(&self) -> String{
- "base3 root".to_string()
- }
-}
-
-impl Super for X {
- fn bar(&self) -> String{
- "super bar".to_string()
- }
-}
-
-pub fn main() {
- let n = X;
- let s = &n as &dyn Super;
- assert_eq!(s.bar(),"super bar".to_string());
- assert_eq!(s.foo(),"base foo".to_string());
- assert_eq!(s.foo1(),"base foo1".to_string());
- assert_eq!(s.foo2(),"base foo2".to_string());
- assert_eq!(s.baz(),"base2 baz".to_string());
- assert_eq!(s.root(),"base3 root".to_string());
-}
--- /dev/null
+// run-pass
+// Issue #34183
+
+macro_rules! foo {
+ () => {
+ fn foo() { }
+ }
+}
+
+macro_rules! bar {
+ () => {
+ fn bar();
+ }
+}
+
+trait Bleh {
+ foo!();
+ bar!();
+}
+
+struct Test;
+
+impl Bleh for Test {
+ fn bar() {}
+}
+
+fn main() {
+ Test::bar();
+ Test::foo();
+}
--- /dev/null
+#![feature(associated_type_defaults)]
+
+struct S;
+
+mod method {
+ trait A {
+ fn a(&self) { }
+ }
+
+ pub trait B {
+ fn b(&self) { }
+ }
+
+ pub trait C: A + B {
+ fn c(&self) { }
+ }
+
+ impl A for ::S {}
+ impl B for ::S {}
+ impl C for ::S {}
+}
+
+mod assoc_const {
+ trait A {
+ const A: u8 = 0;
+ }
+
+ pub trait B {
+ const B: u8 = 0;
+ }
+
+ pub trait C: A + B {
+ const C: u8 = 0;
+ }
+
+ impl A for ::S {}
+ impl B for ::S {}
+ impl C for ::S {}
+}
+
+mod assoc_ty {
+ trait A {
+ type A = u8;
+ }
+
+ pub trait B {
+ type B = u8;
+ }
+
+ pub trait C: A + B {
+ type C = u8;
+ }
+
+ impl A for ::S {}
+ impl B for ::S {}
+ impl C for ::S {}
+}
+
+fn check_method() {
+ // A is private
+ // B is pub, not in scope
+ // C : A + B is pub, in scope
+ use method::C;
+
+ // Methods, method call
+ // a, b, c are resolved as trait items, their traits need to be in scope
+ S.a(); //~ ERROR no method named `a` found
+ S.b(); //~ ERROR no method named `b` found
+ S.c(); // OK
+ // a, b, c are resolved as inherent items, their traits don't need to be in scope
+ let c = &S as &dyn C;
+ c.a(); //~ ERROR associated function `a` is private
+ c.b(); // OK
+ c.c(); // OK
+
+ // Methods, UFCS
+ // a, b, c are resolved as trait items, their traits need to be in scope
+ S::a(&S);
+ //~^ ERROR no function or associated item named `a` found
+ S::b(&S);
+ //~^ ERROR no function or associated item named `b` found
+ S::c(&S); // OK
+ // a, b, c are resolved as inherent items, their traits don't need to be in scope
+ C::a(&S); //~ ERROR associated function `a` is private
+ C::b(&S); // OK
+ C::c(&S); // OK
+}
+
+fn check_assoc_const() {
+ // A is private
+ // B is pub, not in scope
+ // C : A + B is pub, in scope
+ use assoc_const::C;
+
+ // Associated constants
+ // A, B, C are resolved as trait items, their traits need to be in scope
+ S::A; //~ ERROR no associated item named `A` found
+ S::B; //~ ERROR no associated item named `B` found
+ S::C; // OK
+ // A, B, C are resolved as inherent items, their traits don't need to be in scope
+ C::A; //~ ERROR associated constant `A` is private
+ //~^ ERROR the trait `assoc_const::C` cannot be made into an object
+ C::B; // ERROR the trait `assoc_const::C` cannot be made into an object
+ C::C; // OK
+}
+
+fn check_assoc_ty<T: assoc_ty::C>() {
+ // A is private
+ // B is pub, not in scope
+ // C : A + B is pub, in scope
+ use assoc_ty::C;
+
+ // Associated types
+ // A, B, C are resolved as trait items, their traits need to be in scope, not implemented yet
+ let _: S::A; //~ ERROR ambiguous associated type
+ let _: S::B; //~ ERROR ambiguous associated type
+ let _: S::C; //~ ERROR ambiguous associated type
+ // A, B, C are resolved as inherent items, their traits don't need to be in scope
+ let _: T::A; //~ ERROR associated type `A` is private
+ let _: T::B; // OK
+ let _: T::C; // OK
+
+ // Associated types, bindings
+ let _: dyn assoc_ty::B<
+ B = u8, // OK
+ >;
+ let _: dyn C<
+ A = u8, //~ ERROR associated type `A` is private
+ B = u8, // OK
+ C = u8, // OK
+ >;
+}
+
+fn main() {}
--- /dev/null
+error[E0599]: no method named `a` found for struct `S` in the current scope
+ --> $DIR/item-privacy.rs:67:7
+ |
+LL | struct S;
+ | --------- method `a` not found for this
+...
+LL | S.a();
+ | ^ method not found in `S`
+ |
+ = help: items from traits can only be used if the trait is implemented and in scope
+note: `method::A` defines an item `a`, perhaps you need to implement it
+ --> $DIR/item-privacy.rs:6:5
+ |
+LL | trait A {
+ | ^^^^^^^
+
+error[E0599]: no method named `b` found for struct `S` in the current scope
+ --> $DIR/item-privacy.rs:68:7
+ |
+LL | struct S;
+ | --------- method `b` not found for this
+...
+LL | S.b();
+ | ^ method not found in `S`
+ |
+ = help: items from traits can only be used if the trait is in scope
+help: the following trait is implemented but not in scope; perhaps add a `use` for it:
+ |
+LL | use method::B;
+ |
+
+error[E0624]: associated function `a` is private
+ --> $DIR/item-privacy.rs:72:7
+ |
+LL | c.a();
+ | ^ private associated function
+
+error[E0599]: no function or associated item named `a` found for struct `S` in the current scope
+ --> $DIR/item-privacy.rs:78:8
+ |
+LL | struct S;
+ | --------- function or associated item `a` not found for this
+...
+LL | S::a(&S);
+ | ^ function or associated item not found in `S`
+ |
+ = help: items from traits can only be used if the trait is implemented and in scope
+note: `method::A` defines an item `a`, perhaps you need to implement it
+ --> $DIR/item-privacy.rs:6:5
+ |
+LL | trait A {
+ | ^^^^^^^
+
+error[E0599]: no function or associated item named `b` found for struct `S` in the current scope
+ --> $DIR/item-privacy.rs:80:8
+ |
+LL | struct S;
+ | --------- function or associated item `b` not found for this
+...
+LL | S::b(&S);
+ | ^ function or associated item not found in `S`
+ |
+ = help: items from traits can only be used if the trait is in scope
+help: the following trait is implemented but not in scope; perhaps add a `use` for it:
+ |
+LL | use method::B;
+ |
+
+error[E0624]: associated function `a` is private
+ --> $DIR/item-privacy.rs:84:8
+ |
+LL | C::a(&S);
+ | ^ private associated function
+
+error[E0599]: no associated item named `A` found for struct `S` in the current scope
+ --> $DIR/item-privacy.rs:97:8
+ |
+LL | struct S;
+ | --------- associated item `A` not found for this
+...
+LL | S::A;
+ | ^ associated item not found in `S`
+ |
+ = help: items from traits can only be used if the trait is implemented and in scope
+note: `assoc_const::A` defines an item `A`, perhaps you need to implement it
+ --> $DIR/item-privacy.rs:24:5
+ |
+LL | trait A {
+ | ^^^^^^^
+
+error[E0599]: no associated item named `B` found for struct `S` in the current scope
+ --> $DIR/item-privacy.rs:98:8
+ |
+LL | struct S;
+ | --------- associated item `B` not found for this
+...
+LL | S::B;
+ | ^ associated item not found in `S`
+ |
+ = help: items from traits can only be used if the trait is in scope
+help: the following trait is implemented but not in scope; perhaps add a `use` for it:
+ |
+LL | use assoc_const::B;
+ |
+
+error[E0624]: associated constant `A` is private
+ --> $DIR/item-privacy.rs:101:8
+ |
+LL | C::A;
+ | ^ private associated constant
+
+error[E0038]: the trait `assoc_const::C` cannot be made into an object
+ --> $DIR/item-privacy.rs:101:5
+ |
+LL | C::A;
+ | ^^^^ `assoc_const::C` cannot be made into an object
+ |
+ = help: consider moving `C` to another trait
+ = help: consider moving `B` to another trait
+ = help: consider moving `A` to another trait
+note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
+ --> $DIR/item-privacy.rs:25:15
+ |
+LL | const A: u8 = 0;
+ | ^ ...because it contains this associated `const`
+...
+LL | const B: u8 = 0;
+ | ^ ...because it contains this associated `const`
+...
+LL | pub trait C: A + B {
+ | - this trait cannot be made into an object...
+LL | const C: u8 = 0;
+ | ^ ...because it contains this associated `const`
+
+error[E0223]: ambiguous associated type
+ --> $DIR/item-privacy.rs:115:12
+ |
+LL | let _: S::A;
+ | ^^^^ help: use fully-qualified syntax: `<S as Trait>::A`
+
+error[E0223]: ambiguous associated type
+ --> $DIR/item-privacy.rs:116:12
+ |
+LL | let _: S::B;
+ | ^^^^ help: use fully-qualified syntax: `<S as Trait>::B`
+
+error[E0223]: ambiguous associated type
+ --> $DIR/item-privacy.rs:117:12
+ |
+LL | let _: S::C;
+ | ^^^^ help: use fully-qualified syntax: `<S as Trait>::C`
+
+error: associated type `A` is private
+ --> $DIR/item-privacy.rs:119:12
+ |
+LL | let _: T::A;
+ | ^^^^ private associated type
+
+error: associated type `A` is private
+ --> $DIR/item-privacy.rs:128:9
+ |
+LL | A = u8,
+ | ^^^^^^ private associated type
+
+error: aborting due to 15 previous errors
+
+Some errors have detailed explanations: E0038, E0223, E0599, E0624.
+For more information about an error, try `rustc --explain E0038`.
--- /dev/null
+// run-pass
+#![allow(non_snake_case)]
+#![allow(non_camel_case_types)]
+
+#![feature(box_syntax)]
+
+trait repeat<A> { fn get(&self) -> A; }
+
+impl<A:Clone + 'static> repeat<A> for Box<A> {
+ fn get(&self) -> A {
+ (**self).clone()
+ }
+}
+
+fn repeater<A:Clone + 'static>(v: Box<A>) -> Box<dyn repeat<A>+'static> {
+ box v as Box<dyn repeat<A>+'static> // No
+}
+
+pub fn main() {
+ let x = 3;
+ let y = repeater(box x);
+ assert_eq!(x, y.get());
+}
+++ /dev/null
-// run-pass
-#![allow(non_snake_case)]
-#![allow(non_camel_case_types)]
-
-#![feature(box_syntax)]
-
-trait repeat<A> { fn get(&self) -> A; }
-
-impl<A:Clone + 'static> repeat<A> for Box<A> {
- fn get(&self) -> A {
- (**self).clone()
- }
-}
-
-fn repeater<A:Clone + 'static>(v: Box<A>) -> Box<dyn repeat<A>+'static> {
- box v as Box<dyn repeat<A>+'static> // No
-}
-
-pub fn main() {
- let x = 3;
- let y = repeater(box x);
- assert_eq!(x, y.get());
-}
--- /dev/null
+// Tests that the trait matching code takes lifetime parameters into account.
+// (Issue #15517.)
+
+struct Foo<'a,'b> {
+ x: &'a isize,
+ y: &'b isize,
+}
+
+trait Tr : Sized {
+ fn foo(x: Self) {}
+}
+
+impl<'a,'b> Tr for Foo<'a,'b> {
+ fn foo(x: Foo<'b,'a>) {
+ //~^ ERROR method not compatible with trait
+ //~^^ ERROR method not compatible with trait
+ }
+}
+
+fn main(){}
--- /dev/null
+error[E0308]: method not compatible with trait
+ --> $DIR/matching-lifetimes.rs:14:5
+ |
+LL | fn foo(x: Foo<'b,'a>) {
+ | ^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
+ |
+ = note: expected fn pointer `fn(Foo<'a, 'b>)`
+ found fn pointer `fn(Foo<'b, 'a>)`
+note: the lifetime `'b` as defined on the impl at 13:9...
+ --> $DIR/matching-lifetimes.rs:13:9
+ |
+LL | impl<'a,'b> Tr for Foo<'a,'b> {
+ | ^^
+note: ...does not necessarily outlive the lifetime `'a` as defined on the impl at 13:6
+ --> $DIR/matching-lifetimes.rs:13:6
+ |
+LL | impl<'a,'b> Tr for Foo<'a,'b> {
+ | ^^
+
+error[E0308]: method not compatible with trait
+ --> $DIR/matching-lifetimes.rs:14:5
+ |
+LL | fn foo(x: Foo<'b,'a>) {
+ | ^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
+ |
+ = note: expected fn pointer `fn(Foo<'a, 'b>)`
+ found fn pointer `fn(Foo<'b, 'a>)`
+note: the lifetime `'a` as defined on the impl at 13:6...
+ --> $DIR/matching-lifetimes.rs:13:6
+ |
+LL | impl<'a,'b> Tr for Foo<'a,'b> {
+ | ^^
+note: ...does not necessarily outlive the lifetime `'b` as defined on the impl at 13:9
+ --> $DIR/matching-lifetimes.rs:13:9
+ |
+LL | impl<'a,'b> Tr for Foo<'a,'b> {
+ | ^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
--- /dev/null
+mod inner {
+ pub trait Bar {
+ fn method(&self);
+ }
+
+ pub struct Foo;
+
+ impl Foo {
+ fn method(&self) {}
+ }
+
+ impl Bar for Foo {
+ fn method(&self) {}
+ }
+}
+
+fn main() {
+ let foo = inner::Foo;
+ foo.method(); //~ ERROR is private
+}
--- /dev/null
+error[E0624]: associated function `method` is private
+ --> $DIR/method-private.rs:19:9
+ |
+LL | foo.method();
+ | ^^^^^^ private associated function
+ |
+ = help: items from traits can only be used if the trait is in scope
+help: the following trait is implemented but not in scope; perhaps add a `use` for it:
+ |
+LL | use inner::Bar;
+ |
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0624`.
--- /dev/null
+// Test that we detect an illegal combination of types.
+
+trait Convert<Target> {
+ fn convert(&self) -> Target;
+}
+
+impl Convert<u32> for i32 {
+ fn convert(&self) -> u32 {
+ *self as u32
+ }
+}
+
+fn test<T,U>(_: T, _: U)
+where T : Convert<U>
+{
+}
+
+fn a() {
+ test(22i32, 44i32); //~ ERROR mismatched types
+}
+
+fn main() {}
--- /dev/null
+error[E0308]: mismatched types
+ --> $DIR/multidispatch-bad.rs:19:17
+ |
+LL | test(22i32, 44i32);
+ | ^^^^^ expected `u32`, found `i32`
+ |
+help: change the type of the numeric literal from `i32` to `u32`
+ |
+LL | test(22i32, 44u32);
+ | ^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
--- /dev/null
+// Check that we get an error in a multidisptach scenario where the
+// set of impls is ambiguous.
+
+trait Convert<Target> {
+ fn convert(&self) -> Target;
+}
+
+impl Convert<i8> for i32 {
+ fn convert(&self) -> i8 {
+ *self as i8
+ }
+}
+
+impl Convert<i16> for i32 {
+ fn convert(&self) -> i16 {
+ *self as i16
+ }
+}
+
+fn test<T,U>(_: T, _: U)
+where T : Convert<U>
+{
+}
+
+fn a() {
+ test(22, std::default::Default::default());
+ //~^ ERROR type annotations needed [E0282]
+}
+
+fn main() {}
--- /dev/null
+error[E0282]: type annotations needed
+ --> $DIR/multidispatch-convert-ambig-dest.rs:26:5
+ |
+LL | test(22, std::default::Default::default());
+ | ^^^^ cannot infer type for type parameter `U` declared on the function `test`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.
--- /dev/null
+// run-pass
+// Test that we can infer the Target based on the Self or vice versa.
+
+
+use std::mem;
+
+trait Convert<Target> {
+ fn convert(&self) -> Target;
+}
+
+impl Convert<u32> for i16 {
+ fn convert(&self) -> u32 {
+ *self as u32
+ }
+}
+
+impl Convert<i16> for u32 {
+ fn convert(&self) -> i16 {
+ *self as i16
+ }
+}
+
+fn test<T,U>(_: T, _: U, t_size: usize, u_size: usize)
+where T : Convert<U>
+{
+ assert_eq!(mem::size_of::<T>(), t_size);
+ assert_eq!(mem::size_of::<U>(), u_size);
+}
+
+fn main() {
+ // T = i16, U = u32
+ test(22_i16, Default::default(), 2, 4);
+
+ // T = u32, U = i16
+ test(22_u32, Default::default(), 4, 2);
+}
+++ /dev/null
-// run-pass
-// pretty-expanded FIXME #23616
-
-fn f<T:PartialEq + PartialOrd>(_: T) {
-}
-
-pub fn main() {
- f(3);
-}
--- /dev/null
+// Checks to make sure that `dyn Trait + Send` and `dyn Trait + Send + Send` are the same type.
+// Issue: #47010
+
+struct Struct;
+impl Trait for Struct {}
+trait Trait {}
+
+type Send1 = dyn Trait + Send;
+type Send2 = dyn Trait + Send + Send;
+
+fn main () {}
+
+impl dyn Trait + Send {
+ fn test(&self) { println!("one"); } //~ ERROR duplicate definitions with name `test`
+}
+
+impl dyn Trait + Send + Send {
+ fn test(&self) { println!("two"); }
+}
--- /dev/null
+error[E0592]: duplicate definitions with name `test`
+ --> $DIR/auto-dedup-in-impl.rs:14:5
+ |
+LL | fn test(&self) { println!("one"); }
+ | ^^^^^^^^^^^^^^ duplicate definitions for `test`
+...
+LL | fn test(&self) { println!("two"); }
+ | -------------- other definition for `test`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0592`.
--- /dev/null
+// run-pass
+
+#![allow(unused_assignments)]
+
+// Test that duplicate auto trait bounds in trait objects don't create new types.
+#[allow(unused_assignments)]
+use std::marker::Send as SendAlias;
+
+// A dummy trait for the non-auto trait.
+trait Trait {}
+
+// A dummy struct to implement `Trait` and `Send`.
+struct Struct;
+
+impl Trait for Struct {}
+
+// These three functions should be equivalent.
+fn takes_dyn_trait_send(_: Box<dyn Trait + Send>) {}
+fn takes_dyn_trait_send_send(_: Box<dyn Trait + Send + Send>) {}
+fn takes_dyn_trait_send_sendalias(_: Box<dyn Trait + Send + SendAlias>) {}
+
+impl dyn Trait + Send + Send {
+ fn do_nothing(&self) {}
+}
+
+fn main() {
+ // 1. Moving into a variable with more `Send`s and back.
+ let mut dyn_trait_send = Box::new(Struct) as Box<dyn Trait + Send>;
+ let dyn_trait_send_send: Box<dyn Trait + Send + Send> = dyn_trait_send;
+ dyn_trait_send = dyn_trait_send_send;
+
+ // 2. Calling methods with different number of `Send`s.
+ let dyn_trait_send = Box::new(Struct) as Box<dyn Trait + Send>;
+ takes_dyn_trait_send_send(dyn_trait_send);
+
+ let dyn_trait_send_send = Box::new(Struct) as Box<dyn Trait + Send + Send>;
+ takes_dyn_trait_send(dyn_trait_send_send);
+
+ // 3. Aliases to the trait are transparent.
+ let dyn_trait_send = Box::new(Struct) as Box<dyn Trait + Send>;
+ takes_dyn_trait_send_sendalias(dyn_trait_send);
+
+ // 4. Calling an impl that duplicates an auto trait.
+ let dyn_trait_send = Box::new(Struct) as Box<dyn Trait + Send>;
+ dyn_trait_send.do_nothing();
+}
--- /dev/null
+// Check that we don't have a cycle when we try to normalize `Self::U` in the
+// bound below.
+
+// check-pass
+
+trait Is {
+ type T;
+}
+
+impl<U> Is for U {
+ type T = U;
+}
+
+trait Obj {
+ type U: Is<T = Self::U>;
+}
+
+fn is_obj<T: ?Sized + Obj>(_: &T) {}
+
+fn f(x: &dyn Obj<U = i32>) {
+ is_obj(x)
+}
+
+fn main() {}
--- /dev/null
+// Check that we don't have a cycle when we try to normalize `Self::V` in the
+// bound below.
+
+// check-pass
+
+trait Is {
+ type T;
+}
+
+impl<U> Is for U {
+ type T = U;
+}
+
+trait Super {
+ type V;
+}
+
+trait Obj: Super {
+ type U: Is<T = Self::V>;
+}
+
+fn is_obj<T: ?Sized + Obj>(_: &T) {}
+
+fn f(x: &dyn Obj<U = i32, V = i32>) {
+ is_obj(x)
+}
+
+fn main() {}
--- /dev/null
+// Check that we don't have a cycle when we try to normalize `Self::V` in the
+// bound below.
+
+// check-pass
+
+trait Is {
+ type T;
+}
+
+impl<U> Is for U {
+ type T = U;
+}
+
+trait Obj {
+ type U: Is<T = Self::V>;
+ type V;
+}
+
+fn is_obj<T: ?Sized + Obj>(_: &T) {}
+
+fn f(x: &dyn Obj<U = i32, V = i32>) {
+ is_obj(x)
+}
+
+fn main() {}
--- /dev/null
+// Check that we don't have a cycle when we try to normalize `Self::U` in the
+// bound below. Make sure that having a lifetime on the trait object doesn't break things
+
+// check-pass
+
+trait Is {
+ type T;
+}
+
+impl<U> Is for U {
+ type T = U;
+}
+
+trait Obj<'a> {
+ type U: Is<T = Self::V>;
+ type V;
+}
+
+fn is_obj<'a, T: ?Sized + Obj<'a>>(_: &T) {}
+
+fn f<'a>(x: &dyn Obj<'a, U = i32, V = i32>) {
+ is_obj(x)
+}
+
+fn main() {}
--- /dev/null
+// run-pass
+trait Future: 'static {
+ // The requirement for Self: Sized must prevent instantiation of
+ // Future::forget in vtables, otherwise there's an infinite type
+ // recursion through <Map<...> as Future>::forget.
+ fn forget(self) where Self: Sized {
+ Box::new(Map(self)) as Box<dyn Future>;
+ }
+}
+
+struct Map<A>(A);
+impl<A: Future> Future for Map<A> {}
+
+pub struct Promise;
+impl Future for Promise {}
+
+fn main() {
+ Promise.forget();
+}
--- /dev/null
+// run-pass
+// test for #8664
+
+#![feature(box_syntax)]
+
+use std::marker;
+
+pub trait Trait2<A> {
+ 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',
+ * src/librustc/middle/subst.rs:58
+ */
+ t: Box<dyn Trait2<A2>+'static>
+}
+
+impl<A1, A2, A3> Impl<A1, A2, A3> {
+ pub fn step(&self) {
+ self.t.doit();
+ }
+}
+
+// test for #8601
+
+enum Type<T> { Constant(T) }
+
+trait Trait<K,V> {
+ fn method(&self, _: Type<(K,V)>) -> isize;
+}
+
+impl<V> Trait<u8,V> for () {
+ fn method(&self, _x: Type<(u8,V)>) -> isize { 0 }
+}
+
+pub fn main() {
+ let a = box () as Box<dyn Trait<u8, u8>>;
+ assert_eq!(a.method(Type::Constant((1, 2))), 0);
+}
--- /dev/null
+// run-pass
+use std::fmt::Display;
+
+static BYTE: u8 = 33;
+
+fn main() {
+ let x: &(dyn 'static + Display) = &BYTE;
+ let y: Box<dyn 'static + Display> = Box::new(BYTE);
+ let xstr = format!("{}", x);
+ let ystr = format!("{}", y);
+ assert_eq!(xstr, "33");
+ assert_eq!(ystr, "33");
+}
--- /dev/null
+// `ty` matcher accepts trait object types
+
+macro_rules! m {
+ ($t: ty) => ( let _: $t; )
+}
+
+fn main() {
+ m!(dyn Copy + Send + 'static);
+ //~^ ERROR the trait `Copy` cannot be made into an object
+ m!(dyn 'static + Send);
+ m!(dyn 'static +); //~ ERROR at least one trait is required for an object type
+}
--- /dev/null
+error[E0224]: at least one trait is required for an object type
+ --> $DIR/macro-matcher.rs:11:8
+ |
+LL | m!(dyn 'static +);
+ | ^^^^^^^^^^^^^
+
+error[E0038]: the trait `Copy` cannot be made into an object
+ --> $DIR/macro-matcher.rs:8:8
+ |
+LL | m!(dyn Copy + Send + 'static);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ `Copy` cannot be made into an object
+ |
+ = note: the trait cannot be made into an object because it requires `Self: Sized`
+ = note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0038, E0224.
+For more information about an error, try `rustc --explain E0038`.
--- /dev/null
+// Check that static methods are not object-safe.
+
+trait Tr {
+ fn foo();
+ fn bar(&self) { }
+}
+
+struct St;
+
+impl Tr for St {
+ fn foo() {}
+}
+
+fn main() {
+ let _: &dyn Tr = &St; //~ ERROR E0038
+ //~^ ERROR E0038
+}
--- /dev/null
+error[E0038]: the trait `Tr` cannot be made into an object
+ --> $DIR/safety.rs:15:22
+ |
+LL | let _: &dyn Tr = &St;
+ | ^^^ `Tr` cannot be made into an object
+ |
+note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
+ --> $DIR/safety.rs:4:8
+ |
+LL | trait Tr {
+ | -- this trait cannot be made into an object...
+LL | fn foo();
+ | ^^^ ...because associated function `foo` has no `self` parameter
+ = note: required because of the requirements on the impl of `CoerceUnsized<&dyn Tr>` for `&St`
+ = note: required by cast to type `&dyn Tr`
+help: consider turning `foo` into a method by giving it a `&self` argument
+ |
+LL | fn foo(&self);
+ | ^^^^^
+help: alternatively, consider constraining `foo` so it does not apply to trait objects
+ |
+LL | fn foo() where Self: Sized;
+ | ^^^^^^^^^^^^^^^^^
+
+error[E0038]: the trait `Tr` cannot be made into an object
+ --> $DIR/safety.rs:15:12
+ |
+LL | let _: &dyn Tr = &St;
+ | ^^^^^^^ `Tr` cannot be made into an object
+ |
+note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
+ --> $DIR/safety.rs:4:8
+ |
+LL | trait Tr {
+ | -- this trait cannot be made into an object...
+LL | fn foo();
+ | ^^^ ...because associated function `foo` has no `self` parameter
+help: consider turning `foo` into a method by giving it a `&self` argument
+ |
+LL | fn foo(&self);
+ | ^^^^^
+help: alternatively, consider constraining `foo` so it does not apply to trait objects
+ |
+LL | fn foo() where Self: Sized;
+ | ^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0038`.
--- /dev/null
+// check-pass
+
+use std::any::Any;
+
+trait A<T>: Any {
+ fn m(&self) {}
+}
+
+impl<S, T: 'static> A<S> for T {}
+
+fn call_obj<'a>() {
+ let obj: &dyn A<&'a ()> = &();
+ obj.m();
+}
+
+fn main() {}
--- /dev/null
+// A few contrived examples where lifetime should (or should not) be parsed as an object type.
+// Lifetimes parsed as types are still rejected later by semantic checks.
+
+// `'static` is a lifetime, `'static +` is a type, `'a` is a type
+fn g() where
+ 'static: 'static,
+ dyn 'static +: 'static + Copy,
+ //~^ ERROR at least one trait is required for an object type
+{}
+
+fn main() {}
--- /dev/null
+error[E0224]: at least one trait is required for an object type
+ --> $DIR/vs-lifetime-2.rs:7:5
+ |
+LL | dyn 'static +: 'static + Copy,
+ | ^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0224`.
--- /dev/null
+// A few contrived examples where lifetime should (or should not) be parsed as an object type.
+// Lifetimes parsed as types are still rejected later by semantic checks.
+
+struct S<'a, T>(&'a u8, T);
+
+fn main() {
+ // `'static` is a lifetime argument, `'static +` is a type argument
+ let _: S<'static, u8>;
+ let _: S<'static, dyn 'static +>;
+ //~^ at least one trait is required for an object type
+ let _: S<'static, 'static>;
+ //~^ ERROR this struct takes 1 lifetime argument but 2 lifetime arguments were supplied
+ //~| ERROR this struct takes 1 type argument but 0 type arguments were supplied
+ let _: S<dyn 'static +, 'static>;
+ //~^ ERROR type provided when a lifetime was expected
+ //~| ERROR at least one trait is required for an object type
+}
--- /dev/null
+error[E0224]: at least one trait is required for an object type
+ --> $DIR/vs-lifetime.rs:9:23
+ |
+LL | let _: S<'static, dyn 'static +>;
+ | ^^^^^^^^^^^^^
+
+error[E0107]: this struct takes 1 lifetime argument but 2 lifetime arguments were supplied
+ --> $DIR/vs-lifetime.rs:11:12
+ |
+LL | let _: S<'static, 'static>;
+ | ^ --------- help: remove this lifetime argument
+ | |
+ | expected 1 lifetime argument
+ |
+note: struct defined here, with 1 lifetime parameter: `'a`
+ --> $DIR/vs-lifetime.rs:4:8
+ |
+LL | struct S<'a, T>(&'a u8, T);
+ | ^ --
+
+error[E0107]: this struct takes 1 type argument but 0 type arguments were supplied
+ --> $DIR/vs-lifetime.rs:11:12
+ |
+LL | let _: S<'static, 'static>;
+ | ^ expected 1 type argument
+ |
+note: struct defined here, with 1 type parameter: `T`
+ --> $DIR/vs-lifetime.rs:4:8
+ |
+LL | struct S<'a, T>(&'a u8, T);
+ | ^ -
+help: add missing type argument
+ |
+LL | let _: S<'static, 'static, T>;
+ | ^^^
+
+error[E0224]: at least one trait is required for an object type
+ --> $DIR/vs-lifetime.rs:14:14
+ |
+LL | let _: S<dyn 'static +, 'static>;
+ | ^^^^^^^^^^^^^
+
+error[E0747]: type provided when a lifetime was expected
+ --> $DIR/vs-lifetime.rs:14:14
+ |
+LL | let _: S<dyn 'static +, 'static>;
+ | ^^^^^^^^^^^^^
+
+error: aborting due to 5 previous errors
+
+Some errors have detailed explanations: E0107, E0224, E0747.
+For more information about an error, try `rustc --explain E0107`.
--- /dev/null
+// run-pass
+// Uncovered during work on new scoping rules for safe destructors
+// as an important use case to support properly.
+
+
+pub struct E<'a> {
+ pub f: &'a u8,
+}
+impl<'b> E<'b> {
+ pub fn m(&self) -> &'b u8 { self.f }
+}
+
+pub struct P<'c> {
+ pub g: &'c u8,
+}
+pub trait M {
+ fn n(&self) -> u8;
+}
+impl<'d> M for P<'d> {
+ fn n(&self) -> u8 { *self.g }
+}
+
+fn extension<'e>(x: &'e E<'e>) -> Box<dyn M+'e> {
+ loop {
+ let p = P { g: x.m() };
+ return Box::new(p) as Box<dyn M+'e>;
+ }
+}
+
+fn main() {
+ let w = E { f: &10 };
+ let o = extension(&w);
+ assert_eq!(o.n(), 10);
+}
--- /dev/null
+// Regression test for #56288. Checks that if a supertrait defines an associated type
+// projection that references `Self`, then that associated type must still be explicitly
+// specified in the `dyn Trait` variant, since we don't know what `Self` is anymore.
+
+trait Base {
+ type Output;
+}
+
+trait Helper: Base<Output=<Self as Helper>::Target> {
+ type Target;
+}
+
+impl Base for u32
+{
+ type Output = i32;
+}
+
+impl Helper for u32
+{
+ type Target = i32;
+}
+
+trait ConstI32 {
+ type Out;
+}
+
+impl<T: ?Sized> ConstI32 for T {
+ type Out = i32;
+}
+
+// Test that you still need to manually give a projection type if the Output type
+// is normalizable.
+trait NormalizableHelper:
+ Base<Output=<Self as ConstI32>::Out>
+{
+ type Target;
+}
+
+impl NormalizableHelper for u32
+{
+ type Target = i32;
+}
+
+fn main() {
+ let _x: Box<dyn Helper<Target=i32>> = Box::new(2u32);
+ //~^ ERROR the value of the associated type `Output` (from trait `Base`) must be specified
+
+ let _y: Box<dyn NormalizableHelper<Target=i32>> = Box::new(2u32);
+ //~^ ERROR the value of the associated type `Output` (from trait `Base`) must be specified
+}
--- /dev/null
+error[E0191]: the value of the associated type `Output` (from trait `Base`) must be specified
+ --> $DIR/with-self-in-projection-output-bad.rs:45:21
+ |
+LL | type Output;
+ | ------------ `Output` defined here
+...
+LL | let _x: Box<dyn Helper<Target=i32>> = Box::new(2u32);
+ | ^^^^^^^^^^^^^^^^^^ help: specify the associated type: `Helper<Target=i32, Output = Type>`
+
+error[E0191]: the value of the associated type `Output` (from trait `Base`) must be specified
+ --> $DIR/with-self-in-projection-output-bad.rs:48:21
+ |
+LL | type Output;
+ | ------------ `Output` defined here
+...
+LL | let _y: Box<dyn NormalizableHelper<Target=i32>> = Box::new(2u32);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: specify the associated type: `NormalizableHelper<Target=i32, Output = Type>`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0191`.
--- /dev/null
+// build-pass (FIXME(62277): could be check-pass?)
+
+// Regression test related to #56288. Check that a supertrait projection (of
+// `Output`) that references `Self` can be ok if it is referencing a projection (of
+// `Self::Target`, in this case). Note that we still require the user to manually
+// specify both `Target` and `Output` for now.
+
+trait Base {
+ type Output;
+}
+
+trait Helper: Base<Output=<Self as Helper>::Target> {
+ type Target;
+}
+
+impl Base for u32
+{
+ type Output = i32;
+}
+
+impl Helper for u32
+{
+ type Target = i32;
+}
+
+fn main() {
+ let _x: Box<dyn Helper<Target=i32, Output=i32>> = Box::new(2u32);
+}
--- /dev/null
+// build-pass (FIXME(62277): could be check-pass?)
+
+// FIXME(eddyb) shorten the name so windows doesn't choke on it.
+#![crate_name = "trait_test"]
+
+// Regression test related to #56288. Check that a supertrait projection (of
+// `Output`) that references `Self` is ok if there is another occurrence of
+// the same supertrait that specifies the projection explicitly, even if
+// the projection's associated type is not explicitly specified in the object type.
+//
+// Note that in order for this to compile, we need the `Self`-referencing projection
+// to normalize fairly directly to a concrete type, otherwise the trait resolver
+// will hate us.
+//
+// There is a test in `trait-object-with-self-in-projection-output-bad.rs` that
+// having a normalizing, but `Self`-containing projection does not *by itself*
+// allow you to avoid writing the projected type (`Output`, in this example)
+// explicitly.
+
+trait ConstI32 {
+ type Out;
+}
+
+impl<T: ?Sized> ConstI32 for T {
+ type Out = i32;
+}
+
+trait Base {
+ type Output;
+}
+
+trait NormalizingHelper: Base<Output=<Self as ConstI32>::Out> + Base<Output=i32> {
+ type Target;
+}
+
+impl Base for u32
+{
+ type Output = i32;
+}
+
+impl NormalizingHelper for u32
+{
+ type Target = i32;
+}
+
+fn main() {
+ // Make sure this works both with and without the associated type
+ // being specified.
+ let _x: Box<dyn NormalizingHelper<Target=i32>> = Box::new(2u32);
+ let _y: Box<dyn NormalizingHelper<Target=i32, Output=i32>> = Box::new(2u32);
+}
--- /dev/null
+struct Article {
+ proof_reader: ProofReader,
+}
+
+struct ProofReader {
+ name: String,
+}
+
+pub trait HaveRelationship<To> {
+ fn get_relation(&self) -> To;
+}
+
+impl HaveRelationship<&ProofReader> for Article {
+ fn get_relation(&self) -> &ProofReader {
+ //~^ ERROR `impl` item signature doesn't match `trait` item signature
+ &self.proof_reader
+ }
+}
+
+fn main() {}
--- /dev/null
+error: `impl` item signature doesn't match `trait` item signature
+ --> $DIR/param-without-lifetime-constraint.rs:14:5
+ |
+LL | fn get_relation(&self) -> To;
+ | ----------------------------- expected `fn(&Article) -> &ProofReader`
+...
+LL | fn get_relation(&self) -> &ProofReader {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&Article) -> &ProofReader`
+ |
+ = note: expected `fn(&Article) -> &ProofReader`
+ found `fn(&Article) -> &ProofReader`
+help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
+ --> $DIR/param-without-lifetime-constraint.rs:10:31
+ |
+LL | fn get_relation(&self) -> To;
+ | ^^ consider borrowing this type parameter in the trait
+
+error: aborting due to previous error
+
+++ /dev/null
-// run-pass
-// pretty-expanded FIXME #23616
-
-#![allow(dead_code)]
-
-
-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> { fn get(self) -> &'a T; }
-}
-
-fn foo1<T>(_: &(dyn A<T> + Send)) {}
-fn foo2<T>(_: Box<dyn A<T> + Send + Sync>) {}
-fn foo3<T>(_: Box<dyn B<isize, usize> + 'static>) {}
-fn foo4<'a, T>(_: Box<dyn C<'a, T> + 'static + Send>) {}
-fn foo5<'a, T>(_: Box<dyn foo::D<'a, T> + 'static + Send>) {}
-
-pub fn main() {}
--- /dev/null
+// run-pass
+// pretty-expanded FIXME #23616
+
+#![allow(dead_code)]
+
+
+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> { fn get(self) -> &'a T; }
+}
+
+fn foo1<T>(_: &(dyn A<T> + Send)) {}
+fn foo2<T>(_: Box<dyn A<T> + Send + Sync>) {}
+fn foo3<T>(_: Box<dyn B<isize, usize> + 'static>) {}
+fn foo4<'a, T>(_: Box<dyn C<'a, T> + 'static + Send>) {}
+fn foo5<'a, T>(_: Box<dyn foo::D<'a, T> + 'static + Send>) {}
+
+pub fn main() {}
--- /dev/null
+// run-pass
+// Check that trait objects without a principal codegen properly.
+
+use std::sync::atomic::{AtomicUsize, Ordering};
+use std::mem;
+
+// Array is to make sure the size is not exactly pointer-size, so
+// we can be sure we are measuring the right size in the
+// `size_of_val` test.
+struct SetOnDrop<'a>(&'a AtomicUsize, [u8; 64]);
+impl<'a> Drop for SetOnDrop<'a> {
+ fn drop(&mut self) {
+ self.0.store(self.0.load(Ordering::Relaxed) + 1, Ordering::Relaxed);
+ }
+}
+
+trait TypeEq<V: ?Sized> {}
+impl<T: ?Sized> TypeEq<T> for T {}
+fn assert_types_eq<U: ?Sized, V: ?Sized>() where U: TypeEq<V> {}
+
+fn main() {
+ // Check that different ways of writing the same type are equal.
+ assert_types_eq::<dyn Sync, dyn Sync + Sync>();
+ assert_types_eq::<dyn Sync + Send, dyn Send + Sync>();
+ assert_types_eq::<dyn Sync + Send + Sync, dyn Send + Sync>();
+
+ // Check that codegen works.
+ //
+ // Using `AtomicUsize` here because `Cell<u32>` is not `Sync`, and
+ // so can't be made into a `Box<dyn Sync>`.
+ let c = AtomicUsize::new(0);
+ {
+ let d: Box<dyn Sync> = Box::new(SetOnDrop(&c, [0; 64]));
+
+ assert_eq!(mem::size_of_val(&*d),
+ mem::size_of::<SetOnDrop>());
+ assert_eq!(mem::align_of_val(&*d),
+ mem::align_of::<SetOnDrop>());
+ assert_eq!(c.load(Ordering::Relaxed), 0);
+ }
+ assert_eq!(c.load(Ordering::Relaxed), 1);
+}
+++ /dev/null
-// run-pass
-// Check that trait objects without a principal codegen properly.
-
-use std::sync::atomic::{AtomicUsize, Ordering};
-use std::mem;
-
-// Array is to make sure the size is not exactly pointer-size, so
-// we can be sure we are measuring the right size in the
-// `size_of_val` test.
-struct SetOnDrop<'a>(&'a AtomicUsize, [u8; 64]);
-impl<'a> Drop for SetOnDrop<'a> {
- fn drop(&mut self) {
- self.0.store(self.0.load(Ordering::Relaxed) + 1, Ordering::Relaxed);
- }
-}
-
-trait TypeEq<V: ?Sized> {}
-impl<T: ?Sized> TypeEq<T> for T {}
-fn assert_types_eq<U: ?Sized, V: ?Sized>() where U: TypeEq<V> {}
-
-fn main() {
- // Check that different ways of writing the same type are equal.
- assert_types_eq::<dyn Sync, dyn Sync + Sync>();
- assert_types_eq::<dyn Sync + Send, dyn Send + Sync>();
- assert_types_eq::<dyn Sync + Send + Sync, dyn Send + Sync>();
-
- // Check that codegen works.
- //
- // Using `AtomicUsize` here because `Cell<u32>` is not `Sync`, and
- // so can't be made into a `Box<dyn Sync>`.
- let c = AtomicUsize::new(0);
- {
- let d: Box<dyn Sync> = Box::new(SetOnDrop(&c, [0; 64]));
-
- assert_eq!(mem::size_of_val(&*d),
- mem::size_of::<SetOnDrop>());
- assert_eq!(mem::align_of_val(&*d),
- mem::align_of::<SetOnDrop>());
- assert_eq!(c.load(Ordering::Relaxed), 0);
- }
- assert_eq!(c.load(Ordering::Relaxed), 1);
-}
--- /dev/null
+// build-pass (FIXME(62277): could be check-pass?)
+#![allow(dead_code)]
+mod foo {
+ pub use self::bar::T;
+ mod bar {
+ pub trait T {
+ fn f(&self) {}
+ }
+ impl T for () {}
+ }
+}
+
+fn g() {
+ use foo::T;
+ ().f(); // Check that this does not trigger a privacy error
+}
+
+fn f() {
+ let error = ::std::thread::spawn(|| {}).join().unwrap_err();
+ error.type_id(); // Regression test for #21670
+}
+
+
+fn main() {}
--- /dev/null
+// run-pass
+trait Foo {
+ fn f(&self) -> isize;
+}
+
+struct A {
+ x: isize
+}
+
+impl Foo for A {
+ fn f(&self) -> isize {
+ println!("Today's number is {}", self.x);
+ return self.x;
+ }
+}
+
+pub fn main() {
+ let a = A { x: 3 };
+ let b = (&a) as &dyn Foo;
+ assert_eq!(b.f(), 3);
+}
--- /dev/null
+// check that reservation impls are accounted for in negative reasoning.
+
+#![feature(rustc_attrs)]
+
+trait MyTrait {}
+#[rustc_reservation_impl="this impl is reserved"]
+impl MyTrait for () {}
+
+trait OtherTrait {}
+impl OtherTrait for () {}
+impl<T: MyTrait> OtherTrait for T {}
+//~^ ERROR conflicting implementations
+
+fn main() {}
--- /dev/null
+error[E0119]: conflicting implementations of trait `OtherTrait` for type `()`:
+ --> $DIR/coherence-conflict.rs:11:1
+ |
+LL | impl OtherTrait for () {}
+ | ---------------------- first implementation here
+LL | impl<T: MyTrait> OtherTrait for T {}
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()`
+ |
+ = note: this impl is reserved
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
--- /dev/null
+// check that reservation impls can't be used as normal impls in positive reasoning.
+
+#![feature(rustc_attrs)]
+
+trait MyTrait { fn foo(&self); }
+#[rustc_reservation_impl = "foo"]
+impl MyTrait for () { fn foo(&self) {} }
+
+fn main() {
+ <() as MyTrait>::foo(&());
+ //~^ ERROR the trait bound `(): MyTrait` is not satisfied
+}
--- /dev/null
+error[E0277]: the trait bound `(): MyTrait` is not satisfied
+ --> $DIR/no-use.rs:10:26
+ |
+LL | trait MyTrait { fn foo(&self); }
+ | -------------- required by `MyTrait::foo`
+...
+LL | <() as MyTrait>::foo(&());
+ | ^^^ the trait `MyTrait` is not implemented for `()`
+ |
+ = help: the following implementations were found:
+ <() as MyTrait>
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+// build-pass
+
+// Check that a reservation impl does not force other impls to follow
+// a lattice discipline.
+
+// Why did we ever want to do this?
+//
+// We want to eventually add a `impl<T> From<!> for T` impl. That impl conflicts
+// with existing impls - at least the `impl<T> From<T> for T` impl. There are
+// 2 ways we thought of for dealing with that conflict:
+//
+// 1. Using specialization and doing some handling for the
+// overlap. The current thought is to require ["intersection
+// impls"][ii], specialization", which means providing an
+// (higher-priority) impl for the intersection of every 2 conflicting
+// impls that determines what happens in the intersection case. That's
+// the first thing we thought about - see e.g.
+// https://github.com/rust-lang/rust/issues/57012#issuecomment-452150775
+//
+// 2. The other way is to notice that `impl From<!> for T` is basically a
+// marker trait since its only method is uninhabited, and allow for "marker
+// trait overlap", where the conflict "doesn't matter" because it can't
+// actually cause any ambiguity.
+//
+// Now it turned out lattice specialization doesn't work it, because an
+// `impl<T> From<T> for Smaht<T>` would require a `impl From<!> for Smaht<!>`,
+// breaking backwards-compatibility in a fairly painful way. So if we want to
+// go with a known approach, we should go with a "marker trait overlap"-style
+// approach.
+//
+// [ii]: http://smallcultfollowing.com/babysteps/blog/2016/09/24/intersection-impls/
+
+#![feature(rustc_attrs, never_type)]
+
+trait MyTrait {}
+
+impl MyTrait for ! {}
+
+trait MyFrom<T> {
+ fn my_from(x: T) -> Self;
+}
+
+// Given the "normal" impls for From
+#[rustc_reservation_impl="this impl is reserved"]
+impl<T> MyFrom<!> for T {
+ fn my_from(x: !) -> Self { match x {} }
+}
+
+impl<T> MyFrom<T> for T {
+ fn my_from(x: T) -> Self { x }
+}
+
+// ... we *do* want to allow this common pattern, of `From<!> for MySmaht<T>`
+struct MySmaht<T>(T);
+impl<T> MyFrom<T> for MySmaht<T> {
+ fn my_from(x: T) -> Self { MySmaht(x) }
+}
+
+fn main() {}
--- /dev/null
+// run-pass
+
+// rpass test for reservation impls. Not 100% required because `From` uses them,
+// but still.
+
+#![feature(rustc_attrs)]
+
+use std::mem;
+
+trait MyTrait<S> {
+ fn foo(&self, s: S) -> usize;
+}
+
+#[rustc_reservation_impl = "foo"]
+impl<T> MyTrait<u64> for T {
+ fn foo(&self, _x: u64) -> usize { 0 }
+}
+
+// reservation impls don't create coherence conflicts, even with
+// non-chain overlap.
+impl<S> MyTrait<S> for u32 {
+ fn foo(&self, _x: S) -> usize { mem::size_of::<S>() }
+}
+
+fn main() {
+ // ...and the non-reservation impl gets picked.XS
+ assert_eq!(0u32.foo(0u64), mem::size_of::<u64>());
+}
+++ /dev/null
-// check that reservation impls are accounted for in negative reasoning.
-
-#![feature(rustc_attrs)]
-
-trait MyTrait {}
-#[rustc_reservation_impl="this impl is reserved"]
-impl MyTrait for () {}
-
-trait OtherTrait {}
-impl OtherTrait for () {}
-impl<T: MyTrait> OtherTrait for T {}
-//~^ ERROR conflicting implementations
-
-fn main() {}
+++ /dev/null
-error[E0119]: conflicting implementations of trait `OtherTrait` for type `()`:
- --> $DIR/reservation-impl-coherence-conflict.rs:11:1
- |
-LL | impl OtherTrait for () {}
- | ---------------------- first implementation here
-LL | impl<T: MyTrait> OtherTrait for T {}
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()`
- |
- = note: this impl is reserved
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0119`.
+++ /dev/null
-// check that reservation impls can't be used as normal impls in positive reasoning.
-
-#![feature(rustc_attrs)]
-
-trait MyTrait { fn foo(&self); }
-#[rustc_reservation_impl = "foo"]
-impl MyTrait for () { fn foo(&self) {} }
-
-fn main() {
- <() as MyTrait>::foo(&());
- //~^ ERROR the trait bound `(): MyTrait` is not satisfied
-}
+++ /dev/null
-error[E0277]: the trait bound `(): MyTrait` is not satisfied
- --> $DIR/reservation-impl-no-use.rs:10:26
- |
-LL | trait MyTrait { fn foo(&self); }
- | -------------- required by `MyTrait::foo`
-...
-LL | <() as MyTrait>::foo(&());
- | ^^^ the trait `MyTrait` is not implemented for `()`
- |
- = help: the following implementations were found:
- <() as MyTrait>
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-// build-pass
-
-// Check that a reservation impl does not force other impls to follow
-// a lattice discipline.
-
-// Why did we ever want to do this?
-//
-// We want to eventually add a `impl<T> From<!> for T` impl. That impl conflicts
-// with existing impls - at least the `impl<T> From<T> for T` impl. There are
-// 2 ways we thought of for dealing with that conflict:
-//
-// 1. Using specialization and doing some handling for the
-// overlap. The current thought is to require ["intersection
-// impls"][ii], specialization", which means providing an
-// (higher-priority) impl for the intersection of every 2 conflicting
-// impls that determines what happens in the intersection case. That's
-// the first thing we thought about - see e.g.
-// https://github.com/rust-lang/rust/issues/57012#issuecomment-452150775
-//
-// 2. The other way is to notice that `impl From<!> for T` is basically a
-// marker trait since its only method is uninhabited, and allow for "marker
-// trait overlap", where the conflict "doesn't matter" because it can't
-// actually cause any ambiguity.
-//
-// Now it turned out lattice specialization doesn't work it, because an
-// `impl<T> From<T> for Smaht<T>` would require a `impl From<!> for Smaht<!>`,
-// breaking backwards-compatibility in a fairly painful way. So if we want to
-// go with a known approach, we should go with a "marker trait overlap"-style
-// approach.
-//
-// [ii]: http://smallcultfollowing.com/babysteps/blog/2016/09/24/intersection-impls/
-
-#![feature(rustc_attrs, never_type)]
-
-trait MyTrait {}
-
-impl MyTrait for ! {}
-
-trait MyFrom<T> {
- fn my_from(x: T) -> Self;
-}
-
-// Given the "normal" impls for From
-#[rustc_reservation_impl="this impl is reserved"]
-impl<T> MyFrom<!> for T {
- fn my_from(x: !) -> Self { match x {} }
-}
-
-impl<T> MyFrom<T> for T {
- fn my_from(x: T) -> Self { x }
-}
-
-// ... we *do* want to allow this common pattern, of `From<!> for MySmaht<T>`
-struct MySmaht<T>(T);
-impl<T> MyFrom<T> for MySmaht<T> {
- fn my_from(x: T) -> Self { MySmaht(x) }
-}
-
-fn main() {}
+++ /dev/null
-// run-pass
-
-// rpass test for reservation impls. Not 100% required because `From` uses them,
-// but still.
-
-#![feature(rustc_attrs)]
-
-use std::mem;
-
-trait MyTrait<S> {
- fn foo(&self, s: S) -> usize;
-}
-
-#[rustc_reservation_impl = "foo"]
-impl<T> MyTrait<u64> for T {
- fn foo(&self, _x: u64) -> usize { 0 }
-}
-
-// reservation impls don't create coherence conflicts, even with
-// non-chain overlap.
-impl<S> MyTrait<S> for u32 {
- fn foo(&self, _x: S) -> usize { mem::size_of::<S>() }
-}
-
-fn main() {
- // ...and the non-reservation impl gets picked.XS
- assert_eq!(0u32.foo(0u64), mem::size_of::<u64>());
-}
--- /dev/null
+// #12402 Operator overloading only considers the method name, not which trait is implemented
+
+trait MyMul<Rhs, Res> {
+ fn mul(&self, rhs: &Rhs) -> Res;
+}
+
+fn foo<T: MyMul<f64, f64>>(a: &T, b: f64) -> f64 {
+ a * b //~ ERROR cannot multiply `&T` by `f64`
+}
+
+fn main() {}
--- /dev/null
+error[E0369]: cannot multiply `&T` by `f64`
+ --> $DIR/resolution-in-overloaded-op.rs:8:7
+ |
+LL | a * b
+ | - ^ - f64
+ | |
+ | &T
+ |
+help: consider further restricting this bound
+ |
+LL | fn foo<T: MyMul<f64, f64> + std::ops::Mul<Output = f64>>(a: &T, b: f64) -> f64 {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0369`.
--- /dev/null
+// Check that an unsafe impl does not imply that unsafe actions are
+// legal in the methods.
+
+unsafe trait UnsafeTrait : Sized {
+ fn foo(self) { }
+}
+
+unsafe impl UnsafeTrait for *mut isize {
+ fn foo(self) {
+ // Unsafe actions are not made legal by taking place in an unsafe trait:
+ *self += 1;
+ //~^ ERROR E0133
+ }
+}
+
+fn main() { }
--- /dev/null
+error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
+ --> $DIR/safety-fn-body.rs:11:9
+ |
+LL | *self += 1;
+ | ^^^^^^^^^^ dereference of raw pointer
+ |
+ = note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0133`.
--- /dev/null
+// Check that inherent impls cannot be unsafe.
+
+struct SomeStruct;
+
+unsafe impl SomeStruct { //~ ERROR inherent impls cannot be unsafe
+ fn foo(self) { }
+}
+
+fn main() { }
--- /dev/null
+error[E0197]: inherent impls cannot be unsafe
+ --> $DIR/safety-inherent-impl.rs:5:13
+ |
+LL | unsafe impl SomeStruct {
+ | ------ ^^^^^^^^^^ inherent impl for this type
+ | |
+ | unsafe because of this
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0197`.
--- /dev/null
+// run-pass
+// aux-build:trait_safety_lib.rs
+
+// Simple smoke test that unsafe traits can be compiled across crates.
+
+
+extern crate trait_safety_lib as lib;
+
+use lib::Foo;
+
+struct Bar { x: isize }
+unsafe impl Foo for Bar {
+ fn foo(&self) -> isize { self.x }
+}
+
+fn take_foo<F:Foo>(f: &F) -> isize { f.foo() }
+
+fn main() {
+ let x: isize = 22;
+ assert_eq!(22, take_foo(&x));
+
+ let x: Bar = Bar { x: 23 };
+ assert_eq!(23, take_foo(&x));
+}
--- /dev/null
+// run-pass
+// Simple smoke test that unsafe traits can be compiled etc.
+
+
+unsafe trait Foo {
+ fn foo(&self) -> isize;
+}
+
+unsafe impl Foo for isize {
+ fn foo(&self) -> isize { *self }
+}
+
+fn take_foo<F:Foo>(f: &F) -> isize { f.foo() }
+
+fn main() {
+ let x: isize = 22;
+ assert_eq!(22, take_foo(&x));
+}
--- /dev/null
+// aux-build:trait_safety_lib.rs
+
+// Check that unsafe traits require unsafe impls and that inherent
+// impls cannot be unsafe.
+
+extern crate trait_safety_lib as lib;
+
+struct Bar;
+impl lib::Foo for Bar { //~ ERROR requires an `unsafe impl` declaration
+ fn foo(&self) -> isize {
+ panic!();
+ }
+}
+
+fn main() { }
--- /dev/null
+error[E0200]: the trait `Foo` requires an `unsafe impl` declaration
+ --> $DIR/safety-trait-impl-cc.rs:9:1
+ |
+LL | / impl lib::Foo for Bar {
+LL | | fn foo(&self) -> isize {
+LL | | panic!();
+LL | | }
+LL | | }
+ | |_^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0200`.
--- /dev/null
+// Check that unsafe traits require unsafe impls and that inherent
+// impls cannot be unsafe.
+
+trait SafeTrait {
+ fn foo(&self) { }
+}
+
+unsafe trait UnsafeTrait {
+ fn foo(&self) { }
+}
+
+unsafe impl UnsafeTrait for u8 { } // OK
+
+impl UnsafeTrait for u16 { } //~ ERROR requires an `unsafe impl` declaration
+
+unsafe impl SafeTrait for u32 { } //~ ERROR the trait `SafeTrait` is not unsafe
+
+fn main() { }
--- /dev/null
+error[E0200]: the trait `UnsafeTrait` requires an `unsafe impl` declaration
+ --> $DIR/safety-trait-impl.rs:14:1
+ |
+LL | impl UnsafeTrait for u16 { }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error[E0199]: implementing the trait `SafeTrait` is not unsafe
+ --> $DIR/safety-trait-impl.rs:16:1
+ |
+LL | unsafe impl SafeTrait for u32 { }
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0199, E0200.
+For more information about an error, try `rustc --explain E0199`.
--- /dev/null
+// Issue #3902. We are (at least currently) unable to infer `Self`
+// based on `T`, even though there is only a single impl, because of
+// the possibility of associated types and other things (basically: no
+// constraints on `Self` here at all).
+
+mod base {
+ pub trait HasNew<T> {
+ fn new() -> T;
+ fn dummy(&self) { }
+ }
+
+ pub struct Foo {
+ dummy: (),
+ }
+
+ impl HasNew<Foo> for Foo {
+ fn new() -> Foo {
+ Foo { dummy: () }
+ }
+ }
+}
+
+pub fn foo() {
+ let _f: base::Foo = base::HasNew::new();
+ //~^ ERROR type annotations needed
+}
+
+fn main() { }
--- /dev/null
+error[E0283]: type annotations needed
+ --> $DIR/static-method-generic-inference.rs:24:25
+ |
+LL | fn new() -> T;
+ | -------------- required by `HasNew::new`
+...
+LL | let _f: base::Foo = base::HasNew::new();
+ | ^^^^^^^^^^^^^^^^^ cannot infer type
+ |
+ = note: cannot satisfy `_: HasNew<Foo>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0283`.
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+mod base {
+ pub trait HasNew {
+ fn new() -> Self;
+ }
+
+ pub struct Foo {
+ dummy: (),
+ }
+
+ impl ::base::HasNew for Foo {
+ fn new() -> Foo {
+ println!("Foo");
+ Foo { dummy: () }
+ }
+ }
+
+ pub struct Bar {
+ dummy: (),
+ }
+
+ impl ::base::HasNew for Bar {
+ fn new() -> Bar {
+ println!("Bar");
+ Bar { dummy: () }
+ }
+ }
+}
+
+pub fn main() {
+ let _f: base::Foo = base::HasNew::new();
+ let _b: base::Bar = base::HasNew::new();
+}
--- /dev/null
+// run-pass
+
+trait Foo<'a> {
+ fn xyz(self);
+}
+impl<'a, T> Foo<'a> for T where 'static: 'a {
+ fn xyz(self) {}
+}
+
+trait Bar {
+ fn uvw(self);
+}
+impl<T> Bar for T where for<'a> T: Foo<'a> {
+ fn uvw(self) { self.xyz(); }
+}
+
+fn foo<T>(t: T) where T: Bar {
+ t.uvw();
+}
+
+fn main() {
+ foo(0);
+}
--- /dev/null
+// run-rustfix
+use std::net::TcpListener;
+
+struct NoToSocketAddrs(String);
+
+impl std::ops::Deref for NoToSocketAddrs {
+ type Target = String;
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+
+fn main() {
+ let _works = TcpListener::bind("some string");
+ let bad = NoToSocketAddrs("bad".to_owned());
+ let _errors = TcpListener::bind(&*bad);
+ //~^ ERROR the trait bound `NoToSocketAddrs: ToSocketAddrs` is not satisfied
+}
--- /dev/null
+// run-rustfix
+use std::net::TcpListener;
+
+struct NoToSocketAddrs(String);
+
+impl std::ops::Deref for NoToSocketAddrs {
+ type Target = String;
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+
+fn main() {
+ let _works = TcpListener::bind("some string");
+ let bad = NoToSocketAddrs("bad".to_owned());
+ let _errors = TcpListener::bind(&bad);
+ //~^ ERROR the trait bound `NoToSocketAddrs: ToSocketAddrs` is not satisfied
+}
--- /dev/null
+error[E0277]: the trait bound `NoToSocketAddrs: ToSocketAddrs` is not satisfied
+ --> $DIR/issue-39029.rs:16:37
+ |
+LL | let _errors = TcpListener::bind(&bad);
+ | ^^^^
+ | |
+ | the trait `ToSocketAddrs` is not implemented for `NoToSocketAddrs`
+ | help: consider adding dereference here: `&*bad`
+ |
+ ::: $SRC_DIR/std/src/net/tcp.rs:LL:COL
+ |
+LL | pub fn bind<A: ToSocketAddrs>(addr: A) -> io::Result<TcpListener> {
+ | ------------- required by this bound in `TcpListener::bind`
+ |
+ = note: required because of the requirements on the impl of `ToSocketAddrs` for `&NoToSocketAddrs`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+// run-rustfix
+fn takes_str(_x: &str) {}
+
+fn takes_type_parameter<T>(_x: T) where T: SomeTrait {}
+
+trait SomeTrait {}
+impl SomeTrait for &'_ str {}
+impl SomeTrait for char {}
+
+fn main() {
+ let string = String::new();
+ takes_str(&string); // Ok
+ takes_type_parameter(&*string); // Error
+ //~^ ERROR the trait bound `&String: SomeTrait` is not satisfied
+}
--- /dev/null
+// run-rustfix
+fn takes_str(_x: &str) {}
+
+fn takes_type_parameter<T>(_x: T) where T: SomeTrait {}
+
+trait SomeTrait {}
+impl SomeTrait for &'_ str {}
+impl SomeTrait for char {}
+
+fn main() {
+ let string = String::new();
+ takes_str(&string); // Ok
+ takes_type_parameter(&string); // Error
+ //~^ ERROR the trait bound `&String: SomeTrait` is not satisfied
+}
--- /dev/null
+error[E0277]: the trait bound `&String: SomeTrait` is not satisfied
+ --> $DIR/issue-62530.rs:13:26
+ |
+LL | fn takes_type_parameter<T>(_x: T) where T: SomeTrait {}
+ | --------- required by this bound in `takes_type_parameter`
+...
+LL | takes_type_parameter(&string); // Error
+ | ^^^^^^^
+ | |
+ | the trait `SomeTrait` is not implemented for `&String`
+ | help: consider adding dereference here: `&*string`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+// run-rustfix
+use std::ops::Deref;
+
+trait Happy {}
+struct LDM;
+impl Happy for &LDM {}
+
+struct Foo(LDM);
+struct Bar(Foo);
+struct Baz(Bar);
+impl Deref for Foo {
+ type Target = LDM;
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+impl Deref for Bar {
+ type Target = Foo;
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+impl Deref for Baz {
+ type Target = Bar;
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+
+fn foo<T>(_: T) where T: Happy {}
+
+fn main() {
+ let baz = Baz(Bar(Foo(LDM)));
+ foo(&***baz);
+ //~^ ERROR the trait bound `&Baz: Happy` is not satisfied
+}
--- /dev/null
+// run-rustfix
+use std::ops::Deref;
+
+trait Happy {}
+struct LDM;
+impl Happy for &LDM {}
+
+struct Foo(LDM);
+struct Bar(Foo);
+struct Baz(Bar);
+impl Deref for Foo {
+ type Target = LDM;
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+impl Deref for Bar {
+ type Target = Foo;
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+impl Deref for Baz {
+ type Target = Bar;
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+
+fn foo<T>(_: T) where T: Happy {}
+
+fn main() {
+ let baz = Baz(Bar(Foo(LDM)));
+ foo(&baz);
+ //~^ ERROR the trait bound `&Baz: Happy` is not satisfied
+}
--- /dev/null
+error[E0277]: the trait bound `&Baz: Happy` is not satisfied
+ --> $DIR/multiple-0.rs:34:9
+ |
+LL | fn foo<T>(_: T) where T: Happy {}
+ | ----- required by this bound in `foo`
+...
+LL | foo(&baz);
+ | ^^^^
+ | |
+ | the trait `Happy` is not implemented for `&Baz`
+ | help: consider adding dereference here: `&***baz`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+use std::ops::{Deref, DerefMut};
+
+trait Happy {}
+struct LDM;
+impl Happy for &mut LDM {}
+
+struct Foo(LDM);
+struct Bar(Foo);
+struct Baz(Bar);
+impl Deref for Foo {
+ type Target = LDM;
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+impl Deref for Bar {
+ type Target = Foo;
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+impl Deref for Baz {
+ type Target = Bar;
+ fn deref(&self) -> &Self::Target {
+ &self.0
+ }
+}
+impl DerefMut for Foo {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut self.0
+ }
+}
+impl DerefMut for Bar {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut self.0
+ }
+}
+impl DerefMut for Baz {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut self.0
+ }
+}
+
+
+fn foo<T>(_: T) where T: Happy {}
+
+fn main() {
+ // Currently the compiler doesn't try to suggest dereferences for situations
+ // where DerefMut involves. So this test is meant to ensure compiler doesn't
+ // generate incorrect help message.
+ let mut baz = Baz(Bar(Foo(LDM)));
+ foo(&mut baz);
+ //~^ ERROR the trait bound `&mut Baz: Happy` is not satisfied
+}
--- /dev/null
+error[E0277]: the trait bound `&mut Baz: Happy` is not satisfied
+ --> $DIR/multiple-1.rs:52:9
+ |
+LL | fn foo<T>(_: T) where T: Happy {}
+ | ----- required by this bound in `foo`
+...
+LL | foo(&mut baz);
+ | ^^^^^^^^ the trait `Happy` is not implemented for `&mut Baz`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+use std::mem;
+
+struct Misc<T:?Sized>(T);
+
+fn check<T: Iterator, U: ?Sized>() {
+ // suggest a where-clause, if needed
+ mem::size_of::<U>();
+ //~^ ERROR the size for values of type
+
+ mem::size_of::<Misc<U>>();
+ //~^ ERROR the size for values of type
+
+ // ... even if T occurs as a type parameter
+
+ <u64 as From<T>>::from;
+ //~^ ERROR `u64: From<T>` is not satisfied
+
+ <u64 as From<<T as Iterator>::Item>>::from;
+ //~^ ERROR `u64: From<<T as Iterator>::Item>` is not satisfied
+
+ // ... but not if there are inference variables
+
+ <Misc<_> as From<T>>::from;
+ //~^ ERROR `Misc<_>: From<T>` is not satisfied
+
+ // ... and also not if the error is not related to the type
+
+ mem::size_of::<[T]>();
+ //~^ ERROR the size for values of type
+
+ mem::size_of::<[&U]>();
+ //~^ ERROR the size for values of type
+}
+
+fn main() {
+}
--- /dev/null
+error[E0277]: the size for values of type `U` cannot be known at compilation time
+ --> $DIR/suggest-where-clause.rs:7:20
+ |
+LL | fn check<T: Iterator, U: ?Sized>() {
+ | - this type parameter needs to be `Sized`
+LL | // suggest a where-clause, if needed
+LL | mem::size_of::<U>();
+ | ^ doesn't have a size known at compile-time
+ |
+ ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL
+ |
+LL | pub const fn size_of<T>() -> usize {
+ | - required by this bound in `std::mem::size_of`
+
+error[E0277]: the size for values of type `U` cannot be known at compilation time
+ --> $DIR/suggest-where-clause.rs:10:5
+ |
+LL | fn check<T: Iterator, U: ?Sized>() {
+ | - this type parameter needs to be `Sized`
+...
+LL | mem::size_of::<Misc<U>>();
+ | ^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL
+ |
+LL | pub const fn size_of<T>() -> usize {
+ | - required by this bound in `std::mem::size_of`
+ |
+ = note: required because it appears within the type `Misc<U>`
+
+error[E0277]: the trait bound `u64: From<T>` is not satisfied
+ --> $DIR/suggest-where-clause.rs:15:5
+ |
+LL | <u64 as From<T>>::from;
+ | ^^^^^^^^^^^^^^^^^^^^^^ the trait `From<T>` is not implemented for `u64`
+ |
+ = note: required by `from`
+
+error[E0277]: the trait bound `u64: From<<T as Iterator>::Item>` is not satisfied
+ --> $DIR/suggest-where-clause.rs:18:5
+ |
+LL | <u64 as From<<T as Iterator>::Item>>::from;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<<T as Iterator>::Item>` is not implemented for `u64`
+ |
+ = note: required by `from`
+
+error[E0277]: the trait bound `Misc<_>: From<T>` is not satisfied
+ --> $DIR/suggest-where-clause.rs:23:5
+ |
+LL | <Misc<_> as From<T>>::from;
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<T>` is not implemented for `Misc<_>`
+ |
+ = note: required by `from`
+
+error[E0277]: the size for values of type `[T]` cannot be known at compilation time
+ --> $DIR/suggest-where-clause.rs:28:20
+ |
+LL | mem::size_of::<[T]>();
+ | ^^^ doesn't have a size known at compile-time
+ |
+ ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL
+ |
+LL | pub const fn size_of<T>() -> usize {
+ | - required by this bound in `std::mem::size_of`
+ |
+ = help: the trait `Sized` is not implemented for `[T]`
+
+error[E0277]: the size for values of type `[&U]` cannot be known at compilation time
+ --> $DIR/suggest-where-clause.rs:31:5
+ |
+LL | mem::size_of::<[&U]>();
+ | ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+ |
+ ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL
+ |
+LL | pub const fn size_of<T>() -> usize {
+ | - required by this bound in `std::mem::size_of`
+ |
+ = help: the trait `Sized` is not implemented for `[&U]`
+
+error: aborting due to 7 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+#![allow(non_snake_case)]
+
+// There is some other borrowck bug, so we make the stuff not mut.
+
+
+use std::ops::Add;
+
+trait Positioned<S> {
+ fn SetX(&mut self, _: S);
+ fn X(&self) -> S;
+}
+
+trait Movable<S: Add<Output=S>>: Positioned<S> {
+ fn translate(&mut self, dx: S) {
+ let x = self.X() + dx;
+ self.SetX(x);
+ }
+}
+
+struct Point<S> { x: S, y: S }
+
+impl<S: Clone> Positioned<S> for Point<S> {
+ fn SetX(&mut self, x: S) {
+ self.x = x;
+ }
+ fn X(&self) -> S {
+ self.x.clone()
+ }
+}
+
+impl<S: Clone + Add<Output=S>> Movable<S> for Point<S> {}
+
+pub fn main() {
+ let mut p = Point{ x: 1, y: 2};
+ p.translate(3);
+ assert_eq!(p.X(), 4);
+}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-#![allow(non_snake_case)]
-
-// There is some other borrowck bug, so we make the stuff not mut.
-
-
-use std::ops::Add;
-
-trait Positioned<S> {
- fn SetX(&mut self, _: S);
- fn X(&self) -> S;
-}
-
-trait Movable<S: Add<Output=S>>: Positioned<S> {
- fn translate(&mut self, dx: S) {
- let x = self.X() + dx;
- self.SetX(x);
- }
-}
-
-struct Point<S> { x: S, y: S }
-
-impl<S: Clone> Positioned<S> for Point<S> {
- fn SetX(&mut self, x: S) {
- self.x = x;
- }
- fn X(&self) -> S {
- self.x.clone()
- }
-}
-
-impl<S: Clone + Add<Output=S>> Movable<S> for Point<S> {}
-
-pub fn main() {
- let mut p = Point{ x: 1, y: 2};
- p.translate(3);
- assert_eq!(p.X(), 4);
-}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+// pretty-expanded FIXME #23616
+
+#![feature(negative_impls)]
+
+struct TestType;
+
+impl TestType {}
+
+trait TestTrait {}
+
+impl !Send for TestType {}
+
+struct TestType2<T>(T);
+
+impl<T> TestType2<T> {}
+
+impl<T> !Send for TestType2<T> {}
+
+fn main() {}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-// pretty-expanded FIXME #23616
-
-#![feature(negative_impls)]
-
-struct TestType;
-
-impl TestType {}
-
-trait TestTrait {}
-
-impl !Send for TestType {}
-
-struct TestType2<T>(T);
-
-impl<T> TestType2<T> {}
-
-impl<T> !Send for TestType2<T> {}
-
-fn main() {}
--- /dev/null
+#![feature(box_syntax)]
+
+#[allow(non_camel_case_types)]
+trait bar { fn dup(&self) -> Self; fn blah<X>(&self); }
+impl bar for i32 { fn dup(&self) -> i32 { *self } fn blah<X>(&self) {} }
+impl bar for u32 { fn dup(&self) -> u32 { *self } fn blah<X>(&self) {} }
+
+fn main() {
+ 10.dup::<i32>();
+ //~^ ERROR this associated function takes 0 type arguments but 1 type argument was supplied
+ 10.blah::<i32, i32>();
+ //~^ ERROR this associated function takes 1 type argument but 2 type arguments were supplied
+ (box 10 as Box<dyn bar>).dup();
+ //~^ ERROR E0038
+ //~| ERROR E0038
+}
--- /dev/null
+error[E0107]: this associated function takes 0 type arguments but 1 type argument was supplied
+ --> $DIR/test-2.rs:9:8
+ |
+LL | 10.dup::<i32>();
+ | ^^^------- help: remove these generics
+ | |
+ | expected 0 type arguments
+ |
+note: associated function defined here, with 0 type parameters
+ --> $DIR/test-2.rs:4:16
+ |
+LL | trait bar { fn dup(&self) -> Self; fn blah<X>(&self); }
+ | ^^^
+
+error[E0107]: this associated function takes 1 type argument but 2 type arguments were supplied
+ --> $DIR/test-2.rs:11:8
+ |
+LL | 10.blah::<i32, i32>();
+ | ^^^^ ----- help: remove this type argument
+ | |
+ | expected 1 type argument
+ |
+note: associated function defined here, with 1 type parameter: `X`
+ --> $DIR/test-2.rs:4:39
+ |
+LL | trait bar { fn dup(&self) -> Self; fn blah<X>(&self); }
+ | ^^^^ -
+
+error[E0038]: the trait `bar` cannot be made into an object
+ --> $DIR/test-2.rs:13:16
+ |
+LL | (box 10 as Box<dyn bar>).dup();
+ | ^^^^^^^^^^^^ `bar` cannot be made into an object
+ |
+ = help: consider moving `dup` to another trait
+ = help: consider moving `blah` to another trait
+note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
+ --> $DIR/test-2.rs:4:30
+ |
+LL | trait bar { fn dup(&self) -> Self; fn blah<X>(&self); }
+ | --- ^^^^ ^^^^ ...because method `blah` has generic type parameters
+ | | |
+ | | ...because method `dup` references the `Self` type in its return type
+ | this trait cannot be made into an object...
+
+error[E0038]: the trait `bar` cannot be made into an object
+ --> $DIR/test-2.rs:13:6
+ |
+LL | (box 10 as Box<dyn bar>).dup();
+ | ^^^^^^ `bar` cannot be made into an object
+ |
+ = help: consider moving `dup` to another trait
+ = help: consider moving `blah` to another trait
+note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
+ --> $DIR/test-2.rs:4:30
+ |
+LL | trait bar { fn dup(&self) -> Self; fn blah<X>(&self); }
+ | --- ^^^^ ^^^^ ...because method `blah` has generic type parameters
+ | | |
+ | | ...because method `dup` references the `Self` type in its return type
+ | this trait cannot be made into an object...
+ = note: required because of the requirements on the impl of `CoerceUnsized<Box<dyn bar>>` for `Box<{integer}>`
+ = note: required by cast to type `Box<dyn bar>`
+
+error: aborting due to 4 previous errors
+
+Some errors have detailed explanations: E0038, E0107.
+For more information about an error, try `rustc --explain E0038`.
--- /dev/null
+#[allow(non_camel_case_types)]
+trait foo { fn foo(&self); }
+
+impl isize for usize { fn foo(&self) {} } //~ ERROR trait
+
+fn main() {}
--- /dev/null
+error[E0404]: expected trait, found builtin type `isize`
+ --> $DIR/test.rs:4:6
+ |
+LL | impl isize for usize { fn foo(&self) {} }
+ | ^^^^^ not a trait
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0404`.
--- /dev/null
+// run-pass
+#![allow(non_camel_case_types)]
+
+
+trait to_str {
+ fn to_string_(&self) -> String;
+}
+
+impl to_str for isize {
+ fn to_string_(&self) -> String { self.to_string() }
+}
+
+impl<T:to_str> to_str for Vec<T> {
+ fn to_string_(&self) -> String {
+ format!("[{}]",
+ self.iter()
+ .map(|e| e.to_string_())
+ .collect::<Vec<String>>()
+ .join(", "))
+ }
+}
+
+pub fn main() {
+ assert_eq!(1.to_string_(), "1".to_string());
+ assert_eq!((vec![2, 3, 4]).to_string_(), "[2, 3, 4]".to_string());
+
+ fn indirect<T:to_str>(x: T) -> String {
+ format!("{}!", x.to_string_())
+ }
+ assert_eq!(indirect(vec![10, 20]), "[10, 20]!".to_string());
+
+ fn indirect2<T:to_str>(x: T) -> String {
+ indirect(x)
+ }
+ assert_eq!(indirect2(vec![1]), "[1]!".to_string());
+}
+++ /dev/null
-#![feature(trait_alias)]
-
-mod inner {
- pub trait A { fn foo(&self); }
- pub trait B { fn foo(&self); }
-
- impl A for u8 {
- fn foo(&self) {}
- }
- impl B for u8 {
- fn foo(&self) {}
- }
-
- pub trait C = A + B;
-}
-
-use inner::C;
-
-fn main() {
- let t = 1u8;
- t.foo(); //~ ERROR E0034
-
- inner::A::foo(&t); // ok
-}
+++ /dev/null
-error[E0034]: multiple applicable items in scope
- --> $DIR/trait-alias-ambiguous.rs:21:7
- |
-LL | t.foo();
- | ^^^ multiple `foo` found
- |
-note: candidate #1 is defined in an impl of the trait `A` for the type `u8`
- --> $DIR/trait-alias-ambiguous.rs:8:9
- |
-LL | fn foo(&self) {}
- | ^^^^^^^^^^^^^
-note: candidate #2 is defined in an impl of the trait `B` for the type `u8`
- --> $DIR/trait-alias-ambiguous.rs:11:9
- |
-LL | fn foo(&self) {}
- | ^^^^^^^^^^^^^
-help: disambiguate the associated function for candidate #1
- |
-LL | A::foo(&t);
- | ^^^^^^^^^^
-help: disambiguate the associated function for candidate #2
- |
-LL | B::foo(&t);
- | ^^^^^^^^^^
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0034`.
+++ /dev/null
-// run-pass
-// aux-build:trait_alias.rs
-
-#![feature(trait_alias)]
-
-extern crate trait_alias;
-
-// Import only the alias, not the real trait.
-use trait_alias::{Greet, Hi};
-
-fn main() {
- let hi = Hi;
- hi.hello(); // From `Hello`, via `Greet` alias.
-}
+++ /dev/null
-// run-pass
-
-#![feature(trait_alias)]
-
-mod inner {
- pub trait Foo {
- fn foo(&self);
- }
-
- pub struct Qux;
-
- impl Foo for Qux {
- fn foo(&self) {}
- }
-
- pub trait Bar = Foo;
-}
-
-mod two {
- pub trait A {
- fn foo();
- }
-
- impl A for u8 {
- fn foo() {}
- }
-}
-
-// Import only the alias, not the `Foo` trait.
-use inner::{Bar, Qux};
-
-// Declaring an alias also brings in aliased methods.
-trait Two = two::A;
-
-fn main() {
- let q = Qux;
- q.foo(); // From Bar.
-
- u8::foo(); // From A.
-}
+++ /dev/null
-#![feature(trait_alias)]
-
-pub trait SendSync = Send + Sync;
+++ /dev/null
-// check-pass
-
-#![feature(trait_alias)]
-
-trait SomeTrait {
- fn map(&self) {}
-}
-
-impl<T> SomeTrait for Option<T> {}
-
-trait SomeAlias = SomeTrait;
-
-fn main() {
- let x = Some(123);
- // This should resolve to the trait impl for Option
- Option::map(x, |z| z);
- // This should resolve to the trait impl for SomeTrait
- SomeTrait::map(&x);
-}
+++ /dev/null
-// check-pass
-
-#![feature(trait_alias)]
-
-trait Bounded { const MAX: Self; }
-
-impl Bounded for u32 {
- // This should correctly resolve to the associated const in the inherent impl of u32.
- const MAX: Self = u32::MAX;
-}
-
-trait Num = Bounded + Copy;
-
-fn main() {}
+++ /dev/null
-// check-pass
-
-#![feature(trait_alias)]
-
-struct Bar;
-trait Foo {}
-impl Foo for Bar {}
-
-trait Baz = Foo where Bar: Foo;
-
-fn new() -> impl Baz {
- Bar
-}
-
-fn main() {
- let _ = new();
-}
+++ /dev/null
-// run-pass
-
-#![feature(trait_alias)]
-
-use std::marker::PhantomData;
-
-trait Empty {}
-trait EmptyAlias = Empty;
-trait CloneDefault = Clone + Default;
-trait SendSyncAlias = Send + Sync;
-trait WhereSendAlias = where Self: Send;
-trait SendEqAlias<T> = Send where T: PartialEq<Self>;
-trait I32Iterator = Iterator<Item = i32>;
-
-#[allow(dead_code)]
-struct Foo<T: SendSyncAlias>(PhantomData<T>);
-#[allow(dead_code)]
-struct Bar<T>(PhantomData<T>) where T: SendSyncAlias;
-
-impl dyn EmptyAlias {}
-
-impl<T: SendSyncAlias> Empty for T {}
-
-fn a<T: CloneDefault>() -> (T, T) {
- let one = T::default();
- let two = one.clone();
- (one, two)
-}
-
-fn b(x: &impl SendEqAlias<i32>) -> bool {
- 22_i32 == *x
-}
-
-fn c<T: I32Iterator>(x: &mut T) -> Option<i32> {
- x.next()
-}
-
-fn d<T: SendSyncAlias>() {
- is_send_and_sync::<T>();
-}
-
-fn is_send_and_sync<T: Send + Sync>() {}
-
-fn main() {
- let both = a::<i32>();
- assert_eq!(both.0, 0);
- assert_eq!(both.1, 0);
- let both: (i32, i32) = a();
- assert_eq!(both.0, 0);
- assert_eq!(both.1, 0);
-
- assert!(b(&22));
-
- assert_eq!(c(&mut vec![22].into_iter()), Some(22));
-
- d::<i32>();
-}
+++ /dev/null
-// aux-build:trait_alias.rs
-
-#![feature(trait_alias)]
-
-extern crate trait_alias;
-
-use std::rc::Rc;
-use trait_alias::SendSync;
-
-fn use_alias<T: SendSync>() {}
-
-fn main() {
- use_alias::<u32>();
- use_alias::<Rc<u32>>();
- //~^ ERROR `Rc<u32>` cannot be sent between threads safely [E0277]
- //~^^ ERROR `Rc<u32>` cannot be shared between threads safely [E0277]
-}
+++ /dev/null
-error[E0277]: `Rc<u32>` cannot be sent between threads safely
- --> $DIR/trait-alias-cross-crate.rs:14:17
- |
-LL | fn use_alias<T: SendSync>() {}
- | -------- required by this bound in `use_alias`
-...
-LL | use_alias::<Rc<u32>>();
- | ^^^^^^^ `Rc<u32>` cannot be sent between threads safely
- |
- = help: the trait `Send` is not implemented for `Rc<u32>`
-
-error[E0277]: `Rc<u32>` cannot be shared between threads safely
- --> $DIR/trait-alias-cross-crate.rs:14:17
- |
-LL | fn use_alias<T: SendSync>() {}
- | -------- required by this bound in `use_alias`
-...
-LL | use_alias::<Rc<u32>>();
- | ^^^^^^^ `Rc<u32>` cannot be shared between threads safely
- |
- = help: the trait `Sync` is not implemented for `Rc<u32>`
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-#![feature(trait_alias)]
-
-trait DefaultAlias = Default;
-
-impl DefaultAlias for () {} //~ ERROR expected trait, found trait alias
-
-fn main() {}
+++ /dev/null
-error[E0404]: expected trait, found trait alias `DefaultAlias`
- --> $DIR/trait-alias-impl.rs:5:6
- |
-LL | impl DefaultAlias for () {}
- | ^^^^^^^^^^^^ not a trait
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0404`.
+++ /dev/null
-// build-pass (FIXME(62277): could be check-pass?)
-
-// Test that `dyn ... + ?Sized + ...` resulting from the expansion of trait aliases is okay.
-
-#![feature(trait_alias)]
-
-trait Foo {}
-
-trait S = ?Sized;
-
-// Nest a couple of levels deep:
-trait _0 = S;
-trait _1 = _0;
-
-// Straight list expansion:
-type _T0 = dyn _1 + Foo;
-
-// In second position:
-type _T1 = dyn Foo + _1;
-
-// ... and with an auto trait:
-type _T2 = dyn Foo + Send + _1;
-
-// Twice:
-trait _2 = _1 + _1;
-
-type _T3 = dyn _2 + Foo;
-
-fn main() {}
+++ /dev/null
-// The purpose of this test is to demonstrate that duplicating object safe traits
-// that are not auto traits is rejected with trait aliases even though one could
-// reasonably accept this.
-
-#![feature(trait_alias)]
-
-use std::marker::Unpin;
-
-// Some arbitrary object-safe trait:
-trait Obj {}
-
-// Nest a few levels deep:
-trait _0 = Obj;
-trait _1 = _0;
-
-type _T00 = dyn _0 + _0;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T01 = dyn _1 + _0;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T02 = dyn _1 + _1;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T03 = dyn Obj + _1;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T04 = dyn _1 + Obj;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-// Nest some more and in weird ways:
-
-trait _2 = _0 + _1;
-trait _3 = Obj;
-trait _4 = _3;
-
-type _T10 = dyn _2 + _3;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T11 = dyn _3 + _2;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T12 = dyn Obj + _2;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T13 = dyn _2 + Obj;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T14 = dyn _1 + _3;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T15 = dyn _3 + _1;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T16 = dyn _1 + _4;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T17 = dyn _4 + _1;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-// Include auto traits:
-
-trait _5 = Obj + Send;
-
-type _T20 = dyn _5 + _5;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T21 = dyn Obj + _5;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T22 = dyn _5 + Obj;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T23 = dyn _5 + Send + Sync + Obj;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-// Also nest:
-
-trait _6 = _5 + _5; // ==> Obj + Send + Obj + Send
-
-type _T30 = dyn _6;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T31 = dyn _6 + Send;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T32 = dyn Send + _6;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-// Nest some more:
-
-trait _7 = _5 + Sync;
-trait _8 = Unpin + _7;
-
-type _T40 = dyn _8 + Obj;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T41 = dyn Obj + _8;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T42 = dyn _8 + _4;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T43 = dyn _4 + _8;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T44 = dyn _4 + Send + Sync + _8;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-// Take higher ranked types into account.
-
-// Note that `'a` and `'b` are intentionally different to make sure we consider
-// them semantically the same.
-trait ObjL<'l> {}
-trait _9 = for<'a> ObjL<'a>;
-trait _10 = for<'b> ObjL<'b>;
-type _T50 = dyn _9 + _10;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-trait ObjT<T> {}
-trait _11 = ObjT<for<'a> fn(&'a u8)>;
-trait _12 = ObjT<for<'b> fn(&'b u8)>;
-type _T60 = dyn _11 + _12;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-fn main() {}
+++ /dev/null
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:16:22
- |
-LL | trait _0 = Obj;
- | ---
- | |
- | additional non-auto trait
- | first non-auto trait
-...
-LL | type _T00 = dyn _0 + _0;
- | -- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:19:22
- |
-LL | trait _0 = Obj;
- | ---
- | |
- | additional non-auto trait
- | first non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (first use)
-...
-LL | type _T01 = dyn _1 + _0;
- | -- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:22:22
- |
-LL | trait _0 = Obj;
- | ---
- | |
- | additional non-auto trait
- | first non-auto trait
-LL | trait _1 = _0;
- | --
- | |
- | referenced here (additional use)
- | referenced here (first use)
-...
-LL | type _T02 = dyn _1 + _1;
- | -- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:25:23
- |
-LL | trait _0 = Obj;
- | --- additional non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (additional use)
-...
-LL | type _T03 = dyn Obj + _1;
- | --- ^^ trait alias used in trait object type (additional use)
- | |
- | first non-auto trait
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:28:22
- |
-LL | trait _0 = Obj;
- | --- first non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (first use)
-...
-LL | type _T04 = dyn _1 + Obj;
- | -- ^^^ additional non-auto trait
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:37:17
- |
-LL | trait _0 = Obj;
- | ---
- | |
- | additional non-auto trait
- | first non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (additional use)
-...
-LL | trait _2 = _0 + _1;
- | -- -- referenced here (additional use)
- | |
- | referenced here (first use)
-...
-LL | type _T10 = dyn _2 + _3;
- | ^^
- | |
- | trait alias used in trait object type (additional use)
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:40:22
- |
-LL | trait _0 = Obj;
- | --- additional non-auto trait
-...
-LL | trait _2 = _0 + _1;
- | -- referenced here (additional use)
-LL | trait _3 = Obj;
- | --- first non-auto trait
-...
-LL | type _T11 = dyn _3 + _2;
- | -- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:43:23
- |
-LL | trait _0 = Obj;
- | --- additional non-auto trait
-...
-LL | trait _2 = _0 + _1;
- | -- referenced here (additional use)
-...
-LL | type _T12 = dyn Obj + _2;
- | --- ^^ trait alias used in trait object type (additional use)
- | |
- | first non-auto trait
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:46:17
- |
-LL | trait _0 = Obj;
- | ---
- | |
- | additional non-auto trait
- | first non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (additional use)
-...
-LL | trait _2 = _0 + _1;
- | -- -- referenced here (additional use)
- | |
- | referenced here (first use)
-...
-LL | type _T13 = dyn _2 + Obj;
- | ^^
- | |
- | trait alias used in trait object type (additional use)
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:49:22
- |
-LL | trait _0 = Obj;
- | --- first non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (first use)
-...
-LL | trait _3 = Obj;
- | --- additional non-auto trait
-...
-LL | type _T14 = dyn _1 + _3;
- | -- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:52:22
- |
-LL | trait _0 = Obj;
- | --- additional non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (additional use)
-...
-LL | trait _3 = Obj;
- | --- first non-auto trait
-...
-LL | type _T15 = dyn _3 + _1;
- | -- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:55:22
- |
-LL | trait _0 = Obj;
- | --- first non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (first use)
-...
-LL | trait _3 = Obj;
- | --- additional non-auto trait
-LL | trait _4 = _3;
- | -- referenced here (additional use)
-...
-LL | type _T16 = dyn _1 + _4;
- | -- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:58:22
- |
-LL | trait _0 = Obj;
- | --- additional non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (additional use)
-...
-LL | trait _3 = Obj;
- | --- first non-auto trait
-LL | trait _4 = _3;
- | -- referenced here (first use)
-...
-LL | type _T17 = dyn _4 + _1;
- | -- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:65:22
- |
-LL | trait _5 = Obj + Send;
- | ---
- | |
- | additional non-auto trait
- | first non-auto trait
-LL |
-LL | type _T20 = dyn _5 + _5;
- | -- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:68:23
- |
-LL | trait _5 = Obj + Send;
- | --- additional non-auto trait
-...
-LL | type _T21 = dyn Obj + _5;
- | --- ^^ trait alias used in trait object type (additional use)
- | |
- | first non-auto trait
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:71:22
- |
-LL | trait _5 = Obj + Send;
- | --- first non-auto trait
-...
-LL | type _T22 = dyn _5 + Obj;
- | -- ^^^ additional non-auto trait
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:74:36
- |
-LL | trait _5 = Obj + Send;
- | --- first non-auto trait
-...
-LL | type _T23 = dyn _5 + Send + Sync + Obj;
- | -- ^^^ additional non-auto trait
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:81:17
- |
-LL | trait _5 = Obj + Send;
- | ---
- | |
- | additional non-auto trait
- | first non-auto trait
-...
-LL | trait _6 = _5 + _5; // ==> Obj + Send + Obj + Send
- | -- -- referenced here (additional use)
- | |
- | referenced here (first use)
-LL |
-LL | type _T30 = dyn _6;
- | ^^
- | |
- | trait alias used in trait object type (additional use)
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:84:17
- |
-LL | trait _5 = Obj + Send;
- | ---
- | |
- | additional non-auto trait
- | first non-auto trait
-...
-LL | trait _6 = _5 + _5; // ==> Obj + Send + Obj + Send
- | -- -- referenced here (additional use)
- | |
- | referenced here (first use)
-...
-LL | type _T31 = dyn _6 + Send;
- | ^^
- | |
- | trait alias used in trait object type (additional use)
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:87:24
- |
-LL | trait _5 = Obj + Send;
- | ---
- | |
- | additional non-auto trait
- | first non-auto trait
-...
-LL | trait _6 = _5 + _5; // ==> Obj + Send + Obj + Send
- | -- -- referenced here (additional use)
- | |
- | referenced here (first use)
-...
-LL | type _T32 = dyn Send + _6;
- | ^^
- | |
- | trait alias used in trait object type (additional use)
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:95:22
- |
-LL | trait _5 = Obj + Send;
- | --- first non-auto trait
-...
-LL | trait _7 = _5 + Sync;
- | -- referenced here (first use)
-LL | trait _8 = Unpin + _7;
- | -- referenced here (first use)
-LL |
-LL | type _T40 = dyn _8 + Obj;
- | -- ^^^ additional non-auto trait
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:98:23
- |
-LL | trait _5 = Obj + Send;
- | --- additional non-auto trait
-...
-LL | trait _7 = _5 + Sync;
- | -- referenced here (additional use)
-LL | trait _8 = Unpin + _7;
- | -- referenced here (additional use)
-...
-LL | type _T41 = dyn Obj + _8;
- | --- ^^ trait alias used in trait object type (additional use)
- | |
- | first non-auto trait
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:101:22
- |
-LL | trait _3 = Obj;
- | --- additional non-auto trait
-LL | trait _4 = _3;
- | -- referenced here (additional use)
-...
-LL | trait _5 = Obj + Send;
- | --- first non-auto trait
-...
-LL | trait _7 = _5 + Sync;
- | -- referenced here (first use)
-LL | trait _8 = Unpin + _7;
- | -- referenced here (first use)
-...
-LL | type _T42 = dyn _8 + _4;
- | -- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:104:22
- |
-LL | trait _3 = Obj;
- | --- first non-auto trait
-LL | trait _4 = _3;
- | -- referenced here (first use)
-...
-LL | trait _5 = Obj + Send;
- | --- additional non-auto trait
-...
-LL | trait _7 = _5 + Sync;
- | -- referenced here (additional use)
-LL | trait _8 = Unpin + _7;
- | -- referenced here (additional use)
-...
-LL | type _T43 = dyn _4 + _8;
- | -- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:107:36
- |
-LL | trait _3 = Obj;
- | --- first non-auto trait
-LL | trait _4 = _3;
- | -- referenced here (first use)
-...
-LL | trait _5 = Obj + Send;
- | --- additional non-auto trait
-...
-LL | trait _7 = _5 + Sync;
- | -- referenced here (additional use)
-LL | trait _8 = Unpin + _7;
- | -- referenced here (additional use)
-...
-LL | type _T44 = dyn _4 + Send + Sync + _8;
- | -- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:117:22
- |
-LL | trait _9 = for<'a> ObjL<'a>;
- | ---------------- first non-auto trait
-LL | trait _10 = for<'b> ObjL<'b>;
- | ---------------- additional non-auto trait
-LL | type _T50 = dyn _9 + _10;
- | -- ^^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: for<'a> ObjL<'a> + for<'b> ObjL<'b> {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-duplicates.rs:123:23
- |
-LL | trait _11 = ObjT<for<'a> fn(&'a u8)>;
- | ------------------------ first non-auto trait
-LL | trait _12 = ObjT<for<'b> fn(&'b u8)>;
- | ------------------------ additional non-auto trait
-LL | type _T60 = dyn _11 + _12;
- | --- ^^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjT<for<'a> fn(&'a u8)> + ObjT<for<'b> fn(&'b u8)> {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error: aborting due to 27 previous errors
-
-For more information about this error, try `rustc --explain E0225`.
+++ /dev/null
-// The purpose of this test is to demonstrate that trait alias expansion
-// preserves the rule that `dyn Trait` may only reference one non-auto trait.
-
-#![feature(trait_alias)]
-
-use std::marker::Unpin;
-
-// Some arbitrary object-safe traits:
-trait ObjA {}
-trait ObjB {}
-
-// Nest a few levels deep:
-trait _0 = ObjA;
-trait _1 = _0;
-
-type _T00 = dyn _0 + ObjB;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T01 = dyn ObjB + _0;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T02 = dyn ObjB + _1;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T03 = dyn _1 + ObjB;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-// Nest some more and in weird ways:
-
-trait _2 = ObjB;
-trait _3 = _2;
-trait _4 = _3;
-
-type _T10 = dyn _2 + _3;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T11 = dyn _3 + _2;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T12 = dyn _2 + _4;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T13 = dyn _4 + _2;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-// Include auto traits:
-
-trait _5 = Sync + ObjB + Send;
-
-type _T20 = dyn _5 + _1;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T21 = dyn _1 + _5;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T22 = dyn _5 + ObjA;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T23 = dyn ObjA + _5;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T24 = dyn Send + _5 + _1 + Sync;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T25 = dyn _1 + Sync + _5 + Send;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T26 = dyn Sync + Send + _5 + ObjA;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T27 = dyn Send + Sync + ObjA + _5;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-// Also nest:
-
-trait _6 = _1 + _5;
-trait _7 = _6;
-trait _8 = _7;
-
-type _T30 = dyn _6;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T31 = dyn _6 + Send;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T32 = dyn Send + _6;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T33 = dyn _8;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T34 = dyn _8 + Send;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T35 = dyn Send + _8;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-// Nest some more:
-
-trait _9 = _5 + Sync;
-trait _10 = Unpin + _9;
-
-type _T40 = dyn _10 + ObjA;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T41 = dyn ObjA + _10;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T42 = dyn _10 + _1;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T43 = dyn Send + _10 + Sync + ObjA;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T44 = dyn ObjA + _10 + Send + Sync;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _T45 = dyn Sync + Send + _10 + _1;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-fn main() {}
+++ /dev/null
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:16:22
- |
-LL | trait _0 = ObjA;
- | ---- first non-auto trait
-...
-LL | type _T00 = dyn _0 + ObjB;
- | -- ^^^^ additional non-auto trait
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:19:24
- |
-LL | trait _0 = ObjA;
- | ---- additional non-auto trait
-...
-LL | type _T01 = dyn ObjB + _0;
- | ---- ^^ trait alias used in trait object type (additional use)
- | |
- | first non-auto trait
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjA {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:22:24
- |
-LL | trait _0 = ObjA;
- | ---- additional non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (additional use)
-...
-LL | type _T02 = dyn ObjB + _1;
- | ---- ^^ trait alias used in trait object type (additional use)
- | |
- | first non-auto trait
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjA {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:25:22
- |
-LL | trait _0 = ObjA;
- | ---- first non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (first use)
-...
-LL | type _T03 = dyn _1 + ObjB;
- | -- ^^^^ additional non-auto trait
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:34:22
- |
-LL | trait _2 = ObjB;
- | ----
- | |
- | additional non-auto trait
- | first non-auto trait
-LL | trait _3 = _2;
- | -- referenced here (additional use)
-...
-LL | type _T10 = dyn _2 + _3;
- | -- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjB {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:37:22
- |
-LL | trait _2 = ObjB;
- | ----
- | |
- | additional non-auto trait
- | first non-auto trait
-LL | trait _3 = _2;
- | -- referenced here (first use)
-...
-LL | type _T11 = dyn _3 + _2;
- | -- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjB {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:40:22
- |
-LL | trait _2 = ObjB;
- | ----
- | |
- | additional non-auto trait
- | first non-auto trait
-LL | trait _3 = _2;
- | -- referenced here (additional use)
-LL | trait _4 = _3;
- | -- referenced here (additional use)
-...
-LL | type _T12 = dyn _2 + _4;
- | -- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjB {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:43:22
- |
-LL | trait _2 = ObjB;
- | ----
- | |
- | additional non-auto trait
- | first non-auto trait
-LL | trait _3 = _2;
- | -- referenced here (first use)
-LL | trait _4 = _3;
- | -- referenced here (first use)
-...
-LL | type _T13 = dyn _4 + _2;
- | -- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjB {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:50:22
- |
-LL | trait _0 = ObjA;
- | ---- additional non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (additional use)
-...
-LL | trait _5 = Sync + ObjB + Send;
- | ---- first non-auto trait
-LL |
-LL | type _T20 = dyn _5 + _1;
- | -- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjA {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:53:22
- |
-LL | trait _0 = ObjA;
- | ---- first non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (first use)
-...
-LL | trait _5 = Sync + ObjB + Send;
- | ---- additional non-auto trait
-...
-LL | type _T21 = dyn _1 + _5;
- | -- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:56:22
- |
-LL | trait _5 = Sync + ObjB + Send;
- | ---- first non-auto trait
-...
-LL | type _T22 = dyn _5 + ObjA;
- | -- ^^^^ additional non-auto trait
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjA {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:59:24
- |
-LL | trait _5 = Sync + ObjB + Send;
- | ---- additional non-auto trait
-...
-LL | type _T23 = dyn ObjA + _5;
- | ---- ^^ trait alias used in trait object type (additional use)
- | |
- | first non-auto trait
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:62:29
- |
-LL | trait _0 = ObjA;
- | ---- additional non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (additional use)
-...
-LL | trait _5 = Sync + ObjB + Send;
- | ---- first non-auto trait
-...
-LL | type _T24 = dyn Send + _5 + _1 + Sync;
- | -- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjA {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:65:29
- |
-LL | trait _0 = ObjA;
- | ---- first non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (first use)
-...
-LL | trait _5 = Sync + ObjB + Send;
- | ---- additional non-auto trait
-...
-LL | type _T25 = dyn _1 + Sync + _5 + Send;
- | -- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:68:36
- |
-LL | trait _5 = Sync + ObjB + Send;
- | ---- first non-auto trait
-...
-LL | type _T26 = dyn Sync + Send + _5 + ObjA;
- | -- ^^^^ additional non-auto trait
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjA {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:71:38
- |
-LL | trait _5 = Sync + ObjB + Send;
- | ---- additional non-auto trait
-...
-LL | type _T27 = dyn Send + Sync + ObjA + _5;
- | ---- ^^ trait alias used in trait object type (additional use)
- | |
- | first non-auto trait
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:80:17
- |
-LL | trait _0 = ObjA;
- | ---- first non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (first use)
-...
-LL | trait _5 = Sync + ObjB + Send;
- | ---- additional non-auto trait
-...
-LL | trait _6 = _1 + _5;
- | -- -- referenced here (additional use)
- | |
- | referenced here (first use)
-...
-LL | type _T30 = dyn _6;
- | ^^
- | |
- | trait alias used in trait object type (additional use)
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:83:17
- |
-LL | trait _0 = ObjA;
- | ---- first non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (first use)
-...
-LL | trait _5 = Sync + ObjB + Send;
- | ---- additional non-auto trait
-...
-LL | trait _6 = _1 + _5;
- | -- -- referenced here (additional use)
- | |
- | referenced here (first use)
-...
-LL | type _T31 = dyn _6 + Send;
- | ^^
- | |
- | trait alias used in trait object type (additional use)
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:86:24
- |
-LL | trait _0 = ObjA;
- | ---- first non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (first use)
-...
-LL | trait _5 = Sync + ObjB + Send;
- | ---- additional non-auto trait
-...
-LL | trait _6 = _1 + _5;
- | -- -- referenced here (additional use)
- | |
- | referenced here (first use)
-...
-LL | type _T32 = dyn Send + _6;
- | ^^
- | |
- | trait alias used in trait object type (additional use)
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:89:17
- |
-LL | trait _0 = ObjA;
- | ---- first non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (first use)
-...
-LL | trait _5 = Sync + ObjB + Send;
- | ---- additional non-auto trait
-...
-LL | trait _6 = _1 + _5;
- | -- -- referenced here (additional use)
- | |
- | referenced here (first use)
-LL | trait _7 = _6;
- | --
- | |
- | referenced here (additional use)
- | referenced here (first use)
-LL | trait _8 = _7;
- | --
- | |
- | referenced here (additional use)
- | referenced here (first use)
-...
-LL | type _T33 = dyn _8;
- | ^^
- | |
- | trait alias used in trait object type (additional use)
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:92:17
- |
-LL | trait _0 = ObjA;
- | ---- first non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (first use)
-...
-LL | trait _5 = Sync + ObjB + Send;
- | ---- additional non-auto trait
-...
-LL | trait _6 = _1 + _5;
- | -- -- referenced here (additional use)
- | |
- | referenced here (first use)
-LL | trait _7 = _6;
- | --
- | |
- | referenced here (additional use)
- | referenced here (first use)
-LL | trait _8 = _7;
- | --
- | |
- | referenced here (additional use)
- | referenced here (first use)
-...
-LL | type _T34 = dyn _8 + Send;
- | ^^
- | |
- | trait alias used in trait object type (additional use)
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:95:24
- |
-LL | trait _0 = ObjA;
- | ---- first non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (first use)
-...
-LL | trait _5 = Sync + ObjB + Send;
- | ---- additional non-auto trait
-...
-LL | trait _6 = _1 + _5;
- | -- -- referenced here (additional use)
- | |
- | referenced here (first use)
-LL | trait _7 = _6;
- | --
- | |
- | referenced here (additional use)
- | referenced here (first use)
-LL | trait _8 = _7;
- | --
- | |
- | referenced here (additional use)
- | referenced here (first use)
-...
-LL | type _T35 = dyn Send + _8;
- | ^^
- | |
- | trait alias used in trait object type (additional use)
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:103:23
- |
-LL | trait _5 = Sync + ObjB + Send;
- | ---- first non-auto trait
-...
-LL | trait _9 = _5 + Sync;
- | -- referenced here (first use)
-LL | trait _10 = Unpin + _9;
- | -- referenced here (first use)
-LL |
-LL | type _T40 = dyn _10 + ObjA;
- | --- ^^^^ additional non-auto trait
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjA {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:106:24
- |
-LL | trait _5 = Sync + ObjB + Send;
- | ---- additional non-auto trait
-...
-LL | trait _9 = _5 + Sync;
- | -- referenced here (additional use)
-LL | trait _10 = Unpin + _9;
- | -- referenced here (additional use)
-...
-LL | type _T41 = dyn ObjA + _10;
- | ---- ^^^ trait alias used in trait object type (additional use)
- | |
- | first non-auto trait
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:109:23
- |
-LL | trait _0 = ObjA;
- | ---- additional non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (additional use)
-...
-LL | trait _5 = Sync + ObjB + Send;
- | ---- first non-auto trait
-...
-LL | trait _9 = _5 + Sync;
- | -- referenced here (first use)
-LL | trait _10 = Unpin + _9;
- | -- referenced here (first use)
-...
-LL | type _T42 = dyn _10 + _1;
- | --- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjA {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:112:37
- |
-LL | trait _5 = Sync + ObjB + Send;
- | ---- first non-auto trait
-...
-LL | trait _9 = _5 + Sync;
- | -- referenced here (first use)
-LL | trait _10 = Unpin + _9;
- | -- referenced here (first use)
-...
-LL | type _T43 = dyn Send + _10 + Sync + ObjA;
- | --- ^^^^ additional non-auto trait
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjA {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:115:24
- |
-LL | trait _5 = Sync + ObjB + Send;
- | ---- additional non-auto trait
-...
-LL | trait _9 = _5 + Sync;
- | -- referenced here (additional use)
-LL | trait _10 = Unpin + _9;
- | -- referenced here (additional use)
-...
-LL | type _T44 = dyn ObjA + _10 + Send + Sync;
- | ---- ^^^ trait alias used in trait object type (additional use)
- | |
- | first non-auto trait
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjA + ObjB {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/trait-alias-no-extra-traits.rs:118:37
- |
-LL | trait _0 = ObjA;
- | ---- additional non-auto trait
-LL | trait _1 = _0;
- | -- referenced here (additional use)
-...
-LL | trait _5 = Sync + ObjB + Send;
- | ---- first non-auto trait
-...
-LL | trait _9 = _5 + Sync;
- | -- referenced here (first use)
-LL | trait _10 = Unpin + _9;
- | -- referenced here (first use)
-...
-LL | type _T45 = dyn Sync + Send + _10 + _1;
- | --- ^^ trait alias used in trait object type (additional use)
- | |
- | trait alias used in trait object type (first use)
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjB + ObjA {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error: aborting due to 28 previous errors
-
-For more information about this error, try `rustc --explain E0225`.
+++ /dev/null
-#![feature(trait_alias)]
-
-trait EqAlias = Eq;
-trait IteratorAlias = Iterator;
-
-fn main() {
- let _: &dyn EqAlias = &123;
- //~^ ERROR the trait `Eq` cannot be made into an object [E0038]
- let _: &dyn IteratorAlias = &vec![123].into_iter();
- //~^ ERROR must be specified
-}
+++ /dev/null
-error[E0038]: the trait `Eq` cannot be made into an object
- --> $DIR/trait-alias-object-fail.rs:7:13
- |
-LL | let _: &dyn EqAlias = &123;
- | ^^^^^^^^^^^ `Eq` cannot be made into an object
- |
-note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
- --> $SRC_DIR/core/src/cmp.rs:LL:COL
- |
-LL | pub trait Eq: PartialEq<Self> {
- | ^^^^^^^^^^^^^^^ the trait cannot be made into an object because it uses `Self` as a type parameter
-
-error[E0191]: the value of the associated type `Item` (from trait `Iterator`) must be specified
- --> $DIR/trait-alias-object-fail.rs:9:17
- |
-LL | let _: &dyn IteratorAlias = &vec![123].into_iter();
- | ^^^^^^^^^^^^^ help: specify the associated type: `IteratorAlias<Item = Type>`
-
-error: aborting due to 2 previous errors
-
-Some errors have detailed explanations: E0038, E0191.
-For more information about an error, try `rustc --explain E0038`.
+++ /dev/null
-// check-pass
-
-// This test checks that trait objects involving trait aliases are well-formed.
-
-#![feature(trait_alias)]
-
-trait Obj {}
-
-trait _0 = Send + Sync;
-
-// Just auto traits:
-
-trait _1 = _0 + Send + Sync;
-
-use std::marker::Unpin;
-
-fn _f0() {
- let _: Box<dyn _0>;
- let _: Box<dyn _1>;
- let _: Box<dyn Unpin + _1 + Send + Sync>;
-}
-
-// Include object safe traits:
-
-fn _f1() {
- let _: Box<dyn Obj + _0>;
- let _: Box<dyn Obj + _1>;
- let _: Box<dyn Obj + _1 + _0>;
-}
-
-// And when the object safe trait is in a trait alias:
-
-trait _2 = Obj;
-
-fn _f2() {
- let _: Box<dyn _2 + _0>;
- let _: Box<dyn _2 + _1>;
- let _: Box<dyn _2 + _1 + _0>;
-}
-
-// And it should also work when that trait is has auto traits to the right of it.
-
-trait _3 = Obj + Unpin;
-
-fn _f3() {
- let _: Box<dyn _3 + _0>;
- let _: Box<dyn _3 + _1>;
- let _: Box<dyn _3 + _1 + _0>;
-}
-
-// Nest the trait deeply:
-
-trait _4 = _3;
-trait _5 = _4 + Sync + _0 + Send;
-trait _6 = _5 + Send + _1 + Sync;
-
-fn _f4() {
- let _: Box<dyn _6 + _0>;
- let _: Box<dyn _6 + _1>;
- let _: Box<dyn _6 + _1 + _0>;
-}
-
-// Just nest the trait alone:
-
-trait _7 = _2;
-trait _8 = _7;
-trait _9 = _8;
-
-fn _f5() {
- let _: Box<dyn _9>;
-}
-
-// First bound is auto trait:
-
-trait _10 = Send + Obj;
-trait _11 = Obj + Send;
-trait _12 = Sync + _11;
-trait _13 = Send + _12;
-
-fn f6() {
- let _: Box<dyn _10>;
- let _: Box<dyn _13>;
-}
-
-fn main() {}
+++ /dev/null
-// run-pass
-
-#![feature(trait_alias)]
-
-trait Foo = PartialEq<i32> + Send;
-trait Bar = Foo + Sync;
-
-trait I32Iterator = Iterator<Item = i32>;
-
-pub fn main() {
- let a: &dyn Bar = &123;
- assert!(*a == 123);
- let b = Box::new(456) as Box<dyn Foo>;
- assert!(*b == 456);
-
- let c: &mut dyn I32Iterator = &mut vec![123].into_iter();
- assert_eq!(c.next(), Some(123));
-}
+++ /dev/null
-// Test that `dyn ?Sized` (i.e., a trait object with only a maybe buond) is not allowed, when just
-// `?Sized` results from trait alias expansion.
-
-#![feature(trait_alias)]
-
-trait S = ?Sized;
-
-// Nest a couple of levels deep:
-trait _0 = S;
-trait _1 = _0;
-
-// Straight list expansion:
-type _T0 = dyn _1;
-//~^ ERROR at least one trait is required for an object type [E0224]
-
-// Twice:
-trait _2 = _1 + _1;
-
-type _T1 = dyn _2;
-//~^ ERROR at least one trait is required for an object type [E0224]
-
-fn main() {}
+++ /dev/null
-error[E0224]: at least one trait is required for an object type
- --> $DIR/trait-alias-only-maybe-bound.rs:13:12
- |
-LL | type _T0 = dyn _1;
- | ^^^^^^
-
-error[E0224]: at least one trait is required for an object type
- --> $DIR/trait-alias-only-maybe-bound.rs:19:12
- |
-LL | type _T1 = dyn _2;
- | ^^^^^^
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0224`.
+++ /dev/null
-#![feature(trait_alias)]
-
-trait Foo {}
-auto trait A = Foo; //~ ERROR trait aliases cannot be `auto`
-unsafe trait B = Foo; //~ ERROR trait aliases cannot be `unsafe`
-
-trait C: Ord = Eq; //~ ERROR bounds are not allowed on trait aliases
-trait D: = Eq; //~ ERROR bounds are not allowed on trait aliases
-
-fn main() {}
+++ /dev/null
-error: trait aliases cannot be `auto`
- --> $DIR/trait-alias-syntax-fail.rs:4:1
- |
-LL | auto trait A = Foo;
- | ^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `auto`
-
-error: trait aliases cannot be `unsafe`
- --> $DIR/trait-alias-syntax-fail.rs:5:1
- |
-LL | unsafe trait B = Foo;
- | ^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `unsafe`
-
-error: bounds are not allowed on trait aliases
- --> $DIR/trait-alias-syntax-fail.rs:7:8
- |
-LL | trait C: Ord = Eq;
- | ^^^^^
-
-error: bounds are not allowed on trait aliases
- --> $DIR/trait-alias-syntax-fail.rs:8:8
- |
-LL | trait D: = Eq;
- | ^
-
-error: aborting due to 4 previous errors
-
+++ /dev/null
-// run-pass
-
-#![feature(trait_alias)]
-
-trait SimpleAlias = Default;
-trait GenericAlias<T> = Iterator<Item = T>;
-trait Partial<T> = IntoIterator<Item = T>;
-trait SpecificAlias = GenericAlias<i32>;
-trait PartialEqRef<'a, T: 'a> = PartialEq<&'a T>;
-trait StaticAlias = 'static;
-
-trait Things<T> {}
-trait Romeo {}
-#[allow(dead_code)]
-struct The<T>(T);
-#[allow(dead_code)]
-struct Fore<T>(T);
-impl<T, U> Things<T> for The<U> {}
-impl<T> Romeo for Fore<T> {}
-
-trait WithWhere<Art, Thou> = Romeo + Romeo where Fore<(Art, Thou)>: Romeo;
-trait BareWhere<Wild, Are> = where The<Wild>: Things<Are>;
-
-fn main() {}
+++ /dev/null
-#![feature(trait_alias)]
-
-trait Foo {}
-trait A<T: Foo> {}
-trait B<T> = A<T>; //~ ERROR `T: Foo` is not satisfied
-
-fn main() {}
+++ /dev/null
-error[E0277]: the trait bound `T: Foo` is not satisfied
- --> $DIR/trait-alias-wf.rs:5:14
- |
-LL | trait A<T: Foo> {}
- | --- required by this bound in `A`
-LL | trait B<T> = A<T>;
- | ^^^^ the trait `Foo` is not implemented for `T`
- |
-help: consider restricting type parameter `T`
- |
-LL | trait B<T: Foo> = A<T>;
- | ^^^^^
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-// run-pass
-
-#![feature(trait_alias)]
-
-pub trait Foo {}
-pub trait FooAlias = Foo;
-
-fn main() {}
+++ /dev/null
-trait TraitNotAStruct {}
-
-fn main() {
- TraitNotAStruct{ value: 0 };
- //~^ ERROR expected struct, variant or union type, found trait `TraitNotAStruct`
-}
+++ /dev/null
-error[E0574]: expected struct, variant or union type, found trait `TraitNotAStruct`
- --> $DIR/trait-as-struct-constructor.rs:4:5
- |
-LL | TraitNotAStruct{ value: 0 };
- | ^^^^^^^^^^^^^^^ not a struct, variant or union type
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0574`.
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-#![allow(unconditional_recursion)]
-
-// pretty-expanded FIXME #23616
-
-trait Foo {
-}
-
-fn b(_x: Box<dyn Foo+Send>) {
-}
-
-fn c(x: Box<dyn Foo+Sync+Send>) {
- e(x);
-}
-
-fn d(x: Box<dyn Foo+Send>) {
- e(x);
-}
-
-fn e(x: Box<dyn Foo>) {
- e(x);
-}
-
-pub fn main() { }
+++ /dev/null
-// run-pass
-// Tests that type parameter bounds on an implementation need not match the
-// trait exactly, as long as the implementation doesn't demand *more* bounds
-// than the trait.
-
-// pretty-expanded FIXME #23616
-
-trait A {
- fn foo<T: Eq + Ord>(&self);
-}
-
-impl A for isize {
- fn foo<T: Ord>(&self) {} // Ord implies Eq, so this is ok.
-}
-
-fn main() {}
+++ /dev/null
-// run-pass
-#![allow(unused_must_use)]
-// Tests that a heterogeneous list of existential `dyn` types can be put inside an Arc
-// and shared between threads as long as all types fulfill Send.
-
-// ignore-emscripten no threads support
-
-#![feature(box_syntax)]
-
-use std::sync::Arc;
-use std::sync::mpsc::channel;
-use std::thread;
-
-trait Pet {
- fn name(&self, blk: Box<dyn FnMut(&str)>);
- fn num_legs(&self) -> usize;
- fn of_good_pedigree(&self) -> bool;
-}
-
-struct Catte {
- num_whiskers: usize,
- name: String,
-}
-
-struct Dogge {
- bark_decibels: usize,
- tricks_known: usize,
- name: String,
-}
-
-struct Goldfyshe {
- swim_speed: usize,
- name: String,
-}
-
-impl Pet for Catte {
- fn name(&self, mut blk: Box<dyn FnMut(&str)>) { blk(&self.name) }
- fn num_legs(&self) -> usize { 4 }
- fn of_good_pedigree(&self) -> bool { self.num_whiskers >= 4 }
-}
-impl Pet for Dogge {
- fn name(&self, mut blk: Box<dyn FnMut(&str)>) { blk(&self.name) }
- fn num_legs(&self) -> usize { 4 }
- fn of_good_pedigree(&self) -> bool {
- self.bark_decibels < 70 || self.tricks_known > 20
- }
-}
-impl Pet for Goldfyshe {
- fn name(&self, mut blk: Box<dyn FnMut(&str)>) { blk(&self.name) }
- fn num_legs(&self) -> usize { 0 }
- fn of_good_pedigree(&self) -> bool { self.swim_speed >= 500 }
-}
-
-pub fn main() {
- let catte = Catte { num_whiskers: 7, name: "alonzo_church".to_string() };
- let dogge1 = Dogge {
- bark_decibels: 100,
- tricks_known: 42,
- name: "alan_turing".to_string(),
- };
- let dogge2 = Dogge {
- bark_decibels: 55,
- tricks_known: 11,
- name: "albert_einstein".to_string(),
- };
- let fishe = Goldfyshe {
- swim_speed: 998,
- name: "alec_guinness".to_string(),
- };
- let arc = Arc::new(vec![box catte as Box<dyn Pet+Sync+Send>,
- box dogge1 as Box<dyn Pet+Sync+Send>,
- box fishe as Box<dyn Pet+Sync+Send>,
- box dogge2 as Box<dyn Pet+Sync+Send>]);
- let (tx1, rx1) = channel();
- let arc1 = arc.clone();
- let t1 = thread::spawn(move|| { check_legs(arc1); tx1.send(()); });
- let (tx2, rx2) = channel();
- let arc2 = arc.clone();
- let t2 = thread::spawn(move|| { check_names(arc2); tx2.send(()); });
- let (tx3, rx3) = channel();
- let arc3 = arc.clone();
- let t3 = thread::spawn(move|| { check_pedigree(arc3); tx3.send(()); });
- rx1.recv();
- rx2.recv();
- rx3.recv();
- t1.join();
- t2.join();
- t3.join();
-}
-
-fn check_legs(arc: Arc<Vec<Box<dyn Pet+Sync+Send>>>) {
- let mut legs = 0;
- for pet in arc.iter() {
- legs += pet.num_legs();
- }
- assert!(legs == 12);
-}
-fn check_names(arc: Arc<Vec<Box<dyn Pet+Sync+Send>>>) {
- for pet in arc.iter() {
- pet.name(Box::new(|name| {
- assert!(name.as_bytes()[0] == 'a' as u8 && name.as_bytes()[1] == 'l' as u8);
- }))
- }
-}
-fn check_pedigree(arc: Arc<Vec<Box<dyn Pet+Sync+Send>>>) {
- for pet in arc.iter() {
- assert!(pet.of_good_pedigree());
- }
-}
+++ /dev/null
-trait Foo {
- fn dummy(&self) { }
-}
-
-// This should emit the less confusing error, not the more confusing one.
-
-fn foo(_x: Foo + Send) {
- //~^ ERROR the size for values of type
- //~| WARN trait objects without an explicit `dyn` are deprecated
-}
-
-fn main() { }
+++ /dev/null
-warning: trait objects without an explicit `dyn` are deprecated
- --> $DIR/trait-bounds-not-on-bare-trait.rs:7:12
- |
-LL | fn foo(_x: Foo + Send) {
- | ^^^^^^^^^^ help: use `dyn`: `dyn Foo + Send`
- |
- = note: `#[warn(bare_trait_objects)]` on by default
-
-error[E0277]: the size for values of type `(dyn Foo + Send + 'static)` cannot be known at compilation time
- --> $DIR/trait-bounds-not-on-bare-trait.rs:7:8
- |
-LL | fn foo(_x: Foo + Send) {
- | ^^ doesn't have a size known at compile-time
- |
- = help: the trait `Sized` is not implemented for `(dyn Foo + Send + 'static)`
- = help: unsized fn params are gated as an unstable feature
-help: function arguments must have a statically known size, borrowed types always have a known size
- |
-LL | fn foo(&_x: Foo + Send) {
- | ^
-
-error: aborting due to previous error; 1 warning emitted
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-// We don't need those errors. Ideally we would silence them, but to do so we need to move the
-// lint from being an early-lint during parsing to a late-lint, because it needs to be aware of
-// the types involved.
-#![allow(bare_trait_objects)]
-
-struct Foo;
-
-fn foo(_x: Box<Foo + Send>) { } //~ ERROR expected trait, found struct `Foo`
-
-type TypeAlias<T> = Box<dyn Vec<T>>; //~ ERROR expected trait, found struct `Vec`
-
-struct A;
-fn a() -> A + 'static { //~ ERROR expected trait, found
- A
-}
-fn b<'a,T,E>(iter: Iterator<Item=Result<T,E> + 'a>) { //~ ERROR expected trait, found
- panic!()
-}
-fn c() -> 'static + A { //~ ERROR expected trait, found
- A
-}
-fn d<'a,T,E>(iter: Iterator<Item='a + Result<T,E>>) { //~ ERROR expected trait, found
- panic!()
-}
-fn e() -> 'static + A + 'static { //~ ERROR expected trait, found
-//~^ ERROR only a single explicit lifetime bound is permitted
- A
-}
-fn f<'a,T,E>(iter: Iterator<Item='a + Result<T,E> + 'a>) { //~ ERROR expected trait, found
-//~^ ERROR only a single explicit lifetime bound is permitted
- panic!()
-}
-struct Traitor;
-trait Trait {}
-fn g() -> Traitor + 'static { //~ ERROR expected trait, found struct `Traitor`
- A
-}
-fn main() {}
+++ /dev/null
-error[E0226]: only a single explicit lifetime bound is permitted
- --> $DIR/trait-bounds-not-on-struct.rs:25:25
- |
-LL | fn e() -> 'static + A + 'static {
- | ^^^^^^^
-
-error[E0226]: only a single explicit lifetime bound is permitted
- --> $DIR/trait-bounds-not-on-struct.rs:29:53
- |
-LL | fn f<'a,T,E>(iter: Iterator<Item='a + Result<T,E> + 'a>) {
- | ^^
-
-error[E0404]: expected trait, found struct `Foo`
- --> $DIR/trait-bounds-not-on-struct.rs:8:16
- |
-LL | fn foo(_x: Box<Foo + Send>) { }
- | ^^^ not a trait
- |
-help: `+` is used to constrain a "trait object" type with lifetimes or auto-traits; structs and enums can't be bound in that way
- --> $DIR/trait-bounds-not-on-struct.rs:8:22
- |
-LL | fn foo(_x: Box<Foo + Send>) { }
- | --- ^^^^ ...because of this bound
- | |
- | expected this type to be a trait...
-
-error[E0404]: expected trait, found struct `Vec`
- --> $DIR/trait-bounds-not-on-struct.rs:10:29
- |
-LL | type TypeAlias<T> = Box<dyn Vec<T>>;
- | ^^^^^^ not a trait
-
-error[E0404]: expected trait, found struct `A`
- --> $DIR/trait-bounds-not-on-struct.rs:13:11
- |
-LL | fn a() -> A + 'static {
- | ^ not a trait
- |
-help: `+` is used to constrain a "trait object" type with lifetimes or auto-traits; structs and enums can't be bound in that way
- --> $DIR/trait-bounds-not-on-struct.rs:13:15
- |
-LL | fn a() -> A + 'static {
- | - ^^^^^^^ ...because of this bound
- | |
- | expected this type to be a trait...
-help: if you meant to use a type and not a trait here, remove the bounds
- |
-LL | fn a() -> A {
- | --
-
-error[E0404]: expected trait, found enum `Result`
- --> $DIR/trait-bounds-not-on-struct.rs:16:34
- |
-LL | fn b<'a,T,E>(iter: Iterator<Item=Result<T,E> + 'a>) {
- | ^^^^^^^^^^^ not a trait
- |
-help: `+` is used to constrain a "trait object" type with lifetimes or auto-traits; structs and enums can't be bound in that way
- --> $DIR/trait-bounds-not-on-struct.rs:16:48
- |
-LL | fn b<'a,T,E>(iter: Iterator<Item=Result<T,E> + 'a>) {
- | ----------- ^^ ...because of this bound
- | |
- | expected this type to be a trait...
-help: if you meant to use a type and not a trait here, remove the bounds
- |
-LL | fn b<'a,T,E>(iter: Iterator<Item=Result<T,E>>) {
- | --
-
-error[E0404]: expected trait, found struct `A`
- --> $DIR/trait-bounds-not-on-struct.rs:19:21
- |
-LL | fn c() -> 'static + A {
- | ^ not a trait
- |
-help: `+` is used to constrain a "trait object" type with lifetimes or auto-traits; structs and enums can't be bound in that way
- --> $DIR/trait-bounds-not-on-struct.rs:19:11
- |
-LL | fn c() -> 'static + A {
- | ^^^^^^^ - expected this type to be a trait...
- | |
- | ...because of this bound
-help: if you meant to use a type and not a trait here, remove the bounds
- |
-LL | fn c() -> A {
- | --
-
-error[E0404]: expected trait, found enum `Result`
- --> $DIR/trait-bounds-not-on-struct.rs:22:39
- |
-LL | fn d<'a,T,E>(iter: Iterator<Item='a + Result<T,E>>) {
- | ^^^^^^^^^^^ not a trait
- |
-help: `+` is used to constrain a "trait object" type with lifetimes or auto-traits; structs and enums can't be bound in that way
- --> $DIR/trait-bounds-not-on-struct.rs:22:34
- |
-LL | fn d<'a,T,E>(iter: Iterator<Item='a + Result<T,E>>) {
- | ^^ ----------- expected this type to be a trait...
- | |
- | ...because of this bound
-help: if you meant to use a type and not a trait here, remove the bounds
- |
-LL | fn d<'a,T,E>(iter: Iterator<Item=Result<T,E>>) {
- | --
-
-error[E0404]: expected trait, found struct `A`
- --> $DIR/trait-bounds-not-on-struct.rs:25:21
- |
-LL | fn e() -> 'static + A + 'static {
- | ^ not a trait
- |
-help: `+` is used to constrain a "trait object" type with lifetimes or auto-traits; structs and enums can't be bound in that way
- --> $DIR/trait-bounds-not-on-struct.rs:25:11
- |
-LL | fn e() -> 'static + A + 'static {
- | ^^^^^^^ - ^^^^^^^ ...because of these bounds
- | |
- | expected this type to be a trait...
-help: if you meant to use a type and not a trait here, remove the bounds
- |
-LL | fn e() -> A {
- | ---
-
-error[E0404]: expected trait, found enum `Result`
- --> $DIR/trait-bounds-not-on-struct.rs:29:39
- |
-LL | fn f<'a,T,E>(iter: Iterator<Item='a + Result<T,E> + 'a>) {
- | ^^^^^^^^^^^ not a trait
- |
-help: `+` is used to constrain a "trait object" type with lifetimes or auto-traits; structs and enums can't be bound in that way
- --> $DIR/trait-bounds-not-on-struct.rs:29:34
- |
-LL | fn f<'a,T,E>(iter: Iterator<Item='a + Result<T,E> + 'a>) {
- | ^^ ----------- ^^ ...because of these bounds
- | |
- | expected this type to be a trait...
-help: if you meant to use a type and not a trait here, remove the bounds
- |
-LL | fn f<'a,T,E>(iter: Iterator<Item=Result<T,E>>) {
- | -- --
-
-error[E0404]: expected trait, found struct `Traitor`
- --> $DIR/trait-bounds-not-on-struct.rs:35:11
- |
-LL | trait Trait {}
- | ----------- similarly named trait `Trait` defined here
-LL | fn g() -> Traitor + 'static {
- | ^^^^^^^ not a trait
- |
-help: `+` is used to constrain a "trait object" type with lifetimes or auto-traits; structs and enums can't be bound in that way
- --> $DIR/trait-bounds-not-on-struct.rs:35:21
- |
-LL | fn g() -> Traitor + 'static {
- | ------- ^^^^^^^ ...because of this bound
- | |
- | expected this type to be a trait...
-help: if you meant to use a type and not a trait here, remove the bounds
- |
-LL | fn g() -> Traitor {
- | --
-help: a trait with a similar name exists
- |
-LL | fn g() -> Trait + 'static {
- | ^^^^^
-
-error: aborting due to 11 previous errors
-
-Some errors have detailed explanations: E0226, E0404.
-For more information about an error, try `rustc --explain E0226`.
+++ /dev/null
-trait Trait {}
-
-struct Foo<T:Trait> {
- x: T,
-}
-
-enum Bar<T:Trait> {
- ABar(isize),
- BBar(T),
- CBar(usize),
-}
-
-fn explode(x: Foo<u32>) {}
-//~^ ERROR E0277
-
-fn kaboom(y: Bar<f32>) {}
-//~^ ERROR E0277
-
-fn main() {
-}
+++ /dev/null
-error[E0277]: the trait bound `u32: Trait` is not satisfied
- --> $DIR/trait-bounds-on-structs-and-enums-in-fns.rs:13:15
- |
-LL | struct Foo<T:Trait> {
- | ----- required by this bound in `Foo`
-...
-LL | fn explode(x: Foo<u32>) {}
- | ^^^^^^^^ the trait `Trait` is not implemented for `u32`
-
-error[E0277]: the trait bound `f32: Trait` is not satisfied
- --> $DIR/trait-bounds-on-structs-and-enums-in-fns.rs:16:14
- |
-LL | enum Bar<T:Trait> {
- | ----- required by this bound in `Bar`
-...
-LL | fn kaboom(y: Bar<f32>) {}
- | ^^^^^^^^ the trait `Trait` is not implemented for `f32`
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-trait Trait {}
-
-struct Foo<T:Trait> {
- x: T,
-}
-
-enum Bar<T:Trait> {
- ABar(isize),
- BBar(T),
- CBar(usize),
-}
-
-trait PolyTrait<T>
-{
- fn whatever(&self, t: T) {}
-}
-
-struct Struct;
-
-impl PolyTrait<Foo<u16>> for Struct {
-//~^ ERROR E0277
-}
-
-fn main() {
-}
+++ /dev/null
-error[E0277]: the trait bound `u16: Trait` is not satisfied
- --> $DIR/trait-bounds-on-structs-and-enums-in-impls.rs:20:6
- |
-LL | struct Foo<T:Trait> {
- | ----- required by this bound in `Foo`
-...
-LL | impl PolyTrait<Foo<u16>> for Struct {
- | ^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `u16`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-trait Trait {
- fn dummy(&self) { }
-}
-
-struct Foo<T:Trait> {
- x: T,
-}
-
-fn main() {
- let foo = Foo {
- //~^ ERROR E0277
- x: 3
- };
-
- let baz: Foo<usize> = loop { };
- //~^ ERROR E0277
-}
+++ /dev/null
-error[E0277]: the trait bound `usize: Trait` is not satisfied
- --> $DIR/trait-bounds-on-structs-and-enums-locals.rs:15:14
- |
-LL | struct Foo<T:Trait> {
- | ----- required by this bound in `Foo`
-...
-LL | let baz: Foo<usize> = loop { };
- | ^^^^^^^^^^ the trait `Trait` is not implemented for `usize`
-
-error[E0277]: the trait bound `{integer}: Trait` is not satisfied
- --> $DIR/trait-bounds-on-structs-and-enums-locals.rs:10:15
- |
-LL | struct Foo<T:Trait> {
- | ------------------- required by `Foo`
-...
-LL | let foo = Foo {
- | ^^^ the trait `Trait` is not implemented for `{integer}`
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-#![allow(unused_variables)]
-// pretty-expanded FIXME #23616
-
-trait U {}
-trait T<X: U> { fn get(self) -> X; }
-
-trait S2<Y: U> {
- fn m(x: Box<dyn T<Y>+'static>) {}
-}
-
-struct St<X: U> {
- f: Box<dyn T<X>+'static>,
-}
-
-impl<X: U> St<X> {
- fn blah() {}
-}
-
-fn main() {}
+++ /dev/null
-trait Trait {
- fn dummy(&self) { }
-}
-
-struct Foo<T:Trait> {
- x: T,
-}
-
-static X: Foo<usize> = Foo {
-//~^ ERROR E0277
- x: 1,
-};
-
-fn main() {
-}
+++ /dev/null
-error[E0277]: the trait bound `usize: Trait` is not satisfied
- --> $DIR/trait-bounds-on-structs-and-enums-static.rs:9:11
- |
-LL | struct Foo<T:Trait> {
- | ----- required by this bound in `Foo`
-...
-LL | static X: Foo<usize> = Foo {
- | ^^^^^^^^^^ the trait `Trait` is not implemented for `usize`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-// aux-build:trait_bounds_on_structs_and_enums_xc.rs
-
-extern crate trait_bounds_on_structs_and_enums_xc;
-
-use trait_bounds_on_structs_and_enums_xc::{Bar, Foo, Trait};
-
-fn explode(x: Foo<usize>) {}
-//~^ ERROR E0277
-
-fn kaboom(y: Bar<f32>) {}
-//~^ ERROR E0277
-
-fn main() {
-}
+++ /dev/null
-error[E0277]: the trait bound `usize: Trait` is not satisfied
- --> $DIR/trait-bounds-on-structs-and-enums-xc.rs:7:15
- |
-LL | fn explode(x: Foo<usize>) {}
- | ^^^^^^^^^^ the trait `Trait` is not implemented for `usize`
- |
- ::: $DIR/auxiliary/trait_bounds_on_structs_and_enums_xc.rs:5:18
- |
-LL | pub struct Foo<T:Trait> {
- | ----- required by this bound in `Foo`
-
-error[E0277]: the trait bound `f32: Trait` is not satisfied
- --> $DIR/trait-bounds-on-structs-and-enums-xc.rs:10:14
- |
-LL | fn kaboom(y: Bar<f32>) {}
- | ^^^^^^^^ the trait `Trait` is not implemented for `f32`
- |
- ::: $DIR/auxiliary/trait_bounds_on_structs_and_enums_xc.rs:9:16
- |
-LL | pub enum Bar<T:Trait> {
- | ----- required by this bound in `Bar`
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-// aux-build:trait_bounds_on_structs_and_enums_xc.rs
-
-extern crate trait_bounds_on_structs_and_enums_xc;
-
-use trait_bounds_on_structs_and_enums_xc::{Bar, Foo, Trait};
-
-fn main() {
- let foo = Foo {
- //~^ ERROR E0277
- x: 3
- };
- let bar: Bar<f64> = return;
- //~^ ERROR E0277
- let _ = bar;
-}
+++ /dev/null
-error[E0277]: the trait bound `f64: Trait` is not satisfied
- --> $DIR/trait-bounds-on-structs-and-enums-xc1.rs:12:14
- |
-LL | let bar: Bar<f64> = return;
- | ^^^^^^^^ the trait `Trait` is not implemented for `f64`
- |
- ::: $DIR/auxiliary/trait_bounds_on_structs_and_enums_xc.rs:9:16
- |
-LL | pub enum Bar<T:Trait> {
- | ----- required by this bound in `Bar`
-
-error[E0277]: the trait bound `{integer}: Trait` is not satisfied
- --> $DIR/trait-bounds-on-structs-and-enums-xc1.rs:8:15
- |
-LL | let foo = Foo {
- | ^^^ the trait `Trait` is not implemented for `{integer}`
- |
- = note: required by `Foo`
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-trait Trait {}
-
-struct Foo<T:Trait> {
- x: T,
-}
-
-enum Bar<T:Trait> {
- ABar(isize),
- BBar(T),
- CBar(usize),
-}
-
-impl<T> Foo<T> {
-//~^ ERROR `T: Trait` is not satisfied
- fn uhoh() {}
-}
-
-struct Baz {
- a: Foo<isize>, //~ ERROR E0277
-}
-
-enum Boo {
- Quux(Bar<usize>), //~ ERROR E0277
-}
-
-struct Badness<U> {
- b: Foo<U>, //~ ERROR E0277
-}
-
-enum MoreBadness<V> {
- EvenMoreBadness(Bar<V>), //~ ERROR E0277
-}
-
-struct TupleLike(
- Foo<i32>, //~ ERROR E0277
-);
-
-enum Enum {
- DictionaryLike { field: Bar<u8> }, //~ ERROR E0277
-}
-
-fn main() {
-}
+++ /dev/null
-error[E0277]: the trait bound `T: Trait` is not satisfied
- --> $DIR/trait-bounds-on-structs-and-enums.rs:13:9
- |
-LL | struct Foo<T:Trait> {
- | ----- required by this bound in `Foo`
-...
-LL | impl<T> Foo<T> {
- | ^^^^^^ the trait `Trait` is not implemented for `T`
- |
-help: consider restricting type parameter `T`
- |
-LL | impl<T: Trait> Foo<T> {
- | ^^^^^^^
-
-error[E0277]: the trait bound `isize: Trait` is not satisfied
- --> $DIR/trait-bounds-on-structs-and-enums.rs:19:8
- |
-LL | struct Foo<T:Trait> {
- | ----- required by this bound in `Foo`
-...
-LL | a: Foo<isize>,
- | ^^^^^^^^^^ the trait `Trait` is not implemented for `isize`
-
-error[E0277]: the trait bound `usize: Trait` is not satisfied
- --> $DIR/trait-bounds-on-structs-and-enums.rs:23:10
- |
-LL | enum Bar<T:Trait> {
- | ----- required by this bound in `Bar`
-...
-LL | Quux(Bar<usize>),
- | ^^^^^^^^^^ the trait `Trait` is not implemented for `usize`
-
-error[E0277]: the trait bound `U: Trait` is not satisfied
- --> $DIR/trait-bounds-on-structs-and-enums.rs:27:8
- |
-LL | struct Foo<T:Trait> {
- | ----- required by this bound in `Foo`
-...
-LL | b: Foo<U>,
- | ^^^^^^ the trait `Trait` is not implemented for `U`
- |
-help: consider restricting type parameter `U`
- |
-LL | struct Badness<U: Trait> {
- | ^^^^^^^
-
-error[E0277]: the trait bound `V: Trait` is not satisfied
- --> $DIR/trait-bounds-on-structs-and-enums.rs:31:21
- |
-LL | enum Bar<T:Trait> {
- | ----- required by this bound in `Bar`
-...
-LL | EvenMoreBadness(Bar<V>),
- | ^^^^^^ the trait `Trait` is not implemented for `V`
- |
-help: consider restricting type parameter `V`
- |
-LL | enum MoreBadness<V: Trait> {
- | ^^^^^^^
-
-error[E0277]: the trait bound `i32: Trait` is not satisfied
- --> $DIR/trait-bounds-on-structs-and-enums.rs:35:5
- |
-LL | struct Foo<T:Trait> {
- | ----- required by this bound in `Foo`
-...
-LL | Foo<i32>,
- | ^^^^^^^^ the trait `Trait` is not implemented for `i32`
-
-error[E0277]: the trait bound `u8: Trait` is not satisfied
- --> $DIR/trait-bounds-on-structs-and-enums.rs:39:29
- |
-LL | enum Bar<T:Trait> {
- | ----- required by this bound in `Bar`
-...
-LL | DictionaryLike { field: Bar<u8> },
- | ^^^^^^^ the trait `Trait` is not implemented for `u8`
-
-error: aborting due to 7 previous errors
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-// run-pass
-// pretty-expanded FIXME #23616
-
-trait I { fn i(&self) -> Self; }
-
-trait A<T:I> {
- fn id(x:T) -> T { x.i() }
-}
-
-trait J<T> { fn j(&self) -> T; }
-
-trait B<T:J<T>> {
- fn id(x:T) -> T { x.j() }
-}
-
-trait C {
- fn id<T:J<T>>(x:T) -> T { x.j() }
-}
-
-pub fn main() { }
+++ /dev/null
-// aux-build:crate_a1.rs
-// aux-build:crate_a2.rs
-
-// Issue 22750
-// This tests the extra help message reported when a trait bound
-// is not met but the struct implements a trait with the same path.
-
-fn main() {
- let foo = {
- extern crate crate_a2 as a;
- a::Foo
- };
-
- let implements_no_traits = {
- extern crate crate_a2 as a;
- a::DoesNotImplementTrait
- };
-
- let other_variant_implements_mismatched_trait = {
- extern crate crate_a2 as a;
- a::ImplementsWrongTraitConditionally { _marker: std::marker::PhantomData::<isize> }
- };
-
- let other_variant_implements_correct_trait = {
- extern crate crate_a1 as a;
- a::ImplementsTraitForUsize { _marker: std::marker::PhantomData::<isize> }
- };
-
- {
- extern crate crate_a1 as a;
- a::try_foo(foo);
- //~^ ERROR E0277
- //~| trait impl with same name found
- //~| perhaps two different versions of crate `crate_a2`
-
- // We don't want to see the "version mismatch" help message here
- // because `implements_no_traits` has no impl for `Foo`
- a::try_foo(implements_no_traits);
- //~^ ERROR E0277
-
- // We don't want to see the "version mismatch" help message here
- // because `other_variant_implements_mismatched_trait`
- // does not have an impl for its `<isize>` variant,
- // only for its `<usize>` variant.
- a::try_foo(other_variant_implements_mismatched_trait);
- //~^ ERROR E0277
-
- // We don't want to see the "version mismatch" help message here
- // because `ImplementsTraitForUsize` only has
- // impls for the correct trait where the path is not misleading.
- a::try_foo(other_variant_implements_correct_trait);
- //~^ ERROR E0277
- //~| the following implementations were found:
- }
-}
+++ /dev/null
-error[E0277]: the trait bound `Foo: main::a::Bar` is not satisfied
- --> $DIR/trait-bounds-same-crate-name.rs:31:20
- |
-LL | a::try_foo(foo);
- | ^^^ the trait `main::a::Bar` is not implemented for `Foo`
- |
- ::: $DIR/auxiliary/crate_a1.rs:3:24
- |
-LL | pub fn try_foo(x: impl Bar) {}
- | --- required by this bound in `try_foo`
- |
-help: trait impl with same name found
- --> $DIR/auxiliary/crate_a2.rs:5:1
- |
-LL | impl Bar for Foo {}
- | ^^^^^^^^^^^^^^^^^^^
- = note: perhaps two different versions of crate `crate_a2` are being used?
-
-error[E0277]: the trait bound `DoesNotImplementTrait: main::a::Bar` is not satisfied
- --> $DIR/trait-bounds-same-crate-name.rs:38:20
- |
-LL | a::try_foo(implements_no_traits);
- | ^^^^^^^^^^^^^^^^^^^^ the trait `main::a::Bar` is not implemented for `DoesNotImplementTrait`
- |
- ::: $DIR/auxiliary/crate_a1.rs:3:24
- |
-LL | pub fn try_foo(x: impl Bar) {}
- | --- required by this bound in `try_foo`
-
-error[E0277]: the trait bound `ImplementsWrongTraitConditionally<isize>: main::a::Bar` is not satisfied
- --> $DIR/trait-bounds-same-crate-name.rs:45:20
- |
-LL | a::try_foo(other_variant_implements_mismatched_trait);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `main::a::Bar` is not implemented for `ImplementsWrongTraitConditionally<isize>`
- |
- ::: $DIR/auxiliary/crate_a1.rs:3:24
- |
-LL | pub fn try_foo(x: impl Bar) {}
- | --- required by this bound in `try_foo`
- |
-help: trait impl with same name found
- --> $DIR/auxiliary/crate_a2.rs:13:1
- |
-LL | impl Bar for ImplementsWrongTraitConditionally<isize> {}
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- = note: perhaps two different versions of crate `crate_a2` are being used?
-
-error[E0277]: the trait bound `ImplementsTraitForUsize<isize>: main::a::Bar` is not satisfied
- --> $DIR/trait-bounds-same-crate-name.rs:51:20
- |
-LL | a::try_foo(other_variant_implements_correct_trait);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `main::a::Bar` is not implemented for `ImplementsTraitForUsize<isize>`
- |
- ::: $DIR/auxiliary/crate_a1.rs:3:24
- |
-LL | pub fn try_foo(x: impl Bar) {}
- | --- required by this bound in `try_foo`
- |
- = help: the following implementations were found:
- <ImplementsTraitForUsize<usize> as main::a::Bar>
-
-error: aborting due to 4 previous errors
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-// Tests for "default" bounds inferred for traits with no bounds list.
-
-trait Foo {}
-
-fn a(_x: Box<dyn Foo + Send>) {
-}
-
-fn b(_x: &'static (dyn Foo + 'static)) {
-}
-
-fn c(x: Box<dyn Foo + Sync>) {
- a(x); //~ ERROR mismatched types
-}
-
-fn d(x: &'static (dyn Foo + Sync)) {
- b(x);
-}
-
-fn main() {}
+++ /dev/null
-error[E0308]: mismatched types
- --> $DIR/trait-bounds-sugar.rs:12:7
- |
-LL | a(x);
- | ^ expected trait `Foo + Send`, found trait `Foo + Sync`
- |
- = note: expected struct `Box<(dyn Foo + Send + 'static)>`
- found struct `Box<(dyn Foo + Sync + 'static)>`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0308`.
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-#![allow(non_camel_case_types)]
-#![allow(non_snake_case)]
-
-trait connection {
- fn read(&self) -> isize;
-}
-
-trait connection_factory<C:connection> {
- fn create(&self) -> C;
-}
-
-type my_connection = ();
-type my_connection_factory = ();
-
-impl connection for () {
- fn read(&self) -> isize { 43 }
-}
-
-impl connection_factory<my_connection> for my_connection_factory {
- fn create(&self) -> my_connection { () }
-}
-
-pub fn main() {
- let factory = ();
- let connection = factory.create();
- let result = connection.read();
- assert_eq!(result, 43);
-}
+++ /dev/null
-// run-pass
-// Test that the cache results from the default method do not pollute
-// the cache for the later call in `load()`.
-//
-// See issue #18209.
-
-// pretty-expanded FIXME #23616
-
-pub trait Foo {
- fn load_from() -> Box<Self>;
- fn load() -> Box<Self> {
- Foo::load_from()
- }
-}
-
-pub fn load<M: Foo>() -> Box<M> {
- Foo::load()
-}
-
-fn main() { }
+++ /dev/null
-struct Struct {
- person: &'static str
-}
-
-trait Trait<T> {
- fn f(&self, x: T);
-}
-
-impl Trait<&'static str> for Struct {
- fn f(&self, x: &'static str) {
- println!("Hello, {}!", x);
- }
-}
-
-fn main() {
- let s: Box<dyn Trait<isize>> = Box::new(Struct { person: "Fred" });
- //~^ ERROR `Struct: Trait<isize>` is not satisfied
- s.f(1);
-}
+++ /dev/null
-error[E0277]: the trait bound `Struct: Trait<isize>` is not satisfied
- --> $DIR/trait-coercion-generic-bad.rs:16:36
- |
-LL | let s: Box<dyn Trait<isize>> = Box::new(Struct { person: "Fred" });
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait<isize>` is not implemented for `Struct`
- |
- = help: the following implementations were found:
- <Struct as Trait<&'static str>>
- = note: required for the cast to the object type `dyn Trait<isize>`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-struct Struct {
- person: &'static str
-}
-
-trait Trait<T> {
- fn f(&self, x: T);
-}
-
-impl Trait<&'static str> for Struct {
- fn f(&self, x: &'static str) {
- println!("Hello, {}!", x);
- }
-}
-
-fn main() {
- let person = "Fred".to_string();
- let person: &str = &person; //~ ERROR `person` does not live long enough
- let s: Box<dyn Trait<&'static str>> = Box::new(Struct { person: person });
-}
+++ /dev/null
-error[E0597]: `person` does not live long enough
- --> $DIR/trait-coercion-generic-regions.rs:17:24
- |
-LL | let person: &str = &person;
- | ^^^^^^^
- | |
- | borrowed value does not live long enough
- | assignment requires that `person` is borrowed for `'static`
-LL | let s: Box<dyn Trait<&'static str>> = Box::new(Struct { person: person });
-LL | }
- | - `person` dropped here while still borrowed
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0597`.
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-trait Trait<T> {
- fn f(&self, x: T);
-}
-
-#[derive(Copy, Clone)]
-struct Struct {
- x: isize,
- y: isize,
-}
-
-impl Trait<&'static str> for Struct {
- fn f(&self, x: &'static str) {
- println!("Hi, {}!", x);
- }
-}
-
-pub fn main() {
- let a = Struct { x: 1, y: 2 };
- let b: Box<dyn Trait<&'static str>> = Box::new(a);
- b.f("Mary");
- let c: &dyn Trait<&'static str> = &a;
- c.f("Joe");
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-#![allow(unused_mut)]
-#![allow(unused_variables)]
-#![feature(box_syntax)]
-
-use std::io::{self, Write};
-
-trait Trait {
- fn f(&self);
-}
-
-#[derive(Copy, Clone)]
-struct Struct {
- x: isize,
- y: isize,
-}
-
-impl Trait for Struct {
- fn f(&self) {
- println!("Hi!");
- }
-}
-
-fn foo(mut a: Box<dyn Write>) {}
-
-pub fn main() {
- let a = Struct { x: 1, y: 2 };
- let b: Box<dyn Trait> = Box::new(a);
- b.f();
- let c: &dyn Trait = &a;
- c.f();
-
- let out = io::stdout();
- foo(Box::new(out));
-}
+++ /dev/null
-// run-pass
-// pretty-expanded FIXME #23616
-
-trait Foo {
- fn foo(&self);
-}
-
-trait Bar : Foo {
- fn bar(&self);
-}
-
-pub fn main() {}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-// "guessing" in trait selection can affect `copy_or_move`. Check that this
-// is correctly handled. I am not sure what is the "correct" behaviour,
-// but we should at least not ICE.
-
-use std::mem;
-
-struct U([u8; 1337]);
-
-struct S<'a,T:'a>(&'a T);
-impl<'a, T> Clone for S<'a, T> { fn clone(&self) -> Self { S(self.0) } }
-/// This impl triggers inference "guessing" - S<_>: Copy => _ = U
-impl<'a> Copy for S<'a, Option<U>> {}
-
-fn assert_impls_fn<R,T: Fn()->R>(_: &T){}
-
-fn main() {
- let n = None;
- let e = S(&n);
- let f = || {
- // S being copy is critical for this to work
- drop(e);
- mem::size_of_val(e.0)
- };
- assert_impls_fn(&f);
- assert_eq!(f(), 1337+1);
-
- assert_eq!((|| {
- // S being Copy is not critical here, but
- // we check it anyway.
- let n = None;
- let e = S(&n);
- let ret = mem::size_of_val(e.0);
- drop(e);
- ret
- })(), 1337+1);
-}
+++ /dev/null
-// run-pass
-
-
-trait A<T> {
- fn g<U>(&self, x: T, y: U) -> (T, U) { (x, y) }
-}
-
-impl A<i32> for i32 { }
-impl<T> A<T> for u32 { }
-
-fn f<T, U, V: A<T>>(i: V, j: T, k: U) -> (T, U) {
- i.g(j, k)
-}
-
-pub fn main () {
- assert_eq!(f(0, 1, 2), (1, 2));
- assert_eq!(f(0, 1, 2), (1, 2));
-}
+++ /dev/null
-// run-pass
-
-
-trait A<T> {
- fn g(&self, x: T) -> T { x }
-}
-
-impl A<isize> for isize { }
-
-fn f<T, V: A<T>>(i: V, j: T) -> T {
- i.g(j)
-}
-
-pub fn main () {
- assert_eq!(f(0, 2), 2);
-}
+++ /dev/null
-// run-pass
-
-
-trait A {
- fn g<T>(&self, x: T, y: T) -> (T, T) { (x, y) }
-}
-
-impl A for isize { }
-
-fn f<T, V: A>(i: V, j: T, k: T) -> (T, T) {
- i.g(j, k)
-}
-
-pub fn main () {
- assert_eq!(f(0, 1, 2), (1, 2));
- assert_eq!(f(0, 1u8, 2u8), (1u8, 2u8));
-}
+++ /dev/null
-// run-pass
-#![allow(unused_variables)]
-
-
-trait A<T> {
- fn g(&self, x: usize) -> usize { x }
- fn h(&self, x: T) { }
-}
-
-impl<T> A<T> for isize { }
-
-fn f<T, V: A<T>>(i: V, j: usize) -> usize {
- i.g(j)
-}
-
-pub fn main () {
- assert_eq!(f::<f64, isize>(0, 2), 2);
- assert_eq!(f::<usize, isize>(0, 2), 2);
-}
+++ /dev/null
-// run-pass
-
-
-trait A {
- fn g(&self) -> isize { 10 }
-}
-
-impl A for isize { }
-
-fn f<T:A>(i: T) {
- assert_eq!(i.g(), 10);
-}
-
-pub fn main () {
- f(0);
-}
+++ /dev/null
-// run-pass
-// aux-build:trait_default_method_xc_aux.rs
-// aux-build:trait_default_method_xc_aux_2.rs
-
-
-
-extern crate trait_default_method_xc_aux as aux;
-extern crate trait_default_method_xc_aux_2 as aux2;
-use aux::A;
-use aux2::{a_struct, welp};
-
-
-pub fn main () {
-
- let a = a_struct { x: 0 };
- let b = a_struct { x: 1 };
-
- assert_eq!(0.g(), 10);
- assert_eq!(a.g(), 10);
- assert_eq!(a.h(), 11);
- assert_eq!(b.g(), 10);
- assert_eq!(b.h(), 11);
- assert_eq!(A::lurr(&a, &b), 21);
-
- welp(&0);
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-#![allow(non_camel_case_types)]
-
-// aux-build:trait_default_method_xc_aux.rs
-
-
-extern crate trait_default_method_xc_aux as aux;
-use aux::{A, TestEquality, Something};
-use aux::B;
-
-fn f<T: aux::A>(i: T) {
- assert_eq!(i.g(), 10);
-}
-
-fn welp<T>(i: isize, _x: &T) -> isize {
- i.g()
-}
-
-mod stuff {
- pub struct thing { pub x: isize }
-}
-
-impl A for stuff::thing {
- fn f(&self) -> isize { 10 }
-}
-
-fn g<T, U, V: B<T>>(i: V, j: T, k: U) -> (T, U) {
- i.thing(j, k)
-}
-
-fn eq<T: TestEquality>(lhs: &T, rhs: &T) -> bool {
- lhs.test_eq(rhs)
-}
-fn neq<T: TestEquality>(lhs: &T, rhs: &T) -> bool {
- lhs.test_neq(rhs)
-}
-
-
-impl TestEquality for stuff::thing {
- fn test_eq(&self, rhs: &stuff::thing) -> bool {
- //self.x.test_eq(&rhs.x)
- eq(&self.x, &rhs.x)
- }
-}
-
-
-pub fn main() {
- // Some tests of random things
- f(0);
-
- assert_eq!(A::lurr(&0, &1), 21);
-
- let a = stuff::thing { x: 0 };
- let b = stuff::thing { x: 1 };
- let c = Something { x: 1 };
-
- assert_eq!(0.g(), 10);
- assert_eq!(a.g(), 10);
- assert_eq!(a.h(), 11);
- assert_eq!(c.h(), 11);
-
- assert_eq!(0.thing(3.14f64, 1), (3.14f64, 1));
- assert_eq!(B::staticthing(&0, 3.14f64, 1), (3.14f64, 1));
- assert_eq!(B::<f64>::staticthing::<isize>(&0, 3.14, 1), (3.14, 1));
-
- assert_eq!(g(0, 3.14f64, 1), (3.14f64, 1));
- assert_eq!(g(false, 3.14f64, 1), (3.14, 1));
-
-
- // Trying out a real one
- assert!(12.test_neq(&10));
- assert!(!10.test_neq(&10));
- assert!(a.test_neq(&b));
- assert!(!a.test_neq(&a));
-
- assert!(neq(&12, &10));
- assert!(!neq(&10, &10));
- assert!(neq(&a, &b));
- assert!(!neq(&a, &a));
-}
+++ /dev/null
-trait Foo {
- fn orange(&self);
- fn orange(&self); //~ ERROR the name `orange` is defined multiple times
-}
-
-fn main() {}
+++ /dev/null
-error[E0428]: the name `orange` is defined multiple times
- --> $DIR/trait-duplicate-methods.rs:3:5
- |
-LL | fn orange(&self);
- | ----------------- previous definition of the value `orange` here
-LL | fn orange(&self);
- | ^^^^^^^^^^^^^^^^^ `orange` redefined here
- |
- = note: `orange` must be defined only once in the value namespace of this trait
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0428`.
+++ /dev/null
-// run-pass
-// Test that we do not error out because of a (False) ambiguity
-// between the builtin rules for Sized and the where clause. Issue
-// #20959.
-
-// pretty-expanded FIXME #23616
-
-fn foo<K>(x: Option<K>)
- where Option<K> : Sized
-{
- let _y = x;
-}
-
-fn main() {
- foo(Some(22));
-}
+++ /dev/null
-// run-pass
-#![allow(non_camel_case_types)]
-
-
-
-trait to_str {
- fn to_string_(&self) -> String;
-}
-impl to_str for isize {
- fn to_string_(&self) -> String { self.to_string() }
-}
-impl to_str for String {
- fn to_string_(&self) -> String { self.clone() }
-}
-impl to_str for () {
- fn to_string_(&self) -> String { "()".to_string() }
-}
-
-trait map<T> {
- fn map<U, F>(&self, f: F) -> Vec<U> where F: FnMut(&T) -> U;
-}
-impl<T> map<T> for Vec<T> {
- fn map<U, F>(&self, mut f: F) -> Vec<U> where F: FnMut(&T) -> U {
- let mut r = Vec::new();
- for i in self {
- r.push(f(i));
- }
- r
- }
-}
-
-fn foo<U, T: map<U>>(x: T) -> Vec<String> {
- x.map(|_e| "hi".to_string() )
-}
-fn bar<U:to_str,T:map<U>>(x: T) -> Vec<String> {
- x.map(|_e| _e.to_string_() )
-}
-
-pub fn main() {
- assert_eq!(foo(vec![1]), ["hi".to_string()]);
- assert_eq!(bar::<isize, Vec<isize> >(vec![4, 5]), ["4".to_string(), "5".to_string()]);
- assert_eq!(bar::<String, Vec<String> >(vec!["x".to_string(), "y".to_string()]),
- ["x".to_string(), "y".to_string()]);
- assert_eq!(bar::<(), Vec<()>>(vec![()]), ["()".to_string()]);
-}
+++ /dev/null
-// Test calling methods on an impl for a bare trait. This test checks that the
-// trait impl is only applied to a trait object, not concrete types which implement
-// the trait.
-
-trait T {}
-
-impl<'a> dyn T + 'a {
- fn foo(&self) {}
-}
-
-impl T for i32 {}
-
-fn main() {
- let x = &42i32;
- x.foo(); //~ERROR: no method named `foo` found
-}
+++ /dev/null
-error[E0599]: no method named `foo` found for reference `&i32` in the current scope
- --> $DIR/trait-impl-1.rs:15:7
- |
-LL | x.foo();
- | ^^^ method not found in `&i32`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0599`.
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-#![allow(non_snake_case)]
-
-// pretty-expanded FIXME #23616
-
-pub mod Foo {
- pub trait Trait {
- fn foo(&self);
- }
-}
-
-mod Bar {
- impl<'a> dyn (::Foo::Trait) + 'a {
- fn bar(&self) { self.foo() }
- }
-}
-
-fn main() {}
+++ /dev/null
-trait A { }
-
-impl A for isize {
- const BAR: () = (); //~ ERROR const `BAR` is not a member of trait `A`
- type Baz = (); //~ ERROR type `Baz` is not a member of trait `A`
- fn foo(&self) { } //~ ERROR method `foo` is not a member of trait `A`
-}
-
-fn main() { }
+++ /dev/null
-error[E0438]: const `BAR` is not a member of trait `A`
- --> $DIR/trait-impl-can-not-have-untraitful-items.rs:4:5
- |
-LL | const BAR: () = ();
- | ^^^^^^^^^^^^^^^^^^^ not a member of trait `A`
-
-error[E0437]: type `Baz` is not a member of trait `A`
- --> $DIR/trait-impl-can-not-have-untraitful-items.rs:5:5
- |
-LL | type Baz = ();
- | ^^^^^^^^^^^^^^ not a member of trait `A`
-
-error[E0407]: method `foo` is not a member of trait `A`
- --> $DIR/trait-impl-can-not-have-untraitful-items.rs:6:5
- |
-LL | fn foo(&self) { }
- | ^^^^^^^^^^^^^^^^^ not a member of trait `A`
-
-error: aborting due to 3 previous errors
-
-Some errors have detailed explanations: E0407, E0437, E0438.
-For more information about an error, try `rustc --explain E0407`.
+++ /dev/null
-trait Foo {
- fn bar(&self, x: usize) -> Self;
-}
-impl Foo for isize {
- fn bar(&self) -> isize {
- //~^ ERROR method `bar` has 1 parameter but the declaration in trait `Foo::bar` has 2
- *self
- }
-}
-
-fn main() {
-}
+++ /dev/null
-error[E0050]: method `bar` has 1 parameter but the declaration in trait `Foo::bar` has 2
- --> $DIR/trait-impl-different-num-params.rs:5:12
- |
-LL | fn bar(&self, x: usize) -> Self;
- | --------------- trait requires 2 parameters
-...
-LL | fn bar(&self) -> isize {
- | ^^^^^ expected 2 parameters, found 1
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0050`.
+++ /dev/null
-mod a {
-}
-
-trait A {
-}
-
-impl A for a { //~ ERROR expected type, found module
-}
-
-fn main() {
-}
+++ /dev/null
-error[E0573]: expected type, found module `a`
- --> $DIR/trait-impl-for-module.rs:7:12
- |
-LL | trait A {
- | ------- similarly named trait `A` defined here
-...
-LL | impl A for a {
- | ^ help: a trait with a similar name exists: `A`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0573`.
+++ /dev/null
-trait Mumbo {
- fn jumbo(&self, x: &usize) -> usize;
-}
-
-impl Mumbo for usize {
- // Cannot have a larger effect than the trait:
- unsafe fn jumbo(&self, x: &usize) { *self + *x; }
- //~^ ERROR method `jumbo` has an incompatible type for trait
- //~| expected fn pointer `fn
- //~| found fn pointer `unsafe fn
-}
-
-fn main() {}
+++ /dev/null
-error[E0053]: method `jumbo` has an incompatible type for trait
- --> $DIR/trait-impl-method-mismatch.rs:7:5
- |
-LL | fn jumbo(&self, x: &usize) -> usize;
- | ------------------------------------ type in trait
-...
-LL | unsafe fn jumbo(&self, x: &usize) { *self + *x; }
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected normal fn, found unsafe fn
- |
- = note: expected fn pointer `fn(&usize, &usize) -> usize`
- found fn pointer `unsafe fn(&usize, &usize)`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0053`.
+++ /dev/null
-// Check that when we test the supertrait we ensure consistent use of
-// lifetime parameters. In this case, implementing T2<'a,'b> requires
-// an impl of T1<'a>, but we have an impl of T1<'b>.
-
-trait T1<'x> {
- fn x(&self) -> &'x isize;
-}
-
-trait T2<'x, 'y> : T1<'x> {
- fn y(&self) -> &'y isize;
-}
-
-struct S<'a, 'b> {
- a: &'a isize,
- b: &'b isize
-}
-
-impl<'a,'b> T1<'b> for S<'a, 'b> {
- fn x(&self) -> &'b isize {
- self.b
- }
-}
-
-impl<'a,'b> T2<'a, 'b> for S<'a, 'b> { //~ ERROR cannot infer an appropriate lifetime
- fn y(&self) -> &'b isize {
- self.b
- }
-}
-
-pub fn main() {
-}
+++ /dev/null
-error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'b` due to conflicting requirements
- --> $DIR/trait-impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:13
- |
-LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> {
- | ^^^^^^^^^^
- |
-note: first, the lifetime cannot outlive the lifetime `'a` as defined on the impl at 24:6...
- --> $DIR/trait-impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:6
- |
-LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> {
- | ^^
-note: ...but the lifetime must also be valid for the lifetime `'b` as defined on the impl at 24:9...
- --> $DIR/trait-impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:9
- |
-LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> {
- | ^^
-note: ...so that the types are compatible
- --> $DIR/trait-impl-of-supertrait-has-wrong-lifetime-parameters.rs:24:13
- |
-LL | impl<'a,'b> T2<'a, 'b> for S<'a, 'b> {
- | ^^^^^^^^^^
- = note: expected `T1<'a>`
- found `T1<'_>`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0495`.
+++ /dev/null
-// run-pass
-// Test calling methods on an impl for a bare trait.
-
-// aux-build:traitimpl.rs
-
-extern crate traitimpl;
-use traitimpl::Bar;
-
-static mut COUNT: usize = 1;
-
-trait T {
- fn t(&self) {}
-}
-
-impl<'a> dyn T+'a {
- fn foo(&self) {
- unsafe { COUNT *= 2; }
- }
- fn bar() {
- unsafe { COUNT *= 3; }
- }
-}
-
-impl T for isize {}
-
-struct Foo;
-impl<'a> Bar<'a> for Foo {}
-
-fn main() {
- let x: &dyn T = &42;
-
- x.foo();
- T::foo(x);
- T::bar();
-
- unsafe { assert_eq!(COUNT, 12); }
-
- // Cross-crait case
- let x: &dyn Bar = &Foo;
- x.bar();
-}
+++ /dev/null
-// run-pass
-// aux-build:trait_inheritance_auto_xc_2_aux.rs
-
-
-extern crate trait_inheritance_auto_xc_2_aux as aux;
-
-// aux defines impls of Foo, Bar and Baz for A
-use aux::{Foo, Bar, Baz, A};
-
-// We want to extend all Foo, Bar, Bazes to Quuxes
-pub trait Quux: Foo + Bar + Baz { }
-impl<T:Foo + Bar + Baz> Quux for T { }
-
-fn f<T:Quux>(a: &T) {
- assert_eq!(a.f(), 10);
- assert_eq!(a.g(), 20);
- assert_eq!(a.h(), 30);
-}
-
-pub fn main() {
- let a = &A { x: 3 };
- f(a);
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-// aux-build:trait_inheritance_auto_xc_aux.rs
-
-
-extern crate trait_inheritance_auto_xc_aux as aux;
-
-use aux::{Foo, Bar, Baz, Quux};
-
-struct A { x: isize }
-
-impl Foo for A { fn f(&self) -> isize { 10 } }
-impl Bar for A { fn g(&self) -> isize { 20 } }
-impl Baz for A { fn h(&self) -> isize { 30 } }
-
-fn f<T:Quux>(a: &T) {
- assert_eq!(a.f(), 10);
- assert_eq!(a.g(), 20);
- assert_eq!(a.h(), 30);
-}
-
-pub fn main() {
- let a = &A { x: 3 };
- f(a);
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-// Testing that this impl turns A into a Quux, because
-// A is already a Foo Bar Baz
-
-impl<T:Foo + Bar + Baz> Quux for T { }
-
-trait Foo { fn f(&self) -> isize; }
-trait Bar { fn g(&self) -> isize; }
-trait Baz { fn h(&self) -> isize; }
-
-trait Quux: Foo + Bar + Baz { }
-
-struct A { x: isize }
-
-impl Foo for A { fn f(&self) -> isize { 10 } }
-impl Bar for A { fn g(&self) -> isize { 20 } }
-impl Baz for A { fn h(&self) -> isize { 30 } }
-
-fn f<T:Quux>(a: &T) {
- assert_eq!(a.f(), 10);
- assert_eq!(a.g(), 20);
- assert_eq!(a.h(), 30);
-}
-
-pub fn main() {
- let a = &A { x: 3 };
- f(a);
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-
-trait Foo { fn f(&self) -> isize; }
-trait Bar : Foo { fn g(&self) -> isize; }
-
-struct A { x: isize }
-
-impl Foo for A { fn f(&self) -> isize { 10 } }
-impl Bar for A { fn g(&self) -> isize { 20 } }
-
-// Call a function on Foo, given a T: Bar
-fn gg<T:Bar>(a: &T) -> isize {
- a.f()
-}
-
-pub fn main() {
- let a = &A { x: 3 };
- assert_eq!(gg(a), 10);
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-
-trait Foo { fn f(&self) -> isize; }
-trait Bar : Foo { fn g(&self) -> isize; }
-trait Baz : Bar { fn h(&self) -> isize; }
-
-struct A { x: isize }
-
-impl Foo for A { fn f(&self) -> isize { 10 } }
-impl Bar for A { fn g(&self) -> isize { 20 } }
-impl Baz for A { fn h(&self) -> isize { 30 } }
-
-// Call a function on Foo, given a T: Baz,
-// which is inherited via Bar
-fn gg<T:Baz>(a: &T) -> isize {
- a.f()
-}
-
-pub fn main() {
- let a = &A { x: 3 };
- assert_eq!(gg(a), 10);
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-// Testing that we can cast to a subtrait and call subtrait
-// methods. Not testing supertrait methods
-
-
-trait Foo {
- fn f(&self) -> isize;
-}
-
-trait Bar : Foo {
- fn g(&self) -> isize;
-}
-
-struct A {
- x: isize
-}
-
-impl Foo for A {
- fn f(&self) -> isize { 10 }
-}
-
-impl Bar for A {
- fn g(&self) -> isize { 20 }
-}
-
-pub fn main() {
- let a = &A { x: 3 };
- let afoo = a as &dyn Foo;
- let abar = a as &dyn Bar;
- assert_eq!(afoo.f(), 10);
- assert_eq!(abar.g(), 20);
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-// Testing that supertrait methods can be called on subtrait object types
-
-
-trait Foo {
- fn f(&self) -> isize;
-}
-
-trait Bar : Foo {
- fn g(&self) -> isize;
-}
-
-struct A {
- x: isize
-}
-
-impl Foo for A {
- fn f(&self) -> isize { 10 }
-}
-
-impl Bar for A {
- fn g(&self) -> isize { 20 }
-}
-
-pub fn main() {
- let a = &A { x: 3 };
- let afoo = a as &dyn Foo;
- let abar = a as &dyn Bar;
- assert_eq!(afoo.f(), 10);
- assert_eq!(abar.g(), 20);
- assert_eq!(abar.f(), 10);
-}
+++ /dev/null
-// run-pass
-// aux-build:trait_xc_call_aux.rs
-
-
-extern crate trait_xc_call_aux as aux;
-
-use aux::Foo;
-
-trait Bar : Foo {
- fn g(&self) -> isize;
-}
-
-impl Bar for aux::A {
- fn g(&self) -> isize { self.f() }
-}
-
-pub fn main() {
- let a = &aux::A { x: 3 };
- assert_eq!(a.g(), 10);
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-
-trait Foo { fn f(&self) -> isize; }
-trait Bar : Foo { fn g(&self) -> isize; }
-
-struct A { x: isize }
-
-impl Foo for A { fn f(&self) -> isize { 10 } }
-
-impl Bar for A {
- // Testing that this impl can call the impl of Foo
- fn g(&self) -> isize { self.f() }
-}
-
-pub fn main() {
- let a = &A { x: 3 };
- assert_eq!(a.g(), 10);
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-// B and C both require A, so D does as well, twice, but that's just fine
-
-
-trait A { fn a(&self) -> isize; }
-trait B: A { fn b(&self) -> isize; }
-trait C: A { fn c(&self) -> isize; }
-trait D: B + C { fn d(&self) -> isize; }
-
-struct S { bogus: () }
-
-impl A for S { fn a(&self) -> isize { 10 } }
-impl B for S { fn b(&self) -> isize { 20 } }
-impl C for S { fn c(&self) -> isize { 30 } }
-impl D for S { fn d(&self) -> isize { 40 } }
-
-fn f<T:D>(x: &T) {
- assert_eq!(x.a(), 10);
- assert_eq!(x.b(), 20);
- assert_eq!(x.c(), 30);
- assert_eq!(x.d(), 40);
-}
-
-pub fn main() {
- let value = &S { bogus: () };
- f(value);
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-
-trait A { fn a(&self) -> isize; }
-trait B: A { fn b(&self) -> isize; }
-trait C: A { fn c(&self) -> isize; }
-
-struct S { bogus: () }
-
-impl A for S { fn a(&self) -> isize { 10 } }
-impl B for S { fn b(&self) -> isize { 20 } }
-impl C for S { fn c(&self) -> isize { 30 } }
-
-// Both B and C inherit from A
-fn f<T:B + C>(x: &T) {
- assert_eq!(x.a(), 10);
- assert_eq!(x.b(), 20);
- assert_eq!(x.c(), 30);
-}
-
-pub fn main() {
- f(&S { bogus: () })
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-
-trait A { fn a(&self) -> isize; }
-trait B: A { fn b(&self) -> isize; }
-trait C: A { fn c(&self) -> isize; }
-
-struct S { bogus: () }
-
-impl A for S { fn a(&self) -> isize { 10 } }
-impl B for S { fn b(&self) -> isize { 20 } }
-impl C for S { fn c(&self) -> isize { 30 } }
-
-// Multiple type params, multiple levels of inheritance
-fn f<X:A,Y:B,Z:C>(x: &X, y: &Y, z: &Z) {
- assert_eq!(x.a(), 10);
- assert_eq!(y.a(), 10);
- assert_eq!(y.b(), 20);
- assert_eq!(z.a(), 10);
- assert_eq!(z.c(), 30);
-}
-
-pub fn main() {
- let s = &S { bogus: () };
- f(s, s, s);
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-#![allow(unused_variables)]
-// pretty-expanded FIXME #23616
-
-pub trait NumExt: PartialEq + PartialOrd {}
-
-pub trait FloatExt: NumExt {}
-
-fn greater_than_one<T: NumExt>(n: &T) -> bool { loop {} }
-fn greater_than_one_float<T: FloatExt>(n: &T) -> bool { loop {} }
-
-pub fn main() {}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-// Extending Num and using inherited static methods
-
-// pretty-expanded FIXME #23616
-
-use std::cmp::PartialOrd;
-
-pub trait NumCast: Sized {
- fn from(i: i32) -> Option<Self>;
-}
-
-pub trait Num {
- fn from_int(i: isize) -> Self;
- fn gt(&self, other: &Self) -> bool;
-}
-
-pub trait NumExt: NumCast + PartialOrd { }
-
-fn greater_than_one<T:NumExt>(n: &T) -> bool {
- n.gt(&NumCast::from(1).unwrap())
-}
-
-pub fn main() {}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-// pretty-expanded FIXME #23616
-
-pub trait NumCast: Sized {
- fn from(i: i32) -> Option<Self>;
-}
-
-pub trait NumExt: NumCast + PartialOrd { }
-
-fn greater_than_one<T:NumExt>(n: &T) -> bool {
- *n > NumCast::from(1).unwrap()
-}
-
-pub fn main() {}
+++ /dev/null
-// run-pass
-// A more complex example of numeric extensions
-
-pub trait TypeExt {}
-
-impl TypeExt for u8 {}
-impl TypeExt for u16 {}
-impl TypeExt for u32 {}
-impl TypeExt for u64 {}
-impl TypeExt for usize {}
-
-impl TypeExt for i8 {}
-impl TypeExt for i16 {}
-impl TypeExt for i32 {}
-impl TypeExt for i64 {}
-impl TypeExt for isize {}
-
-impl TypeExt for f32 {}
-impl TypeExt for f64 {}
-
-
-pub trait NumExt: TypeExt + PartialEq + PartialOrd {}
-
-impl NumExt for u8 {}
-impl NumExt for u16 {}
-impl NumExt for u32 {}
-impl NumExt for u64 {}
-impl NumExt for usize {}
-
-impl NumExt for i8 {}
-impl NumExt for i16 {}
-impl NumExt for i32 {}
-impl NumExt for i64 {}
-impl NumExt for isize {}
-
-impl NumExt for f32 {}
-impl NumExt for f64 {}
-
-
-pub trait UnSignedExt: NumExt {}
-
-impl UnSignedExt for u8 {}
-impl UnSignedExt for u16 {}
-impl UnSignedExt for u32 {}
-impl UnSignedExt for u64 {}
-impl UnSignedExt for usize {}
-
-
-pub trait SignedExt: NumExt {}
-
-impl SignedExt for i8 {}
-impl SignedExt for i16 {}
-impl SignedExt for i32 {}
-impl SignedExt for i64 {}
-impl SignedExt for isize {}
-
-impl SignedExt for f32 {}
-impl SignedExt for f64 {}
-
-
-pub trait IntegerExt: NumExt {}
-
-impl IntegerExt for u8 {}
-impl IntegerExt for u16 {}
-impl IntegerExt for u32 {}
-impl IntegerExt for u64 {}
-impl IntegerExt for usize {}
-
-impl IntegerExt for i8 {}
-impl IntegerExt for i16 {}
-impl IntegerExt for i32 {}
-impl IntegerExt for i64 {}
-impl IntegerExt for isize {}
-
-
-pub trait FloatExt: NumExt {}
-
-impl FloatExt for f32 {}
-impl FloatExt for f64 {}
-
-
-fn test_float_ext<T:FloatExt>(n: T) { println!("{}", n < n) }
-
-pub fn main() {
- test_float_ext(1f32);
-}
+++ /dev/null
-// run-pass
-pub trait NumCast: Sized {
- fn from(i: i32) -> Option<Self>;
-}
-
-pub trait NumExt: PartialEq + PartialOrd + NumCast {}
-
-impl NumExt for f32 {}
-impl NumCast for f32 {
- fn from(i: i32) -> Option<f32> { Some(i as f32) }
-}
-
-fn num_eq_one<T: NumExt>(n: T) {
- println!("{}", n == NumCast::from(1).unwrap())
-}
-
-pub fn main() {
- num_eq_one(1f32); // you need to actually use the function to trigger the ICE
-}
+++ /dev/null
-// run-pass
-// pretty-expanded FIXME #23616
-
-pub trait NumCast: Sized {
- fn from(i: i32) -> Option<Self>;
-}
-
-pub trait NumExt: PartialEq + NumCast {}
-
-impl NumExt for f32 {}
-impl NumExt for isize {}
-
-impl NumCast for f32 {
- fn from(i: i32) -> Option<f32> { Some(i as f32) }
-}
-impl NumCast for isize {
- fn from(i: i32) -> Option<isize> { Some(i as isize) }
-}
-
-fn num_eq_one<T:NumExt>() -> T {
- NumCast::from(1).unwrap()
-}
-
-pub fn main() {
- num_eq_one::<isize>(); // you need to actually use the function to trigger the ICE
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-use std::cmp::PartialEq;
-
-trait MyNum : PartialEq { }
-
-#[derive(Debug)]
-struct MyInt { val: isize }
-
-impl PartialEq for MyInt {
- fn eq(&self, other: &MyInt) -> bool { self.val == other.val }
- fn ne(&self, other: &MyInt) -> bool { !self.eq(other) }
-}
-
-impl MyNum for MyInt {}
-
-fn f<T:MyNum>(x: T, y: T) -> bool {
- return x == y;
-}
-
-fn mi(v: isize) -> MyInt { MyInt { val: v } }
-
-pub fn main() {
- let (x, y, z) = (mi(3), mi(5), mi(3));
- assert!(x != y);
- assert_eq!(x, z);
-}
+++ /dev/null
-// run-pass
-// aux-build:trait_inheritance_overloading_xc.rs
-
-
-extern crate trait_inheritance_overloading_xc;
-use trait_inheritance_overloading_xc::{MyNum, MyInt};
-
-fn f<T:MyNum>(x: T, y: T) -> (T, T, T) {
- return (x.clone() + y.clone(), x.clone() - y.clone(), x * y);
-}
-
-fn mi(v: isize) -> MyInt { MyInt { val: v } }
-
-pub fn main() {
- let (x, y) = (mi(3), mi(5));
- let (a, b, c) = f(x, y);
- assert_eq!(a, mi(8));
- assert_eq!(b, mi(-2));
- assert_eq!(c, mi(15));
-}
+++ /dev/null
-// run-pass
-use std::cmp::PartialEq;
-use std::ops::{Add, Sub, Mul};
-
-trait MyNum : Add<Output=Self> + Sub<Output=Self> + Mul<Output=Self> + PartialEq + Clone { }
-
-#[derive(Clone, Debug)]
-struct MyInt { val: isize }
-
-impl Add for MyInt {
- type Output = MyInt;
-
- fn add(self, other: MyInt) -> MyInt { mi(self.val + other.val) }
-}
-
-impl Sub for MyInt {
- type Output = MyInt;
-
- fn sub(self, other: MyInt) -> MyInt { mi(self.val - other.val) }
-}
-
-impl Mul for MyInt {
- type Output = MyInt;
-
- fn mul(self, other: MyInt) -> MyInt { mi(self.val * other.val) }
-}
-
-impl PartialEq for MyInt {
- fn eq(&self, other: &MyInt) -> bool { self.val == other.val }
- fn ne(&self, other: &MyInt) -> bool { !self.eq(other) }
-}
-
-impl MyNum for MyInt {}
-
-fn f<T:MyNum>(x: T, y: T) -> (T, T, T) {
- return (x.clone() + y.clone(), x.clone() - y.clone(), x * y);
-}
-
-fn mi(v: isize) -> MyInt { MyInt { val: v } }
-
-pub fn main() {
- let (x, y) = (mi(3), mi(5));
- let (a, b, c) = f(x, y);
- assert_eq!(a, mi(8));
- assert_eq!(b, mi(-2));
- assert_eq!(c, mi(15));
-}
+++ /dev/null
-// run-pass
-// Test for issue #4183: use of Self in supertraits.
-
-pub static FUZZY_EPSILON: f64 = 0.1;
-
-pub trait FuzzyEq<Eps> {
- fn fuzzy_eq(&self, other: &Self) -> bool;
- fn fuzzy_eq_eps(&self, other: &Self, epsilon: &Eps) -> bool;
-}
-
-trait Float: Sized+FuzzyEq<Self> {
- fn two_pi() -> Self;
-}
-
-impl FuzzyEq<f32> for f32 {
- fn fuzzy_eq(&self, other: &f32) -> bool {
- self.fuzzy_eq_eps(other, &(FUZZY_EPSILON as f32))
- }
-
- fn fuzzy_eq_eps(&self, other: &f32, epsilon: &f32) -> bool {
- (*self - *other).abs() < *epsilon
- }
-}
-
-impl Float for f32 {
- fn two_pi() -> f32 { 6.28318530717958647692528676655900576_f32 }
-}
-
-impl FuzzyEq<f64> for f64 {
- fn fuzzy_eq(&self, other: &f64) -> bool {
- self.fuzzy_eq_eps(other, &(FUZZY_EPSILON as f64))
- }
-
- fn fuzzy_eq_eps(&self, other: &f64, epsilon: &f64) -> bool {
- (*self - *other).abs() < *epsilon
- }
-}
-
-impl Float for f64 {
- fn two_pi() -> f64 { 6.28318530717958647692528676655900576_f64 }
-}
-
-fn compare<F:Float>(f1: F) -> bool {
- let f2 = Float::two_pi();
- f1.fuzzy_eq(&f2)
-}
-
-pub fn main() {
- assert!(compare::<f32>(6.28318530717958647692528676655900576));
- assert!(compare::<f32>(6.29));
- assert!(compare::<f32>(6.3));
- assert!(compare::<f32>(6.19));
- assert!(!compare::<f32>(7.28318530717958647692528676655900576));
- assert!(!compare::<f32>(6.18));
-
- assert!(compare::<f64>(6.28318530717958647692528676655900576));
- assert!(compare::<f64>(6.29));
- assert!(compare::<f64>(6.3));
- assert!(compare::<f64>(6.19));
- assert!(!compare::<f64>(7.28318530717958647692528676655900576));
- assert!(!compare::<f64>(6.18));
-}
+++ /dev/null
-// run-pass
-trait Foo<T> {
- fn f(&self, x: &T);
-}
-
-trait Bar : Sized + Foo<Self> {
- fn g(&self);
-}
-
-struct S {
- x: isize
-}
-
-impl Foo<S> for S {
- fn f(&self, x: &S) {
- println!("{}", x.x);
- }
-}
-
-impl Bar for S {
- fn g(&self) {
- self.f(self);
- }
-}
-
-pub fn main() {
- let s = S { x: 1 };
- s.g();
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-
-trait Foo { fn f(&self) -> isize; }
-trait Bar : Foo { fn g(&self) -> isize; }
-
-struct A { x: isize }
-
-impl Foo for A { fn f(&self) -> isize { 10 } }
-impl Bar for A { fn g(&self) -> isize { 20 } }
-
-fn ff<T:Foo>(a: &T) -> isize {
- a.f()
-}
-
-fn gg<T:Bar>(a: &T) -> isize {
- a.g()
-}
-
-pub fn main() {
- let a = &A { x: 3 };
- assert_eq!(ff(a), 10);
- assert_eq!(gg(a), 20);
-}
+++ /dev/null
-// run-pass
-
-pub trait MyNum {
- fn from_int(_: isize) -> Self;
-}
-
-pub trait NumExt: MyNum { }
-
-struct S { v: isize }
-
-impl MyNum for S {
- fn from_int(i: isize) -> S {
- S {
- v: i
- }
- }
-}
-
-impl NumExt for S { }
-
-fn greater_than_one<T:NumExt>() -> T { MyNum::from_int(1) }
-
-pub fn main() {
- let v: S = greater_than_one();
- assert_eq!(v.v, 1);
-}
+++ /dev/null
-// run-pass
-pub trait MyEq {}
-
-pub trait MyNum {
- fn from_int(_: isize) -> Self;
-}
-
-pub trait NumExt: MyEq + MyNum { }
-
-struct S { v: isize }
-
-impl MyEq for S { }
-
-impl MyNum for S {
- fn from_int(i: isize) -> S {
- S {
- v: i
- }
- }
-}
-
-impl NumExt for S { }
-
-fn greater_than_one<T:NumExt>() -> T { MyNum::from_int(1) }
-
-pub fn main() {
- let v: S = greater_than_one();
- assert_eq!(v.v, 1);
-}
+++ /dev/null
-// run-pass
-
-pub trait Add<RHS,Result> {
- fn add(&self, rhs: &RHS) -> Result;
-}
-
-trait MyNum : Sized + Add<Self,Self> { }
-
-struct MyInt { val: isize }
-
-impl Add<MyInt, MyInt> for MyInt {
- fn add(&self, other: &MyInt) -> MyInt { mi(self.val + other.val) }
-}
-
-impl MyNum for MyInt {}
-
-fn f<T:MyNum>(x: T, y: T) -> T {
- return x.add(&y);
-}
-
-fn mi(v: isize) -> MyInt { MyInt { val: v } }
-
-pub fn main() {
- let (x, y) = (mi(3), mi(5));
- let z = f(x, y);
- assert_eq!(z.val, 8)
-}
+++ /dev/null
-// run-pass
-
-trait Panda<T> {
- fn chomp(&self, bamboo: &T) -> T;
-}
-
-trait Add<RHS,Result>: Panda<RHS> {
- fn add(&self, rhs: &RHS) -> Result;
-}
-
-trait MyNum : Sized + Add<Self,Self> { }
-
-struct MyInt { val: isize }
-
-impl Panda<MyInt> for MyInt {
- fn chomp(&self, bamboo: &MyInt) -> MyInt {
- mi(self.val + bamboo.val)
- }
-}
-
-impl Add<MyInt, MyInt> for MyInt {
- fn add(&self, other: &MyInt) -> MyInt { self.chomp(other) }
-}
-
-impl MyNum for MyInt {}
-
-fn f<T:MyNum>(x: T, y: T) -> T {
- return x.add(&y).chomp(&y);
-}
-
-fn mi(v: isize) -> MyInt { MyInt { val: v } }
-
-pub fn main() {
- let (x, y) = (mi(3), mi(5));
- let z = f(x, y);
- assert_eq!(z.val, 13);
-}
+++ /dev/null
-// run-pass
-
-mod traits {
- pub trait Foo { fn f(&self) -> isize; }
-
- impl Foo for isize { fn f(&self) -> isize { 10 } }
-}
-
-trait Quux: traits::Foo { }
-impl<T:traits::Foo> Quux for T { }
-
-// Foo is not in scope but because Quux is we can still access
-// Foo's methods on a Quux bound typaram
-fn f<T:Quux>(x: &T) {
- assert_eq!(x.f(), 10);
-}
-
-pub fn main() {
- f(&0)
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-
-trait Foo { fn f(&self) -> isize; }
-trait Bar { fn g(&self) -> isize; }
-trait Baz { fn h(&self) -> isize; }
-
-trait Quux: Foo + Bar + Baz { }
-
-struct A { x: isize }
-
-impl Foo for A { fn f(&self) -> isize { 10 } }
-impl Bar for A { fn g(&self) -> isize { 20 } }
-impl Baz for A { fn h(&self) -> isize { 30 } }
-impl Quux for A {}
-
-fn f<T:Quux + Foo + Bar + Baz>(a: &T) {
- assert_eq!(a.f(), 10);
- assert_eq!(a.g(), 20);
- assert_eq!(a.h(), 30);
-}
-
-pub fn main() {
- let a = &A { x: 3 };
- f(a);
-}
+++ /dev/null
-// run-pass
-// Issue #34183
-
-macro_rules! foo {
- () => {
- fn foo() { }
- }
-}
-
-macro_rules! bar {
- () => {
- fn bar();
- }
-}
-
-trait Bleh {
- foo!();
- bar!();
-}
-
-struct Test;
-
-impl Bleh for Test {
- fn bar() {}
-}
-
-fn main() {
- Test::bar();
- Test::foo();
-}
+++ /dev/null
-#![feature(associated_type_defaults)]
-
-struct S;
-
-mod method {
- trait A {
- fn a(&self) { }
- }
-
- pub trait B {
- fn b(&self) { }
- }
-
- pub trait C: A + B {
- fn c(&self) { }
- }
-
- impl A for ::S {}
- impl B for ::S {}
- impl C for ::S {}
-}
-
-mod assoc_const {
- trait A {
- const A: u8 = 0;
- }
-
- pub trait B {
- const B: u8 = 0;
- }
-
- pub trait C: A + B {
- const C: u8 = 0;
- }
-
- impl A for ::S {}
- impl B for ::S {}
- impl C for ::S {}
-}
-
-mod assoc_ty {
- trait A {
- type A = u8;
- }
-
- pub trait B {
- type B = u8;
- }
-
- pub trait C: A + B {
- type C = u8;
- }
-
- impl A for ::S {}
- impl B for ::S {}
- impl C for ::S {}
-}
-
-fn check_method() {
- // A is private
- // B is pub, not in scope
- // C : A + B is pub, in scope
- use method::C;
-
- // Methods, method call
- // a, b, c are resolved as trait items, their traits need to be in scope
- S.a(); //~ ERROR no method named `a` found
- S.b(); //~ ERROR no method named `b` found
- S.c(); // OK
- // a, b, c are resolved as inherent items, their traits don't need to be in scope
- let c = &S as &dyn C;
- c.a(); //~ ERROR associated function `a` is private
- c.b(); // OK
- c.c(); // OK
-
- // Methods, UFCS
- // a, b, c are resolved as trait items, their traits need to be in scope
- S::a(&S);
- //~^ ERROR no function or associated item named `a` found
- S::b(&S);
- //~^ ERROR no function or associated item named `b` found
- S::c(&S); // OK
- // a, b, c are resolved as inherent items, their traits don't need to be in scope
- C::a(&S); //~ ERROR associated function `a` is private
- C::b(&S); // OK
- C::c(&S); // OK
-}
-
-fn check_assoc_const() {
- // A is private
- // B is pub, not in scope
- // C : A + B is pub, in scope
- use assoc_const::C;
-
- // Associated constants
- // A, B, C are resolved as trait items, their traits need to be in scope
- S::A; //~ ERROR no associated item named `A` found
- S::B; //~ ERROR no associated item named `B` found
- S::C; // OK
- // A, B, C are resolved as inherent items, their traits don't need to be in scope
- C::A; //~ ERROR associated constant `A` is private
- //~^ ERROR the trait `assoc_const::C` cannot be made into an object
- C::B; // ERROR the trait `assoc_const::C` cannot be made into an object
- C::C; // OK
-}
-
-fn check_assoc_ty<T: assoc_ty::C>() {
- // A is private
- // B is pub, not in scope
- // C : A + B is pub, in scope
- use assoc_ty::C;
-
- // Associated types
- // A, B, C are resolved as trait items, their traits need to be in scope, not implemented yet
- let _: S::A; //~ ERROR ambiguous associated type
- let _: S::B; //~ ERROR ambiguous associated type
- let _: S::C; //~ ERROR ambiguous associated type
- // A, B, C are resolved as inherent items, their traits don't need to be in scope
- let _: T::A; //~ ERROR associated type `A` is private
- let _: T::B; // OK
- let _: T::C; // OK
-
- // Associated types, bindings
- let _: dyn assoc_ty::B<
- B = u8, // OK
- >;
- let _: dyn C<
- A = u8, //~ ERROR associated type `A` is private
- B = u8, // OK
- C = u8, // OK
- >;
-}
-
-fn main() {}
+++ /dev/null
-error[E0599]: no method named `a` found for struct `S` in the current scope
- --> $DIR/trait-item-privacy.rs:67:7
- |
-LL | struct S;
- | --------- method `a` not found for this
-...
-LL | S.a();
- | ^ method not found in `S`
- |
- = help: items from traits can only be used if the trait is implemented and in scope
-note: `method::A` defines an item `a`, perhaps you need to implement it
- --> $DIR/trait-item-privacy.rs:6:5
- |
-LL | trait A {
- | ^^^^^^^
-
-error[E0599]: no method named `b` found for struct `S` in the current scope
- --> $DIR/trait-item-privacy.rs:68:7
- |
-LL | struct S;
- | --------- method `b` not found for this
-...
-LL | S.b();
- | ^ method not found in `S`
- |
- = help: items from traits can only be used if the trait is in scope
-help: the following trait is implemented but not in scope; perhaps add a `use` for it:
- |
-LL | use method::B;
- |
-
-error[E0624]: associated function `a` is private
- --> $DIR/trait-item-privacy.rs:72:7
- |
-LL | c.a();
- | ^ private associated function
-
-error[E0599]: no function or associated item named `a` found for struct `S` in the current scope
- --> $DIR/trait-item-privacy.rs:78:8
- |
-LL | struct S;
- | --------- function or associated item `a` not found for this
-...
-LL | S::a(&S);
- | ^ function or associated item not found in `S`
- |
- = help: items from traits can only be used if the trait is implemented and in scope
-note: `method::A` defines an item `a`, perhaps you need to implement it
- --> $DIR/trait-item-privacy.rs:6:5
- |
-LL | trait A {
- | ^^^^^^^
-
-error[E0599]: no function or associated item named `b` found for struct `S` in the current scope
- --> $DIR/trait-item-privacy.rs:80:8
- |
-LL | struct S;
- | --------- function or associated item `b` not found for this
-...
-LL | S::b(&S);
- | ^ function or associated item not found in `S`
- |
- = help: items from traits can only be used if the trait is in scope
-help: the following trait is implemented but not in scope; perhaps add a `use` for it:
- |
-LL | use method::B;
- |
-
-error[E0624]: associated function `a` is private
- --> $DIR/trait-item-privacy.rs:84:8
- |
-LL | C::a(&S);
- | ^ private associated function
-
-error[E0599]: no associated item named `A` found for struct `S` in the current scope
- --> $DIR/trait-item-privacy.rs:97:8
- |
-LL | struct S;
- | --------- associated item `A` not found for this
-...
-LL | S::A;
- | ^ associated item not found in `S`
- |
- = help: items from traits can only be used if the trait is implemented and in scope
-note: `assoc_const::A` defines an item `A`, perhaps you need to implement it
- --> $DIR/trait-item-privacy.rs:24:5
- |
-LL | trait A {
- | ^^^^^^^
-
-error[E0599]: no associated item named `B` found for struct `S` in the current scope
- --> $DIR/trait-item-privacy.rs:98:8
- |
-LL | struct S;
- | --------- associated item `B` not found for this
-...
-LL | S::B;
- | ^ associated item not found in `S`
- |
- = help: items from traits can only be used if the trait is in scope
-help: the following trait is implemented but not in scope; perhaps add a `use` for it:
- |
-LL | use assoc_const::B;
- |
-
-error[E0624]: associated constant `A` is private
- --> $DIR/trait-item-privacy.rs:101:8
- |
-LL | C::A;
- | ^ private associated constant
-
-error[E0038]: the trait `assoc_const::C` cannot be made into an object
- --> $DIR/trait-item-privacy.rs:101:5
- |
-LL | C::A;
- | ^^^^ `assoc_const::C` cannot be made into an object
- |
- = help: consider moving `C` to another trait
- = help: consider moving `B` to another trait
- = help: consider moving `A` to another trait
-note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
- --> $DIR/trait-item-privacy.rs:25:15
- |
-LL | const A: u8 = 0;
- | ^ ...because it contains this associated `const`
-...
-LL | const B: u8 = 0;
- | ^ ...because it contains this associated `const`
-...
-LL | pub trait C: A + B {
- | - this trait cannot be made into an object...
-LL | const C: u8 = 0;
- | ^ ...because it contains this associated `const`
-
-error[E0223]: ambiguous associated type
- --> $DIR/trait-item-privacy.rs:115:12
- |
-LL | let _: S::A;
- | ^^^^ help: use fully-qualified syntax: `<S as Trait>::A`
-
-error[E0223]: ambiguous associated type
- --> $DIR/trait-item-privacy.rs:116:12
- |
-LL | let _: S::B;
- | ^^^^ help: use fully-qualified syntax: `<S as Trait>::B`
-
-error[E0223]: ambiguous associated type
- --> $DIR/trait-item-privacy.rs:117:12
- |
-LL | let _: S::C;
- | ^^^^ help: use fully-qualified syntax: `<S as Trait>::C`
-
-error: associated type `A` is private
- --> $DIR/trait-item-privacy.rs:119:12
- |
-LL | let _: T::A;
- | ^^^^ private associated type
-
-error: associated type `A` is private
- --> $DIR/trait-item-privacy.rs:128:9
- |
-LL | A = u8,
- | ^^^^^^ private associated type
-
-error: aborting due to 15 previous errors
-
-Some errors have detailed explanations: E0038, E0223, E0599, E0624.
-For more information about an error, try `rustc --explain E0038`.
+++ /dev/null
-// Tests that the trait matching code takes lifetime parameters into account.
-// (Issue #15517.)
-
-struct Foo<'a,'b> {
- x: &'a isize,
- y: &'b isize,
-}
-
-trait Tr : Sized {
- fn foo(x: Self) {}
-}
-
-impl<'a,'b> Tr for Foo<'a,'b> {
- fn foo(x: Foo<'b,'a>) {
- //~^ ERROR method not compatible with trait
- //~^^ ERROR method not compatible with trait
- }
-}
-
-fn main(){}
+++ /dev/null
-error[E0308]: method not compatible with trait
- --> $DIR/trait-matching-lifetimes.rs:14:5
- |
-LL | fn foo(x: Foo<'b,'a>) {
- | ^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
- |
- = note: expected fn pointer `fn(Foo<'a, 'b>)`
- found fn pointer `fn(Foo<'b, 'a>)`
-note: the lifetime `'b` as defined on the impl at 13:9...
- --> $DIR/trait-matching-lifetimes.rs:13:9
- |
-LL | impl<'a,'b> Tr for Foo<'a,'b> {
- | ^^
-note: ...does not necessarily outlive the lifetime `'a` as defined on the impl at 13:6
- --> $DIR/trait-matching-lifetimes.rs:13:6
- |
-LL | impl<'a,'b> Tr for Foo<'a,'b> {
- | ^^
-
-error[E0308]: method not compatible with trait
- --> $DIR/trait-matching-lifetimes.rs:14:5
- |
-LL | fn foo(x: Foo<'b,'a>) {
- | ^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
- |
- = note: expected fn pointer `fn(Foo<'a, 'b>)`
- found fn pointer `fn(Foo<'b, 'a>)`
-note: the lifetime `'a` as defined on the impl at 13:6...
- --> $DIR/trait-matching-lifetimes.rs:13:6
- |
-LL | impl<'a,'b> Tr for Foo<'a,'b> {
- | ^^
-note: ...does not necessarily outlive the lifetime `'b` as defined on the impl at 13:9
- --> $DIR/trait-matching-lifetimes.rs:13:9
- |
-LL | impl<'a,'b> Tr for Foo<'a,'b> {
- | ^^
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0308`.
+++ /dev/null
-mod inner {
- pub trait Bar {
- fn method(&self);
- }
-
- pub struct Foo;
-
- impl Foo {
- fn method(&self) {}
- }
-
- impl Bar for Foo {
- fn method(&self) {}
- }
-}
-
-fn main() {
- let foo = inner::Foo;
- foo.method(); //~ ERROR is private
-}
+++ /dev/null
-error[E0624]: associated function `method` is private
- --> $DIR/trait-method-private.rs:19:9
- |
-LL | foo.method();
- | ^^^^^^ private associated function
- |
- = help: items from traits can only be used if the trait is in scope
-help: the following trait is implemented but not in scope; perhaps add a `use` for it:
- |
-LL | use inner::Bar;
- |
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0624`.
+++ /dev/null
-// Checks to make sure that `dyn Trait + Send` and `dyn Trait + Send + Send` are the same type.
-// Issue: #47010
-
-struct Struct;
-impl Trait for Struct {}
-trait Trait {}
-
-type Send1 = dyn Trait + Send;
-type Send2 = dyn Trait + Send + Send;
-
-fn main () {}
-
-impl dyn Trait + Send {
- fn test(&self) { println!("one"); } //~ ERROR duplicate definitions with name `test`
-}
-
-impl dyn Trait + Send + Send {
- fn test(&self) { println!("two"); }
-}
+++ /dev/null
-error[E0592]: duplicate definitions with name `test`
- --> $DIR/trait-object-auto-dedup-in-impl.rs:14:5
- |
-LL | fn test(&self) { println!("one"); }
- | ^^^^^^^^^^^^^^ duplicate definitions for `test`
-...
-LL | fn test(&self) { println!("two"); }
- | -------------- other definition for `test`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0592`.
+++ /dev/null
-// run-pass
-
-#![allow(unused_assignments)]
-
-// Test that duplicate auto trait bounds in trait objects don't create new types.
-#[allow(unused_assignments)]
-use std::marker::Send as SendAlias;
-
-// A dummy trait for the non-auto trait.
-trait Trait {}
-
-// A dummy struct to implement `Trait` and `Send`.
-struct Struct;
-
-impl Trait for Struct {}
-
-// These three functions should be equivalent.
-fn takes_dyn_trait_send(_: Box<dyn Trait + Send>) {}
-fn takes_dyn_trait_send_send(_: Box<dyn Trait + Send + Send>) {}
-fn takes_dyn_trait_send_sendalias(_: Box<dyn Trait + Send + SendAlias>) {}
-
-impl dyn Trait + Send + Send {
- fn do_nothing(&self) {}
-}
-
-fn main() {
- // 1. Moving into a variable with more `Send`s and back.
- let mut dyn_trait_send = Box::new(Struct) as Box<dyn Trait + Send>;
- let dyn_trait_send_send: Box<dyn Trait + Send + Send> = dyn_trait_send;
- dyn_trait_send = dyn_trait_send_send;
-
- // 2. Calling methods with different number of `Send`s.
- let dyn_trait_send = Box::new(Struct) as Box<dyn Trait + Send>;
- takes_dyn_trait_send_send(dyn_trait_send);
-
- let dyn_trait_send_send = Box::new(Struct) as Box<dyn Trait + Send + Send>;
- takes_dyn_trait_send(dyn_trait_send_send);
-
- // 3. Aliases to the trait are transparent.
- let dyn_trait_send = Box::new(Struct) as Box<dyn Trait + Send>;
- takes_dyn_trait_send_sendalias(dyn_trait_send);
-
- // 4. Calling an impl that duplicates an auto trait.
- let dyn_trait_send = Box::new(Struct) as Box<dyn Trait + Send>;
- dyn_trait_send.do_nothing();
-}
+++ /dev/null
-// Check that we don't have a cycle when we try to normalize `Self::U` in the
-// bound below.
-
-// check-pass
-
-trait Is {
- type T;
-}
-
-impl<U> Is for U {
- type T = U;
-}
-
-trait Obj {
- type U: Is<T = Self::U>;
-}
-
-fn is_obj<T: ?Sized + Obj>(_: &T) {}
-
-fn f(x: &dyn Obj<U = i32>) {
- is_obj(x)
-}
-
-fn main() {}
+++ /dev/null
-// Check that we don't have a cycle when we try to normalize `Self::V` in the
-// bound below.
-
-// check-pass
-
-trait Is {
- type T;
-}
-
-impl<U> Is for U {
- type T = U;
-}
-
-trait Super {
- type V;
-}
-
-trait Obj: Super {
- type U: Is<T = Self::V>;
-}
-
-fn is_obj<T: ?Sized + Obj>(_: &T) {}
-
-fn f(x: &dyn Obj<U = i32, V = i32>) {
- is_obj(x)
-}
-
-fn main() {}
+++ /dev/null
-// Check that we don't have a cycle when we try to normalize `Self::V` in the
-// bound below.
-
-// check-pass
-
-trait Is {
- type T;
-}
-
-impl<U> Is for U {
- type T = U;
-}
-
-trait Obj {
- type U: Is<T = Self::V>;
- type V;
-}
-
-fn is_obj<T: ?Sized + Obj>(_: &T) {}
-
-fn f(x: &dyn Obj<U = i32, V = i32>) {
- is_obj(x)
-}
-
-fn main() {}
+++ /dev/null
-// Check that we don't have a cycle when we try to normalize `Self::U` in the
-// bound below. Make sure that having a lifetime on the trait object doesn't break things
-
-// check-pass
-
-trait Is {
- type T;
-}
-
-impl<U> Is for U {
- type T = U;
-}
-
-trait Obj<'a> {
- type U: Is<T = Self::V>;
- type V;
-}
-
-fn is_obj<'a, T: ?Sized + Obj<'a>>(_: &T) {}
-
-fn f<'a>(x: &dyn Obj<'a, U = i32, V = i32>) {
- is_obj(x)
-}
-
-fn main() {}
+++ /dev/null
-// run-pass
-trait Future: 'static {
- // The requirement for Self: Sized must prevent instantiation of
- // Future::forget in vtables, otherwise there's an infinite type
- // recursion through <Map<...> as Future>::forget.
- fn forget(self) where Self: Sized {
- Box::new(Map(self)) as Box<dyn Future>;
- }
-}
-
-struct Map<A>(A);
-impl<A: Future> Future for Map<A> {}
-
-pub struct Promise;
-impl Future for Promise {}
-
-fn main() {
- Promise.forget();
-}
+++ /dev/null
-// run-pass
-// test for #8664
-
-#![feature(box_syntax)]
-
-use std::marker;
-
-pub trait Trait2<A> {
- 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',
- * src/librustc/middle/subst.rs:58
- */
- t: Box<dyn Trait2<A2>+'static>
-}
-
-impl<A1, A2, A3> Impl<A1, A2, A3> {
- pub fn step(&self) {
- self.t.doit();
- }
-}
-
-// test for #8601
-
-enum Type<T> { Constant(T) }
-
-trait Trait<K,V> {
- fn method(&self, _: Type<(K,V)>) -> isize;
-}
-
-impl<V> Trait<u8,V> for () {
- fn method(&self, _x: Type<(u8,V)>) -> isize { 0 }
-}
-
-pub fn main() {
- let a = box () as Box<dyn Trait<u8, u8>>;
- assert_eq!(a.method(Type::Constant((1, 2))), 0);
-}
+++ /dev/null
-// run-pass
-use std::fmt::Display;
-
-static BYTE: u8 = 33;
-
-fn main() {
- let x: &(dyn 'static + Display) = &BYTE;
- let y: Box<dyn 'static + Display> = Box::new(BYTE);
- let xstr = format!("{}", x);
- let ystr = format!("{}", y);
- assert_eq!(xstr, "33");
- assert_eq!(ystr, "33");
-}
+++ /dev/null
-// `ty` matcher accepts trait object types
-
-macro_rules! m {
- ($t: ty) => ( let _: $t; )
-}
-
-fn main() {
- m!(dyn Copy + Send + 'static);
- //~^ ERROR the trait `Copy` cannot be made into an object
- m!(dyn 'static + Send);
- m!(dyn 'static +); //~ ERROR at least one trait is required for an object type
-}
+++ /dev/null
-error[E0224]: at least one trait is required for an object type
- --> $DIR/trait-object-macro-matcher.rs:11:8
- |
-LL | m!(dyn 'static +);
- | ^^^^^^^^^^^^^
-
-error[E0038]: the trait `Copy` cannot be made into an object
- --> $DIR/trait-object-macro-matcher.rs:8:8
- |
-LL | m!(dyn Copy + Send + 'static);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^ `Copy` cannot be made into an object
- |
- = note: the trait cannot be made into an object because it requires `Self: Sized`
- = note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
-
-error: aborting due to 2 previous errors
-
-Some errors have detailed explanations: E0038, E0224.
-For more information about an error, try `rustc --explain E0038`.
+++ /dev/null
-// Check that static methods are not object-safe.
-
-trait Tr {
- fn foo();
- fn bar(&self) { }
-}
-
-struct St;
-
-impl Tr for St {
- fn foo() {}
-}
-
-fn main() {
- let _: &dyn Tr = &St; //~ ERROR E0038
- //~^ ERROR E0038
-}
+++ /dev/null
-error[E0038]: the trait `Tr` cannot be made into an object
- --> $DIR/trait-object-safety.rs:15:22
- |
-LL | let _: &dyn Tr = &St;
- | ^^^ `Tr` cannot be made into an object
- |
-note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
- --> $DIR/trait-object-safety.rs:4:8
- |
-LL | trait Tr {
- | -- this trait cannot be made into an object...
-LL | fn foo();
- | ^^^ ...because associated function `foo` has no `self` parameter
- = note: required because of the requirements on the impl of `CoerceUnsized<&dyn Tr>` for `&St`
- = note: required by cast to type `&dyn Tr`
-help: consider turning `foo` into a method by giving it a `&self` argument
- |
-LL | fn foo(&self);
- | ^^^^^
-help: alternatively, consider constraining `foo` so it does not apply to trait objects
- |
-LL | fn foo() where Self: Sized;
- | ^^^^^^^^^^^^^^^^^
-
-error[E0038]: the trait `Tr` cannot be made into an object
- --> $DIR/trait-object-safety.rs:15:12
- |
-LL | let _: &dyn Tr = &St;
- | ^^^^^^^ `Tr` cannot be made into an object
- |
-note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
- --> $DIR/trait-object-safety.rs:4:8
- |
-LL | trait Tr {
- | -- this trait cannot be made into an object...
-LL | fn foo();
- | ^^^ ...because associated function `foo` has no `self` parameter
-help: consider turning `foo` into a method by giving it a `&self` argument
- |
-LL | fn foo(&self);
- | ^^^^^
-help: alternatively, consider constraining `foo` so it does not apply to trait objects
- |
-LL | fn foo() where Self: Sized;
- | ^^^^^^^^^^^^^^^^^
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0038`.
+++ /dev/null
-// check-pass
-
-use std::any::Any;
-
-trait A<T>: Any {
- fn m(&self) {}
-}
-
-impl<S, T: 'static> A<S> for T {}
-
-fn call_obj<'a>() {
- let obj: &dyn A<&'a ()> = &();
- obj.m();
-}
-
-fn main() {}
+++ /dev/null
-// A few contrived examples where lifetime should (or should not) be parsed as an object type.
-// Lifetimes parsed as types are still rejected later by semantic checks.
-
-// `'static` is a lifetime, `'static +` is a type, `'a` is a type
-fn g() where
- 'static: 'static,
- dyn 'static +: 'static + Copy,
- //~^ ERROR at least one trait is required for an object type
-{}
-
-fn main() {}
+++ /dev/null
-error[E0224]: at least one trait is required for an object type
- --> $DIR/trait-object-vs-lifetime-2.rs:7:5
- |
-LL | dyn 'static +: 'static + Copy,
- | ^^^^^^^^^^^^^
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0224`.
+++ /dev/null
-// A few contrived examples where lifetime should (or should not) be parsed as an object type.
-// Lifetimes parsed as types are still rejected later by semantic checks.
-
-struct S<'a, T>(&'a u8, T);
-
-fn main() {
- // `'static` is a lifetime argument, `'static +` is a type argument
- let _: S<'static, u8>;
- let _: S<'static, dyn 'static +>;
- //~^ at least one trait is required for an object type
- let _: S<'static, 'static>;
- //~^ ERROR this struct takes 1 lifetime argument but 2 lifetime arguments were supplied
- //~| ERROR this struct takes 1 type argument but 0 type arguments were supplied
- let _: S<dyn 'static +, 'static>;
- //~^ ERROR type provided when a lifetime was expected
- //~| ERROR at least one trait is required for an object type
-}
+++ /dev/null
-error[E0224]: at least one trait is required for an object type
- --> $DIR/trait-object-vs-lifetime.rs:9:23
- |
-LL | let _: S<'static, dyn 'static +>;
- | ^^^^^^^^^^^^^
-
-error[E0107]: this struct takes 1 lifetime argument but 2 lifetime arguments were supplied
- --> $DIR/trait-object-vs-lifetime.rs:11:12
- |
-LL | let _: S<'static, 'static>;
- | ^ --------- help: remove this lifetime argument
- | |
- | expected 1 lifetime argument
- |
-note: struct defined here, with 1 lifetime parameter: `'a`
- --> $DIR/trait-object-vs-lifetime.rs:4:8
- |
-LL | struct S<'a, T>(&'a u8, T);
- | ^ --
-
-error[E0107]: this struct takes 1 type argument but 0 type arguments were supplied
- --> $DIR/trait-object-vs-lifetime.rs:11:12
- |
-LL | let _: S<'static, 'static>;
- | ^ expected 1 type argument
- |
-note: struct defined here, with 1 type parameter: `T`
- --> $DIR/trait-object-vs-lifetime.rs:4:8
- |
-LL | struct S<'a, T>(&'a u8, T);
- | ^ -
-help: add missing type argument
- |
-LL | let _: S<'static, 'static, T>;
- | ^^^
-
-error[E0224]: at least one trait is required for an object type
- --> $DIR/trait-object-vs-lifetime.rs:14:14
- |
-LL | let _: S<dyn 'static +, 'static>;
- | ^^^^^^^^^^^^^
-
-error[E0747]: type provided when a lifetime was expected
- --> $DIR/trait-object-vs-lifetime.rs:14:14
- |
-LL | let _: S<dyn 'static +, 'static>;
- | ^^^^^^^^^^^^^
-
-error: aborting due to 5 previous errors
-
-Some errors have detailed explanations: E0107, E0224, E0747.
-For more information about an error, try `rustc --explain E0107`.
+++ /dev/null
-// run-pass
-// Uncovered during work on new scoping rules for safe destructors
-// as an important use case to support properly.
-
-
-pub struct E<'a> {
- pub f: &'a u8,
-}
-impl<'b> E<'b> {
- pub fn m(&self) -> &'b u8 { self.f }
-}
-
-pub struct P<'c> {
- pub g: &'c u8,
-}
-pub trait M {
- fn n(&self) -> u8;
-}
-impl<'d> M for P<'d> {
- fn n(&self) -> u8 { *self.g }
-}
-
-fn extension<'e>(x: &'e E<'e>) -> Box<dyn M+'e> {
- loop {
- let p = P { g: x.m() };
- return Box::new(p) as Box<dyn M+'e>;
- }
-}
-
-fn main() {
- let w = E { f: &10 };
- let o = extension(&w);
- assert_eq!(o.n(), 10);
-}
+++ /dev/null
-// Regression test for #56288. Checks that if a supertrait defines an associated type
-// projection that references `Self`, then that associated type must still be explicitly
-// specified in the `dyn Trait` variant, since we don't know what `Self` is anymore.
-
-trait Base {
- type Output;
-}
-
-trait Helper: Base<Output=<Self as Helper>::Target> {
- type Target;
-}
-
-impl Base for u32
-{
- type Output = i32;
-}
-
-impl Helper for u32
-{
- type Target = i32;
-}
-
-trait ConstI32 {
- type Out;
-}
-
-impl<T: ?Sized> ConstI32 for T {
- type Out = i32;
-}
-
-// Test that you still need to manually give a projection type if the Output type
-// is normalizable.
-trait NormalizableHelper:
- Base<Output=<Self as ConstI32>::Out>
-{
- type Target;
-}
-
-impl NormalizableHelper for u32
-{
- type Target = i32;
-}
-
-fn main() {
- let _x: Box<dyn Helper<Target=i32>> = Box::new(2u32);
- //~^ ERROR the value of the associated type `Output` (from trait `Base`) must be specified
-
- let _y: Box<dyn NormalizableHelper<Target=i32>> = Box::new(2u32);
- //~^ ERROR the value of the associated type `Output` (from trait `Base`) must be specified
-}
+++ /dev/null
-error[E0191]: the value of the associated type `Output` (from trait `Base`) must be specified
- --> $DIR/trait-object-with-self-in-projection-output-bad.rs:45:21
- |
-LL | type Output;
- | ------------ `Output` defined here
-...
-LL | let _x: Box<dyn Helper<Target=i32>> = Box::new(2u32);
- | ^^^^^^^^^^^^^^^^^^ help: specify the associated type: `Helper<Target=i32, Output = Type>`
-
-error[E0191]: the value of the associated type `Output` (from trait `Base`) must be specified
- --> $DIR/trait-object-with-self-in-projection-output-bad.rs:48:21
- |
-LL | type Output;
- | ------------ `Output` defined here
-...
-LL | let _y: Box<dyn NormalizableHelper<Target=i32>> = Box::new(2u32);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: specify the associated type: `NormalizableHelper<Target=i32, Output = Type>`
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0191`.
+++ /dev/null
-// build-pass (FIXME(62277): could be check-pass?)
-
-// Regression test related to #56288. Check that a supertrait projection (of
-// `Output`) that references `Self` can be ok if it is referencing a projection (of
-// `Self::Target`, in this case). Note that we still require the user to manually
-// specify both `Target` and `Output` for now.
-
-trait Base {
- type Output;
-}
-
-trait Helper: Base<Output=<Self as Helper>::Target> {
- type Target;
-}
-
-impl Base for u32
-{
- type Output = i32;
-}
-
-impl Helper for u32
-{
- type Target = i32;
-}
-
-fn main() {
- let _x: Box<dyn Helper<Target=i32, Output=i32>> = Box::new(2u32);
-}
+++ /dev/null
-// build-pass (FIXME(62277): could be check-pass?)
-
-// FIXME(eddyb) shorten the name so windows doesn't choke on it.
-#![crate_name = "trait_test"]
-
-// Regression test related to #56288. Check that a supertrait projection (of
-// `Output`) that references `Self` is ok if there is another occurrence of
-// the same supertrait that specifies the projection explicitly, even if
-// the projection's associated type is not explicitly specified in the object type.
-//
-// Note that in order for this to compile, we need the `Self`-referencing projection
-// to normalize fairly directly to a concrete type, otherwise the trait resolver
-// will hate us.
-//
-// There is a test in `trait-object-with-self-in-projection-output-bad.rs` that
-// having a normalizing, but `Self`-containing projection does not *by itself*
-// allow you to avoid writing the projected type (`Output`, in this example)
-// explicitly.
-
-trait ConstI32 {
- type Out;
-}
-
-impl<T: ?Sized> ConstI32 for T {
- type Out = i32;
-}
-
-trait Base {
- type Output;
-}
-
-trait NormalizingHelper: Base<Output=<Self as ConstI32>::Out> + Base<Output=i32> {
- type Target;
-}
-
-impl Base for u32
-{
- type Output = i32;
-}
-
-impl NormalizingHelper for u32
-{
- type Target = i32;
-}
-
-fn main() {
- // Make sure this works both with and without the associated type
- // being specified.
- let _x: Box<dyn NormalizingHelper<Target=i32>> = Box::new(2u32);
- let _y: Box<dyn NormalizingHelper<Target=i32, Output=i32>> = Box::new(2u32);
-}
+++ /dev/null
-struct Article {
- proof_reader: ProofReader,
-}
-
-struct ProofReader {
- name: String,
-}
-
-pub trait HaveRelationship<To> {
- fn get_relation(&self) -> To;
-}
-
-impl HaveRelationship<&ProofReader> for Article {
- fn get_relation(&self) -> &ProofReader {
- //~^ ERROR `impl` item signature doesn't match `trait` item signature
- &self.proof_reader
- }
-}
-
-fn main() {}
+++ /dev/null
-error: `impl` item signature doesn't match `trait` item signature
- --> $DIR/trait-param-without-lifetime-constraint.rs:14:5
- |
-LL | fn get_relation(&self) -> To;
- | ----------------------------- expected `fn(&Article) -> &ProofReader`
-...
-LL | fn get_relation(&self) -> &ProofReader {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&Article) -> &ProofReader`
- |
- = note: expected `fn(&Article) -> &ProofReader`
- found `fn(&Article) -> &ProofReader`
-help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
- --> $DIR/trait-param-without-lifetime-constraint.rs:10:31
- |
-LL | fn get_relation(&self) -> To;
- | ^^ consider borrowing this type parameter in the trait
-
-error: aborting due to previous error
-
+++ /dev/null
-// build-pass (FIXME(62277): could be check-pass?)
-#![allow(dead_code)]
-mod foo {
- pub use self::bar::T;
- mod bar {
- pub trait T {
- fn f(&self) {}
- }
- impl T for () {}
- }
-}
-
-fn g() {
- use foo::T;
- ().f(); // Check that this does not trigger a privacy error
-}
-
-fn f() {
- let error = ::std::thread::spawn(|| {}).join().unwrap_err();
- error.type_id(); // Regression test for #21670
-}
-
-
-fn main() {}
+++ /dev/null
-// run-pass
-trait Foo {
- fn f(&self) -> isize;
-}
-
-struct A {
- x: isize
-}
-
-impl Foo for A {
- fn f(&self) -> isize {
- println!("Today's number is {}", self.x);
- return self.x;
- }
-}
-
-pub fn main() {
- let a = A { x: 3 };
- let b = (&a) as &dyn Foo;
- assert_eq!(b.f(), 3);
-}
+++ /dev/null
-// #12402 Operator overloading only considers the method name, not which trait is implemented
-
-trait MyMul<Rhs, Res> {
- fn mul(&self, rhs: &Rhs) -> Res;
-}
-
-fn foo<T: MyMul<f64, f64>>(a: &T, b: f64) -> f64 {
- a * b //~ ERROR cannot multiply `&T` by `f64`
-}
-
-fn main() {}
+++ /dev/null
-error[E0369]: cannot multiply `&T` by `f64`
- --> $DIR/trait-resolution-in-overloaded-op.rs:8:7
- |
-LL | a * b
- | - ^ - f64
- | |
- | &T
- |
-help: consider further restricting this bound
- |
-LL | fn foo<T: MyMul<f64, f64> + std::ops::Mul<Output = f64>>(a: &T, b: f64) -> f64 {
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0369`.
+++ /dev/null
-// Check that an unsafe impl does not imply that unsafe actions are
-// legal in the methods.
-
-unsafe trait UnsafeTrait : Sized {
- fn foo(self) { }
-}
-
-unsafe impl UnsafeTrait for *mut isize {
- fn foo(self) {
- // Unsafe actions are not made legal by taking place in an unsafe trait:
- *self += 1;
- //~^ ERROR E0133
- }
-}
-
-fn main() { }
+++ /dev/null
-error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
- --> $DIR/trait-safety-fn-body.rs:11:9
- |
-LL | *self += 1;
- | ^^^^^^^^^^ dereference of raw pointer
- |
- = note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0133`.
+++ /dev/null
-// Check that inherent impls cannot be unsafe.
-
-struct SomeStruct;
-
-unsafe impl SomeStruct { //~ ERROR inherent impls cannot be unsafe
- fn foo(self) { }
-}
-
-fn main() { }
+++ /dev/null
-error[E0197]: inherent impls cannot be unsafe
- --> $DIR/trait-safety-inherent-impl.rs:5:13
- |
-LL | unsafe impl SomeStruct {
- | ------ ^^^^^^^^^^ inherent impl for this type
- | |
- | unsafe because of this
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0197`.
+++ /dev/null
-// run-pass
-// aux-build:trait_safety_lib.rs
-
-// Simple smoke test that unsafe traits can be compiled across crates.
-
-
-extern crate trait_safety_lib as lib;
-
-use lib::Foo;
-
-struct Bar { x: isize }
-unsafe impl Foo for Bar {
- fn foo(&self) -> isize { self.x }
-}
-
-fn take_foo<F:Foo>(f: &F) -> isize { f.foo() }
-
-fn main() {
- let x: isize = 22;
- assert_eq!(22, take_foo(&x));
-
- let x: Bar = Bar { x: 23 };
- assert_eq!(23, take_foo(&x));
-}
+++ /dev/null
-// run-pass
-// Simple smoke test that unsafe traits can be compiled etc.
-
-
-unsafe trait Foo {
- fn foo(&self) -> isize;
-}
-
-unsafe impl Foo for isize {
- fn foo(&self) -> isize { *self }
-}
-
-fn take_foo<F:Foo>(f: &F) -> isize { f.foo() }
-
-fn main() {
- let x: isize = 22;
- assert_eq!(22, take_foo(&x));
-}
+++ /dev/null
-// aux-build:trait_safety_lib.rs
-
-// Check that unsafe traits require unsafe impls and that inherent
-// impls cannot be unsafe.
-
-extern crate trait_safety_lib as lib;
-
-struct Bar;
-impl lib::Foo for Bar { //~ ERROR requires an `unsafe impl` declaration
- fn foo(&self) -> isize {
- panic!();
- }
-}
-
-fn main() { }
+++ /dev/null
-error[E0200]: the trait `Foo` requires an `unsafe impl` declaration
- --> $DIR/trait-safety-trait-impl-cc.rs:9:1
- |
-LL | / impl lib::Foo for Bar {
-LL | | fn foo(&self) -> isize {
-LL | | panic!();
-LL | | }
-LL | | }
- | |_^
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0200`.
+++ /dev/null
-// Check that unsafe traits require unsafe impls and that inherent
-// impls cannot be unsafe.
-
-trait SafeTrait {
- fn foo(&self) { }
-}
-
-unsafe trait UnsafeTrait {
- fn foo(&self) { }
-}
-
-unsafe impl UnsafeTrait for u8 { } // OK
-
-impl UnsafeTrait for u16 { } //~ ERROR requires an `unsafe impl` declaration
-
-unsafe impl SafeTrait for u32 { } //~ ERROR the trait `SafeTrait` is not unsafe
-
-fn main() { }
+++ /dev/null
-error[E0200]: the trait `UnsafeTrait` requires an `unsafe impl` declaration
- --> $DIR/trait-safety-trait-impl.rs:14:1
- |
-LL | impl UnsafeTrait for u16 { }
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error[E0199]: implementing the trait `SafeTrait` is not unsafe
- --> $DIR/trait-safety-trait-impl.rs:16:1
- |
-LL | unsafe impl SafeTrait for u32 { }
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: aborting due to 2 previous errors
-
-Some errors have detailed explanations: E0199, E0200.
-For more information about an error, try `rustc --explain E0199`.
+++ /dev/null
-// Issue #3902. We are (at least currently) unable to infer `Self`
-// based on `T`, even though there is only a single impl, because of
-// the possibility of associated types and other things (basically: no
-// constraints on `Self` here at all).
-
-mod base {
- pub trait HasNew<T> {
- fn new() -> T;
- fn dummy(&self) { }
- }
-
- pub struct Foo {
- dummy: (),
- }
-
- impl HasNew<Foo> for Foo {
- fn new() -> Foo {
- Foo { dummy: () }
- }
- }
-}
-
-pub fn foo() {
- let _f: base::Foo = base::HasNew::new();
- //~^ ERROR type annotations needed
-}
-
-fn main() { }
+++ /dev/null
-error[E0283]: type annotations needed
- --> $DIR/trait-static-method-generic-inference.rs:24:25
- |
-LL | fn new() -> T;
- | -------------- required by `HasNew::new`
-...
-LL | let _f: base::Foo = base::HasNew::new();
- | ^^^^^^^^^^^^^^^^^ cannot infer type
- |
- = note: cannot satisfy `_: HasNew<Foo>`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0283`.
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-mod base {
- pub trait HasNew {
- fn new() -> Self;
- }
-
- pub struct Foo {
- dummy: (),
- }
-
- impl ::base::HasNew for Foo {
- fn new() -> Foo {
- println!("Foo");
- Foo { dummy: () }
- }
- }
-
- pub struct Bar {
- dummy: (),
- }
-
- impl ::base::HasNew for Bar {
- fn new() -> Bar {
- println!("Bar");
- Bar { dummy: () }
- }
- }
-}
-
-pub fn main() {
- let _f: base::Foo = base::HasNew::new();
- let _b: base::Bar = base::HasNew::new();
-}
+++ /dev/null
-// run-rustfix
-use std::net::TcpListener;
-
-struct NoToSocketAddrs(String);
-
-impl std::ops::Deref for NoToSocketAddrs {
- type Target = String;
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-
-fn main() {
- let _works = TcpListener::bind("some string");
- let bad = NoToSocketAddrs("bad".to_owned());
- let _errors = TcpListener::bind(&*bad);
- //~^ ERROR the trait bound `NoToSocketAddrs: ToSocketAddrs` is not satisfied
-}
+++ /dev/null
-// run-rustfix
-use std::net::TcpListener;
-
-struct NoToSocketAddrs(String);
-
-impl std::ops::Deref for NoToSocketAddrs {
- type Target = String;
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-
-fn main() {
- let _works = TcpListener::bind("some string");
- let bad = NoToSocketAddrs("bad".to_owned());
- let _errors = TcpListener::bind(&bad);
- //~^ ERROR the trait bound `NoToSocketAddrs: ToSocketAddrs` is not satisfied
-}
+++ /dev/null
-error[E0277]: the trait bound `NoToSocketAddrs: ToSocketAddrs` is not satisfied
- --> $DIR/trait-suggest-deferences-issue-39029.rs:16:37
- |
-LL | let _errors = TcpListener::bind(&bad);
- | ^^^^
- | |
- | the trait `ToSocketAddrs` is not implemented for `NoToSocketAddrs`
- | help: consider adding dereference here: `&*bad`
- |
- ::: $SRC_DIR/std/src/net/tcp.rs:LL:COL
- |
-LL | pub fn bind<A: ToSocketAddrs>(addr: A) -> io::Result<TcpListener> {
- | ------------- required by this bound in `TcpListener::bind`
- |
- = note: required because of the requirements on the impl of `ToSocketAddrs` for `&NoToSocketAddrs`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-// run-rustfix
-fn takes_str(_x: &str) {}
-
-fn takes_type_parameter<T>(_x: T) where T: SomeTrait {}
-
-trait SomeTrait {}
-impl SomeTrait for &'_ str {}
-impl SomeTrait for char {}
-
-fn main() {
- let string = String::new();
- takes_str(&string); // Ok
- takes_type_parameter(&*string); // Error
- //~^ ERROR the trait bound `&String: SomeTrait` is not satisfied
-}
+++ /dev/null
-// run-rustfix
-fn takes_str(_x: &str) {}
-
-fn takes_type_parameter<T>(_x: T) where T: SomeTrait {}
-
-trait SomeTrait {}
-impl SomeTrait for &'_ str {}
-impl SomeTrait for char {}
-
-fn main() {
- let string = String::new();
- takes_str(&string); // Ok
- takes_type_parameter(&string); // Error
- //~^ ERROR the trait bound `&String: SomeTrait` is not satisfied
-}
+++ /dev/null
-error[E0277]: the trait bound `&String: SomeTrait` is not satisfied
- --> $DIR/trait-suggest-deferences-issue-62530.rs:13:26
- |
-LL | fn takes_type_parameter<T>(_x: T) where T: SomeTrait {}
- | --------- required by this bound in `takes_type_parameter`
-...
-LL | takes_type_parameter(&string); // Error
- | ^^^^^^^
- | |
- | the trait `SomeTrait` is not implemented for `&String`
- | help: consider adding dereference here: `&*string`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-// run-rustfix
-use std::ops::Deref;
-
-trait Happy {}
-struct LDM;
-impl Happy for &LDM {}
-
-struct Foo(LDM);
-struct Bar(Foo);
-struct Baz(Bar);
-impl Deref for Foo {
- type Target = LDM;
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-impl Deref for Bar {
- type Target = Foo;
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-impl Deref for Baz {
- type Target = Bar;
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-
-fn foo<T>(_: T) where T: Happy {}
-
-fn main() {
- let baz = Baz(Bar(Foo(LDM)));
- foo(&***baz);
- //~^ ERROR the trait bound `&Baz: Happy` is not satisfied
-}
+++ /dev/null
-// run-rustfix
-use std::ops::Deref;
-
-trait Happy {}
-struct LDM;
-impl Happy for &LDM {}
-
-struct Foo(LDM);
-struct Bar(Foo);
-struct Baz(Bar);
-impl Deref for Foo {
- type Target = LDM;
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-impl Deref for Bar {
- type Target = Foo;
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-impl Deref for Baz {
- type Target = Bar;
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-
-fn foo<T>(_: T) where T: Happy {}
-
-fn main() {
- let baz = Baz(Bar(Foo(LDM)));
- foo(&baz);
- //~^ ERROR the trait bound `&Baz: Happy` is not satisfied
-}
+++ /dev/null
-error[E0277]: the trait bound `&Baz: Happy` is not satisfied
- --> $DIR/trait-suggest-deferences-multiple-0.rs:34:9
- |
-LL | fn foo<T>(_: T) where T: Happy {}
- | ----- required by this bound in `foo`
-...
-LL | foo(&baz);
- | ^^^^
- | |
- | the trait `Happy` is not implemented for `&Baz`
- | help: consider adding dereference here: `&***baz`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-use std::ops::{Deref, DerefMut};
-
-trait Happy {}
-struct LDM;
-impl Happy for &mut LDM {}
-
-struct Foo(LDM);
-struct Bar(Foo);
-struct Baz(Bar);
-impl Deref for Foo {
- type Target = LDM;
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-impl Deref for Bar {
- type Target = Foo;
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-impl Deref for Baz {
- type Target = Bar;
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-impl DerefMut for Foo {
- fn deref_mut(&mut self) -> &mut Self::Target {
- &mut self.0
- }
-}
-impl DerefMut for Bar {
- fn deref_mut(&mut self) -> &mut Self::Target {
- &mut self.0
- }
-}
-impl DerefMut for Baz {
- fn deref_mut(&mut self) -> &mut Self::Target {
- &mut self.0
- }
-}
-
-
-fn foo<T>(_: T) where T: Happy {}
-
-fn main() {
- // Currently the compiler doesn't try to suggest dereferences for situations
- // where DerefMut involves. So this test is meant to ensure compiler doesn't
- // generate incorrect help message.
- let mut baz = Baz(Bar(Foo(LDM)));
- foo(&mut baz);
- //~^ ERROR the trait bound `&mut Baz: Happy` is not satisfied
-}
+++ /dev/null
-error[E0277]: the trait bound `&mut Baz: Happy` is not satisfied
- --> $DIR/trait-suggest-deferences-multiple-1.rs:52:9
- |
-LL | fn foo<T>(_: T) where T: Happy {}
- | ----- required by this bound in `foo`
-...
-LL | foo(&mut baz);
- | ^^^^^^^^ the trait `Happy` is not implemented for `&mut Baz`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-use std::mem;
-
-struct Misc<T:?Sized>(T);
-
-fn check<T: Iterator, U: ?Sized>() {
- // suggest a where-clause, if needed
- mem::size_of::<U>();
- //~^ ERROR the size for values of type
-
- mem::size_of::<Misc<U>>();
- //~^ ERROR the size for values of type
-
- // ... even if T occurs as a type parameter
-
- <u64 as From<T>>::from;
- //~^ ERROR `u64: From<T>` is not satisfied
-
- <u64 as From<<T as Iterator>::Item>>::from;
- //~^ ERROR `u64: From<<T as Iterator>::Item>` is not satisfied
-
- // ... but not if there are inference variables
-
- <Misc<_> as From<T>>::from;
- //~^ ERROR `Misc<_>: From<T>` is not satisfied
-
- // ... and also not if the error is not related to the type
-
- mem::size_of::<[T]>();
- //~^ ERROR the size for values of type
-
- mem::size_of::<[&U]>();
- //~^ ERROR the size for values of type
-}
-
-fn main() {
-}
+++ /dev/null
-error[E0277]: the size for values of type `U` cannot be known at compilation time
- --> $DIR/trait-suggest-where-clause.rs:7:20
- |
-LL | fn check<T: Iterator, U: ?Sized>() {
- | - this type parameter needs to be `Sized`
-LL | // suggest a where-clause, if needed
-LL | mem::size_of::<U>();
- | ^ doesn't have a size known at compile-time
- |
- ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL
- |
-LL | pub const fn size_of<T>() -> usize {
- | - required by this bound in `std::mem::size_of`
-
-error[E0277]: the size for values of type `U` cannot be known at compilation time
- --> $DIR/trait-suggest-where-clause.rs:10:5
- |
-LL | fn check<T: Iterator, U: ?Sized>() {
- | - this type parameter needs to be `Sized`
-...
-LL | mem::size_of::<Misc<U>>();
- | ^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
- |
- ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL
- |
-LL | pub const fn size_of<T>() -> usize {
- | - required by this bound in `std::mem::size_of`
- |
- = note: required because it appears within the type `Misc<U>`
-
-error[E0277]: the trait bound `u64: From<T>` is not satisfied
- --> $DIR/trait-suggest-where-clause.rs:15:5
- |
-LL | <u64 as From<T>>::from;
- | ^^^^^^^^^^^^^^^^^^^^^^ the trait `From<T>` is not implemented for `u64`
- |
- = note: required by `from`
-
-error[E0277]: the trait bound `u64: From<<T as Iterator>::Item>` is not satisfied
- --> $DIR/trait-suggest-where-clause.rs:18:5
- |
-LL | <u64 as From<<T as Iterator>::Item>>::from;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<<T as Iterator>::Item>` is not implemented for `u64`
- |
- = note: required by `from`
-
-error[E0277]: the trait bound `Misc<_>: From<T>` is not satisfied
- --> $DIR/trait-suggest-where-clause.rs:23:5
- |
-LL | <Misc<_> as From<T>>::from;
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<T>` is not implemented for `Misc<_>`
- |
- = note: required by `from`
-
-error[E0277]: the size for values of type `[T]` cannot be known at compilation time
- --> $DIR/trait-suggest-where-clause.rs:28:20
- |
-LL | mem::size_of::<[T]>();
- | ^^^ doesn't have a size known at compile-time
- |
- ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL
- |
-LL | pub const fn size_of<T>() -> usize {
- | - required by this bound in `std::mem::size_of`
- |
- = help: the trait `Sized` is not implemented for `[T]`
-
-error[E0277]: the size for values of type `[&U]` cannot be known at compilation time
- --> $DIR/trait-suggest-where-clause.rs:31:5
- |
-LL | mem::size_of::<[&U]>();
- | ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
- |
- ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL
- |
-LL | pub const fn size_of<T>() -> usize {
- | - required by this bound in `std::mem::size_of`
- |
- = help: the trait `Sized` is not implemented for `[&U]`
-
-error: aborting due to 7 previous errors
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-#![feature(box_syntax)]
-
-#[allow(non_camel_case_types)]
-trait bar { fn dup(&self) -> Self; fn blah<X>(&self); }
-impl bar for i32 { fn dup(&self) -> i32 { *self } fn blah<X>(&self) {} }
-impl bar for u32 { fn dup(&self) -> u32 { *self } fn blah<X>(&self) {} }
-
-fn main() {
- 10.dup::<i32>();
- //~^ ERROR this associated function takes 0 type arguments but 1 type argument was supplied
- 10.blah::<i32, i32>();
- //~^ ERROR this associated function takes 1 type argument but 2 type arguments were supplied
- (box 10 as Box<dyn bar>).dup();
- //~^ ERROR E0038
- //~| ERROR E0038
-}
+++ /dev/null
-error[E0107]: this associated function takes 0 type arguments but 1 type argument was supplied
- --> $DIR/trait-test-2.rs:9:8
- |
-LL | 10.dup::<i32>();
- | ^^^------- help: remove these generics
- | |
- | expected 0 type arguments
- |
-note: associated function defined here, with 0 type parameters
- --> $DIR/trait-test-2.rs:4:16
- |
-LL | trait bar { fn dup(&self) -> Self; fn blah<X>(&self); }
- | ^^^
-
-error[E0107]: this associated function takes 1 type argument but 2 type arguments were supplied
- --> $DIR/trait-test-2.rs:11:8
- |
-LL | 10.blah::<i32, i32>();
- | ^^^^ ----- help: remove this type argument
- | |
- | expected 1 type argument
- |
-note: associated function defined here, with 1 type parameter: `X`
- --> $DIR/trait-test-2.rs:4:39
- |
-LL | trait bar { fn dup(&self) -> Self; fn blah<X>(&self); }
- | ^^^^ -
-
-error[E0038]: the trait `bar` cannot be made into an object
- --> $DIR/trait-test-2.rs:13:16
- |
-LL | (box 10 as Box<dyn bar>).dup();
- | ^^^^^^^^^^^^ `bar` cannot be made into an object
- |
- = help: consider moving `dup` to another trait
- = help: consider moving `blah` to another trait
-note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
- --> $DIR/trait-test-2.rs:4:30
- |
-LL | trait bar { fn dup(&self) -> Self; fn blah<X>(&self); }
- | --- ^^^^ ^^^^ ...because method `blah` has generic type parameters
- | | |
- | | ...because method `dup` references the `Self` type in its return type
- | this trait cannot be made into an object...
-
-error[E0038]: the trait `bar` cannot be made into an object
- --> $DIR/trait-test-2.rs:13:6
- |
-LL | (box 10 as Box<dyn bar>).dup();
- | ^^^^^^ `bar` cannot be made into an object
- |
- = help: consider moving `dup` to another trait
- = help: consider moving `blah` to another trait
-note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
- --> $DIR/trait-test-2.rs:4:30
- |
-LL | trait bar { fn dup(&self) -> Self; fn blah<X>(&self); }
- | --- ^^^^ ^^^^ ...because method `blah` has generic type parameters
- | | |
- | | ...because method `dup` references the `Self` type in its return type
- | this trait cannot be made into an object...
- = note: required because of the requirements on the impl of `CoerceUnsized<Box<dyn bar>>` for `Box<{integer}>`
- = note: required by cast to type `Box<dyn bar>`
-
-error: aborting due to 4 previous errors
-
-Some errors have detailed explanations: E0038, E0107.
-For more information about an error, try `rustc --explain E0038`.
+++ /dev/null
-#[allow(non_camel_case_types)]
-trait foo { fn foo(&self); }
-
-impl isize for usize { fn foo(&self) {} } //~ ERROR trait
-
-fn main() {}
+++ /dev/null
-error[E0404]: expected trait, found builtin type `isize`
- --> $DIR/trait-test.rs:4:6
- |
-LL | impl isize for usize { fn foo(&self) {} }
- | ^^^^^ not a trait
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0404`.
+++ /dev/null
-// run-pass
-#![allow(non_camel_case_types)]
-
-
-trait to_str {
- fn to_string_(&self) -> String;
-}
-
-impl to_str for isize {
- fn to_string_(&self) -> String { self.to_string() }
-}
-
-impl<T:to_str> to_str for Vec<T> {
- fn to_string_(&self) -> String {
- format!("[{}]",
- self.iter()
- .map(|e| e.to_string_())
- .collect::<Vec<String>>()
- .join(", "))
- }
-}
-
-pub fn main() {
- assert_eq!(1.to_string_(), "1".to_string());
- assert_eq!((vec![2, 3, 4]).to_string_(), "[2, 3, 4]".to_string());
-
- fn indirect<T:to_str>(x: T) -> String {
- format!("{}!", x.to_string_())
- }
- assert_eq!(indirect(vec![10, 20]), "[10, 20]!".to_string());
-
- fn indirect2<T:to_str>(x: T) -> String {
- indirect(x)
- }
- assert_eq!(indirect2(vec![1]), "[1]!".to_string());
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-#![allow(unused_variables)]
-// Test that when there is a conditional (but blanket) impl and a
-// where clause, we don't get confused in trait resolution.
-//
-// Issue #18453.
-
-// pretty-expanded FIXME #23616
-
-use std::rc::Rc;
-
-pub trait Foo<M> {
- fn foo(&mut self, msg: M);
-}
-
-pub trait Bar<M> {
- fn dummy(&self) -> M;
-}
-
-impl<M, F: Bar<M>> Foo<M> for F {
- fn foo(&mut self, msg: M) {
- }
-}
-
-pub struct Both<M, F> {
- inner: Rc<(M, F)>,
-}
-
-impl<M, F: Foo<M>> Clone for Both<M, F> {
- fn clone(&self) -> Both<M, F> {
- Both { inner: self.inner.clone() }
- }
-}
-
-fn repro1<M, F: Foo<M>>(_both: Both<M, F>) {
-}
-
-fn repro2<M, F: Foo<M>>(msg: M, foo: F) {
- let both = Both { inner: Rc::new((msg, foo)) };
- repro1(both.clone()); // <--- This clone causes problem
-}
-
-pub fn main() {
-}
+++ /dev/null
-// run-pass
-
-pub trait Clone2 {
- /// Returns a copy of the value. The contents of boxes
- /// are copied to maintain uniqueness, while the contents of
- /// managed pointers are not copied.
- fn clone(&self) -> Self;
-}
-
-trait Getter<T: Clone> {
- fn do_get(&self) -> T;
-
- fn do_get2(&self) -> (T, T) {
- let x = self.do_get();
- (x.clone(), x.clone())
- }
-
-}
-
-impl Getter<isize> for isize {
- fn do_get(&self) -> isize { *self }
-}
-
-impl<T: Clone> Getter<T> for Option<T> {
- fn do_get(&self) -> T { self.as_ref().unwrap().clone() }
-}
-
-
-pub fn main() {
- assert_eq!(3.do_get2(), (3, 3));
- assert_eq!(Some("hi".to_string()).do_get2(), ("hi".to_string(), "hi".to_string()));
-}
+++ /dev/null
-// build-pass (FIXME(62277): could be check-pass?)
-// #55266
-
-struct VTable<DST: ?Sized> {
- _to_dst_ptr: fn(*mut ()) -> *mut DST,
-}
-
-trait HasVTableFor<DST: ?Sized + 'static> {
- const VTABLE: &'static VTable<DST>;
-}
-
-impl<T, DST: ?Sized + 'static> HasVTableFor<DST> for T {
- const VTABLE: &'static VTable<DST> = &VTable {
- _to_dst_ptr: |_: *mut ()| unsafe { std::mem::zeroed() },
- };
-}
-
-pub fn push<DST: ?Sized + 'static, T>() {
- <T as HasVTableFor<DST>>::VTABLE;
-}
-
-fn main() {}
+++ /dev/null
-// Test case where an associated type is referenced from within the
-// supertrait definition, and the impl makes the wrong
-// associations. Issue #20220.
-
-use std::vec::IntoIter;
-
-pub trait Foo: Iterator<Item=<Self as Foo>::Key> {
- type Key;
-}
-
-impl Foo for IntoIter<i32> {
- type Key = u32; //~ ERROR type mismatch
-}
-
-fn main() {
-}
+++ /dev/null
-error[E0271]: type mismatch resolving `<std::vec::IntoIter<i32> as Iterator>::Item == u32`
- --> $DIR/traits-assoc-type-in-supertrait-bad.rs:12:16
- |
-LL | type Key = u32;
- | ^^^ expected `i32`, found `u32`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0271`.
+++ /dev/null
-// run-pass
-// Test case where an associated type is referenced from within the
-// supertrait definition. Issue #20220.
-
-
-use std::vec::IntoIter;
-
-pub trait Foo: Iterator<Item=<Self as Foo>::Key> {
- type Key;
-}
-
-impl Foo for IntoIter<i32> {
- type Key = i32;
-}
-
-fn sum_foo<F:Foo<Key=i32>>(f: F) -> i32 {
- f.fold(0, |a,b| a + b)
-}
-
-fn main() {
- let x = sum_foo(vec![11, 10, 1].into_iter());
- assert_eq!(x, 22);
-}
+++ /dev/null
-// run-pass
-// Test that we are able to resolve conditional dispatch. Here, the
-// blanket impl for T:Copy coexists with an impl for Box<T>, because
-// Box does not impl Copy.
-
-#![feature(box_syntax)]
-
-trait Get {
- fn get(&self) -> Self;
-}
-
-trait MyCopy { fn copy(&self) -> Self; }
-impl MyCopy for u16 { fn copy(&self) -> Self { *self } }
-impl MyCopy for u32 { fn copy(&self) -> Self { *self } }
-impl MyCopy for i32 { fn copy(&self) -> Self { *self } }
-impl<T:Copy> MyCopy for Option<T> { fn copy(&self) -> Self { *self } }
-
-impl<T:MyCopy> Get for T {
- fn get(&self) -> T { self.copy() }
-}
-
-impl Get for Box<i32> {
- fn get(&self) -> Box<i32> { box get_it(&**self) }
-}
-
-fn get_it<T:Get>(t: &T) -> T {
- (*t).get()
-}
-
-fn main() {
- assert_eq!(get_it(&1_u32), 1_u32);
- assert_eq!(get_it(&1_u16), 1_u16);
- assert_eq!(get_it(&Some(1_u16)), Some(1_u16));
- assert_eq!(get_it(&Box::new(1)), Box::new(1));
-}
+++ /dev/null
-// run-pass
-#![allow(unused_imports)]
-// A model for how the `Fn` traits could work. You can implement at
-// most one of `Go`, `GoMut`, or `GoOnce`, and then the others follow
-// automatically.
-
-// aux-build:go_trait.rs
-
-extern crate go_trait;
-
-use go_trait::{Go, GoMut, GoOnce, go, go_mut, go_once};
-
-use std::rc::Rc;
-use std::cell::Cell;
-
-struct SomeGoableThing {
- counter: Rc<Cell<isize>>
-}
-
-impl Go for SomeGoableThing {
- fn go(&self, arg: isize) {
- self.counter.set(self.counter.get() + arg);
- }
-}
-
-struct SomeGoOnceableThing {
- counter: Rc<Cell<isize>>
-}
-
-impl GoOnce for SomeGoOnceableThing {
- fn go_once(self, arg: isize) {
- self.counter.set(self.counter.get() + arg);
- }
-}
-
-fn main() {
- let counter = Rc::new(Cell::new(0));
- let mut x = SomeGoableThing { counter: counter.clone() };
-
- go(&x, 10);
- assert_eq!(counter.get(), 10);
-
- go_mut(&mut x, 100);
- assert_eq!(counter.get(), 110);
-
- go_once(x, 1_000);
- assert_eq!(counter.get(), 1_110);
-
- let x = SomeGoOnceableThing { counter: counter.clone() };
-
- go_once(x, 10_000);
- assert_eq!(counter.get(), 11_110);
-}
+++ /dev/null
-// run-pass
-
-
-trait Foo {
- fn bar(&self) -> String {
- format!("test")
- }
-}
-
-enum Baz {
- Quux
-}
-
-impl Foo for Baz {
-}
-
-pub fn main() {
- let q = Baz::Quux;
- assert_eq!(q.bar(), "test".to_string());
-}
+++ /dev/null
-// run-pass
-#![allow(unused_assignments)]
-// pretty-expanded FIXME #23616
-
-#![allow(unused_variables)]
-
-trait Foo {
- fn foo(&self, mut v: isize) { v = 1; }
-}
-
-pub fn main() {}
+++ /dev/null
-// run-pass
-
-
-trait Cat {
- fn meow(&self) -> bool;
- fn scratch(&self) -> bool { self.purr() }
- fn purr(&self) -> bool { true }
-}
-
-impl Cat for isize {
- fn meow(&self) -> bool {
- self.scratch()
- }
-}
-
-pub fn main() {
- assert!(5.meow());
-}
+++ /dev/null
-// run-pass
-
-
-trait Cat {
- fn meow(&self) -> bool;
- fn scratch(&self) -> bool;
- fn purr(&self) -> bool { true }
-}
-
-impl Cat for isize {
- fn meow(&self) -> bool {
- self.scratch()
- }
- fn scratch(&self) -> bool {
- self.purr()
- }
-}
-
-pub fn main() {
- assert!(5.meow());
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-
-// Test that we elaborate `Type: 'region` constraints and infer various important things.
-
-trait Master<'a, T: ?Sized> {
- fn foo() where T: 'a;
-}
-
-// [U]: 'a => U: 'a
-impl<'a, U> Master<'a, [U]> for () {
- fn foo() where U: 'a { }
-}
-
-// &'b U: 'a => 'b: 'a, U: 'a
-impl<'a, 'b, U> Master<'a, &'b U> for () {
- fn foo() where 'b: 'a, U: 'a { }
-}
-
-// &'b [U]: 'a => 'b: 'a, U: 'a
-impl<'a, 'b, U> Master<'a, &'b [U]> for () {
- fn foo() where 'b: 'a, U: 'a { }
-}
-
-// Foo<'b>: 'a => 'b: 'a
-struct Foo<'a> { x: &'a () }
-impl<'a, 'b> Master<'a, Foo<'b>> for () {
- fn foo() where 'b: 'a { }
-}
-
-// Bar<'b, T>: 'a => 'b: 'a, T: 'a
-struct Bar<'a, T: 'a> { x: &'a T }
-impl<'a, 'b, T> Master<'a, Bar<'b, T>> for () {
- fn foo() where 'b: 'a, T: 'a { }
-}
-
-// fn(T): 'a => T: 'a
-impl<'a, T> Master<'a, fn(T)> for () {
- fn foo() where T: 'a { }
-}
-
-// fn() -> T: 'a => T: 'a
-impl<'a, T> Master<'a, fn() -> T> for () {
- fn foo() where T: 'a { }
-}
-
-fn main() {
- println!("Hello, world!");
-}
+++ /dev/null
-// run-pass
-// Test that we are able to compile the case where both a blanket impl
-// and the object type itself supply the required trait obligation.
-// In this case, the blanket impl for `Foo` applies to any type,
-// including `Bar`, but the object type `Bar` also implicitly supplies
-// this context.
-
-trait Foo { fn dummy(&self) { } }
-
-trait Bar: Foo { }
-
-impl<T:?Sized> Foo for T { }
-
-fn want_foo<B:?Sized+Foo>() { }
-
-fn main() {
- want_foo::<dyn Bar>();
-}
+++ /dev/null
-// Test that we don't hit the recursion limit for short cycles involving lifetimes.
-
-// Shouldn't hit this, we should realize that we're in a cycle sooner.
-#![recursion_limit="20"]
-
-trait NotAuto {}
-trait Y {
- type P;
-}
-
-impl<'a> Y for C<'a> {
- type P = Box<X<C<'a>>>;
-}
-
-struct C<'a>(&'a ());
-struct X<T: Y>(T::P);
-
-impl<T: NotAuto> NotAuto for Box<T> {}
-impl<T: Y> NotAuto for X<T> where T::P: NotAuto {}
-impl<'a> NotAuto for C<'a> {}
-
-fn is_send<S: NotAuto>() {}
-//~^ NOTE: required
-
-fn main() {
- // Should only be a few notes.
- is_send::<X<C<'static>>>();
- //~^ ERROR overflow evaluating
- //~| NOTE: required
-}
+++ /dev/null
-error[E0275]: overflow evaluating the requirement `Box<X<C<'_>>>: NotAuto`
- --> $DIR/traits-inductive-overflow-lifetime.rs:27:5
- |
-LL | fn is_send<S: NotAuto>() {}
- | ------- required by this bound in `is_send`
-...
-LL | is_send::<X<C<'static>>>();
- | ^^^^^^^^^^^^^^^^^^^^^^^^
- |
- = note: required because of the requirements on the impl of `NotAuto` for `X<C<'static>>`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0275`.
+++ /dev/null
-// Regression test for #33344, initial version. This example allowed
-// arbitrary trait bounds to be synthesized.
-
-trait Tweedledum: IntoIterator {}
-trait Tweedledee: IntoIterator {}
-
-impl<T: Tweedledum> Tweedledee for T {}
-impl<T: Tweedledee> Tweedledum for T {}
-
-trait Combo: IntoIterator {}
-impl<T: Tweedledee + Tweedledum> Combo for T {}
-
-fn is_ee<T: Combo>(t: T) {
- t.into_iter();
-}
-
-fn main() {
- is_ee(4);
- //~^ ERROR overflow evaluating the requirement `{integer}: Tweedle
-}
+++ /dev/null
-error[E0275]: overflow evaluating the requirement `{integer}: Tweedledum`
- --> $DIR/traits-inductive-overflow-simultaneous.rs:18:5
- |
-LL | fn is_ee<T: Combo>(t: T) {
- | ----- required by this bound in `is_ee`
-...
-LL | is_ee(4);
- | ^^^^^
- |
- = note: required because of the requirements on the impl of `Combo` for `{integer}`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0275`.
+++ /dev/null
-// Auto-trait-based version of #29859, supertrait version. Test that using
-// a simple auto trait `..` impl alone still doesn't allow arbitrary bounds
-// to be synthesized.
-
-#![feature(auto_traits)]
-#![feature(negative_impls)]
-
-auto trait Magic: Copy {} //~ ERROR E0568
-
-fn copy<T: Magic>(x: T) -> (T, T) { (x, x) }
-
-#[derive(Debug)]
-struct NoClone;
-
-fn main() {
- let (a, b) = copy(NoClone); //~ ERROR
- println!("{:?} {:?}", a, b);
-}
+++ /dev/null
-error[E0568]: auto traits cannot have super traits
- --> $DIR/traits-inductive-overflow-supertrait-auto-trait.rs:8:19
- |
-LL | auto trait Magic: Copy {}
- | ----- ^^^^ help: remove the super traits
- | |
- | auto trait cannot have super traits
-
-error[E0277]: the trait bound `NoClone: Copy` is not satisfied
- --> $DIR/traits-inductive-overflow-supertrait-auto-trait.rs:16:23
- |
-LL | fn copy<T: Magic>(x: T) -> (T, T) { (x, x) }
- | ----- required by this bound in `copy`
-...
-LL | let (a, b) = copy(NoClone);
- | ^^^^^^^ the trait `Copy` is not implemented for `NoClone`
- |
- = note: required because of the requirements on the impl of `Magic` for `NoClone`
-
-error: aborting due to 2 previous errors
-
-Some errors have detailed explanations: E0277, E0568.
-For more information about an error, try `rustc --explain E0277`.
+++ /dev/null
-// Regression test for #29859, supertrait version. This example
-// allowed arbitrary trait bounds to be synthesized.
-
-trait Magic: Copy {}
-impl<T: Magic> Magic for T {}
-
-fn copy<T: Magic>(x: T) -> (T, T) { (x, x) }
-
-#[derive(Debug)]
-struct NoClone;
-
-fn main() {
- let (a, b) = copy(NoClone); //~ ERROR E0275
- println!("{:?} {:?}", a, b);
-}
+++ /dev/null
-error[E0275]: overflow evaluating the requirement `NoClone: Magic`
- --> $DIR/traits-inductive-overflow-supertrait.rs:13:18
- |
-LL | fn copy<T: Magic>(x: T) -> (T, T) { (x, x) }
- | ----- required by this bound in `copy`
-...
-LL | let (a, b) = copy(NoClone);
- | ^^^^
- |
- = note: required because of the requirements on the impl of `Magic` for `NoClone`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0275`.
+++ /dev/null
-// Regression test for #29859, initial version. This example allowed
-// arbitrary trait bounds to be synthesized.
-
-// Trait that you want all types to implement.
-use std::marker::{Sync as Trait};
-
-pub trait Magic {
- type X: Trait;
-}
-impl<T: Magic> Magic for T {
- type X = Self;
- //~^ ERROR E0277
-}
-
-fn check<T: Trait>() {}
-
-fn wizard<T: Magic>() { check::<<T as Magic>::X>(); }
-
-fn main() {
- wizard::<*mut ()>(); //~ ERROR E0275
- // check::<*mut ()>();
-}
+++ /dev/null
-error[E0277]: `T` cannot be shared between threads safely
- --> $DIR/traits-inductive-overflow-two-traits.rs:11:5
- |
-LL | type X: Trait;
- | ----- required by this bound in `Magic::X`
-...
-LL | type X = Self;
- | ^^^^^^^^^^^^^^ `T` cannot be shared between threads safely
- |
-help: consider further restricting this bound
- |
-LL | impl<T: Magic + Sync> Magic for T {
- | ^^^^^^
-
-error[E0275]: overflow evaluating the requirement `*mut (): Magic`
- --> $DIR/traits-inductive-overflow-two-traits.rs:20:5
- |
-LL | fn wizard<T: Magic>() { check::<<T as Magic>::X>(); }
- | ----- required by this bound in `wizard`
-...
-LL | wizard::<*mut ()>();
- | ^^^^^^^^^^^^^^^^^
-
-error: aborting due to 2 previous errors
-
-Some errors have detailed explanations: E0275, E0277.
-For more information about an error, try `rustc --explain E0275`.
+++ /dev/null
-// run-pass
-// Test an issue where global caching was causing free regions from
-// distinct scopes to be compared (`'g` and `'h`). The only important
-// thing is that compilation succeeds here.
-
-// pretty-expanded FIXME #23616
-
-#![allow(missing_copy_implementations)]
-#![allow(unused_variables)]
-
-use std::borrow::ToOwned;
-
-pub struct CFGNode;
-
-pub type Node<'a> = &'a CFGNode;
-
-pub trait GraphWalk<'c, N> {
- /// Returns all the nodes in this graph.
- fn nodes(&'c self) where [N]:ToOwned<Owned=Vec<N>>;
-}
-
-impl<'g> GraphWalk<'g, Node<'g>> for u32
-{
- fn nodes(&'g self) where [Node<'g>]:ToOwned<Owned=Vec<Node<'g>>>
- { loop { } }
-}
-
-impl<'h> GraphWalk<'h, Node<'h>> for u64
-{
- fn nodes(&'h self) where [Node<'h>]:ToOwned<Owned=Vec<Node<'h>>>
- { loop { } }
-}
-
-fn main() { }
+++ /dev/null
-// run-pass
-// Test an issue where we reported ambiguity between the where-clause
-// and the blanket impl. The only important thing is that compilation
-// succeeds here. Issue #22110.
-
-// pretty-expanded FIXME #23616
-
-#![allow(dead_code)]
-
-trait Foo<A> {
- fn foo(&self, a: A);
-}
-
-impl<A,F:Fn(A)> Foo<A> for F {
- fn foo(&self, _: A) { }
-}
-
-fn baz<A,F:for<'a> Foo<(&'a A,)>>(_: F) { }
-
-fn components<T,A>(t: fn(&A))
- where fn(&A) : for<'a> Foo<(&'a A,)>,
-{
- baz(t)
-}
-
-fn main() {
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-// Regression test for issue #22655: This test should not lead to
-// infinite recursion.
-
-// pretty-expanded FIXME #23616
-
-unsafe impl<T: Send + ?Sized> Send for Unique<T> { }
-
-pub struct Unique<T:?Sized> {
- pointer: *const T,
-}
-
-pub struct Node<V> {
- vals: V,
- edges: Unique<Node<V>>,
-}
-
-fn is_send<T: Send>() {}
-
-fn main() {
- is_send::<Node<&'static ()>>();
-}
+++ /dev/null
-// A variant of traits-issue-23003 in which an infinite series of
-// types are required. This test now just compiles fine, since the
-// relevant rules that triggered the overflow were removed.
-
-// check-pass
-#![allow(dead_code)]
-
-use std::marker::PhantomData;
-
-trait Async {
- type Cancel;
-}
-
-struct Receipt<A:Async> {
- marker: PhantomData<A>,
-}
-
-struct Complete<B> {
- core: Option<B>,
-}
-
-impl<B> Async for Complete<B> {
- type Cancel = Receipt<Complete<Option<B>>>;
-}
-
-fn foo(_: Receipt<Complete<()>>) { }
-
-
-fn main() { }
+++ /dev/null
-// run-pass
-// Test stack overflow triggered by evaluating the implications. To be
-// WF, the type `Receipt<Complete>` would require that `<Complete as
-// Async>::Cancel` be WF. This normalizes to `Receipt<Complete>`
-// again, leading to an infinite cycle. Issue #23003.
-
-// pretty-expanded FIXME #23616
-
-#![allow(dead_code)]
-#![allow(unused_variables)]
-
-use std::marker::PhantomData;
-
-trait Async {
- type Cancel;
-}
-
-struct Receipt<A:Async> {
- marker: PhantomData<A>,
-}
-
-struct Complete {
- core: Option<()>,
-}
-
-impl Async for Complete {
- type Cancel = Receipt<Complete>;
-}
-
-fn foo(r: Receipt<Complete>) { }
-
-fn main() { }
+++ /dev/null
-// run-pass
-// Test that the right implementation is called through a trait
-// object when supertraits include multiple references to the
-// same trait, with different type parameters.
-
-trait A: PartialEq<Foo> + PartialEq<Bar> { }
-
-struct Foo;
-struct Bar;
-
-struct Aimpl;
-
-impl PartialEq<Foo> for Aimpl {
- fn eq(&self, _rhs: &Foo) -> bool {
- true
- }
-}
-
-impl PartialEq<Bar> for Aimpl {
- fn eq(&self, _rhs: &Bar) -> bool {
- false
- }
-}
-
-impl A for Aimpl { }
-
-fn main() {
- let a = &Aimpl as &dyn A;
-
- assert!(*a == Foo);
-}
+++ /dev/null
-struct Foo(u8);
-
-#[derive(Clone)]
-struct FooHolster {
- the_foos: Vec<Foo>, //~ERROR Clone
-}
-
-fn main() {}
+++ /dev/null
-error[E0277]: the trait bound `Foo: Clone` is not satisfied
- --> $DIR/traits-issue-71136.rs:5:5
- |
-LL | the_foos: Vec<Foo>,
- | ^^^^^^^^^^^^^^^^^^ expected an implementor of trait `Clone`
- |
- = note: required because of the requirements on the impl of `Clone` for `Vec<Foo>`
- = note: required by `clone`
- = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-// Test that we detect an illegal combination of types.
-
-trait Convert<Target> {
- fn convert(&self) -> Target;
-}
-
-impl Convert<u32> for i32 {
- fn convert(&self) -> u32 {
- *self as u32
- }
-}
-
-fn test<T,U>(_: T, _: U)
-where T : Convert<U>
-{
-}
-
-fn a() {
- test(22i32, 44i32); //~ ERROR mismatched types
-}
-
-fn main() {}
+++ /dev/null
-error[E0308]: mismatched types
- --> $DIR/traits-multidispatch-bad.rs:19:17
- |
-LL | test(22i32, 44i32);
- | ^^^^^ expected `u32`, found `i32`
- |
-help: change the type of the numeric literal from `i32` to `u32`
- |
-LL | test(22i32, 44u32);
- | ^^^^^
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0308`.
+++ /dev/null
-// Check that we get an error in a multidisptach scenario where the
-// set of impls is ambiguous.
-
-trait Convert<Target> {
- fn convert(&self) -> Target;
-}
-
-impl Convert<i8> for i32 {
- fn convert(&self) -> i8 {
- *self as i8
- }
-}
-
-impl Convert<i16> for i32 {
- fn convert(&self) -> i16 {
- *self as i16
- }
-}
-
-fn test<T,U>(_: T, _: U)
-where T : Convert<U>
-{
-}
-
-fn a() {
- test(22, std::default::Default::default());
- //~^ ERROR type annotations needed [E0282]
-}
-
-fn main() {}
+++ /dev/null
-error[E0282]: type annotations needed
- --> $DIR/traits-multidispatch-convert-ambig-dest.rs:26:5
- |
-LL | test(22, std::default::Default::default());
- | ^^^^ cannot infer type for type parameter `U` declared on the function `test`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0282`.
+++ /dev/null
-// run-pass
-// Test that we can infer the Target based on the Self or vice versa.
-
-
-use std::mem;
-
-trait Convert<Target> {
- fn convert(&self) -> Target;
-}
-
-impl Convert<u32> for i16 {
- fn convert(&self) -> u32 {
- *self as u32
- }
-}
-
-impl Convert<i16> for u32 {
- fn convert(&self) -> i16 {
- *self as i16
- }
-}
-
-fn test<T,U>(_: T, _: U, t_size: usize, u_size: usize)
-where T : Convert<U>
-{
- assert_eq!(mem::size_of::<T>(), t_size);
- assert_eq!(mem::size_of::<U>(), u_size);
-}
-
-fn main() {
- // T = i16, U = u32
- test(22_i16, Default::default(), 2, 4);
-
- // T = u32, U = i16
- test(22_u32, Default::default(), 4, 2);
-}
+++ /dev/null
-// Test a case of a trait which extends the same supertrait twice, but
-// with difference type parameters. Test then that when we don't give
-// enough information to pick between these, no selection is made. In
-// this particular case, the two choices are i64/u64 -- so when we use
-// an integer literal, we wind up falling this literal back to i32.
-// See also `run-pass/trait-repeated-supertrait.rs`.
-
-trait CompareTo<T> {
- fn same_as(&self, t: T) -> bool;
-}
-
-trait CompareToInts : CompareTo<i64> + CompareTo<u64> {
-}
-
-impl CompareTo<i64> for i64 {
- fn same_as(&self, t: i64) -> bool { *self == t }
-}
-
-impl CompareTo<u64> for i64 {
- fn same_as(&self, t: u64) -> bool { *self == (t as i64) }
-}
-
-impl CompareToInts for i64 { }
-
-fn with_obj(c: &dyn CompareToInts) -> bool {
- c.same_as(22) //~ ERROR `dyn CompareToInts: CompareTo<i32>` is not satisfied
-}
-
-fn with_trait<C:CompareToInts>(c: &C) -> bool {
- c.same_as(22) //~ ERROR `C: CompareTo<i32>` is not satisfied
-}
-
-fn with_ufcs1<C:CompareToInts>(c: &C) -> bool {
- CompareToInts::same_as(c, 22) //~ ERROR `dyn CompareToInts: CompareTo<i32>` is not satisfied
-}
-
-fn with_ufcs2<C:CompareToInts>(c: &C) -> bool {
- CompareTo::same_as(c, 22) //~ ERROR `C: CompareTo<i32>` is not satisfied
-}
-
-fn main() {
- assert_eq!(22_i64.same_as(22), true); //~ ERROR `i64: CompareTo<i32>` is not satisfied
-}
+++ /dev/null
-error[E0277]: the trait bound `dyn CompareToInts: CompareTo<i32>` is not satisfied
- --> $DIR/traits-repeated-supertrait-ambig.rs:26:7
- |
-LL | c.same_as(22)
- | ^^^^^^^ the trait `CompareTo<i32>` is not implemented for `dyn CompareToInts`
-
-error[E0277]: the trait bound `C: CompareTo<i32>` is not satisfied
- --> $DIR/traits-repeated-supertrait-ambig.rs:30:7
- |
-LL | c.same_as(22)
- | ^^^^^^^ the trait `CompareTo<i32>` is not implemented for `C`
- |
-help: consider further restricting this bound
- |
-LL | fn with_trait<C:CompareToInts + CompareTo<i32>>(c: &C) -> bool {
- | ^^^^^^^^^^^^^^^^
-
-error[E0277]: the trait bound `dyn CompareToInts: CompareTo<i32>` is not satisfied
- --> $DIR/traits-repeated-supertrait-ambig.rs:34:5
- |
-LL | fn same_as(&self, t: T) -> bool;
- | -------------------------------- required by `CompareTo::same_as`
-...
-LL | CompareToInts::same_as(c, 22)
- | ^^^^^^^^^^^^^^^^^^^^^^ the trait `CompareTo<i32>` is not implemented for `dyn CompareToInts`
-
-error[E0277]: the trait bound `C: CompareTo<i32>` is not satisfied
- --> $DIR/traits-repeated-supertrait-ambig.rs:38:5
- |
-LL | fn same_as(&self, t: T) -> bool;
- | -------------------------------- required by `CompareTo::same_as`
-...
-LL | CompareTo::same_as(c, 22)
- | ^^^^^^^^^^^^^^^^^^ the trait `CompareTo<i32>` is not implemented for `C`
- |
-help: consider further restricting this bound
- |
-LL | fn with_ufcs2<C:CompareToInts + CompareTo<i32>>(c: &C) -> bool {
- | ^^^^^^^^^^^^^^^^
-
-error[E0277]: the trait bound `i64: CompareTo<i32>` is not satisfied
- --> $DIR/traits-repeated-supertrait-ambig.rs:42:23
- |
-LL | assert_eq!(22_i64.same_as(22), true);
- | ^^^^^^^ the trait `CompareTo<i32>` is not implemented for `i64`
- |
- = help: the following implementations were found:
- <i64 as CompareTo<i64>>
- <i64 as CompareTo<u64>>
-
-error: aborting due to 5 previous errors
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-// run-pass
-// Test a case of a trait which extends the same supertrait twice, but
-// with difference type parameters. Test that we can invoke the
-// various methods in various ways successfully.
-// See also `ui/traits/trait-repeated-supertrait-ambig.rs`.
-
-
-trait CompareTo<T> {
- fn same_as(&self, t: T) -> bool;
-}
-
-trait CompareToInts : CompareTo<i64> + CompareTo<u64> {
-}
-
-impl CompareTo<i64> for i64 {
- fn same_as(&self, t: i64) -> bool { *self == t }
-}
-
-impl CompareTo<u64> for i64 {
- fn same_as(&self, t: u64) -> bool { *self == (t as i64) }
-}
-
-impl CompareToInts for i64 { }
-
-fn with_obj(c: &dyn CompareToInts) -> bool {
- c.same_as(22_i64) && c.same_as(22_u64)
-}
-
-fn with_trait<C:CompareToInts>(c: &C) -> bool {
- c.same_as(22_i64) && c.same_as(22_u64)
-}
-
-fn with_ufcs1<C:CompareToInts>(c: &C) -> bool {
- CompareToInts::same_as(c, 22_i64) && CompareToInts::same_as(c, 22_u64)
-}
-
-fn with_ufcs2<C:CompareToInts>(c: &C) -> bool {
- CompareTo::same_as(c, 22_i64) && CompareTo::same_as(c, 22_u64)
-}
-
-fn main() {
- assert_eq!(22_i64.same_as(22_i64), true);
- assert_eq!(22_i64.same_as(22_u64), true);
- assert_eq!(with_trait(&22), true);
- assert_eq!(with_obj(&22), true);
- assert_eq!(with_ufcs1(&22), true);
- assert_eq!(with_ufcs2(&22), true);
-}
+++ /dev/null
-// run-pass
-
-trait Foo<'a> {
- fn xyz(self);
-}
-impl<'a, T> Foo<'a> for T where 'static: 'a {
- fn xyz(self) {}
-}
-
-trait Bar {
- fn uvw(self);
-}
-impl<T> Bar for T where for<'a> T: Foo<'a> {
- fn uvw(self) { self.xyz(); }
-}
-
-fn foo<T>(t: T) where T: Bar {
- t.uvw();
-}
-
-fn main() {
- foo(0);
-}
--- /dev/null
+// run-pass
+// Test that when you use ufcs form to invoke a trait method (on a
+// trait object) everything works fine.
+
+
+trait Foo {
+ fn test(&self) -> i32;
+}
+
+impl Foo for i32 {
+ fn test(&self) -> i32 { *self }
+}
+
+fn main() {
+ let a: &dyn Foo = &22;
+ assert_eq!(Foo::test(a), 22);
+}
+++ /dev/null
-// run-pass
-// Test that when you use ufcs form to invoke a trait method (on a
-// trait object) everything works fine.
-
-
-trait Foo {
- fn test(&self) -> i32;
-}
-
-impl Foo for i32 {
- fn test(&self) -> i32 { *self }
-}
-
-fn main() {
- let a: &dyn Foo = &22;
- assert_eq!(Foo::test(a), 22);
-}
--- /dev/null
+// run-pass
+#![allow(non_camel_case_types)]
+
+// Issue #1761
+
+// pretty-expanded FIXME #23616
+
+impl foo for isize { fn foo(&self) -> isize { 10 } }
+trait foo { fn foo(&self) -> isize; }
+pub fn main() {}
+++ /dev/null
-// run-pass
-#![allow(non_camel_case_types)]
-
-// Issue #1761
-
-// pretty-expanded FIXME #23616
-
-impl foo for isize { fn foo(&self) -> isize { 10 } }
-trait foo { fn foo(&self) -> isize; }
-pub fn main() {}
--- /dev/null
+// Test that `dyn ... + ?Sized + ...` is okay (though `?Sized` has no effect in trait objects).
+
+trait Foo {}
+
+type _0 = dyn ?Sized + Foo;
+//~^ ERROR `?Trait` is not permitted in trait object types
+
+type _1 = dyn Foo + ?Sized;
+//~^ ERROR `?Trait` is not permitted in trait object types
+
+type _2 = dyn Foo + ?Sized + ?Sized;
+//~^ ERROR `?Trait` is not permitted in trait object types
+//~| ERROR `?Trait` is not permitted in trait object types
+
+type _3 = dyn ?Sized + Foo;
+//~^ ERROR `?Trait` is not permitted in trait object types
+
+fn main() {}
--- /dev/null
+error: `?Trait` is not permitted in trait object types
+ --> $DIR/maybe-bound.rs:5:15
+ |
+LL | type _0 = dyn ?Sized + Foo;
+ | ^^^^^^
+
+error: `?Trait` is not permitted in trait object types
+ --> $DIR/maybe-bound.rs:8:21
+ |
+LL | type _1 = dyn Foo + ?Sized;
+ | ^^^^^^
+
+error: `?Trait` is not permitted in trait object types
+ --> $DIR/maybe-bound.rs:11:21
+ |
+LL | type _2 = dyn Foo + ?Sized + ?Sized;
+ | ^^^^^^
+
+error: `?Trait` is not permitted in trait object types
+ --> $DIR/maybe-bound.rs:11:30
+ |
+LL | type _2 = dyn Foo + ?Sized + ?Sized;
+ | ^^^^^^
+
+error: `?Trait` is not permitted in trait object types
+ --> $DIR/maybe-bound.rs:15:15
+ |
+LL | type _3 = dyn ?Sized + Foo;
+ | ^^^^^^
+
+error: aborting due to 5 previous errors
+
--- /dev/null
+// The purpose of this test is to demonstrate that duplicating object safe traits
+// that are not auto-traits is rejected even though one could reasonably accept this.
+
+// Some arbitrary object-safe trait:
+trait Obj {}
+
+// Demonstrate that recursive expansion of trait aliases doesn't affect stable behavior:
+type _0 = dyn Obj + Obj;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+// Some variations:
+
+type _1 = dyn Send + Obj + Obj;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _2 = dyn Obj + Send + Obj;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+type _3 = dyn Obj + Send + Send; // But it is OK to duplicate auto traits.
+
+// Take higher ranked types into account.
+
+// Note that `'a` and `'b` are intentionally different to make sure we consider
+// them semantically the same.
+trait ObjL<'l> {}
+type _4 = dyn for<'a> ObjL<'a> + for<'b> ObjL<'b>;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+trait ObjT<T> {}
+type _5 = dyn ObjT<for<'a> fn(&'a u8)> + ObjT<for<'b> fn(&'b u8)>;
+//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
+
+fn main() {}
--- /dev/null
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:8:21
+ |
+LL | type _0 = dyn Obj + Obj;
+ | --- ^^^ additional non-auto trait
+ | |
+ | first non-auto trait
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:13:28
+ |
+LL | type _1 = dyn Send + Obj + Obj;
+ | --- ^^^ additional non-auto trait
+ | |
+ | first non-auto trait
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:16:28
+ |
+LL | type _2 = dyn Obj + Send + Obj;
+ | --- ^^^ additional non-auto trait
+ | |
+ | first non-auto trait
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:26:34
+ |
+LL | type _4 = dyn for<'a> ObjL<'a> + for<'b> ObjL<'b>;
+ | ---------------- ^^^^^^^^^^^^^^^^ additional non-auto trait
+ | |
+ | first non-auto trait
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: for<'a> ObjL<'a> + for<'b> ObjL<'b> {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error[E0225]: only auto traits can be used as additional traits in a trait object
+ --> $DIR/no-duplicates.rs:30:42
+ |
+LL | type _5 = dyn ObjT<for<'a> fn(&'a u8)> + ObjT<for<'b> fn(&'b u8)>;
+ | ------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^ additional non-auto trait
+ | |
+ | first non-auto trait
+ |
+ = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjT<for<'a> fn(&'a u8)> + ObjT<for<'b> fn(&'b u8)> {}`
+ = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
+
+error: aborting due to 5 previous errors
+
+For more information about this error, try `rustc --explain E0225`.
--- /dev/null
+// Test that `dyn ?Sized` (i.e., a trait object with only a maybe buond) is not allowed.
+
+type _0 = dyn ?Sized;
+//~^ ERROR at least one trait is required for an object type [E0224]
+//~| ERROR ?Trait` is not permitted in trait object types
+
+fn main() {}
--- /dev/null
+error: `?Trait` is not permitted in trait object types
+ --> $DIR/only-maybe-bound.rs:3:15
+ |
+LL | type _0 = dyn ?Sized;
+ | ^^^^^^
+
+error[E0224]: at least one trait is required for an object type
+ --> $DIR/only-maybe-bound.rs:3:11
+ |
+LL | type _0 = dyn ?Sized;
+ | ^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0224`.
--- /dev/null
+// run-pass
+
+// Ensure that `dyn $($AutoTrait)+ ObjSafe` is well-formed.
+
+use std::marker::Unpin;
+
+// Some arbitrary object-safe trait:
+trait Obj {}
+
+type _0 = dyn Unpin;
+type _1 = dyn Send + Obj;
+type _2 = dyn Send + Unpin + Obj;
+type _3 = dyn Send + Unpin + Sync + Obj;
+
+fn main() {}
+++ /dev/null
-// Test that `dyn ... + ?Sized + ...` is okay (though `?Sized` has no effect in trait objects).
-
-trait Foo {}
-
-type _0 = dyn ?Sized + Foo;
-//~^ ERROR `?Trait` is not permitted in trait object types
-
-type _1 = dyn Foo + ?Sized;
-//~^ ERROR `?Trait` is not permitted in trait object types
-
-type _2 = dyn Foo + ?Sized + ?Sized;
-//~^ ERROR `?Trait` is not permitted in trait object types
-//~| ERROR `?Trait` is not permitted in trait object types
-
-type _3 = dyn ?Sized + Foo;
-//~^ ERROR `?Trait` is not permitted in trait object types
-
-fn main() {}
+++ /dev/null
-error: `?Trait` is not permitted in trait object types
- --> $DIR/wf-trait-object-maybe-bound.rs:5:15
- |
-LL | type _0 = dyn ?Sized + Foo;
- | ^^^^^^
-
-error: `?Trait` is not permitted in trait object types
- --> $DIR/wf-trait-object-maybe-bound.rs:8:21
- |
-LL | type _1 = dyn Foo + ?Sized;
- | ^^^^^^
-
-error: `?Trait` is not permitted in trait object types
- --> $DIR/wf-trait-object-maybe-bound.rs:11:21
- |
-LL | type _2 = dyn Foo + ?Sized + ?Sized;
- | ^^^^^^
-
-error: `?Trait` is not permitted in trait object types
- --> $DIR/wf-trait-object-maybe-bound.rs:11:30
- |
-LL | type _2 = dyn Foo + ?Sized + ?Sized;
- | ^^^^^^
-
-error: `?Trait` is not permitted in trait object types
- --> $DIR/wf-trait-object-maybe-bound.rs:15:15
- |
-LL | type _3 = dyn ?Sized + Foo;
- | ^^^^^^
-
-error: aborting due to 5 previous errors
-
+++ /dev/null
-// The purpose of this test is to demonstrate that duplicating object safe traits
-// that are not auto-traits is rejected even though one could reasonably accept this.
-
-// Some arbitrary object-safe trait:
-trait Obj {}
-
-// Demonstrate that recursive expansion of trait aliases doesn't affect stable behavior:
-type _0 = dyn Obj + Obj;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-// Some variations:
-
-type _1 = dyn Send + Obj + Obj;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _2 = dyn Obj + Send + Obj;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-type _3 = dyn Obj + Send + Send; // But it is OK to duplicate auto traits.
-
-// Take higher ranked types into account.
-
-// Note that `'a` and `'b` are intentionally different to make sure we consider
-// them semantically the same.
-trait ObjL<'l> {}
-type _4 = dyn for<'a> ObjL<'a> + for<'b> ObjL<'b>;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-trait ObjT<T> {}
-type _5 = dyn ObjT<for<'a> fn(&'a u8)> + ObjT<for<'b> fn(&'b u8)>;
-//~^ ERROR only auto traits can be used as additional traits in a trait object [E0225]
-
-fn main() {}
+++ /dev/null
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/wf-trait-object-no-duplicates.rs:8:21
- |
-LL | type _0 = dyn Obj + Obj;
- | --- ^^^ additional non-auto trait
- | |
- | first non-auto trait
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/wf-trait-object-no-duplicates.rs:13:28
- |
-LL | type _1 = dyn Send + Obj + Obj;
- | --- ^^^ additional non-auto trait
- | |
- | first non-auto trait
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/wf-trait-object-no-duplicates.rs:16:28
- |
-LL | type _2 = dyn Obj + Send + Obj;
- | --- ^^^ additional non-auto trait
- | |
- | first non-auto trait
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: Obj + Obj {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/wf-trait-object-no-duplicates.rs:26:34
- |
-LL | type _4 = dyn for<'a> ObjL<'a> + for<'b> ObjL<'b>;
- | ---------------- ^^^^^^^^^^^^^^^^ additional non-auto trait
- | |
- | first non-auto trait
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: for<'a> ObjL<'a> + for<'b> ObjL<'b> {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error[E0225]: only auto traits can be used as additional traits in a trait object
- --> $DIR/wf-trait-object-no-duplicates.rs:30:42
- |
-LL | type _5 = dyn ObjT<for<'a> fn(&'a u8)> + ObjT<for<'b> fn(&'b u8)>;
- | ------------------------ ^^^^^^^^^^^^^^^^^^^^^^^^ additional non-auto trait
- | |
- | first non-auto trait
- |
- = help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: ObjT<for<'a> fn(&'a u8)> + ObjT<for<'b> fn(&'b u8)> {}`
- = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
-
-error: aborting due to 5 previous errors
-
-For more information about this error, try `rustc --explain E0225`.
+++ /dev/null
-// Test that `dyn ?Sized` (i.e., a trait object with only a maybe buond) is not allowed.
-
-type _0 = dyn ?Sized;
-//~^ ERROR at least one trait is required for an object type [E0224]
-//~| ERROR ?Trait` is not permitted in trait object types
-
-fn main() {}
+++ /dev/null
-error: `?Trait` is not permitted in trait object types
- --> $DIR/wf-trait-object-only-maybe-bound.rs:3:15
- |
-LL | type _0 = dyn ?Sized;
- | ^^^^^^
-
-error[E0224]: at least one trait is required for an object type
- --> $DIR/wf-trait-object-only-maybe-bound.rs:3:11
- |
-LL | type _0 = dyn ?Sized;
- | ^^^^^^^^^^
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0224`.
+++ /dev/null
-// run-pass
-
-// Ensure that `dyn $($AutoTrait)+ ObjSafe` is well-formed.
-
-use std::marker::Unpin;
-
-// Some arbitrary object-safe trait:
-trait Obj {}
-
-type _0 = dyn Unpin;
-type _1 = dyn Send + Obj;
-type _2 = dyn Send + Unpin + Obj;
-type _3 = dyn Send + Unpin + Sync + Obj;
-
-fn main() {}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+#![allow(unused_variables)]
+// Test that when there is a conditional (but blanket) impl and a
+// where clause, we don't get confused in trait resolution.
+//
+// Issue #18453.
+
+// pretty-expanded FIXME #23616
+
+use std::rc::Rc;
+
+pub trait Foo<M> {
+ fn foo(&mut self, msg: M);
+}
+
+pub trait Bar<M> {
+ fn dummy(&self) -> M;
+}
+
+impl<M, F: Bar<M>> Foo<M> for F {
+ fn foo(&mut self, msg: M) {
+ }
+}
+
+pub struct Both<M, F> {
+ inner: Rc<(M, F)>,
+}
+
+impl<M, F: Foo<M>> Clone for Both<M, F> {
+ fn clone(&self) -> Both<M, F> {
+ Both { inner: self.inner.clone() }
+ }
+}
+
+fn repro1<M, F: Foo<M>>(_both: Both<M, F>) {
+}
+
+fn repro2<M, F: Foo<M>>(msg: M, foo: F) {
+ let both = Both { inner: Rc::new((msg, foo)) };
+ repro1(both.clone()); // <--- This clone causes problem
+}
+
+pub fn main() {
+}
--- /dev/null
+// run-pass
+
+pub trait Clone2 {
+ /// Returns a copy of the value. The contents of boxes
+ /// are copied to maintain uniqueness, while the contents of
+ /// managed pointers are not copied.
+ fn clone(&self) -> Self;
+}
+
+trait Getter<T: Clone> {
+ fn do_get(&self) -> T;
+
+ fn do_get2(&self) -> (T, T) {
+ let x = self.do_get();
+ (x.clone(), x.clone())
+ }
+
+}
+
+impl Getter<isize> for isize {
+ fn do_get(&self) -> isize { *self }
+}
+
+impl<T: Clone> Getter<T> for Option<T> {
+ fn do_get(&self) -> T { self.as_ref().unwrap().clone() }
+}
+
+
+pub fn main() {
+ assert_eq!(3.do_get2(), (3, 3));
+ assert_eq!(Some("hi".to_string()).do_get2(), ("hi".to_string(), "hi".to_string()));
+}
--- /dev/null
+// build-pass (FIXME(62277): could be check-pass?)
+// #55266
+
+struct VTable<DST: ?Sized> {
+ _to_dst_ptr: fn(*mut ()) -> *mut DST,
+}
+
+trait HasVTableFor<DST: ?Sized + 'static> {
+ const VTABLE: &'static VTable<DST>;
+}
+
+impl<T, DST: ?Sized + 'static> HasVTableFor<DST> for T {
+ const VTABLE: &'static VTable<DST> = &VTable {
+ _to_dst_ptr: |_: *mut ()| unsafe { std::mem::zeroed() },
+ };
+}
+
+pub fn push<DST: ?Sized + 'static, T>() {
+ <T as HasVTableFor<DST>>::VTABLE;
+}
+
+fn main() {}