Skip to content

Compiling #![no_std] crates with --test gives unhelpful error message #18843

Description

@veddan

test-error.rs:

#![no_std]

Compiling:

$> rustc --test test-error.rs 
test-error.rs:1:1: 1:4 error: unresolved import `std::slice::AsSlice`. Maybe a missing `extern crate std`?
test-error.rs:1 #![no_std]
                ^~~
error: aborting due to previous error

This isn't very helpful. Changing the file to

#![no_std]
extern crate core;
mod std { mod slice { pub use core::slice::AsSlice; } }

instead gives the error message

test-error.rs:1:1: 1:1 error: failed to resolve. Could not find `os` in `std`.
test-error.rs:1 #![no_std]
                ^
test-error.rs:1:1: 1:1 error: unresolved name `std::os::args`.
test-error.rs:1 #![no_std]
                ^
error: aborting due to 2 previous errors

The error always refers to the first line of the file, so if you have feature gates before #![no_std], the error will refer to them.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-frontendArea: Compiler frontend (errors, parsing and HIR)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions