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

Access to extern crates through prelude is experimental when using pyclass in module #233

Closed
pganssle opened this issue Sep 26, 2018 · 1 comment

Comments

@pganssle
Copy link
Member

For whatever reason, using #[pyclass] from a separate module file (i.e. not in the lib.rs root file), requires the extern_prelude feature to be enabled in lib.rs, though it's not entirely clear why this is.

The error message is quite confusing, so if it can't be fixed, it might be worth documenting the fix somewhere. True, the compiler error does tell you to enable the feature, but it's unclear that the feature must be enabled in the root file as opposed to in the file generating the error. Googling for extern_prelude gives almost no explanation of this error, but it seems like it has to do with the use of something like pyo3::prelude::blah outside of a use statement. I'm guessing that happens somewhere in what the #[pyclass] macro expands to.

Reproducing

cargo new --lib eprelude && cd eprelude

Cargo.toml:

[package]
name = "eprelude"
version = "0.1.0"
authors = ["Author <author@domain.biz>"]

[dependencies.pyo3]
version = "0.5.0-alpha.1"

lib.rs:

#![feature(specialization)]
// Including this feature here fixes the problem:
// #![feature(extern_prelude)]

extern crate pyo3;

pub mod foo;

foo.rs:

use pyo3::prelude::{pyclass};

#[pyclass]
pub struct Foo {}
@konstin
Copy link
Member

konstin commented Sep 26, 2018

The error message is misleading here; The problem is that the generated code use std:: instead of ::std::

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

2 participants