Auto merge of #29620 - petrochenkov:reachable2, r=alexcrichton

Handle them in `middle::reachable` instead (no optimizations so far, just drop all trait impl items into the reachable set, as before). Addresses the concerns from https://github.com/rust-lang/rust/pull/29291#discussion_r43672413
\+ In `middle::reachable` don't treat impls of `Drop` specially, they are subsumed by the general impl treatment.
\+ Add some tests checking reachability of trait methods written in UFCS form
\+ Minor refactoring in the second commit

r? @alexcrichton
This commit is contained in:
bors 2015-11-06 13:13:08 +00:00
commit 7cd8f69a4f
8 changed files with 85 additions and 55 deletions

View file

@ -11,13 +11,18 @@
mod inner {
pub trait Trait {
fn f(&self) { f(); }
fn f_ufcs(&self) { f_ufcs(); }
}
impl Trait for isize {}
fn f() {}
fn f_ufcs() {}
}
pub fn foo<T: inner::Trait>(t: T) {
t.f();
}
pub fn foo_ufcs<T: inner::Trait>(t: T) {
T::f_ufcs(&t);
}

View file

@ -14,15 +14,18 @@ mod inner {
pub struct Foo;
pub trait Trait {
fn f(&self);
fn f_ufcs(&self);
}
impl Trait for Foo {
fn f(&self) { }
fn f_ufcs(&self) { }
}
}
pub trait Outer {
fn foo<T: Trait>(&self, t: T) { t.f(); }
fn foo_ufcs<T: Trait>(&self, t: T) { T::f(&t); }
}
impl Outer for isize {}
@ -30,3 +33,6 @@ impl Outer for isize {}
pub fn foo<T: Outer>(t: T) {
t.foo(inner::Foo);
}
pub fn foo_ufcs<T: Outer>(t: T) {
T::foo_ufcs(&t, inner::Foo)
}

View file

@ -10,20 +10,29 @@
trait PrivateTrait {
fn private_trait_method(&self);
fn private_trait_method_ufcs(&self);
}
struct PrivateStruct;
impl PrivateStruct {
fn private_inherent_method(&self) { }
fn private_inherent_method_ufcs(&self) { }
}
impl PrivateTrait for PrivateStruct {
fn private_trait_method(&self) { }
fn private_trait_method_ufcs(&self) { }
}
#[inline]
pub fn public_generic_function() {
pub fn public_inlinable_function() {
PrivateStruct.private_trait_method();
PrivateStruct.private_inherent_method();
}
#[inline]
pub fn public_inlinable_function_ufcs() {
PrivateStruct::private_trait_method(&PrivateStruct);
PrivateStruct::private_inherent_method(&PrivateStruct);
}

View file

@ -16,4 +16,5 @@ extern crate issue_11225_1 as foo;
pub fn main() {
foo::foo(1);
foo::foo_ufcs(1);
}

View file

@ -16,4 +16,5 @@ extern crate issue_11225_2 as foo;
pub fn main() {
foo::foo(1);
foo::foo_ufcs(1);
}

View file

@ -15,5 +15,6 @@
extern crate issue_11225_3;
pub fn main() {
issue_11225_3::public_generic_function();
issue_11225_3::public_inlinable_function();
issue_11225_3::public_inlinable_function_ufcs();
}