Skip to content

Closing assorted resolve bugs #13409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/liblibc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub use types::os::arch::c95::{c_ushort, clock_t, ptrdiff_t};
pub use types::os::arch::c95::{size_t, time_t};
pub use types::os::arch::c99::{c_longlong, c_ulonglong, intptr_t};
pub use types::os::arch::c99::{uintptr_t};
pub use types::os::arch::posix88::{dev_t, dirent_t, ino_t, mode_t};
pub use types::os::arch::posix88::{dev_t, ino_t, mode_t};
pub use types::os::arch::posix88::{off_t, pid_t, ssize_t};

pub use consts::os::c95::{_IOFBF, _IOLBF, _IONBF, BUFSIZ, EOF};
Expand Down
2 changes: 1 addition & 1 deletion src/libnative/io/file_win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ pub fn mkdir(p: &CString, _mode: io::FilePermission) -> IoResult<()> {
}

pub fn readdir(p: &CString) -> IoResult<~[Path]> {
use rt::global_heap::malloc_raw;
use std::rt::global_heap::malloc_raw;

fn prune(root: &CString, dirs: ~[Path]) -> ~[Path] {
let root = unsafe { CString::new(root.with_ref(|p| p), false) };
Expand Down
14 changes: 8 additions & 6 deletions src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,20 +297,22 @@ mod __test {

fn mk_std(cx: &TestCtxt) -> ast::ViewItem {
let id_test = token::str_to_ident("test");
let vi = if cx.is_test_crate {
ast::ViewItemUse(
let (vi, vis) = if cx.is_test_crate {
(ast::ViewItemUse(
vec!(@nospan(ast::ViewPathSimple(id_test,
path_node(vec!(id_test)),
ast::DUMMY_NODE_ID))))
ast::DUMMY_NODE_ID)))),
ast::Public)
} else {
ast::ViewItemExternCrate(id_test,
(ast::ViewItemExternCrate(id_test,
with_version("test"),
ast::DUMMY_NODE_ID)
ast::DUMMY_NODE_ID),
ast::Inherited)
};
ast::ViewItem {
node: vi,
attrs: Vec::new(),
vis: ast::Inherited,
vis: vis,
span: DUMMY_SP
}
}
Expand Down
32 changes: 25 additions & 7 deletions src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ impl NamespaceResult {
_ => false
}
}
fn is_unbound(&self) -> bool {
match *self {
UnboundResult => true,
_ => false
}
}
}

