mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-04 19:12:50 +00:00
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
This commit is contained in:
commit
b5a110c7fe
@ -73,7 +73,7 @@ impl fold::Folder for StandardLibraryInjector {
|
|||||||
with_version("std"),
|
with_version("std"),
|
||||||
ast::DUMMY_NODE_ID),
|
ast::DUMMY_NODE_ID),
|
||||||
attrs: ~[],
|
attrs: ~[],
|
||||||
vis: ast::Private,
|
vis: ast::Inherited,
|
||||||
span: DUMMY_SP
|
span: DUMMY_SP
|
||||||
}];
|
}];
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ impl fold::Folder for StandardLibraryInjector {
|
|||||||
with_version("green"),
|
with_version("green"),
|
||||||
ast::DUMMY_NODE_ID),
|
ast::DUMMY_NODE_ID),
|
||||||
attrs: ~[],
|
attrs: ~[],
|
||||||
vis: ast::Private,
|
vis: ast::Inherited,
|
||||||
span: DUMMY_SP
|
span: DUMMY_SP
|
||||||
});
|
});
|
||||||
vis.push(ast::ViewItem {
|
vis.push(ast::ViewItem {
|
||||||
@ -91,7 +91,7 @@ impl fold::Folder for StandardLibraryInjector {
|
|||||||
with_version("rustuv"),
|
with_version("rustuv"),
|
||||||
ast::DUMMY_NODE_ID),
|
ast::DUMMY_NODE_ID),
|
||||||
attrs: ~[],
|
attrs: ~[],
|
||||||
vis: ast::Private,
|
vis: ast::Inherited,
|
||||||
span: DUMMY_SP
|
span: DUMMY_SP
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ impl fold::Folder for StandardLibraryInjector {
|
|||||||
let vi2 = ast::ViewItem {
|
let vi2 = ast::ViewItem {
|
||||||
node: ast::ViewItemUse(~[vp]),
|
node: ast::ViewItemUse(~[vp]),
|
||||||
attrs: ~[],
|
attrs: ~[],
|
||||||
vis: ast::Private,
|
vis: ast::Inherited,
|
||||||
span: DUMMY_SP,
|
span: DUMMY_SP,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -301,7 +301,7 @@ fn mk_std(cx: &TestCtxt) -> ast::ViewItem {
|
|||||||
ast::ViewItem {
|
ast::ViewItem {
|
||||||
node: vi,
|
node: vi,
|
||||||
attrs: ~[],
|
attrs: ~[],
|
||||||
vis: ast::Public,
|
vis: ast::Inherited,
|
||||||
span: DUMMY_SP
|
span: DUMMY_SP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -839,6 +839,32 @@ impl Visitor<()> for SanePrivacyVisitor {
|
|||||||
visit::walk_fn(self, fk, fd, b, s, n, ());
|
visit::walk_fn(self, fk, fd, b, s, n, ());
|
||||||
self.in_fn = orig_in_fn;
|
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 {
|
impl SanePrivacyVisitor {
|
||||||
|
@ -648,7 +648,7 @@ fn expand_wrapper(cx: &ExtCtxt,
|
|||||||
sp: Span,
|
sp: Span,
|
||||||
cx_expr: @ast::Expr,
|
cx_expr: @ast::Expr,
|
||||||
expr: @ast::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",
|
ids_ext(~[~"syntax",
|
||||||
~"ext",
|
~"ext",
|
||||||
~"quote",
|
~"quote",
|
||||||
|
23
src/test/compile-fail/issue-9957.rs
Normal file
23
src/test/compile-fail/issue-9957.rs
Normal file
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user