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

refactor: use ::core instead of core #296

Merged
merged 1 commit into from
Dec 12, 2023
Merged

Conversation

SteveLauC
Copy link
Contributor

@SteveLauC SteveLauC commented Dec 8, 2023

The issue I encountered

In my project, I have a module named core, it clashes with the Rust core within the ctor macro, as you can see from the error:

$ ls -l src
Permissions Links Size User  Group Date Modified Name
.rw-r--r--      1    0 steve steve  8 Dec 19:57  core.rs
.rw-r--r--      1   79 steve steve  8 Dec 19:57  main.rs

$ cat src/main.rs
mod core;

use ctor::ctor;

#[ctor]
static INT: i32 = {
    1
};

fn main() {}

$ cargo b -q
error[E0433]: failed to resolve: could not find `marker` in `core`
 --> src/main.rs:5:1
  |
5 | #[ctor]
  | ^^^^^^^ could not find `marker` in `core`
  |
  = note: this error originates in the attribute macro `ctor` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing one of these items
  |
3 + use core::marker;
  |
3 + use std::marker;
  |

error[E0433]: failed to resolve: could not find `ops` in `core`
 --> src/main.rs:5:1
  |
5 | #[ctor]
  | ^^^^^^^ could not find `ops` in `core`
  |
  = note: this error originates in the attribute macro `ctor` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing one of these items
  |
3 + use core::ops;
  |
3 + use std::ops;
  |

For more information about this error, try `rustc --explain E0433`.
error: could not compile `rust` (bin "rust") due to 2 previous errors

How to fix it

Add :: before core so that it will use the external core module, i.e., the Rust core (not the core from my project)

$ cat Cargo.toml | grep ctor
ctor = { git = "https://github.com/SteveLauC/rust-ctor", branch = "core" }

$ cargo b -q

@mmastrac mmastrac merged commit ef34367 into mmastrac:master Dec 12, 2023
4 checks passed
@mmastrac
Copy link
Owner

Released in ctor v0.2.6

@SteveLauC SteveLauC deleted the core branch December 12, 2023 03:00
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

Successfully merging this pull request may close these issues.

2 participants