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

no_std project broken after 9/15 nightly #54589

Closed
Visic opened this issue Sep 26, 2018 · 2 comments
Closed

no_std project broken after 9/15 nightly #54589

Visic opened this issue Sep 26, 2018 · 2 comments

Comments

@Visic
Copy link

Visic commented Sep 26, 2018

The code below compiles using the 9/15 nightly (nightly-2018-09-15-i686-pc-windows-msvc), but fails to compile since then.

----Code---------------------------------------------------------------------

#![no_std]
#![feature(lang_items, alloc_system, alloc_error_handler)]

extern crate alloc_system;

use alloc_system::System;
use alloc::boxed::Box;
use alloc::vec::Vec;
use core::panic::PanicInfo;

#[global_allocator] static GLOBAL: System = System;
#[alloc_error_handler] #[no_mangle] pub extern "C" fn alloc_error(_: core::alloc::Layout) -> ! { loop {} }
#[panic_handler] #[no_mangle] pub extern "C" fn panic(_info: &PanicInfo) -> ! { loop {} }
#[lang = "eh_personality"] #[no_mangle] pub extern "C" fn eh_personality() {}

#[no_mangle]
pub fn hello_world_in_rust() -> i32 {
    let _: Box<[u8]> = Box::new([0; 10]);
    let _: [i32; 3] = [0,1,2];
    let _: Vec<i32> = Vec::new();
    100
}

----Cargo.toml--------------------------------------------------------------------

[package]
edition = '2018'
name = "test_lib"
version = "0.1.0"
authors = (removed)

[lib]
name = "test_lib"
path = "src/lib.rs"
crate-type = ["staticlib"]

[dependencies]

----Build Output---------------------------------------------------------------------

PS D:\Dev\MyProjects\Rust\test_lib> cargo build --release
Compiling test_lib v0.1.0 (D:\Dev\MyProjects\Rust\test_lib)
error[E0433]: failed to resolve. Could not find alloc in {{root}}
--> src/lib.rs:7:5
|
7 | use alloc::boxed::Box;
| ^^^^^ Could not find alloc in {{root}}

error[E0433]: failed to resolve. Could not find alloc in {{root}}
--> src/lib.rs:8:5
|
8 | use alloc::vec::Vec;
| ^^^^^ Could not find alloc in {{root}}

error[E0432]: unresolved import alloc_system
--> src/lib.rs:6:5
|
6 | use alloc_system::System;
| ^^^^^^^^^^^^ Did you mean self::alloc_system?

error[E0433]: failed to resolve. Use of undeclared type or module Box
--> src/lib.rs:18:24
|
18 | let _: Box<[u8]> = Box::new([0; 10]);
| ^^^ Use of undeclared type or module Box

error[E0433]: failed to resolve. Use of undeclared type or module Vec
--> src/lib.rs:20:23
|
20 | let _: Vec = Vec::new();
| ^^^ Use of undeclared type or module Vec

error[E0412]: cannot find type Box in this scope
--> src/lib.rs:18:12
|
18 | let _: Box<[u8]> = Box::new([0; 10]);
| ^^^ not found in this scope
help: possible candidates are found in other modules, you can import them into scope
|
6 | use std::boxed::Box;
|
6 | use std::prelude::v1::Box;
|

error[E0412]: cannot find type Vec in this scope
--> src/lib.rs:20:12
|
20 | let _: Vec = Vec::new();
| ^^^ not found in this scope
help: possible candidates are found in other modules, you can import them into scope
|
6 | use std::prelude::v1::Vec;
|
6 | use std::vec::Vec;
|

warning: unused import: alloc::boxed::Box
--> src/lib.rs:7:5
|
7 | use alloc::boxed::Box;
| ^^^^^^^^^^^^^^^^^
|
= note: #[warn(unused_imports)] on by default

warning: unused import: alloc::vec::Vec
--> src/lib.rs:8:5
|
8 | use alloc::vec::Vec;
| ^^^^^^^^^^^^^^^

error[E0152]: duplicate lang item found: oom.
--> src/lib.rs:12:37
|
12 | #[alloc_error_handler] #[no_mangle] pub extern "C" fn alloc_error(_: core::alloc::Layout) -> ! { loop {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: first defined in crate std.

error[E0152]: duplicate lang item found: panic_impl.
--> src/lib.rs:13:31
|
13 | #[panic_handler] #[no_mangle] pub extern "C" fn panic(_info: &PanicInfo) -> ! { loop {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: first defined in crate std.

error[E0152]: duplicate lang item found: eh_personality.
--> src/lib.rs:14:41
|
14 | #[lang = "eh_personality"] #[no_mangle] pub extern "C" fn eh_personality() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: first defined in crate panic_unwind.

error: aborting due to 10 previous errors

Some errors occurred: E0152, E0412, E0432, E0433.
For more information about an error, try rustc --explain E0152.
error: Could not compile test_lib.

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

@jonas-schievink
Copy link
Contributor

probably caused by #54116 and not a bug

@Visic
Copy link
Author

Visic commented Sep 26, 2018

Thanks for your help @jonas-schievink I wound up needing to add an extern crate for alloc and change some "use" statements around a little. I should have guessed the extern crate because of the "Could not find alloc in {{root}}" message, but the "duplicate lang item" ... "note: first defined in crate std" lead me to assume there was some sort of bug, since I should have no reference to std to begin with.

#![no_std]
#![feature(lang_items, alloc_system, alloc_error_handler, alloc)]

extern crate alloc_system;
extern crate alloc;

use crate::alloc_system::System;
use crate::alloc::boxed::Box;
use crate::alloc::vec::Vec;
use core::panic::PanicInfo;

@Visic Visic closed this as completed Sep 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants