Skip to content

Commit 2accc52

Browse files
committed
---
yaml --- r: 272717 b: refs/heads/beta c: d846f49 h: refs/heads/master i: 272715: 65d2c7d
1 parent 16a8fe6 commit 2accc52

File tree

12 files changed

+185
-145
lines changed

12 files changed

+185
-145
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 4ed3826f27055e51a85378afa5493c6630cbe80d
26+
refs/heads/beta: d846f490a04df5899471218dfe904e7cfe42b13f
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/libcore/cell.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,6 @@ impl<T:Copy> Cell<T> {
241241
#[stable(feature = "rust1", since = "1.0.0")]
242242
unsafe impl<T> Send for Cell<T> where T: Send {}
243243

244-
#[stable(feature = "rust1", since = "1.0.0")]
245-
impl<T> !Sync for Cell<T> {}
246-
247244
#[stable(feature = "rust1", since = "1.0.0")]
248245
impl<T:Copy> Clone for Cell<T> {
249246
#[inline]
@@ -464,9 +461,6 @@ impl<T: ?Sized> RefCell<T> {
464461
#[stable(feature = "rust1", since = "1.0.0")]
465462
unsafe impl<T: ?Sized> Send for RefCell<T> where T: Send {}
466463

467-
#[stable(feature = "rust1", since = "1.0.0")]
468-
impl<T: ?Sized> !Sync for RefCell<T> {}
469-
470464
#[stable(feature = "rust1", since = "1.0.0")]
471465
impl<T: Clone> Clone for RefCell<T> {
472466
#[inline]

branches/beta/src/librustc_privacy/lib.rs

Lines changed: 70 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,19 +1129,43 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
11291129

11301130
struct SanePrivacyVisitor<'a, 'tcx: 'a> {
11311131
tcx: &'a ty::ctxt<'tcx>,
1132+
in_block: bool,
11321133
}
11331134

11341135
impl<'a, 'tcx, 'v> Visitor<'v> for SanePrivacyVisitor<'a, 'tcx> {
1136+
/// We want to visit items in the context of their containing
1137+
/// module and so forth, so supply a crate for doing a deep walk.
1138+
fn visit_nested_item(&mut self, item: hir::ItemId) {
1139+
self.visit_item(self.tcx.map.expect_item(item.id))
1140+
}
1141+
11351142
fn visit_item(&mut self, item: &hir::Item) {
11361143
self.check_sane_privacy(item);
1144+
if self.in_block {
1145+
self.check_all_inherited(item);
1146+
}
1147+
1148+
let orig_in_block = self.in_block;
1149+
1150+
// Modules turn privacy back on, otherwise we inherit
1151+
self.in_block = if let hir::ItemMod(..) = item.node { false } else { orig_in_block };
1152+
11371153
intravisit::walk_item(self, item);
1154+
self.in_block = orig_in_block;
1155+
}
1156+
1157+
fn visit_block(&mut self, b: &'v hir::Block) {
1158+
let orig_in_block = replace(&mut self.in_block, true);
1159+
intravisit::walk_block(self, b);
1160+
self.in_block = orig_in_block;
11381161
}
11391162
}
11401163

11411164
impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
1142-
/// Validate that items that shouldn't have visibility qualifiers don't have them.
1143-
/// Such qualifiers can be set by syntax extensions even if the parser doesn't allow them,
1144-
/// so we check things like variant fields too.
1165+
/// Validates all of the visibility qualifiers placed on the item given. This
1166+
/// ensures that there are no extraneous qualifiers that don't actually do
1167+
/// anything. In theory these qualifiers wouldn't parse, but that may happen
1168+
/// later on down the road...
11451169
fn check_sane_privacy(&self, item: &hir::Item) {
11461170
let check_inherited = |sp, vis, note: &str| {
11471171
if vis != hir::Inherited {
@@ -1155,12 +1179,13 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
11551179
};
11561180

11571181
match item.node {
1182+
// implementations of traits don't need visibility qualifiers because
1183+
// that's controlled by having the trait in scope.
11581184
hir::ItemImpl(_, _, _, Some(..), _, ref impl_items) => {
11591185
check_inherited(item.span, item.vis,
11601186
"visibility qualifiers have no effect on trait impls");
11611187
for impl_item in impl_items {
1162-
check_inherited(impl_item.span, impl_item.vis,
1163-
"visibility qualifiers have no effect on trait impl items");
1188+
check_inherited(impl_item.span, impl_item.vis, "");
11641189
}
11651190
}
11661191
hir::ItemImpl(_, _, _, None, _, _) => {
@@ -1175,15 +1200,41 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
11751200
check_inherited(item.span, item.vis,
11761201
"place qualifiers on individual functions instead");
11771202
}
1178-
hir::ItemEnum(ref def, _) => {
1179-
for variant in &def.variants {
1180-
for field in variant.node.data.fields() {
1181-
check_inherited(field.span, field.node.kind.visibility(),
1182-
"visibility qualifiers have no effect on variant fields");
1183-
}
1203+
hir::ItemStruct(..) | hir::ItemEnum(..) | hir::ItemTrait(..) |
1204+
hir::ItemConst(..) | hir::ItemStatic(..) | hir::ItemFn(..) |
1205+
hir::ItemMod(..) | hir::ItemExternCrate(..) |
1206+
hir::ItemUse(..) | hir::ItemTy(..) => {}
1207+
}
1208+
}
1209+
1210+
/// When inside of something like a function or a method, visibility has no
1211+
/// control over anything so this forbids any mention of any visibility
1212+
fn check_all_inherited(&self, item: &hir::Item) {
1213+
let check_inherited = |sp, vis| {
1214+
if vis != hir::Inherited {
1215+
span_err!(self.tcx.sess, sp, E0447,
1216+
"visibility has no effect inside functions or block expressions");
1217+
}
1218+
};
1219+
1220+
check_inherited(item.span, item.vis);
1221+
match item.node {
1222+
hir::ItemImpl(_, _, _, _, _, ref impl_items) => {
1223+
for impl_item in impl_items {
1224+
check_inherited(impl_item.span, impl_item.vis);
11841225
}
11851226
}
1186-
hir::ItemStruct(..) | hir::ItemTrait(..) |
1227+
hir::ItemForeignMod(ref fm) => {
1228+
for fi in &fm.items {
1229+
check_inherited(fi.span, fi.vis);
1230+
}
1231+
}
1232+
hir::ItemStruct(ref vdata, _) => {
1233+
for f in vdata.fields() {
1234+
check_inherited(f.span, f.node.kind.visibility());
1235+
}
1236+
}
1237+
hir::ItemDefaultImpl(..) | hir::ItemEnum(..) | hir::ItemTrait(..) |
11871238
hir::ItemConst(..) | hir::ItemStatic(..) | hir::ItemFn(..) |
11881239
hir::ItemMod(..) | hir::ItemExternCrate(..) |
11891240
hir::ItemUse(..) | hir::ItemTy(..) => {}
@@ -1770,9 +1821,13 @@ pub fn check_crate(tcx: &ty::ctxt,
17701821

17711822
let krate = tcx.map.krate();
17721823

1773-
// Sanity check to make sure that all privacy usage is reasonable.
1774-
let mut visitor = SanePrivacyVisitor { tcx: tcx };
1775-
krate.visit_all_items(&mut visitor);
1824+
// Sanity check to make sure that all privacy usage and controls are
1825+
// reasonable.
1826+
let mut visitor = SanePrivacyVisitor {
1827+
tcx: tcx,
1828+
in_block: false,
1829+
};
1830+
intravisit::walk_crate(&mut visitor, krate);
17761831

17771832
// Figure out who everyone's parent is
17781833
let mut visitor = ParentVisitor {

branches/beta/src/libstd/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn main() {
2323

2424
let target = env::var("TARGET").unwrap();
2525
let host = env::var("HOST").unwrap();
26-
if !target.contains("apple") && !target.contains("msvc") {
26+
if !target.contains("apple") && !target.contains("msvc") && !target.contains("emscripten"){
2727
build_libbacktrace(&host, &target);
2828
}
2929

branches/beta/src/libstd/sync/mpsc/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,6 @@ pub struct Receiver<T> {
299299
#[stable(feature = "rust1", since = "1.0.0")]
300300
unsafe impl<T: Send> Send for Receiver<T> { }
301301

302-
#[stable(feature = "rust1", since = "1.0.0")]
303-
impl<T> !Sync for Receiver<T> { }
304-
305302
/// An iterator over messages on a receiver, this iterator will block
306303
/// whenever `next` is called, waiting for a new message, and `None` will be
307304
/// returned when the corresponding channel has hung up.
@@ -330,9 +327,6 @@ pub struct Sender<T> {
330327
#[stable(feature = "rust1", since = "1.0.0")]
331328
unsafe impl<T: Send> Send for Sender<T> { }
332329

333-
#[stable(feature = "rust1", since = "1.0.0")]
334-
impl<T> !Sync for Sender<T> { }
335-
336330
/// The sending-half of Rust's synchronous channel type. This half can only be
337331
/// owned by one thread, but it can be cloned to send to other threads.
338332
#[stable(feature = "rust1", since = "1.0.0")]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::sync::mpsc::Receiver;
12+
13+
fn test<T: Sync>() {}
14+
15+
fn main() {
16+
test::<Receiver<isize>>(); //~ ERROR: `core::marker::Sync` is not implemented
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::sync::mpsc::Sender;
12+
13+
fn test<T: Sync>() {}
14+
15+
fn main() {
16+
test::<Sender<isize>>(); //~ ERROR: `core::marker::Sync` is not implemented
17+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::rc::Rc;
12+
use std::cell::RefCell;
13+
14+
fn bar<T: Sync>(_: T) {}
15+
16+
fn main() {
17+
let x = Rc::new(RefCell::new(5));
18+
bar(x);
19+
//~^ ERROR the trait `core::marker::Sync` is not implemented
20+
}

branches/beta/src/test/compile-fail/not-sync.rs

Lines changed: 0 additions & 34 deletions
This file was deleted.

branches/beta/src/test/compile-fail/privacy-sanity.rs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,60 +40,74 @@ pub extern "C" { //~ ERROR unnecessary visibility qualifier
4040

4141
const MAIN: u8 = {
4242
trait MarkerTr {}
43-
pub trait Tr {
43+
pub trait Tr { //~ ERROR visibility has no effect inside functions or block
4444
fn f();
4545
const C: u8;
4646
type T;
4747
}
48-
pub struct S {
49-
pub a: u8
48+
pub struct S { //~ ERROR visibility has no effect inside functions or block
49+
pub a: u8 //~ ERROR visibility has no effect inside functions or block
5050
}
51-
struct Ts(pub u8);
51+
struct Ts(pub u8); //~ ERROR visibility has no effect inside functions or block
5252

5353
pub impl MarkerTr for .. {} //~ ERROR unnecessary visibility qualifier
54+
//~^ ERROR visibility has no effect inside functions or block
5455
pub impl Tr for S { //~ ERROR unnecessary visibility qualifier
56+
//~^ ERROR visibility has no effect inside functions or block
5557
pub fn f() {} //~ ERROR unnecessary visibility qualifier
58+
//~^ ERROR visibility has no effect inside functions or block
5659
pub const C: u8 = 0; //~ ERROR unnecessary visibility qualifier
60+
//~^ ERROR visibility has no effect inside functions or block
5761
pub type T = u8; //~ ERROR unnecessary visibility qualifier
62+
//~^ ERROR visibility has no effect inside functions or block
5863
}
5964
pub impl S { //~ ERROR unnecessary visibility qualifier
60-
pub fn f() {}
61-
pub const C: u8 = 0;
62-
// pub type T = u8;
65+
//~^ ERROR visibility has no effect inside functions or block
66+
pub fn f() {} //~ ERROR visibility has no effect inside functions or block
67+
pub const C: u8 = 0; //~ ERROR visibility has no effect inside functions or block
68+
// pub type T = u8; // ERROR visibility has no effect inside functions or block
6369
}
6470
pub extern "C" { //~ ERROR unnecessary visibility qualifier
65-
pub fn f();
66-
pub static St: u8;
71+
//~^ ERROR visibility has no effect inside functions or block
72+
pub fn f(); //~ ERROR visibility has no effect inside functions or block
73+
pub static St: u8; //~ ERROR visibility has no effect inside functions or block
6774
}
6875

6976
0
7077
};
7178

7279
fn main() {
7380
trait MarkerTr {}
74-
pub trait Tr {
81+
pub trait Tr { //~ ERROR visibility has no effect inside functions or block
7582
fn f();
7683
const C: u8;
7784
type T;
7885
}
79-
pub struct S {
80-
pub a: u8
86+
pub struct S { //~ ERROR visibility has no effect inside functions or block
87+
pub a: u8 //~ ERROR visibility has no effect inside functions or block
8188
}
82-
struct Ts(pub u8);
89+
struct Ts(pub u8); //~ ERROR visibility has no effect inside functions or block
8390

8491
pub impl MarkerTr for .. {} //~ ERROR unnecessary visibility qualifier
92+
//~^ ERROR visibility has no effect inside functions or block
8593
pub impl Tr for S { //~ ERROR unnecessary visibility qualifier
94+
//~^ ERROR visibility has no effect inside functions or block
8695
pub fn f() {} //~ ERROR unnecessary visibility qualifier
96+
//~^ ERROR visibility has no effect inside functions or block
8797
pub const C: u8 = 0; //~ ERROR unnecessary visibility qualifier
98+
//~^ ERROR visibility has no effect inside functions or block
8899
pub type T = u8; //~ ERROR unnecessary visibility qualifier
100+
//~^ ERROR visibility has no effect inside functions or block
89101
}
90102
pub impl S { //~ ERROR unnecessary visibility qualifier
91-
pub fn f() {}
92-
pub const C: u8 = 0;
93-
// pub type T = u8;
103+
//~^ ERROR visibility has no effect inside functions or block
104+
pub fn f() {} //~ ERROR visibility has no effect inside functions or block
105+
pub const C: u8 = 0; //~ ERROR visibility has no effect inside functions or block
106+
// pub type T = u8; // ERROR visibility has no effect inside functions or block
94107
}
95108
pub extern "C" { //~ ERROR unnecessary visibility qualifier
96-
pub fn f();
97-
pub static St: u8;
109+
//~^ ERROR visibility has no effect inside functions or block
110+
pub fn f(); //~ ERROR visibility has no effect inside functions or block
111+
pub static St: u8; //~ ERROR visibility has no effect inside functions or block
98112
}
99113
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
pub use std::usize; //~ ERROR: visibility has no effect
13+
pub struct A; //~ ERROR: visibility has no effect
14+
pub enum B {} //~ ERROR: visibility has no effect
15+
pub trait C { //~ ERROR: visibility has no effect
16+
fn foo(&self) {}
17+
}
18+
impl A {
19+
pub fn foo(&self) {} //~ ERROR: visibility has no effect
20+
}
21+
22+
struct D {
23+
pub foo: isize, //~ ERROR: visibility has no effect
24+
}
25+
pub fn foo() {} //~ ERROR: visibility has no effect
26+
pub mod bar {} //~ ERROR: visibility has no effect
27+
}

0 commit comments

Comments
 (0)