enum NameDefinition {
Expand Down Expand Up @@ -1976,6 +1982,7 @@ impl<'a> Resolver<'a> {
// the source of this name is different now
resolution.type_id.set(id);
resolution.value_id.set(id);
resolution.is_public.set(is_public);
}
None => {
debug!("(building import directive) creating new");
Expand Down Expand Up @@ -2286,10 +2293,12 @@ impl<'a> Resolver<'a> {
}
Some(child_name_bindings) => {
if child_name_bindings.defined_in_namespace(ValueNS) {
debug!("(resolving single import) found value binding");
value_result = BoundResult(containing_module,
*child_name_bindings);
}
if child_name_bindings.defined_in_namespace(TypeNS) {
debug!("(resolving single import) found type binding");
type_result = BoundResult(containing_module,
*child_name_bindings);
}
Expand Down Expand Up @@ -2320,6 +2329,7 @@ impl<'a> Resolver<'a> {
.borrow();
match import_resolutions.find(&source.name) {
None => {
debug!("(resolving single import) no import");
// The containing module definitely doesn't have an
// exported import with the name in question. We can
// therefore accurately report that the names are
Expand Down Expand Up @@ -2353,6 +2363,8 @@ impl<'a> Resolver<'a> {
return UnboundResult;
}
Some(target) => {
debug!("(resolving single import) found \
import in ns {:?}", namespace);
let id = import_resolution.id(namespace);
this.used_imports.insert((id, namespace));
return BoundResult(target.target_module,
Expand Down Expand Up @@ -2396,6 +2408,8 @@ impl<'a> Resolver<'a> {
.find_copy(&source.name) {
None => {} // Continue.
Some(module) => {
debug!("(resolving single import) found external \
module");
let name_bindings =
@Resolver::create_name_bindings_from_module(
module);
Expand Down Expand Up @@ -2442,8 +2456,7 @@ impl<'a> Resolver<'a> {
}
}

if import_resolution.value_target.borrow().is_none() &&
import_resolution.type_target.borrow().is_none() {
if value_result.is_unbound() && type_result.is_unbound() {
let msg = format!("unresolved import: there is no \
`{}` in `{}`",
token::get_ident(source),
Expand Down Expand Up @@ -2669,7 +2682,8 @@ impl<'a> Resolver<'a> {
match self.resolve_name_in_module(search_module,
name,
TypeNS,
name_search_type) {
name_search_type,
false) {
Failed => {
let segment_name = token::get_ident(name);
let module_name = self.module_to_str(search_module);
Expand Down Expand Up @@ -2977,7 +2991,8 @@ impl<'a> Resolver<'a> {
match self.resolve_name_in_module(search_module,
name,
namespace,
PathSearch) {
PathSearch,
true) {
Failed => {
// Continue up the search chain.
}
Expand Down Expand Up @@ -3141,7 +3156,8 @@ impl<'a> Resolver<'a> {
module_: @Module,
name: Ident,
namespace: Namespace,
name_search_type: NameSearchType)
name_search_type: NameSearchType,
allow_private_imports: bool)
-> ResolveResult<(Target, bool)> {
debug!("(resolving name in module) resolving `{}` in `{}`",
token::get_ident(name),
Expand Down Expand Up @@ -3172,7 +3188,9 @@ impl<'a> Resolver<'a> {

// Check the list of resolved imports.
match module_.import_resolutions.borrow().find(&name.name) {
Some(import_resolution) => {
Some(import_resolution) if allow_private_imports ||
import_resolution.is_public.get() => {

if import_resolution.is_public.get() &&
import_resolution.outstanding_references.get() != 0 {
debug!("(resolving name in module) import \
Expand All @@ -3193,7 +3211,7 @@ impl<'a> Resolver<'a> {
}
}
}
None => {} // Continue.
Some(..) | None => {} // Continue.
}

// Finally, search through external children.
Expand Down
1 change: 0 additions & 1 deletion src/libstd/io/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ macro_rules! iotest (
use io::process::*;
use unstable::running_on_valgrind;
use str;
use util;

fn f() $b

Expand Down
13 changes: 13 additions & 0 deletions src/test/auxiliary/issue-12612-1.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions src/test/auxiliary/issue-12612-2.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 24 additions & 0 deletions src/test/compile-fail/issue-12612.rs
Original file line number Diff line number Diff line change
@@ -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() {}

21 changes: 21 additions & 0 deletions src/test/compile-fail/issue-13404.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.

use a::f;
use b::f;
//~^ ERROR: unresolved import
//~^^ ERROR: failed to resolve import

mod a { pub fn f() {} }
mod b { }

fn main() {
f();
}
33 changes: 33 additions & 0 deletions src/test/compile-fail/resolve-priv-shadowing-pub.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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.

mod a {
pub fn foobar() -> int { 1 }
}

mod b {
pub fn foobar() -> int { 2 }
}

mod c {
// Technically the second use shadows the first, but in theory it should
// only be shadowed for this module. The implementation of resolve currently
// doesn't implement this, so this test is ensuring that using "c::foobar"
// is *not* getting b::foobar. Today it's an error, but perhaps one day it
// can correctly get a::foobar instead.
pub use a::foobar;
use b::foobar;
}

fn main() {
assert_eq!(c::foobar(), 1);
//~^ ERROR: unresolved name `c::foobar`
}

10 changes: 4 additions & 6 deletions src/test/run-pass/issue-11881.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
23 changes: 23 additions & 0 deletions src/test/run-pass/issue-12612.rs
Original file line number Diff line number Diff line change
@@ -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() {}