duplicate item in crate `core`
chaozju opened this issue · 13 comments
I am testing with hello world case for build-std
feature
my code
fn main() {
println!("Hello, world!");
println!("3 + 4 = {}",3+4);
}
then got
cargo +nightly build -Z build-std \
--release --target x86_64-unknown-linux-gnu
Compiling compiler_builtins v0.1.25
Compiling core v0.0.0 (/home/chao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore)
Compiling cc v1.0.50
Compiling libc v0.2.66
Compiling autocfg v0.1.7
Compiling std v0.0.0 (/home/chao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd)
Compiling hashbrown v0.6.2
Compiling backtrace-sys v0.1.32
Compiling unwind v0.0.0 (/home/chao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libunwind)
Compiling rustc-std-workspace-core v1.99.0 (/home/chao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/tools/rustc-std-workspace-core)
Compiling cfg-if v0.1.10
Compiling alloc v0.0.0 (/home/chao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/liballoc)
Compiling rustc-demangle v0.1.16
Compiling panic_abort v0.0.0 (/home/chao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libpanic_abort)
Compiling backtrace v0.3.44
Compiling rustc-std-workspace-alloc v1.99.0 (/home/chao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/tools/rustc-std-workspace-alloc)
Compiling panic_unwind v0.0.0 (/home/chao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libpanic_unwind)
Compiling proc_macro v0.0.0 (/home/chao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libproc_macro)
Compiling hello v0.1.0 (/home/chao/rust-playground/hello)
error: duplicate lang item in crate `core`: `bool`.
|
= note: the lang item is first defined in crate `core` (which `std` depends on)
error: duplicate lang item in crate `core`: `char`.
|
= note: the lang item is first defined in crate `core` (which `std` depends on)
error: duplicate lang item in crate `core`: `str`.
|
= note: the lang item is first defined in crate `core` (which `std` depends on)
error: duplicate lang item in crate `core`: `slice`.
|
= note: the lang item is first defined in crate `core` (which `std` depends on)
and
error[E0277]: the size for values of type `()` cannot be known at compilation time
--> src/main.rs:3:27
|
3 | println!("3 + 4 = {}",3+4);
| ^^^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `()`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: required by `std::result::Result`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the size for values of type `std::fmt::Error` cannot be known at compilation time
--> src/main.rs:3:27
|
3 | println!("3 + 4 = {}",3+4);
| ^^^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `std::fmt::Error`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: required by `std::result::Result`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the size for values of type `{integer}` cannot be known at compilation time
--> src/main.rs:3:5
|
3 | println!("3 + 4 = {}",3+4);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
::: /home/chao/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/fmt/mod.rs:281:20
|
281 | pub fn new<'b, T>(x: &'b T, f: fn(&T, &mut Formatter<'_>) -> Result) -> ArgumentV1<'b> {
| - required by this bound in `std::fmt::ArgumentV1::<'a>::new`
|
= help: the trait `std::marker::Sized` is not implemented for `{integer}`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 84 previous errors
For more information about this error, try `rustc --explain E0277`.
error: could not compile `hello`.
To learn more, run the command again with --verbose.
Makefile:18: recipe for target 'x86_64-gnu' failed
make: *** [x86_64-gnu] Error 101
Hm, I can't seem to reproduce. What version of nightly are you using?
@ehuss
Hi, My toolchain info is
chao@DESKTOP-B79IRTG:~/rust-playground/hello$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home: /home/chao/.rustup
installed toolchains
--------------------
stable-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu
1.40.0-x86_64-unknown-linux-gnu
installed targets for active toolchain
--------------------------------------
riscv64gc-unknown-linux-gnu
riscv64gc-unknown-none-elf
wasm32-wasi
x86_64-unknown-linux-gnu
x86_64-unknown-linux-musl
active toolchain
----------------
stable-x86_64-unknown-linux-gnu (default)
rustc 1.42.0 (b8cedc004 2020-03-09)
That doesn't show the nightly version you are using. rustc +nightly -V
shows which nightly version you have.
OOPS
chao@DESKTOP-B79IRTG:~/rust-playground/hello$ rustc +nightly -V
rustc 1.44.0-nightly (f509b26a7 2020-03-18)
2020-03-18
This is quite old. Can you try with the latest nightly? rustup update nightly
can be used to update.
Which exact version did you use?
I'm getting the same error with 1.46.0-nightly (0c03aee8b 2020-07-05)
and panic="abort" in Cargo.toml. Changing panic to "unwind" removes the error.
@chaozju, did you use panic="abort"?
panic="abort" also works when using -Z build-std=panic_abort,std
, as suggested by @alexcrichton in #29.
Hi, I got the same error with rustc 1.51.0-nightly (04caa632d 2021-01-30)
and adding a dependencie:
Cargo.toml:
[package]
name = "rust_issue"
version = "0.1.0"
authors = ["gmorer"]
edition = "2018"
[lib]
crate-type = ["lib"]
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"
[dependencies]
wasm-bindgen = "0.2"
src/lib.rs:
#![no_std]
extern crate alloc;
use alloc::boxed::Box;
pub fn my_fn() -> i32 {
let mem = Box::new(4);
*mem
}
compile line:
cargo build --target=wasm32-unknown-unknown -Z build-std=alloc,panic_abort
Got the following error:
$> cargo build --target=wasm32-unknown-unknown -Z build-std=alloc,panic_abort
Compiling core v0.0.0 (/home/me/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
[...]
Compiling panic_abort v0.0.0 (/home/me/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/panic_abort)
Compiling rust_issue v0.1.0 (/home/me/gits/rust_issue)
error: duplicate lang item in crate `core` (which `alloc` depends on): `bool`.
|
= note: the lang item is first defined in crate `core` (which `rust_issue` depends on)
= note: first definition in `core` loaded from /home/me/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcore-73412d1456c20040.rlib
= note: second definition in `core` loaded from /home/me/gits/rust_issue/target/wasm32-unknown-unknown/debug/deps/libcore-d3db196937483bcf.rmeta
error: duplicate lang item in crate `core` (which `alloc` depends on): `char`.
|
= note: the lang item is first defined in crate `core` (which `rust_issue` depends on)
= note: first definition in `core` loaded from /home/me/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcore-73412d1456c20040.rlib
= note: second definition in `core` loaded from /home/me/gits/rust_issue/target/wasm32-unknown-unknown/debug/deps/libcore-d3db196937483bcf.rmeta
error: duplicate lang item in crate `core` (which `alloc` depends on): `str`.
|
= note: the lang item is first defined in crate `core` (which `rust_issue` depends on)
= note: first definition in `core` loaded from /home/me/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib/libcore-73412d1456c20040.rlib
= note: second definition in `core` loaded from /home/me/gits/rust_issue/target/wasm32-unknown-unknown/debug/deps/libcore-d3db196937483bcf.rmeta
@gmorer you have to ensure your dependencies do not use std
if you are not building std
. wasm-bindgen
has a default std
feature, so it has to be turned off:
wasm-bindgen = {version="0.2", default-features=false}
However, it looks like wasm-bindgen is broken in no_std environments. This line assumes mem::
is available, but it is gated here.