Skip to content

Suggest possible fix for missing library link #5729

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

Closed
wants to merge 2 commits into from

Conversation

hellertime
Copy link

I'm attempting to learn to write programs using Rust. One problem I encountered early on was errors about failed imports due to unresolved names. The problem was I overlooked the need to declare the link to std before importing names into my module.

I thought rustc could use a more helpful diagnostic message when it encounters this issue, so I went ahead and implemented a reference fix. Hopefully the message will be useful to future Rust programmers.

@hellertime
Copy link
Author

So I've built a small test for this case, but I'm not entirely sure how to set it up for the test runner. The docs say that using error-pattern: ... is frowned upon and instead to make use of //~ ERROR comments. However, I am reporting my message as a note, should I still use an //~ ERROR comment?

The documentation on this matter is rather thin. At least any documentation I have found. Pointers to more relevant info would be welcome.

I'm attempting to learn to write programs using Rust. One problem I
encountered early on was errors about failed imports due to unre-
solved names. The problem was I overlooked the need to declare the
link to `std` before importing names into my module.

I thought `rustc` could use a more helpful diagnostic message when
it encounters this issue, so I went ahead and implemented a refer-
ence fix. Hopefully the message will be useful to future Rust prog-
rammers.
@hellertime
Copy link
Author

I cleaned up the history of this pull request, but it seems that comments are attached to the history as well -- which I wasn't aware was the case. So apologies for screwing up the comment history of this request.

For future reference, is it acceptable to rewrite pull request history, or would it be preferred to close out a pull request and open a new one with the rewritten history?

@jdm
Copy link
Contributor

jdm commented Apr 6, 2013

Rewritten is fine.

@kud1ing
Copy link

kud1ing commented Apr 6, 2013

Good idea

@hellertime
Copy link
Author

Thanks. I wasn't sure if note_span is the best approach to this. Ideally there could be multiline messages output much like GHC's warning format. I've see some wrapped comments in the source but the output isn't formatted nicely. However enhancing the diagnostic formatter is a project unto itself.

@bstrie
Copy link
Contributor

bstrie commented Apr 9, 2013

Will this suggest that people do extern mod foo; in the cases where what they really want is just mod foo; ? Is the same code path used for each?

@hellertime
Copy link
Author

I'm still new enough to rust that I need to ask if you could provide an example of such a case, I can certainly test it.

@brson
Copy link
Contributor

brson commented Apr 16, 2013

Per @bstrie , this seems like it could invoke additional confusion.

e.g. if you write

mod foo {
    mod bar {
        use baz::*;
    }
    mod baz {
    }
}

It will suggest you extern mod baz, but you really probably wanted `use super::baz::*.

Also:

mod foo {
   use std::*;
}

rustc will suggest you add extern mod std, so you write

mod foo {
    extern mod std;
    use std::*;
}

That of course doesn't work because use searches from the top level.

If we're going to suggest extern mod foo it would be pretty easy to first search for a crate matching foo using metadata::loader::find_library_crate.

@brson
Copy link
Contributor

brson commented May 10, 2013

Ok, I think this branch needs a little more work, but this seems like a useful idea so I opened #6379 on this subject. Closing for now.

@brson brson closed this May 10, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Aug 28, 2020
Add a cast to the suggestion when the return expression has adjustments.
These adjustments are lost when the suggestion is applied.

This is similar to the problem in issue rust-lang#4437.

Closes rust-lang#5729
flip1995 pushed a commit to flip1995/rust that referenced this pull request Aug 28, 2020
Fix `let_and_return` bad suggestion

Add a cast to the suggestion when the return expression has adjustments.
These adjustments are lost when the suggestion is applied.

This is similar to the problem in issue rust-lang#4437.

Closes rust-lang#5729

changelog: Fix `let_and_return` bad suggestion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants