Skip to content

cargo directly piping rustc output generates confusion with --explain #1554

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
huonw opened this issue Apr 28, 2015 · 7 comments · Fixed by rust-lang/rust#25381
Closed

cargo directly piping rustc output generates confusion with --explain #1554

huonw opened this issue Apr 28, 2015 · 7 comments · Fixed by rust-lang/rust#25381
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. A-tooling Area: interaction with other tools

Comments

@huonw
Copy link
Member

huonw commented Apr 28, 2015

fn foo() {
    match () {
        () => {}
        _ => {}
    }
}
cargo build
   Compiling error-explain v0.1.0 (file:///home/huon/projects/test-rust/error-explain)
src/lib.rs:4:9: 4:10 error: unreachable pattern [E0001]
src/lib.rs:4         _ => {}
                     ^
src/lib.rs:4:9: 4:10 help: pass `--explain E0001` to see a detailed explanation
error: aborting due to previous error
Could not compile `error-explain`.

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

The error message looks a lot like cargo build --explain ... should work, but it's really rustc telling the user to pass that flag to rustc, and cargo is just dumping rustc's output straight out.

@huonw huonw added A-tooling Area: interaction with other tools A-diagnostics Area: Error and warning messages generated by Cargo itself. labels Apr 28, 2015
@alexcrichton
Copy link
Member

In the past we had lots of problems if we didn't just blindly pipe the output of the compiler back to the user, so I'm not sure how much Cargo itself can do here other than add an --explain flag which recommends running the compiler instead.

@huonw
Copy link
Member Author

huonw commented Apr 28, 2015

Anything that avoids the confusion. :)

What if cargo ... --explain ran the compiler with --explain?

@alexcrichton
Copy link
Member

I'd probably prefer to just change the wording to say something like "Run rustc --explain" as otherwise we'd have to add --explain to a whole lot of subcommands (test, run, bench, build, ...)

@caspark
Copy link

caspark commented Apr 29, 2015

"Run rustc --explain E0001" would have been sufficient to avoid my confusion ( @huonw raised this on my behalf).

More generally though, this was just one case of a newbie - i.e. me, or perhaps I'm just passing the newbie stage, since I didn't actually need the extended explanation! I was just curious what it said - being tripped up by Cargo & (what I see as) the rest of Rust not playing nicely together as I expect.

Another example is cargo test -- --nocapture, where to me it would make more sense to be instructing Cargo to not swallow the output (even though I gather (?) the args are going to the test executable, so it kind of makes sense).

More succinctly, it's my expectation that I never need to know about rustc or its intricacies when using cargo. Now, maybe you aren't intending to meet that expectation. However, I can't remember the last time I had to interact with javac or scalac directly (or worry about their specifics) rather than expressing my intent to Maven/Gradle/SBT. Hence, I expect others from a similar background would have similar expectations.

@alexcrichton
Copy link
Member

@caspark the --nocapture example at least is something where Cargo itself understands nothing about the option, but the underlying binary being run (the test harness) is the one that understands the --nocapture option. The extra -- tells Cargo that the following flags should all be passed down blindly to the the binary.

More succinctly, it's my expectation that I never need to know about rustc or its intricacies when using cargo.

Aha interesting! I had never really thought about it this way, and I suspect that's probably because I'm a little biased! This is definitely an interesting perspective to take, though, and something to keep in mind.

@huonw
Copy link
Member Author

huonw commented May 1, 2015

@alexcrichton I think the point about --nocapture is that it feels awkward: from the outside, cargo test is an abstraction around the details of test runners, and this breaks that abstraction, forcing users to understand how they work (and their flags) too.

(That is, someone using only cargo and no rustc finds it disconcerting that cargo understands nothing.)

@caspark
Copy link

caspark commented May 1, 2015

Yep - what @huonw said about --nocapture is what I was trying to say.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. A-tooling Area: interaction with other tools
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants