diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 707446a78fe21..a0da1680d0041 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -167,6 +167,23 @@ struct EmbargoVisitor<'a> { reexports: HashSet, } +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; @@ -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. _ => { diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 2d52986294d1c..13d67ff354a83 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -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 diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs index d7e11d2f3a70f..95fdce99ea654 100644 --- a/src/libstd/local_data.rs +++ b/src/libstd/local_data.rs @@ -62,6 +62,7 @@ pub type Key = &'static KeyValue; #[allow(missing_doc)] pub enum KeyValue { Key } +#[allow(missing_doc)] trait LocalData {} impl LocalData for T {} diff --git a/src/test/auxiliary/issue-11224.rs b/src/test/auxiliary/issue-11224.rs new file mode 100644 index 0000000000000..448ef8ef81801 --- /dev/null +++ b/src/test/auxiliary/issue-11224.rs @@ -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 or the MIT license +// , 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(); +} diff --git a/src/test/auxiliary/issue-11225-1.rs b/src/test/auxiliary/issue-11225-1.rs new file mode 100644 index 0000000000000..88277af4a5118 --- /dev/null +++ b/src/test/auxiliary/issue-11225-1.rs @@ -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 or the MIT license +// , 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: T) { + t.f(); +} diff --git a/src/test/auxiliary/issue-11225-2.rs b/src/test/auxiliary/issue-11225-2.rs new file mode 100644 index 0000000000000..848574a61fe8f --- /dev/null +++ b/src/test/auxiliary/issue-11225-2.rs @@ -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 or the MIT license +// , 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(&self, t: T) { t.f(); } +} + +impl Outer for int {} + +pub fn foo(t: T) { + t.foo(inner::Foo); +} diff --git a/src/test/compile-fail/lint-missing-doc.rs b/src/test/compile-fail/lint-missing-doc.rs index a083948bf8406..a6440e67f9beb 100644 --- a/src/test/compile-fail/lint-missing-doc.rs +++ b/src/test/compile-fail/lint-missing-doc.rs @@ -50,6 +50,7 @@ pub trait A { /// dox fn foo_with_impl() {} } +#[allow(missing_doc)] trait B { fn foo(); fn foo_with_impl() {} diff --git a/src/test/run-pass/issue-11224.rs b/src/test/run-pass/issue-11224.rs new file mode 100644 index 0000000000000..bf412ceab2886 --- /dev/null +++ b/src/test/run-pass/issue-11224.rs @@ -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 or the MIT license +// , 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() {} diff --git a/src/test/run-pass/issue-11225-1.rs b/src/test/run-pass/issue-11225-1.rs new file mode 100644 index 0000000000000..ad8cb1e79abf2 --- /dev/null +++ b/src/test/run-pass/issue-11225-1.rs @@ -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 or the MIT license +// , 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); +} diff --git a/src/test/run-pass/issue-11225-2.rs b/src/test/run-pass/issue-11225-2.rs new file mode 100644 index 0000000000000..e572e56362bcb --- /dev/null +++ b/src/test/run-pass/issue-11225-2.rs @@ -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 or the MIT license +// , 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); +}