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

Features 'rustc-dep-of-std' and 'extra_traits' don't work together #2064

Open
osa1 opened this issue Feb 10, 2021 · 3 comments
Open

Features 'rustc-dep-of-std' and 'extra_traits' don't work together #2064

osa1 opened this issue Feb 10, 2021 · 3 comments
Labels
C-bug Category: bug
Milestone

Comments

@osa1
Copy link

osa1 commented Feb 10, 2021

These features individually work, but if I enable both I get hundreds of build errors.

The repro I have is: clone rust repo, update library/test/Cargo.toml to add features = ['rustc-dep-of-std', 'extra_traits'] to libc. If you add only rustc-dep-of-std the crate builds fine. But if you add both you get a few hundred build errors, most in the form "X not found, try core::blah::X". Diff for the repro:

diff --git a/library/test/Cargo.toml b/library/test/Cargo.toml
index 226557430df..80e964e84f5 100644
--- a/library/test/Cargo.toml
+++ b/library/test/Cargo.toml
@@ -13,7 +13,7 @@ getopts = { version = "0.2.21", features = ['rustc-dep-of-std'] }
 term = { path = "../term" }
 std = { path = "../std" }
 core = { path = "../core" }
-libc = { version = "0.2", default-features = false }
+libc = { version = "0.2", default-features = false, features = ['rustc-dep-of-std', 'extra_traits'] }
 panic_unwind = { path = "../panic_unwind" }
 panic_abort = { path = "../panic_abort" }

I was able to most of the build errors for my platform by just prefixing Debug with core::fmt:Debug, and the same for other symbols from core (Eq, PartialEq, ...). I also tried tweaking cfg_attrs in lib.rs but couldn't make this work with just cfg_attr tweaks.

Remaining issues are fixed by adding a few anonymous lifetime annotations, like &core::fmt::Formatter<'_> instead of &Formatter.

Why is this needed?

I was hoping to use the ctrlc crate in rustc's test runner, which uses nix, which uses libc with the 'extra_traits' feature. Without 'extra_traits' it's possible to use libc in rustc test runner without the 'rustc-dep-of-std' feature, but with 'extra_traits' we need 'rustc-dep-of-std' too.


I'm happy to submit a PR to add prefixes to symbols like Debug, Formatter, PartialEq, etc. but I'm not sure if that's the best way to fix this. It's easily possiblewith a combination of fd and sed, but the diff is large.

@osa1 osa1 added the C-bug Category: bug label Feb 10, 2021
@JohnTitor
Copy link
Member

We don't expect that these features are used together currently. The problem here is anonymous lifetime isn't available on old stable rustc (i.e. 1.25.0) so we should enable it only when rustc-dep-of-std and extra_traits. And these fixes make the code more complex, as you said, I'd like to avoid it generally :(

@jyn514
Copy link
Member

jyn514 commented Feb 13, 2021

Could you shrink the diff with use core::fmt::Debug; or something similar? You could use #[no_prelude] so you don't need conditional imports.

@osa1
Copy link
Author

osa1 commented Feb 18, 2021

Could you shrink the diff with use core::fmt::Debug; or something similar?

This helps, the diff can be seen in #2074.

The patch is not complete: it works on my x86_64 Linux system, but modules for other platforms will also need to be updated.

If the diff looks OK and manageable I'll update the module for other platforms too and rely on CI to check my work as I only have access to x86_64 Linux.

bors added a commit that referenced this issue Feb 27, 2021
Make extra_traits work with rustc-dep-of-std

Fixes #2064

---

Files for other platforms also need to be updated.
@tgross35 tgross35 added this to the 1.0 milestone Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants