Skip to content

Reevaluate extern mod as syntax for importing crates. #9880

Closed

Description

@brson

It's not that well loved. It doesn't have anything to do with other uses of extern, and lexically it must be written in a different position than other extern things.

Activity

  1. brson commented on Oct 15, 2013

    @brson
    ContributorAuthor

    Nominating.

  2. catamorphism commented on Oct 15, 2013

    @catamorphism
    Contributor

    +1. I always feel embarrassed when I have to explain this to someone.

  3. Kimundi commented on Oct 16, 2013

    @Kimundi
    Contributor

    The mod part is also confusing, as it doesn't declare a new module, but rather create an import of an external binaries crate root.

    For example, this creates two interchangeable paths to the same module tree:

    extern mod extra;
    mod foo {
        extern mod extra;
    }
    

    While this creates two distinct modules:

    mod extra;
    mod foo {
        mod extra;
    }
    
  4. catamorphism commented on Oct 17, 2013

    @catamorphism
    Contributor

    1.0, backcompat

  5. brson commented on Oct 31, 2013

    @brson
    ContributorAuthor

    "crate" seems to be the consensus.

  6. brson commented on Jan 27, 2014

    @brson
    ContributorAuthor

    @huonw can mentor

  7. huonw commented on Jan 27, 2014

    @huonw
    Contributor

    If someone does want some mentorship, feel free to contact me by commenting here, on IRC (nick: dbaupp) or via email (in my profile).

  8. flaper87 commented on Jan 27, 2014

    @flaper87
    Contributor

    I'll work on this one

  9. thestinger commented on Jan 29, 2014

    @thestinger
    Contributor

    I like extern mod, as it works the same way as a mod statement but includes an external module rather than an internal one via source code. I think the term crate is very much insider Rust jargon and won't be as helpful for a newcomer. I don't think this is why people have trouble with Rust's module system.

  10. eddyb commented on Jan 29, 2014

    @eddyb
    Contributor

    Do we really want to add another keyword with just one use case?
    And so I'm not completely negative, I see two other ways we can say extern crate without crate being a keyword:

    // A procedural macro can expand to an ExternCrate AST node.
    extern_crate! extra;
    // Similar here, though attributes may not map as well to the AST.
    #[extern_crate(extra)];
    // These should still work (do we allow visibility on extern mod?):
    #[cfg(foo="bar")]
    pub extern_crate! foobar;
  11. sfackler commented on Jan 29, 2014

    @sfackler
    Member

    Would crate really need to be an extra keyword? Is there any reason that the compiler can't special case a crate ident coming after an extern keyword?

  12. flaper87 commented on Jan 30, 2014

    @flaper87
    Contributor

    @sfackler not 100% but I think that in the case of extern mod it is already treated as an ident.

  13. Kimundi commented on Jan 30, 2014

    @Kimundi
    Contributor

    For the record, extern mod does not currently work the same as mod:

    • Like mod, it adds new definitions to be usable from inside the crate.
    • But like use, multiple extern mod statements that refer to the same crate refer to the same definitions, and the items in them can be used interchangeably.

    Example:

    extern mod extra; 
    mod foo { 
        extern mod extra; 
        pub fn bar() { 
            let x: ::extra::arc::Arc<uint> = ::foo::extra::arc::Arc::new(5u); 
            println!("{:?}", x); 
        }
    } 
    fn main() {
        foo::bar(); 
    }
  14. 32 remaining items

  15. flaper87 commented on Feb 14, 2014

    @flaper87
    Contributor

    The patch that introduced the crate keyword landed already. The step left is creating a new snapshot for stage0 and replace all usages of extern mod with extern crate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-grammarArea: The grammar of RustE-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions