Skip to content

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

Closed
@Alvenix

Description

@Alvenix

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions