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

Updated metadata::creader::resolve_crate_deps to use the correct span #12146

Merged
merged 1 commit into from
Feb 18, 2014

Conversation

cmacknz
Copy link
Contributor

@cmacknz cmacknz commented Feb 10, 2014

Addresses FIXME described in issue #2404

@alexcrichton
Copy link
Member

I'm not sure that this solves the bug at hand. The problem here is that you're loading the dependency of an explicitly mentioned crate, but you then fail to load the dependency. As implemented, you'll get an error message that looks like:

extern mod extra; //~ ERROR: could not find crate for `std`

I agree that the span is probably pointing at the right location right now, but I think that the error message needs to be updated to fix the bug in question.

Additionally, this change should be accompanied with a compile-fail test that ensures that the message is printed at the right location.

@cmacknz
Copy link
Contributor Author

cmacknz commented Feb 12, 2014

@alexcrichton Since #2404 is pretty light on details do you have any suggestions as to how to set up a test case to reproduce the error I'm trying to fix? My understanding of how crates are resolved/loaded is a work in progress.

@alexcrichton
Copy link
Member

Try these steps:

  1. Compile crate A.
  2. Compile crate B, which depends on A.
  3. Remove crate A.
  4. Compile crate C which depends on B.

The 4th step should have a message saying that A couldn't be found which is a dependency of B with a span pointing at extern mod B;

@cmacknz
Copy link
Contributor Author

cmacknz commented Feb 12, 2014

Thanks. How should I modify the error message?

Before correcting the FIXME I get:

crateC.rs:1:1: 1:1 error: can't find crate for `crateA`
crateC.rs:1 extern mod crateB;
            ^

After:

crateC.rs:1:1: 1:19 error: can't find crate for `crateA`
crateC.rs:1 extern mod crateB;
            ^~~~~~~~~~~~~~~~~~

@alexcrichton
Copy link
Member

Something like:

crateC.rs:1:1: 1:19 error: can't find crate for `crateA`, which `crateB` depends on
crateC.rs:1 extern mod crateB;
            ^~~~~~~~~~~~~~~~~~

@cmacknz
Copy link
Contributor Author

cmacknz commented Feb 13, 2014

Error message is now as follows:

crateC.rs:1:1: 1:19 error: can't find crate for `crateA` which `extern mod crateB` depends on
crateC.rs:1 extern mod crateB;
            ^~~~~~~~~~~~~~~~~~

@alexcrichton
Copy link
Member

This seems to look quite similar to the original version, perhaps a forgotten force-push?

@cmacknz
Copy link
Contributor Author

cmacknz commented Feb 14, 2014

Sorry, should have said "Error message will be as follows".

I'm still trying to figure out the best way to write a test for this. That I need to compile two crates and then delete one of them requires the Makefile functionality from tests/run-make. However, that isn't compatible with the requirement that this is a compile-fail test.

Have any suggestions on this?

@alexcrichton
Copy link
Member

Oh sorry, I'd change extern mod crateB to just crateB, but otherwise that looks good to me!

As for testing, the usual compiletest infrastructure may not be good enough here, but you should be able to write a run-make test to do the fancy things. Sadly it's not as accurate with checking where the error is emitted, but you could always grep for line numbers which would just be a little fragile if it changed (but not too bad).

@cmacknz
Copy link
Contributor Author

cmacknz commented Feb 15, 2014

Changes are up now.

// except according to those terms.

extern mod crateB;
//~^ ERROR can't find crate for `crateA` which `crateB` depends on
Copy link
Member

Choose a reason for hiding this comment

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

Sadly ERROR directives are not parsed during the run-make tests. I would recommend storing the output of rustc and then invoking grep to make sure that it printed a vaguely correct message.

@cmacknz
Copy link
Contributor Author

cmacknz commented Feb 17, 2014

Updated to be syntax agnostic.

// Now resolve the crates referenced by this crate
let cnum_map = resolve_crate_deps(e, metadata.as_slice());
let cnum_map = resolve_crate_deps(e,
Some(root_crate.clone()),
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't have to clone() here.

@alexcrichton
Copy link
Member

Looks good to me, thanks!

Could you squash these commits together and make sure that Closes #2404 shows up in the commit message as well?

…. Clarified error message when an external crate's dependency is missing. Closes rust-lang#2404.
@cmacknz
Copy link
Contributor Author

cmacknz commented Feb 17, 2014

Done.

bors added a commit that referenced this pull request Feb 18, 2014
@bors bors closed this Feb 18, 2014
@bors bors merged commit 37bf97a into rust-lang:master Feb 18, 2014
@cmacknz cmacknz deleted the issue-2404 branch February 18, 2014 01:55
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jan 25, 2024
…s-with-dashes, r=Manishearth

Fix [`multiple_crate_versions`] to correctly normalize package names to avoid missing the local one

Fixes rust-lang#12145

changelog: [`multiple_crate_versions`]: correctly normalize package name
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.

3 participants