rustc: Disallow importing through use statements
Resolve is currently erroneously allowing imports through private `use`
statements in some circumstances, even across module boundaries. For example,
this code compiles successfully today:
use std::c_str;
mod test {
use c_str::CString;
}
This should not be allowed because it was explicitly decided that private `use`
statements are purely bringing local names into scope, they are not
participating further in name resolution.
As a consequence of this patch, this code, while valid today, is now invalid:
mod test {
use std::c_str;
unsafe fn foo() {
::test::c_str::CString::new(0 as *u8, false);
}
}
While plausibly acceptable, I found it to be more consistent if private imports
were only considered candidates to resolve the first component in a path, and no
others.
Closes #12612
This commit is contained in:
parent
0bf4e900d4
commit
83d2c0b8a6
8 changed files with 101 additions and 18 deletions
13
src/test/auxiliary/issue-12612-1.rs
Normal file
13
src/test/auxiliary/issue-12612-1.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// 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 mod bar {
|
||||
pub fn foo() {}
|
||||
}
|
||||
11
src/test/auxiliary/issue-12612-2.rs
Normal file
11
src/test/auxiliary/issue-12612-2.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
// 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 fn baz() {}
|
||||
24
src/test/compile-fail/issue-12612.rs
Normal file
24
src/test/compile-fail/issue-12612.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// 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.
|
||||
|
||||
// aux-build:issue-12612-1.rs
|
||||
|
||||
extern crate foo = "issue-12612-1";
|
||||
|
||||
use foo::bar;
|
||||
|
||||
mod test {
|
||||
use bar::foo;
|
||||
//~^ ERROR: unresolved import
|
||||
//~^^ ERROR: failed to resolve import
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
||||
|
|
@ -8,13 +8,11 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
extern crate ser = "serialize";
|
||||
extern crate serialize;
|
||||
|
||||
use serialize = self::ser;
|
||||
//necessary for deriving(Encodable)
|
||||
use ser::{Encodable, Encoder};
|
||||
use ser::json;
|
||||
use ser::ebml::writer;
|
||||
use serialize::{Encodable, Encoder};
|
||||
use serialize::json;
|
||||
use serialize::ebml::writer;
|
||||
use std::io::MemWriter;
|
||||
use std::str::from_utf8_owned;
|
||||
|
||||
|
|
|
|||
23
src/test/run-pass/issue-12612.rs
Normal file
23
src/test/run-pass/issue-12612.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.
|
||||
|
||||
// aux-build:issue-12612-1.rs
|
||||
// aux-build:issue-12612-2.rs
|
||||
|
||||
extern crate foo = "issue-12612-1";
|
||||
extern crate bar = "issue-12612-2";
|
||||
|
||||
use foo::bar;
|
||||
|
||||
mod test {
|
||||
use bar::baz;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue