2017-04-16 16:06:26 +00:00
|
|
|
#![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 {}
|
2017-04-25 19:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2017-04-16 16:06:26 +00:00
|
|
|
|
2017-04-25 19:38:21 +00:00
|
|
|
impl A for ::S {}
|
|
|
|
impl B for ::S {}
|
|
|
|
impl C for ::S {}
|
2017-04-16 16:06:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {}
|
|
|
|
}
|
|
|
|
|
2017-04-25 19:38:21 +00:00
|
|
|
fn check_method() {
|
2017-04-16 16:06:26 +00:00
|
|
|
// 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
|
2020-01-08 16:05:31 +00:00
|
|
|
S.a(); //~ ERROR no method named `a` found
|
|
|
|
S.b(); //~ ERROR no method named `b` found
|
2017-04-16 16:06:26 +00:00
|
|
|
S.c(); // OK
|
|
|
|
// a, b, c are resolved as inherent items, their traits don't need to be in scope
|
2019-05-28 18:46:13 +00:00
|
|
|
let c = &S as &dyn C;
|
2020-03-05 03:03:15 +00:00
|
|
|
c.a(); //~ ERROR associated function `a` is private
|
2017-04-16 16:06:26 +00:00
|
|
|
c.b(); // OK
|
|
|
|
c.c(); // OK
|
|
|
|
|
|
|
|
// Methods, UFCS
|
|
|
|
// a, b, c are resolved as trait items, their traits need to be in scope
|
2017-06-02 20:20:36 +00:00
|
|
|
S::a(&S);
|
2020-01-08 16:05:31 +00:00
|
|
|
//~^ ERROR no function or associated item named `a` found
|
2017-06-02 20:20:36 +00:00
|
|
|
S::b(&S);
|
2020-01-08 16:05:31 +00:00
|
|
|
//~^ ERROR no function or associated item named `b` found
|
2017-04-16 16:06:26 +00:00
|
|
|
S::c(&S); // OK
|
|
|
|
// a, b, c are resolved as inherent items, their traits don't need to be in scope
|
2021-03-07 15:47:39 +00:00
|
|
|
<dyn C>::a(&S); //~ ERROR associated function `a` is private
|
|
|
|
<dyn C>::b(&S); // OK
|
2017-04-16 16:06:26 +00:00
|
|
|
C::c(&S); // OK
|
2017-04-25 19:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn check_assoc_const() {
|
|
|
|
// A is private
|
|
|
|
// B is pub, not in scope
|
|
|
|
// C : A + B is pub, in scope
|
|
|
|
use assoc_const::C;
|
2017-04-16 16:06:26 +00:00
|
|
|
|
|
|
|
// Associated constants
|
|
|
|
// A, B, C are resolved as trait items, their traits need to be in scope
|
2020-01-08 16:05:31 +00:00
|
|
|
S::A; //~ ERROR no associated item named `A` found
|
|
|
|
S::B; //~ ERROR no associated item named `B` found
|
2017-04-16 16:06:26 +00:00
|
|
|
S::C; // OK
|
|
|
|
// A, B, C are resolved as inherent items, their traits don't need to be in scope
|
2021-03-07 15:47:39 +00:00
|
|
|
<dyn C>::A; //~ ERROR associated constant `A` is private
|
|
|
|
//~^ ERROR the trait `assoc_const::C` cannot be made into an object
|
|
|
|
<dyn C>::B; // ERROR the trait `assoc_const::C` cannot be made into an object
|
2017-04-16 16:06:26 +00:00
|
|
|
C::C; // OK
|
|
|
|
}
|
2017-04-25 19:38:21 +00:00
|
|
|
|
|
|
|
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
|
2017-11-18 15:38:56 +00:00
|
|
|
|
|
|
|
// Associated types, bindings
|
2019-05-28 18:46:13 +00:00
|
|
|
let _: dyn assoc_ty::B<
|
2017-11-18 15:38:56 +00:00
|
|
|
B = u8, // OK
|
|
|
|
>;
|
2019-05-28 18:46:13 +00:00
|
|
|
let _: dyn C<
|
2017-11-18 15:38:56 +00:00
|
|
|
A = u8, //~ ERROR associated type `A` is private
|
|
|
|
B = u8, // OK
|
|
|
|
C = u8, // OK
|
|
|
|
>;
|
2017-04-25 19:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|