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

Import suggestions suggest inserting imports in the wrong place #42835

Closed
nrc opened this issue Jun 22, 2017 · 2 comments · Fixed by #43929
Closed

Import suggestions suggest inserting imports in the wrong place #42835

nrc opened this issue Jun 22, 2017 · 2 comments · Fixed by #43929
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@nrc
Copy link
Member

nrc commented Jun 22, 2017

For this kind of error:

pub mod foo {
    struct Foo;
}

fn main() {
    let a = Foo;
}

We get an error like

error[E0425]: cannot find value `Foo` in this scope
  --> <anon>:10:14
   |
10 |     let a = Foo;
   |             ^^^ not found in this scope
   |
help: possible candidate is found in another module, you can import it into scope
   | use foo::Foo;

Which is good. But if you put this whole example in a submodule and then look at the json error, the suggestion is add the import to the enclosing module, not the submodule, which is incorrect.

cc #42823, @oli-obk

@nrc nrc added the A-diagnostics Area: Messages for errors, warnings, and lints label Jun 22, 2017
@nrc
Copy link
Member Author

nrc commented Jun 22, 2017

And even in top level module the location for insertion is not great. I'm not sure how it chooses, it seems to change depending on the module layout. In some cases it inserts it at the start of the file (after any comments), which then breaks any inner attributes. IMO, it should find the last use in the current module and insert it after that. If there are no uses, then it should insert after any extern crate or mod statements and after any inner attributes.

@oli-obk
Copy link
Contributor

oli-obk commented Jun 22, 2017

The impl simply asks the current module for its inner span. I can check if it's also possible to get the AST of the module, so we can iterate through its items to find a good spot

@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
bors added a commit that referenced this issue Aug 21, 2017
Improve placement of `use` suggestions

r? @nrc

cc @estebank @Mark-Simulacrum

fixes #42835
fixes #42548
fixes #43769
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 C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants