diff options
| author | bors <bors@rust-lang.org> | 2017-06-10 21:35:31 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-06-10 21:35:31 +0000 |
| commit | 4bf5c99afc75f411a4e064150781eefc749c10df (patch) | |
| tree | 19279906f7615fac487662fb27f3f43832ff1084 | |
| parent | b7613f82814e803bf75c074ae4e50a584fee3e70 (diff) | |
| parent | b89db83e6c6dd8186875188de049057d9743ba8a (diff) | |
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
| -rw-r--r-- | src/librustc_resolve/resolve_imports.rs | 10 | ||||
| -rw-r--r-- | src/test/compile-fail/E0429.rs | 1 | ||||
| -rw-r--r-- | src/test/compile-fail/use-keyword.rs | 5 | ||||
| -rw-r--r-- | src/test/compile-fail/use-mod-4.rs | 3 |
4 files changed, 15 insertions, 4 deletions
diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index a892f9df6a6..405b2ed6ba9 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -482,6 +482,16 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { if let Some(err) = self.finalize_import(import) { errors = true; + if let SingleImport { source, ref result, .. } = import.subclass { + if source.name == "self" { + // Silence `unresolved import` error if E0429 is already emitted + match result.value_ns.get() { + Err(Determined) => continue, + _ => {}, + } + } + } + // If the error is a single failed import then create a "fake" import // resolution for it so that later resolve stages won't complain. self.import_dummy_binding(import); diff --git a/src/test/compile-fail/E0429.rs b/src/test/compile-fail/E0429.rs index a7d19744f3f..f1cad200be6 100644 --- a/src/test/compile-fail/E0429.rs +++ b/src/test/compile-fail/E0429.rs @@ -9,7 +9,6 @@ // except according to those terms. use std::fmt::self; //~ ERROR E0429 - //~^ ERROR E0432 fn main () { } diff --git a/src/test/compile-fail/use-keyword.rs b/src/test/compile-fail/use-keyword.rs index 6df20d414a7..aff54f18c19 100644 --- a/src/test/compile-fail/use-keyword.rs +++ b/src/test/compile-fail/use-keyword.rs @@ -13,9 +13,8 @@ mod a { mod b { - use self as A; //~ ERROR `self` imports are only allowed within a { } list - //~^ ERROR unresolved import `self` [E0432] - //~| no `self` in the root + use self as A; + //~^ ERROR `self` imports are only allowed within a { } list use super as B; //~^ ERROR unresolved import `super` [E0432] //~| no `super` in the root diff --git a/src/test/compile-fail/use-mod-4.rs b/src/test/compile-fail/use-mod-4.rs index 146d37f41d6..f102a68c2c5 100644 --- a/src/test/compile-fail/use-mod-4.rs +++ b/src/test/compile-fail/use-mod-4.rs @@ -11,4 +11,7 @@ use foo::self; //~ ERROR unresolved import `foo::self` //~^ ERROR `self` imports are only allowed within a { } list +use std::mem::self; +//~^ ERROR `self` imports are only allowed within a { } list + fn main() {} |
