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

circular imports with globs #3352

Closed
jesse99 opened this issue Sep 2, 2012 · 18 comments
Closed

circular imports with globs #3352

jesse99 opened this issue Sep 2, 2012 · 18 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries P-low Low priority

Comments

@jesse99
Copy link
Contributor

jesse99 commented Sep 2, 2012

Given that a crate is the unit of compilation it seems both silly and annoying to not be able to have modules within a crate use each other.

If, for some reason, this is not fixed then the error message should be. It's currently "failed to resolve imports" which provides essentially no insight into where the problem is. Identifying a circular import given that does not sound like fun at all, especially in a large project where the circular imports could be indirect.

@pcwalton
Copy link
Contributor

pcwalton commented Sep 2, 2012

This will be fixed with the "use mod foo;" change.
On Sep 2, 2012 1:51 PM, "Jesse Jones" notifications@github.com wrote:

Given that a crate is the unit of compilation it seems both silly and
annoying to not be able to have modules within a crate use each other.

If, for some reason, this is not fixed then the error message should be.
It's currently "failed to resolve imports" which provides essentially no
insight into where the problem is. Identifying a circular import given that
does not sound like fun at all, especially in a large project where the
circular imports could be indirect.


Reply to this email directly or view it on GitHubhttps://github.com//issues/3352.

@brendanzab
Copy link
Member

I might have just struck this one:

#3409

@brendanzab
Copy link
Member

Yes, I've just confirmed that it was a circular import that was messing me up. I was using glob format like so:

mat.rs

// ...
import quat::*;
// ...

quat.rs

// ...
import mat::*;
// ...

I fixed it by changing it to:

mat.rs

// ...
import quat::quat;
// ...

quat.rs

// ...
import mat::{mat3, mat4};
// ...

As jesse99 states, the failed to resolve imports was a little obtuse, good to hear that you're working on a solution to the root of the problem.

@jesse99
Copy link
Contributor Author

jesse99 commented Sep 7, 2012

I've been fixing this by moving stuff around which is kind of painful. Better work around, I think, is to remove the use/imports causing problems and replace them with the qualified name. So instead of

use my_foo_module::*;

let type1 = foo;

do

let type1 = my_foo_module::foo;

Not ideal, but way better than trying to move stuff around to avoid circular imports.

@nikomatsakis
Copy link
Contributor

Not critical for 0.6; removing milestone

@graydon
Copy link
Contributor

graydon commented Apr 30, 2013

Here is a testcase. It seems to still be broken.

pub mod a {
    use b::*;
    pub fn foo() {
        bar();
    }
}

pub mod b {
    use a::*;
    pub fn bar() {
        foo();
    }
}

fn main() {
}

@catamorphism
Copy link
Contributor

I think "well-defined", not "feature-complete"; re-nominating.

@graydon
Copy link
Contributor

graydon commented Jun 20, 2013

accepted for well-defined milestone

@pnkfelix
Copy link
Member

pnkfelix commented Jul 2, 2013

linking to #6143 for unified tracking of resolve

@emberian
Copy link
Member

Triage bump; still relevant.

@brson
Copy link
Contributor

brson commented Apr 8, 2014

Afaict this is just about globs, which are already feature-gated and slated for neutering (#11870). Nominating for closing.

@pnkfelix
Copy link
Member

Graydon's example does not involved pub use globs at all, and still exhibits the bug. So this bug remains.

@pnkfelix
Copy link
Member

(keeping this where it is, 1.0, P-backcompat-lang)

@brson brson changed the title circular imports circular imports with globs Apr 10, 2014
@brson brson removed the I-nominated label Apr 10, 2014
aflatter added a commit to aflatter/rustsqlite that referenced this issue Apr 29, 2014
`pub use` globs will be removed from the language, but non-public globs
are still buggy, see: rust-lang/rust#3352
@pcwalton
Copy link
Contributor

All globs are feature gated. Nominated for no longer backcompat-lang.

@pnkfelix
Copy link
Member

Marking as P-low and taking off the milestone. (There are some questions to be resolved with the (potential re)design of globs, but for now as pcwalton said, it is feature gated.)

@pnkfelix pnkfelix removed this from the 1.0 milestone May 22, 2014
@frewsxcv
Copy link
Member

Visiting for triage: Can confirm this is still an issue

Rust playpen link: http://is.gd/jvqc02

@steveklabnik
Copy link
Member

re-nominating, globs are no longer gated

@steveklabnik
Copy link
Member

Traige: this is effectively a feature request for globs, and so I'm moving it to the RFCs repo: rust-lang/rfcs#889

jaisnan pushed a commit to jaisnan/rust-dev that referenced this issue Jul 29, 2024
Update Rust toolchain from nightly-2024-07-16 to nightly-2024-07-17
without any other source changes.
This is an automatically generated pull request. If any of the CI checks
fail, manual intervention is required. In such a case, review the
changes at https://github.com/rust-lang/rust from
rust-lang@24d2ac0
up to
rust-lang@032be6f.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries P-low Low priority
Projects
None yet
Development

No branches or pull requests