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

Cargo should abort with one error when target does not exist #111909

Closed
Alvenix opened this issue May 24, 2023 · 2 comments
Closed

Cargo should abort with one error when target does not exist #111909

Alvenix opened this issue May 24, 2023 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Alvenix
Copy link

Alvenix commented May 24, 2023

Code

fn main() {
    println!("Hello, world!");
}

Current output

error[E0463]: can't find crate for `std`
  |
  = note: the `x86_64-pc-windows-gnu` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-pc-windows-gnu`

error: cannot find macro `println` in this scope
 --> src/main.rs:2:5
  |
2 |     println!("Hello, world!");
  |     ^^^^^^^

error: requires `sized` lang_item

For more information about this error, try `rustc --explain E0463`.

Desired output

error[E0463]: can't find crate for `std`
  |
  = note: the `x86_64-pc-windows-gnu` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-pc-windows-gnu`

Rationale and extra context

When you have a lot of code or using a lot of crates the first line get covered by the terminal and you get mystified. For example adding a dependency increase the number of error lines a lot, few more dependencies and it will get over the terminal scroll limit.

[dependencies]
tokio = "1.28.1"

Other cases

error[E0463]: can't find crate for `core`
  |
  = note: the `x86_64-pc-windows-gnu` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-pc-windows-gnu`

error[E0463]: can't find crate for `compiler_builtins`

error[E0463]: can't find crate for `core`
    --> /home/abdullah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pin-project-lite-0.2.9/src/lib.rs:1503:9
     |
1503 |     use core::mem::ManuallyDrop;
     |         ^^^^ can't find crate
     |
     = note: the `x86_64-pc-windows-gnu` target may not be installed
     = help: consider downloading the target with `rustup target add x86_64-pc-windows-gnu`

error[E0463]: can't find crate for `core`
    --> /home/abdullah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pin-project-lite-0.2.9/src/lib.rs:1505:13
     |
1505 |     pub use core::{
     |             ^^^^ can't find crate
     |
     = note: the `x86_64-pc-windows-gnu` target may not be installed
     = help: consider downloading the target with `rustup target add x86_64-pc-windows-gnu`

error[E0405]: cannot find trait `Sized` in this scope
    --> /home/abdullah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pin-project-lite-0.2.9/src/lib.rs:1514:32
     |
1514 |     pub struct AlwaysUnpin<T: ?Sized>(PhantomData<T>);
     |                                ^^^^^ not found in this scope

error[E0405]: cannot find trait `Sized` in this scope
    --> /home/abdullah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pin-project-lite-0.2.9/src/lib.rs:1516:14
     |
1516 |     impl<T: ?Sized> Unpin for AlwaysUnpin<T> {}
     |              ^^^^^ not found in this scope

error[E0405]: cannot find trait `Sized` in this scope
    --> /home/abdullah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pin-project-lite-0.2.9/src/lib.rs:1520:43
     |
1520 |     pub struct UnsafeDropInPlaceGuard<T: ?Sized>(*mut T);
     |                                           ^^^^^ not found in this scope

error[E0405]: cannot find trait `Sized` in this scope
    --> /home/abdullah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pin-project-lite-0.2.9/src/lib.rs:1522:14
     |
1522 |     impl<T: ?Sized> UnsafeDropInPlaceGuard<T> {
     |              ^^^^^ not found in this scope

error[E0405]: cannot find trait `Sized` in this scope
    --> /home/abdullah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pin-project-lite-0.2.9/src/lib.rs:1529:14
     |
1529 |     impl<T: ?Sized> Drop for UnsafeDropInPlaceGuard<T> {
     |              ^^^^^ not found in this scope

Some errors have detailed explanations: E0405, E0463.
For more information about an error, try `rustc --explain E0405`.
error: could not compile `pin-project-lite` due to 9 previous errors
warning: build failed, waiting for other jobs to finish...

Anything else?

Sometimes when compiling for a target that is not installed, a long list errors is printed. The user won’t know the reason he cannot scroll up past the terminal limit.

If possible, I think it will be easier if cargo prints that the target does not exist.

I have been bitted by this issue few times, and I had to help people with this issue.

@Alvenix Alvenix added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 24, 2023
@jyn514
Copy link
Member

jyn514 commented May 24, 2023

cc #96799

@Alvenix
Copy link
Author

Alvenix commented May 25, 2023

Thank you, I am closing the issue because it is duplicate.

@Alvenix Alvenix closed this as completed May 25, 2023
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants