Skip to content

Conversation

r-chiba
Copy link

@r-chiba r-chiba commented Oct 3, 2025

Description

This change fixes to import size_of and align_of from the core crate.

We have seen an error failing to resolve this import directive.

Sources

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget);
    especially relevant for platforms that may not be checked in CI

@rustbot label +stable-nominated

We have seen an error failing to resolve this import directive.
Fix the path to import from the core crate.
@rustbot rustbot added S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels Oct 3, 2025
@tgross35
Copy link
Contributor

tgross35 commented Oct 3, 2025

What is the error you are seeing? We import core::mem so I'm not sure why things wouldn't be working. I'd expect fmt::Debug to be in the same boat.

@r-chiba
Copy link
Author

r-chiba commented Oct 3, 2025

We saw this error on a Windows environment:

00:47:54 error[E0432]: unresolved import `mem`
00:47:54 --> external/+_repo_rules2+libc/src\macros.rs:81:28
00:47:54 |
00:47:54 81 |             pub(crate) use mem::{align_of, align_of_val, size_of, size_of_val};
00:47:54 |                            ^^^ help: a similar path exists: `self::mem`
00:47:54 |
00:47:54 ::: external/+_repo_rules2+libc/src/lib.rs:57:9
00:47:54 |
00:47:54 57 |         prelude!();
00:47:54 |         ---------- in this macro invocation
00:47:54 |
00:47:54 = note: this error originates in the macro `prelude` (in Nightly builds, run with -Z macro-backtrace for more info)
00:47:54 
00:47:54 error: aborting due to 1 previous error

@tgross35
Copy link
Contributor

tgross35 commented Oct 3, 2025

Do you have the rustc invocation that caused that and some more toolchain info? I'm not able to reproduce, of course, and I don't really understand where the error would be coming from. Libc isn't getting built with an old edition or something, is it?

@r-chiba
Copy link
Author

r-chiba commented Oct 3, 2025

I think the rustc version is 1.88.0 but I couldn't find the exact command used for the build.

The context is that the error happened to one of the components of (the internal version of) Android's AOSP project when I updated the libc crate version used for Android build (internal version of https://cs.android.com/android/platform/superproject/main/+/main:external/rust/android-crates-io/) from 0.2.172 to 0.2.175.

I'm so sorry but I'm not a developer of the component failed to build and I have no idea how the component is built. And unfortunately I don't have a minimal reproducible case of the failure.

@tgross35
Copy link
Contributor

tgross35 commented Oct 22, 2025

Sorry for the delay, just got a chance to circle back here. I think the problem is indeed that you are somehow building with the old edition. If I invoke rustc directly with rustc src/lib.rs --crate-type=lib to use the default 2015 edition, I get:

error[E0432]: unresolved import `fmt`                                                                                                                                                                                  --> src/macros.rs:88:28                                                                                                                                                                                               |                                                                                                                                                                                                                 88 |             pub(crate) use fmt::Debug;                                                                                                                                                                             |                            ^^^ help: a similar path exists: `self::fmt`                                                                                                                                            |                                                                                                                                                                                                                   ::: src/lib.rs:96:9
   |
96 |         prelude!();
   |         ---------- in this macro invocation
   |
   = note: this error originates in the macro `prelude` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0432]: unresolved import `mem`
  --> src/macros.rs:90:28
   |
90 |             pub(crate) use mem::{align_of, align_of_val, size_of, size_of_val};
   |                            ^^^ help: a similar path exists: `self::mem`
   |
  ::: src/lib.rs:96:9
   |
96 |         prelude!();
   |         ---------- in this macro invocation
   |
   = note: this error originates in the macro `prelude` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0659]: `Debug` is ambiguous
  --> src/unix/mod.rs:41:14
   |
41 |     #[derive(Debug)]
   |              ^^^^^ ambiguous name
   |
   = note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution
note: `Debug` could refer to the unresolved item imported here
  --> src/unix/mod.rs:6:5
   |
 6 | use crate::prelude::*;
   |     ^^^^^^^^^^^^^^^^^

Which seems to be what you have plus a few fmt-related errors (I assume you may be testing before a6e7563). Adding the --edition=2021 flag to the rustc invocation fixes things.

The edition is configured to 2021 here, which gets set automatically if you build with Cargo. So my guess is that the build system you're using is just missing this step, and it happened to work until now.

As this is Android-related, @maurer may know some more

@tgross35
Copy link
Contributor

I'm going to close this since I don't think there is any action we can take on our side. Things should work for you again once the build system starts passing an edition to rustc, which it's probably already doing for most other crates anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stable-nominated This PR should be considered for cherry-pick to libc's stable release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants