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

Duplicate error messages #3531

Closed
mjbshaw opened this issue Jan 11, 2017 · 5 comments
Closed

Duplicate error messages #3531

mjbshaw opened this issue Jan 11, 2017 · 5 comments

Comments

@mjbshaw
Copy link

mjbshaw commented Jan 11, 2017

When I build with cargo, I often get duplicate error messages printed to the console. The following shows my versions of rustc and cargo, as well as a way to reproduce the issue:

$ rustup update
info: syncing channel updates for 'stable-x86_64-apple-darwin'
info: syncing channel updates for 'nightly-x86_64-apple-darwin'
info: checking for self-updates

   stable-x86_64-apple-darwin unchanged - rustc 1.14.0 (e8a012324 2016-12-16)
  nightly-x86_64-apple-darwin unchanged - rustc 1.16.0-nightly (47c8d9fdc 2017-01-08)

$ cargo new example
     Created library `example` project
$ echo this_will_fail >> example/src/lib.rs
$ cd example && cargo test
   Compiling example v0.1.0 (file:///private/tmp/example)
error: expected one of `!` or `::`, found `<eof>`
 --> src/lib.rs:7:1
  |
7 | this_will_fail
  | ^^^^^^^^^^^^^^
error: expected one of `!` or `::`, found `<eof>`
 --> src/lib.rs:7:1
  |
7 | this_will_fail
  | ^^^^^^^^^^^^^^


error: aborting due to previous error
error: aborting due to previous error


Build failed, waiting for other jobs to finish...
error: Could not compile `example`.

To learn more, run the command again with --verbose.

Notice that cargo test results in the same error message being printed twice to the console. If I directly run rustc manually, I only get the error printed to the console once, as expected:

$ rustc --crate-name example src/lib.rs --crate-type lib --emit=dep-info,link -g -C metadata=238e0b62da27c7ce -C extra-filename=-238e0b62da27c7ce --out-dir /private/tmp/example/target/debug/deps -L dependency=/private/tmp/example/target/debug/deps
error: expected one of `!` or `::`, found `<eof>`
 --> src/lib.rs:7:1
  |
7 | this_will_fail
  | ^^^^^^^^^^^^^^

error: aborting due to previous error

This suggests there is a bug in Cargo that is causing error messages to be printed twice. This is reproducible in iTerm2 and Terminal on OS X 10.12.2 with both zsh 5.2 and bash. This has been happening for quite some time, and is not unique to the latest nightly version of Cargo.

@mjbshaw
Copy link
Author

mjbshaw commented Jan 12, 2017

Minor update: the issue is with cargo test. cargo build prints the error only once. And I can confirm these errors are being printed to stderr only (not stdout).

@alexcrichton
Copy link
Member

Thanks for the report! What's actually happening here is that the library is being compiled twice (once with --test and once for doc tests later on), and this is a dupe of #1534 and #851 (now tracked at #1198). This is intended behavior though, and you can use various flags like --test, --lib, or -j to not run rustc in parallel, so I'm going to close this.

@mjbshaw
Copy link
Author

mjbshaw commented Jan 12, 2017

Thanks for the response and explanation! Given all these duplicate bug reports reporting the same issue, do you think that perhaps that might be indicative of a tooling issue?

Compiling twice makes sense once you understand what is going on, but for beginners like me it's rather surprising to see error messages duplicated (and interleaved). I suppose cargo test --verbose hints at the reason, since it shows two rustc invocations, but it doesn't really explain what's going on and what each invocation of rustc is meant to be doing. Additionally, it only shows one of the two processes as having exited with an error, which could be incorrectly taken to mean the error messages were coming from just one of the two rustc processes.

It would be really nice if there was better information available about this to the user (e.g. cargo printing out a message that it's compiling in parallel for unit tests and doc tests).

@alexcrichton
Copy link
Member

I'm all for fixing this or making the situation better, I just don't know how to do so without hurting the experience of successful compilations.

@corebreaker
Copy link

corebreaker commented Sep 11, 2020

I have the problem, with rustc 1.46 and cargo 1.46:

image

And here, a message is repeated 3 times:

image

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

No branches or pull requests

3 participants