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

Tricky error with rustc-std-workspace-core crate. #64356

Closed
crlf0710 opened this issue Sep 10, 2019 · 9 comments
Closed

Tricky error with rustc-std-workspace-core crate. #64356

crlf0710 opened this issue Sep 10, 2019 · 9 comments

Comments

@crlf0710
Copy link
Member

I'm not very sure whether this is a bug or not. But let me write down the reproduction steps. I'm using the newest stable.
Cargo.toml:

[package]
name = "dummy"
version = "0.0.1"
edition = "2018"

[dependencies]
core = { version = "1.0", package = "rustc-std-workspace-core"}

src/lib.rs

#![no_std]

compiler output:

   Compiling dummy v0.1.0 (L:\ThirdParty\rust\dummy)
error[E0433]: failed to resolve: could not find `prelude` in `core`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0433`.
error: Could not compile `dummy`.

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

The rustc-std-workspace-core crate here is the one on crates.io. @alexcrichton

@crlf0710
Copy link
Member Author

If i add this to lib.rs:

#[derive(Clone)]
struct S;

There'll be extra error:

error[E0433]: failed to resolve: could not find `clone` in `$crate`
 --> src\lib.rs:3:10
  |
3 | #[derive(Clone)]
  |          ^^^^^ could not find `clone` in `$crate`

@Mark-Simulacrum
Copy link
Member

Why are you using core = { version = "1.0", package = "rustc-std-workspace-core"} in Cargo.toml? That should only be for rustc-std deps, it shouldn't generally be used by anyone else.

I believe what you're finding is that you've overridden core crate with what is essentially an empty crate which is not going to contain Clone appropriately...

cc @petrochenkov

@crlf0710
Copy link
Member Author

i'm trying to add these dependencies to the crate winapi. And i'm checking whether these hacks works outside rustbuild. Then i saw this error.
cc #63725

@Mark-Simulacrum
Copy link
Member

See e.g. how libc does it for a working example. https://github.com/rust-lang/libc/blob/master/src/lib.rs#L41

You'll only want to replace core with rustc-std-workspace-core if a rustc-dep-of-std feature is set or so

@crlf0710
Copy link
Member Author

https://github.com/unicode-rs/unicode-width/blob/master/Cargo.toml#L22
This also fails when running cargo build --features core.
@alexcrichton Could you also release a new dot version for rustc-std-workspace-core? I'm not entirely sure what the content should be, maybe something like this:

extern crate core;
pub use core::*;

@alexcrichton
Copy link
Member

Hm can you explain why it's necessary? The rustc-std-workspace-core crate from crates.io should never actually be compiled, the feature should never be turned on by consumers.

@crlf0710
Copy link
Member Author

I just think it might be a little strange if the most important crates in the ecosystem has an optional dependency that's causing compilation errors when enabled~

Maybe it's not a must. but if the rustc-std-workspace-* crates on crates.io can work as a drop-in replacement for the sysroot corresponding crates, it might be slightly more natural?

@mati865
Copy link
Contributor

mati865 commented Sep 11, 2019

@crlf0710 you are not supposed to use it directly or have it enabled by default.
libc is a good example as it pulls this crate only when rustc-std-workspace-core feature is enabled meaning it never gets enabled outside of libstd.

@Mark-Simulacrum
Copy link
Member

I'm going to close this as won't fix.

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

4 participants