Skip to content

Only emit one error for use foo::self; #42580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/E0429.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

use std::fmt::self; //~ ERROR E0429
//~^ ERROR E0432

fn main () {
}
5 changes: 2 additions & 3 deletions src/test/compile-fail/use-keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/test/compile-fail/use-mod-4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
use foo::self; //~ ERROR unresolved import `foo::self`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess if foo is invalid we should still have both errors?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it makes sense to improve errors in this area, all examples from #42559 should be legal anyway, I'll try to submit a PR somewhere after June 17.

//~^ ERROR `self` imports are only allowed within a { } list

use std::mem::self;
//~^ ERROR `self` imports are only allowed within a { } list

fn main() {}