Skip to content

Added long diagnostics for E0254. #26992

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 7 commits into from
Closed

Added long diagnostics for E0254. #26992

wants to merge 7 commits into from

Conversation

uatach
Copy link

@uatach uatach commented Jul 12, 2015

No description provided.

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

```
extern crate foo; // foo is a crate that exported its own symbol

use foo::*; // error, `foo::*` also resolves to `foo` already imported
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless I'm misunderstanding, I think you meant use foo here. The following example will compile:

// crate foo
pub struct Blub;
// some other program
extern crate foo
use foo::*;

fn main() {
  let _blub = Blub;
}

Copy link
Author

Choose a reason for hiding this comment

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

If you add pub mod foo; to the crate foo, it won't work.
That is what I meant by 'exported its own symbol', maybe I should change that?

// other program
extern crate foo;

use foo::*; // error, `foo::*` tries to bind `foo::foo` to `foo`
Copy link
Member

Choose a reason for hiding this comment

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

I would discourage reusing the same name foo for such totally different roles, unless it is strictly necessary for replicating this particular error diagnostic. Its okay for the example program to be a little bit longer, if it makes the example clearer. (Also, if I read this correctly, you are using the mod foo; form, but have not included the text of the associated foo.rs file that would hold the body of that module? That also seems overly difficult for the reader to understand; why not just put the definition of mod foo inline?)

Copy link
Member

Choose a reason for hiding this comment

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

(i'm investigating this now; I can see that the most trivial examples of duplicate imported symbols flag other error codes, so let me see if I can tease out exactly what it is about your example that matters)

Copy link
Member

Choose a reason for hiding this comment

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

Okay so here is what I think is a more direct example:

This works for any external crate, but I'll include a trivial one that provides zero exports. (But if you want to add a one line definition to it, that's fine, as long as its not named foo too.)

external crate foo.rs:

#![crate_type="lib"]

client code bar.rs:

extern crate foo; // this puts `foo` into the root type+module namespace

use inner_mod::foo; // this also tries to put `foo` in the same namespace

mod inner_mod {
    pub mod foo { }
}

And then one might note that this variant of bar.rs also has the same problem:

extern crate foo; // this puts `foo` into the root type+module namespace

use inner_mod::foo; // this also tries to put `foo` in the same namespace

mod inner_mod {
    pub type foo = i32;
}

Copy link
Member

Choose a reason for hiding this comment

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

(we could remove the foo.rs entirely by referring to a crate that is always available. For example by using core everywhere that foo occurs in my example. But its probably better to explicitly include the foo crate itself, even if it is a trivial crate with no exports.)

Copy link
Author

Choose a reason for hiding this comment

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

I agree that it's more direct but it doesn't make clear that an import from an external crate can cause this problem too (and I say this because, reading your code, I wouldn't be able to figure out that the code I was writing were correct and the external lib I was using that exported something weird.)
Still, I will do some rewriting, thanks.

@bors
Copy link
Collaborator

bors commented Jul 19, 2015

☔ The latest upstream changes (presumably #27111) made this pull request unmergeable. Please resolve the merge conflicts.

extern crate foo;

use inner_mod::foo; // error, both of these `use` declarations add a symbol
use another_mod::foo; // that conflicts with the external crate's symbol.
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure I would personally have put both of the examples errors into a single example file, since if you show it this way, then removing the extern crate foo; above actually fails to yield code that will compile (since these two imports are themselves in conflict).

The only reason that I included both examples in my write up to you is because you (I think) had included two distinct examples in your original draft.

I would strongly consider either putting in both as separate examples, or just removing the variant that uses mod inner_mod { pub mod foo { } } and instead just use the one that exports a type.

@Gankra
Copy link
Contributor

Gankra commented Jul 27, 2015

r? @Manishearth

@uatach
Copy link
Author

uatach commented Aug 11, 2015

I'm not sure, am I the one that must solve the conflicts?

@Manishearth
Copy link
Member

Yes, if you know how. Otherwise I can rebase it for you ocne you address review comments

There's an external crate and it, also, can have no exports as foo.rs:

```
#![crate_type="lib"]
Copy link
Member

Choose a reason for hiding this comment

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

No need for this code example, it just confuses the situation

@Manishearth
Copy link
Member

Any updates?

@alexcrichton
Copy link
Member

Closing due to inactivity, but feel free to resubmit with a rebase!

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.

8 participants