Skip to content

Trait exportation modifications plus a small doctest fix #11245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/librustc/middle/privacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,23 @@ struct EmbargoVisitor<'a> {
reexports: HashSet<ast::NodeId>,
}

impl<'a> EmbargoVisitor<'a> {
// There are checks inside of privacy which depend on knowing whether a
// trait should be exported or not. The two current consumers of this are:
//
// 1. Should default methods of a trait be exported?
// 2. Should the methods of an implementation of a trait be exported?
//
// The answer to both of these questions partly rely on whether the trait
// itself is exported or not. If the trait is somehow exported, then the
// answers to both questions must be yes. Right now this question involves
// more analysis than is currently done in rustc, so we conservatively
// answer "yes" so that all traits need to be exported.
fn exported_trait(&self, _id: ast::NodeId) -> bool {
true
}
}

impl<'a> Visitor<()> for EmbargoVisitor<'a> {
fn visit_item(&mut self, item: @ast::item, _: ()) {
let orig_all_pub = self.prev_exported;
Expand All @@ -175,6 +192,12 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
// cannot have visibility qualifiers on them anyway
ast::item_impl(..) | ast::item_foreign_mod(..) => {}

// Traits are a little special in that even if they themselves are
// not public they may still be exported.
ast::item_trait(..) => {
self.prev_exported = self.exported_trait(item.id);
}

// Private by default, hence we only retain the "public chain" if
// `pub` is explicitly listed.
_ => {
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Some examples of obvious things you might want to do
# let _g = ::std::io::ignore_io_error();
let mut file = File::create(&Path::new("message.txt"));
file.write(bytes!("hello, file!\n"));
# drop(file);
# ::std::io::fs::unlink(&Path::new("message.txt"));
```

* Iterate over the lines of a file
Expand Down
1 change: 1 addition & 0 deletions src/libstd/local_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub type Key<T> = &'static KeyValue<T>;
#[allow(missing_doc)]
pub enum KeyValue<T> { Key }

#[allow(missing_doc)]
trait LocalData {}
impl<T: 'static> LocalData for T {}

Expand Down
26 changes: 26 additions & 0 deletions src/test/auxiliary/issue-11224.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[deny(dead_code)];

mod inner {
pub trait Trait {
fn f(&self) { f(); }
}

impl Trait for int {}

fn f() {}
}

pub fn foo() {
let a = &1 as &inner::Trait;
a.f();
}
23 changes: 23 additions & 0 deletions src/test/auxiliary/issue-11225-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

mod inner {
pub trait Trait {
fn f(&self) { f(); }
}

impl Trait for int {}

fn f() {}
}

pub fn foo<T: inner::Trait>(t: T) {
t.f();
}
32 changes: 32 additions & 0 deletions src/test/auxiliary/issue-11225-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use inner::Trait;

mod inner {
pub struct Foo;
pub trait Trait {
fn f(&self);
}

impl Trait for Foo {
fn f(&self) { }
}
}

pub trait Outer {
fn foo<T: Trait>(&self, t: T) { t.f(); }
}

impl Outer for int {}

pub fn foo<T: Outer>(t: T) {
t.foo(inner::Foo);
}
1 change: 1 addition & 0 deletions src/test/compile-fail/lint-missing-doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub trait A {
/// dox
fn foo_with_impl() {}
}
#[allow(missing_doc)]
trait B {
fn foo();
fn foo_with_impl() {}
Expand Down
16 changes: 16 additions & 0 deletions src/test/run-pass/issue-11224.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// aux-build:issue-11224.rs
// xfail-fast

extern mod unused = "issue-11224";

fn main() {}
18 changes: 18 additions & 0 deletions src/test/run-pass/issue-11225-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// aux-build:issue-11225-1.rs
// xfail-fast

extern mod foo = "issue-11225-1";

fn main() {
foo::foo(1);
}
18 changes: 18 additions & 0 deletions src/test/run-pass/issue-11225-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// aux-build:issue-11225-2.rs
// xfail-fast

extern mod foo = "issue-11225-2";

fn main() {
foo::foo(1);
}