Skip to content

Commit

Permalink
rustc: Don't succeed on shadowed nonexistent import
Browse files Browse the repository at this point in the history
Previously resolve was checking the "import resolution" for whether an import
had succeeded or not, but this was the same structure filled in by a previous
import if a name is shadowed. Instead, this alters resolve to consult the local
resolve state (as opposed to the shared one) to test whether an import succeeded
or not.

Closes rust-lang#13404
  • Loading branch information
alexcrichton committed Apr 10, 2014
1 parent b36b2e8 commit 015a9c5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
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
9 changes: 7 additions & 2 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 @@ -2449,8 +2455,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
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();
}

0 comments on commit 015a9c5

Please sign in to comment.