rustc: Don't succeed on shadowed nonexistent import

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 #13404
This commit is contained in:
Alex Crichton 2014-04-08 15:03:29 -07:00
parent 83d2c0b8a6
commit df533c6e87
3 changed files with 29 additions and 3 deletions

View File

@ -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::c95::{size_t, time_t};
pub use types::os::arch::c99::{c_longlong, c_ulonglong, intptr_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::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 types::os::arch::posix88::{off_t, pid_t, ssize_t};
pub use consts::os::c95::{_IOFBF, _IOLBF, _IONBF, BUFSIZ, EOF}; pub use consts::os::c95::{_IOFBF, _IOLBF, _IONBF, BUFSIZ, EOF};

View File

@ -144,6 +144,12 @@ impl NamespaceResult {
_ => false _ => false
} }
} }
fn is_unbound(&self) -> bool {
match *self {
UnboundResult => true,
_ => false
}
}
} }
enum NameDefinition { enum NameDefinition {
@ -2449,8 +2455,7 @@ impl<'a> Resolver<'a> {
} }
} }
if import_resolution.value_target.borrow().is_none() && if value_result.is_unbound() && type_result.is_unbound() {
import_resolution.type_target.borrow().is_none() {
let msg = format!("unresolved import: there is no \ let msg = format!("unresolved import: there is no \
`{}` in `{}`", `{}` in `{}`",
token::get_ident(source), token::get_ident(source),

View File

@ -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();
}