Skip to content

Commit df533c6

Browse files
committed
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
1 parent 83d2c0b commit df533c6

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

src/liblibc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub use types::os::arch::c95::{c_ushort, clock_t, ptrdiff_t};
146146
pub use types::os::arch::c95::{size_t, time_t};
147147
pub use types::os::arch::c99::{c_longlong, c_ulonglong, intptr_t};
148148
pub use types::os::arch::c99::{uintptr_t};
149-
pub use types::os::arch::posix88::{dev_t, dirent_t, ino_t, mode_t};
149+
pub use types::os::arch::posix88::{dev_t, ino_t, mode_t};
150150
pub use types::os::arch::posix88::{off_t, pid_t, ssize_t};
151151

152152
pub use consts::os::c95::{_IOFBF, _IOLBF, _IONBF, BUFSIZ, EOF};

src/librustc/middle/resolve.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ impl NamespaceResult {
144144
_ => false
145145
}
146146
}
147+
fn is_unbound(&self) -> bool {
148+
match *self {
149+
UnboundResult => true,
150+
_ => false
151+
}
152+
}
147153
}
148154

149155
enum NameDefinition {
@@ -2449,8 +2455,7 @@ impl<'a> Resolver<'a> {
24492455
}
24502456
}
24512457

2452-
if import_resolution.value_target.borrow().is_none() &&
2453-
import_resolution.type_target.borrow().is_none() {
2458+
if value_result.is_unbound() && type_result.is_unbound() {
24542459
let msg = format!("unresolved import: there is no \
24552460
`{}` in `{}`",
24562461
token::get_ident(source),

src/test/compile-fail/issue-13404.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use a::f;
12+
use b::f;
13+
//~^ ERROR: unresolved import
14+
//~^^ ERROR: failed to resolve import
15+
16+
mod a { pub fn f() {} }
17+
mod b { }
18+
19+
fn main() {
20+
f();
21+
}

0 commit comments

Comments
 (0)