Skip to content

Improve usage of compiler-builtins #49851

Closed
@jamesmunns

Description

@jamesmunns

This is regarding the changes made in #49380. This change works, however when the user makes some kind of mistake, especially forgetting to install the new targets (like thumbv7em-none-eabihf), the error messages are not currently helpful.

The current error message when forgetting to install the target looks like this:

cargo build --target thumbv7em-none-eabihf --example blinky
   Compiling vcell v0.1.0
   Compiling bare-metal v0.1.1
   Compiling aligned v0.1.1
   Compiling untagged-option v0.1.1
error[E0463]: can't find crate for `compiler_builtins`

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

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error[E0463]: can't find crate for `compiler_builtins`

error: aborting due to previous error

error[E0463]: can't find crate for `compiler_builtins`
For more information about this error, try `rustc --explain E0463`.

error: aborting due to previous error

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

compared to the following when you try to compile for a not-installed target:

cargo build --target i686-unknown-linux-gnu
   Compiling foo v0.1.0 (file:///tmp/foo)
error[E0463]: can't find crate for `std`
  |
  = note: the `i686-unknown-linux-gnu` target may not be installed

error: aborting due to previous error

For more information about this error

The following #[no_std] code shows (the first part of) a typical embedded project:

//! Blinks an LED

#![deny(unsafe_code)]
#![deny(warnings)]
#![no_std]

extern crate cortex_m;

using cargo expand, this code expands to:

#![feature(prelude_import)]
#![no_std]
//! Blinks an LED

#![deny(unsafe_code)]
#![deny(warnings)]
#![no_std]
#[prelude_import]
use core::prelude::v1::*;
#[macro_use]
extern crate compiler_builtins;
#[macro_use]
extern crate core;

extern crate cortex_m;

The Embedded WG talked about this, and we think the error messages would be improved if the order of extern crate compiler_builtins; and extern crate core; were swapped.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions