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

Explicitly using extern crate in documentation examples gives unhelpful error #27301

Closed
Syntaf opened this issue Jul 26, 2015 · 1 comment
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@Syntaf
Copy link

Syntaf commented Jul 26, 2015

This would be more an enhancement than anything, but say if you have a library bignum and wanted to write an example in your docs

//lib.rs
//...

impl BigNum {

    //...


    /// Constructs a ...
    ///
    /// # Examples
    ///
    /// ```
    /// extern crate bignum;
    /// use bignum::inits::Zero;
    ///
    /// let a = bignum::BigNum::new(Zero::zero());
    /// ```
    ///
    pub fn new(base: BigNum) -> BigNum {
        // ...
    }

The error I made initially was I didn't know extern crate bignum is implicit, but the compiler errors I generated were what led me on a goose hunt. If I tried to compile this with cargo test I would get

---- new_0 stdout ----
    <anon>:3:9: 3:15 error: unresolved import `bignum::inits::Zero`. Did you mean `self::bignum::inits`?
<anon>:3     use bignum::inits::Zero;
                 ^~~~~~
error: aborting due to previous error
thread 'new_0' panicked at 'Box<Any>', /home/rustbuild/src/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libsyntax/diagnostic.rs:192

So I followed the errors advice, changing that statement but instead got?

---- new_0 stdout ----
    <anon>:3:9: 3:15 error: unresolved import `self::bignum::inits::Zero`. Did you mean `self::self::bignum::inits`?
<anon>:3     use self::bignum::inits::Zero;
                 ^~~~~~
error: aborting due to previous error
thread 'new_0' panicked at 'Box<Any>', /home/rustbuild/src/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libsyntax/diagnostic.rs:192

which leads you to the final error

---- new_0 stdout ----
    <anon>:3:9: 3:13 error: unresolved import `self::self::bignum::inits::Zero`. Maybe a missing `extern crate self`?
<anon>:3     use self::self::bignum::inits::Zero;
                 ^~~~
error: aborting due to previous error
thread 'new_0' panicked at 'Box<Any>', /home/rustbuild/src/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libsyntax/diagnostic.rs:192

Maybe in the future it would be useful to instead tell the user extern crate bignum is implicit? I spent a good while digging around before I realized my silly mistake, but the errors didn't seem lead me in any helpful direction.

@Syntaf Syntaf changed the title Explicitly using extern crate in documentation examples gives strange error Explicitly using extern crate in documentation examples gives unhelpful error Jul 26, 2015
@steveklabnik steveklabnik added the A-diagnostics Area: Messages for errors, warnings, and lints label Jul 29, 2015
@steveklabnik steveklabnik added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Nov 30, 2016
@steveklabnik steveklabnik added T-tools and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 9, 2017
@steveklabnik steveklabnik added T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. and removed T-tools labels May 18, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
@steveklabnik
Copy link
Member

steveklabnik commented Dec 10, 2018

Triage: with no other comments since the initial report, and with rust 2018 making extern crate no longer necessary, I'm going to give this a close. Thanks for the suggestion @Syntaf !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants