Skip to content

Commit 823e185

Browse files
committed
Suggest only if resolution was previously resolved
1 parent cd692cc commit 823e185

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/librustc_resolve/resolve_imports.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,19 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
639639
let names = resolutions.iter().filter_map(|(&(ref i, _), resolution)| {
640640
if *i == ident { return None; } // Never suggest the same name
641641
match *resolution.borrow() {
642-
NameResolution { binding: Some(_), .. } => Some(&i.name),
642+
NameResolution { binding: Some(name_binding), .. } => {
643+
match name_binding.kind {
644+
NameBindingKind::Import { binding, .. } => {
645+
match binding.kind {
646+
// Never suggest the name that has binding error
647+
// i.e. the name that cannot be previously resolved
648+
NameBindingKind::Def(Def::Err) => return None,
649+
_ => Some(&i.name),
650+
}
651+
},
652+
_ => Some(&i.name),
653+
}
654+
},
643655
NameResolution { single_imports: SingleImports::None, .. } => None,
644656
_ => Some(&i.name),
645657
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2017 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 Foo;
12+
13+
use Foo1;
14+
15+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0432]: unresolved import `Foo`
2+
--> $DIR/issue-38054-do-not-show-unresolved-names.rs:11:5
3+
|
4+
11 | use Foo;
5+
| ^^^ no `Foo` in the root
6+
7+
error[E0432]: unresolved import `Foo1`
8+
--> $DIR/issue-38054-do-not-show-unresolved-names.rs:13:5
9+
|
10+
13 | use Foo1;
11+
| ^^^^ no `Foo1` in the root
12+
13+
error: aborting due to 2 previous errors
14+

0 commit comments

Comments
 (0)