Make privacy checking on default methods for cross crate structs not fail. Closes #7481.
It is unclear to me that the way method call privacy checking is done makes any sense, though. It is only performed if the type is a struct...
This commit is contained in:
parent
419a14772a
commit
7238d5a141
@ -245,6 +245,14 @@ pub fn check_crate<'mm>(tcx: ty::ctxt,
|
||||
method_id: def_id,
|
||||
name: &ident) =
|
||||
|span, method_id, name| {
|
||||
// If the method is a default method, we need to use the def_id of
|
||||
// the default implementation.
|
||||
// Having to do this this is really unfortunate.
|
||||
let method_id = match tcx.provided_method_sources.find(&method_id) {
|
||||
None => method_id,
|
||||
Some(source) => source.method_id
|
||||
};
|
||||
|
||||
if method_id.crate == local_crate {
|
||||
let is_private = method_is_private(span, method_id.node);
|
||||
let container_id = local_method_container_id(span,
|
||||
|
@ -1,5 +1,7 @@
|
||||
#[allow(default_methods)];
|
||||
|
||||
pub struct Something { x: int }
|
||||
|
||||
pub trait A {
|
||||
fn f(&self) -> int;
|
||||
fn g(&self) -> int { 10 }
|
||||
@ -11,6 +13,10 @@ impl A for int {
|
||||
fn f(&self) -> int { 10 }
|
||||
}
|
||||
|
||||
impl A for Something {
|
||||
fn f(&self) -> int { 10 }
|
||||
}
|
||||
|
||||
trait B<T> {
|
||||
fn thing<U>(&self, x: T, y: U) -> (T, U) { (x, y) }
|
||||
}
|
||||
|
@ -4,16 +4,18 @@
|
||||
#[allow(default_methods)];
|
||||
|
||||
extern mod aux(name = "trait_default_method_xc_aux");
|
||||
use aux::{A, B, TestEquality};
|
||||
use aux::{A, B, TestEquality, Something};
|
||||
|
||||
|
||||
fn f<T: aux::A>(i: T) {
|
||||
assert_eq!(i.g(), 10);
|
||||
}
|
||||
|
||||
mod stuff {
|
||||
pub struct thing { x: int }
|
||||
}
|
||||
|
||||
pub struct thing { x: int }
|
||||
impl A for thing {
|
||||
impl A for stuff::thing {
|
||||
fn f(&self) -> int { 10 }
|
||||
}
|
||||
|
||||
@ -29,8 +31,8 @@ fn neq<T: TestEquality>(lhs: &T, rhs: &T) -> bool {
|
||||
}
|
||||
|
||||
|
||||
impl TestEquality for thing {
|
||||
fn test_eq(&self, rhs: &thing) -> bool {
|
||||
impl TestEquality for stuff::thing {
|
||||
fn test_eq(&self, rhs: &stuff::thing) -> bool {
|
||||
//self.x.test_eq(&rhs.x)
|
||||
eq(&self.x, &rhs.x)
|
||||
}
|
||||
@ -41,15 +43,17 @@ fn main () {
|
||||
// Some tests of random things
|
||||
f(0);
|
||||
|
||||
let a = thing { x: 0 };
|
||||
let b = thing { x: 1 };
|
||||
let a = stuff::thing { x: 0 };
|
||||
let b = stuff::thing { x: 1 };
|
||||
let c = Something { x: 1 };
|
||||
|
||||
//assert_eq!(0i.g(), 10);
|
||||
assert_eq!(0i.g(), 10);
|
||||
assert_eq!(a.g(), 10);
|
||||
assert_eq!(a.h(), 10);
|
||||
assert_eq!(c.h(), 10);
|
||||
|
||||
|
||||
//assert_eq!(0i.thing(3.14, 1), (3.14, 1));
|
||||
0i.thing(3.14, 1);
|
||||
assert_eq!(0i.thing(3.14, 1), (3.14, 1));
|
||||
|
||||
assert_eq!(g(0i, 3.14, 1), (3.14, 1));
|
||||
assert_eq!(g(false, 3.14, 1), (3.14, 1));
|
||||
@ -59,8 +63,8 @@ fn main () {
|
||||
|
||||
|
||||
// Trying out a real one
|
||||
//assert!(12.test_neq(&10));
|
||||
//assert!(!10.test_neq(&10));
|
||||
assert!(12.test_neq(&10));
|
||||
assert!(!10.test_neq(&10));
|
||||
assert!(a.test_neq(&b));
|
||||
assert!(!a.test_neq(&a));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user