Skip to content
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

add name bindings for bad imports #31209

Closed
nrc opened this issue Jan 26, 2016 · 8 comments
Closed

add name bindings for bad imports #31209

nrc opened this issue Jan 26, 2016 · 8 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically

Comments

@nrc
Copy link
Member

nrc commented Jan 26, 2016

e.g.,

use foo::bar;

fn main() {
    bar();
}

Assuming bar doesn't exist, we signal two errors here - one on the use and one on the call. We should insert a dummy definition for bar so we don't signal the second error.

Note that this is somewhat fixing a regression caused by #31065

@nrc nrc added A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically labels Jan 26, 2016
@dirk
Copy link
Contributor

dirk commented Jan 27, 2016

@nrc: Trying to understand where the dummy definition inserting should occur. From looking at the linked PR and librustc_resolve, it looks like the insertion could occur in/around resolve_import_for_module. Is this a good guess, or should I be looking elsewhere?

@nrc
Copy link
Member Author

nrc commented Jan 27, 2016

Should probably happen in this function: https://dxr.mozilla.org/rust/source/src/librustc_resolve/lib.rs#1861-1888

Or possibly one of its callers.

@dirk
Copy link
Contributor

dirk commented Jan 27, 2016

@nrc: Ohhh, that definitely seems like the right place. I'll give this a shot tomorrow; thanks for pointing me in the right direction!

@dirk
Copy link
Contributor

dirk commented Jan 29, 2016

@nrc: If I've read things correctly, it looks like that Resolver::report_unresolved_imports function won't have the path that caused the import error in question. It seems like where paths get determined to be incorrect is happening in ImportResolver::resolve_imports.

Both of those paths, however, converge on resolve_struct_error, so I'm guessing perhaps the match branch for ResolutionError::UnresolvedImport would be the correct place to see if there's a path determined and then, if there is, create the dummy definition(s) for any names on the tail of the Path. How does that sound?

@nrc
Copy link
Member Author

nrc commented Jan 31, 2016

Every error ends up converging in resolve_struct_error, so I am wary about putting anything there except for formatting error messages, etc. I would add some code to resolve_imports, you might want to factor that into a function if it is complex or repeated.

@dirk
Copy link
Contributor

dirk commented Jan 31, 2016

@nrc: Understood, thanks. I'll give that a shot. 😄

bors added a commit that referenced this issue Feb 3, 2016
…=nrc

WIP implementation of #31209.

The goal is to insert fake/dummy definitions for names that we failed to import so that later resolver stages won't complain about them.
@dirk
Copy link
Contributor

dirk commented Feb 6, 2016

@nrc: Can this be closed now that #31338 is merged?

@nrc
Copy link
Member Author

nrc commented Feb 8, 2016

Closed by #31338

@nrc nrc closed this as completed Feb 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically
Projects
None yet
Development

No branches or pull requests

2 participants