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

duplicate item in crate core #56

Closed
chaozju opened this issue Jun 12, 2020 · 14 comments
Closed

duplicate item in crate core #56

chaozju opened this issue Jun 12, 2020 · 14 comments

Comments

@chaozju
Copy link

chaozju commented Jun 12, 2020

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
@ehuss
Copy link
Contributor

ehuss commented Jun 13, 2020

Hm, I can't seem to reproduce. What version of nightly are you using?

@chaozju
Copy link
Author

chaozju commented Jun 13, 2020

@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)

@ehuss
Copy link
Contributor

ehuss commented Jun 13, 2020

That doesn't show the nightly version you are using. rustc +nightly -V shows which nightly version you have.

@chaozju
Copy link
Author

chaozju commented Jun 13, 2020

@ehuss

OOPS

chao@DESKTOP-B79IRTG:~/rust-playground/hello$ rustc +nightly -V
rustc 1.44.0-nightly (f509b26a7 2020-03-18)

@ehuss
Copy link
Contributor

ehuss commented Jun 13, 2020

2020-03-18 This is quite old. Can you try with the latest nightly? rustup update nightly can be used to update.

@chaozju
Copy link
Author

chaozju commented Jun 14, 2020

@ehuss
same error after updating nightly

@ehuss
Copy link
Contributor

ehuss commented Jun 14, 2020

Which exact version did you use?

@chaozju
Copy link
Author

chaozju commented Jun 14, 2020

@ehuss
rustc 1.46.0-nightly (feb3536eb 2020-06-09)

@dbdr
Copy link

dbdr commented Jul 7, 2020

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.

@chaozju
Copy link
Author

chaozju commented Jul 8, 2020

@dbdr It works, THX

@gmorer
Copy link

gmorer commented Feb 15, 2021

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

@ehuss
Copy link
Contributor

ehuss commented Mar 8, 2021

@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.

nicholasbishop added a commit to nicholasbishop/uefi-rs that referenced this issue Aug 7, 2021
Tested with:

    CARGO_PROFILE_DEV_PANIC=unwind \
        cargo test -Zbuild-std=std --target x86_64-unknown-linux-gnu

(Changing panic to unwind avoids
rust-lang/wg-cargo-std-aware#56)
GabrielMajeri pushed a commit to rust-osdev/uefi-rs that referenced this issue Aug 9, 2021
Tested with:

    CARGO_PROFILE_DEV_PANIC=unwind \
        cargo test -Zbuild-std=std --target x86_64-unknown-linux-gnu

(Changing panic to unwind avoids
rust-lang/wg-cargo-std-aware#56)
@ehuss
Copy link
Contributor

ehuss commented May 3, 2023

I'm going to close as it isn't clear that there is an issue here. Better panic support is tracked in #29, and it looks like the wasm_bindgen issue was an issue with an external package.

@tbu-
Copy link

tbu- commented Mar 25, 2025

I had a similar problem and passing -Z build-std=panic_abort,std helped.

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

5 participants