Skip to content

Commit 4bf5c99

Browse files
committed
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

+10
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

-1
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

+2-3
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

+3
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)