about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-01-18 13:01:47 -0800
committerbors <bors@rust-lang.org>2014-01-18 13:01:47 -0800
commitb5a110c7feed3a87a0daee1e829fa0cb03026a4e (patch)
tree3844da3af36ea7c9932b6074348c923e333aa51f
parentc5d05acf392afc9c480ee7b23f2132c1a110de8c (diff)
parent4a78364d491ee2d3a49f4ed5e62f63cd5748d898 (diff)
downloadrust-b5a110c7feed3a87a0daee1e829fa0cb03026a4e.tar.gz
rust-b5a110c7feed3a87a0daee1e829fa0cb03026a4e.zip
auto merge of #11607 : alexcrichton/rust/issue-9957, r=cmr
For `use` statements, this means disallowing qualifiers when in functions and
disallowing `priv` outside of functions.

For `extern mod` statements, this means disallowing everything everywhere. It
may have been envisioned for `pub extern mod foo` to be a thing, but it
currently doesn't do anything (resolve doesn't pick it up), so better to err on
the side of forwards-compatibility and forbid it entirely for now.

Closes #9957
-rw-r--r--src/librustc/front/std_inject.rs8
-rw-r--r--src/librustc/front/test.rs2
-rw-r--r--src/librustc/middle/privacy.rs26
-rw-r--r--src/libsyntax/ext/quote.rs2
-rw-r--r--src/test/compile-fail/issue-9957.rs23
5 files changed, 55 insertions, 6 deletions
diff --git a/src/librustc/front/std_inject.rs b/src/librustc/front/std_inject.rs
index f2bc03b21ba..c1c31dc310e 100644
--- a/src/librustc/front/std_inject.rs
+++ b/src/librustc/front/std_inject.rs
@@ -73,7 +73,7 @@ impl fold::Folder for StandardLibraryInjector {
                                          with_version("std"),
                                          ast::DUMMY_NODE_ID),
             attrs: ~[],
-            vis: ast::Private,
+            vis: ast::Inherited,
             span: DUMMY_SP
         }];
 
@@ -83,7 +83,7 @@ impl fold::Folder for StandardLibraryInjector {
                                              with_version("green"),
                                              ast::DUMMY_NODE_ID),
                 attrs: ~[],
-                vis: ast::Private,
+                vis: ast::Inherited,
                 span: DUMMY_SP
             });
             vis.push(ast::ViewItem {
@@ -91,7 +91,7 @@ impl fold::Folder for StandardLibraryInjector {
                                              with_version("rustuv"),
                                              ast::DUMMY_NODE_ID),
                 attrs: ~[],
-                vis: ast::Private,
+                vis: ast::Inherited,
                 span: DUMMY_SP
             });
         }
@@ -147,7 +147,7 @@ impl fold::Folder for StandardLibraryInjector {
         let vi2 = ast::ViewItem {
             node: ast::ViewItemUse(~[vp]),
             attrs: ~[],
-            vis: ast::Private,
+            vis: ast::Inherited,
             span: DUMMY_SP,
         };
 
diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs
index 95bf171562d..0714c1c620b 100644
--- a/src/librustc/front/test.rs
+++ b/src/librustc/front/test.rs
@@ -301,7 +301,7 @@ fn mk_std(cx: &TestCtxt) -> ast::ViewItem {
     ast::ViewItem {
         node: vi,
         attrs: ~[],
-        vis: ast::Public,
+        vis: ast::Inherited,
         span: DUMMY_SP
     }
 }
diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs
index 767ca7fcc70..4318fde9b3a 100644
--- a/src/librustc/middle/privacy.rs
+++ b/src/librustc/middle/privacy.rs
@@ -839,6 +839,32 @@ impl Visitor<()> for SanePrivacyVisitor {
         visit::walk_fn(self, fk, fd, b, s, n, ());
         self.in_fn = orig_in_fn;
     }
+
+    fn visit_view_item(&mut self, i: &ast::ViewItem, _: ()) {
+        match i.vis {
+            ast::Inherited => {}
+            ast::Private => {
+                self.tcx.sess.span_err(i.span, "unnecessary visibility \
+                                                qualifier");
+            }
+            ast::Public => {
+                if self.in_fn {
+                    self.tcx.sess.span_err(i.span, "unnecessary `pub`, imports \
+                                                    in functions are never \
+                                                    reachable");
+                } else {
+                    match i.node {
+                        ast::ViewItemExternMod(..) => {
+                            self.tcx.sess.span_err(i.span, "`pub` visibility \
+                                                            is not allowed");
+                        }
+                        _ => {}
+                    }
+                }
+            }
+        }
+        visit::walk_view_item(self, i, ());
+    }
 }
 
 impl SanePrivacyVisitor {
diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs
index 27f41356a4b..8b5e6872839 100644
--- a/src/libsyntax/ext/quote.rs
+++ b/src/libsyntax/ext/quote.rs
@@ -648,7 +648,7 @@ fn expand_wrapper(cx: &ExtCtxt,
                   sp: Span,
                   cx_expr: @ast::Expr,
                   expr: @ast::Expr) -> @ast::Expr {
-    let uses = ~[ cx.view_use_glob(sp, ast::Public,
+    let uses = ~[ cx.view_use_glob(sp, ast::Inherited,
                                    ids_ext(~[~"syntax",
                                              ~"ext",
                                              ~"quote",
diff --git a/src/test/compile-fail/issue-9957.rs b/src/test/compile-fail/issue-9957.rs
new file mode 100644
index 00000000000..b8292d61752
--- /dev/null
+++ b/src/test/compile-fail/issue-9957.rs
@@ -0,0 +1,23 @@
+// Copyright 2014 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.
+
+pub extern mod std; //~ ERROR: `pub` visibility is not allowed
+priv extern mod std; //~ ERROR: unnecessary visibility qualifier
+extern mod std;
+
+pub use std::bool;
+priv use std::bool; //~ ERROR: unnecessary visibility qualifier
+use std::bool;
+
+fn main() {
+    pub use std::bool; //~ ERROR: imports in functions are never reachable
+    priv use std::bool; //~ ERROR: unnecessary visibility qualifier
+    use std::bool;
+}