提交 b5a110c7 编写于 作者: B bors

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
......@@ -73,7 +73,7 @@ fn fold_crate(&mut self, crate: ast::Crate) -> ast::Crate {
with_version("std"),
ast::DUMMY_NODE_ID),
attrs: ~[],
vis: ast::Private,
vis: ast::Inherited,
span: DUMMY_SP
}];
......@@ -83,7 +83,7 @@ fn fold_crate(&mut self, crate: ast::Crate) -> ast::Crate {
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 @@ fn fold_crate(&mut self, crate: ast::Crate) -> ast::Crate {
with_version("rustuv"),
ast::DUMMY_NODE_ID),
attrs: ~[],
vis: ast::Private,
vis: ast::Inherited,
span: DUMMY_SP
});
}
......@@ -147,7 +147,7 @@ fn fold_mod(&mut self, module: &ast::Mod) -> ast::Mod {
let vi2 = ast::ViewItem {
node: ast::ViewItemUse(~[vp]),
attrs: ~[],
vis: ast::Private,
vis: ast::Inherited,
span: DUMMY_SP,
};
......
......@@ -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
}
}
......
......@@ -839,6 +839,32 @@ fn visit_fn(&mut self, fk: &visit::FnKind, fd: &ast::FnDecl,
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 {
......
......@@ -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",
......
// 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;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册