Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4bf5c99

Browse files
committedJun 10, 2017
Auto merge of #42580 - tommyip:import-error, r=petrochenkov
Only emit one error for `use foo::self;` Currently `use foo::self;` would emit both E0429 and E0432. This commit silence the latter one (assuming `foo` is a valid module). Fixes #42559
2 parents b7613f8 + b89db83 commit 4bf5c99

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed
 

‎src/librustc_resolve/resolve_imports.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,16 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
482482
if let Some(err) = self.finalize_import(import) {
483483
errors = true;
484484

485+
if let SingleImport { source, ref result, .. } = import.subclass {
486+
if source.name == "self" {
487+
// Silence `unresolved import` error if E0429 is already emitted
488+
match result.value_ns.get() {
489+
Err(Determined) => continue,
490+
_ => {},
491+
}
492+
}
493+
}
494+
485495
// If the error is a single failed import then create a "fake" import
486496
// resolution for it so that later resolve stages won't complain.
487497
self.import_dummy_binding(import);

‎src/test/compile-fail/E0429.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use std::fmt::self; //~ ERROR E0429
12-
//~^ ERROR E0432
1312

1413
fn main () {
1514
}

‎src/test/compile-fail/use-keyword.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313

1414
mod a {
1515
mod b {
16-
use self as A; //~ ERROR `self` imports are only allowed within a { } list
17-
//~^ ERROR unresolved import `self` [E0432]
18-
//~| no `self` in the root
16+
use self as A;
17+
//~^ ERROR `self` imports are only allowed within a { } list
1918
use super as B;
2019
//~^ ERROR unresolved import `super` [E0432]
2120
//~| no `super` in the root

‎src/test/compile-fail/use-mod-4.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@
1111
use foo::self; //~ ERROR unresolved import `foo::self`
1212
//~^ ERROR `self` imports are only allowed within a { } list
1313

14+
use std::mem::self;
15+
//~^ ERROR `self` imports are only allowed within a { } list
16+
1417
fn main() {}

0 commit comments

Comments
 (0)
Please sign in to comment.