rust-cpython icon indicating copy to clipboard operation
rust-cpython copied to clipboard

Consistently refer to the right `Result` in macro expansion

Open dtolnay opened this issue 2 years ago • 0 comments

Without this, importing any other crate's Result type alias in a module that uses cpython's macros causes compilation to fail in a variety of interesting ways.

Repro:

use cpython::{py_class, PyResult};
use std::io::Result;

py_class!(class Struct |py| {
    def __new__(_cls) -> PyResult<Struct> {
        Struct::create_instance(py)
    }
});

The resulting diagnostic:

error[E0107]: this type alias takes 1 generic argument but 2 generic arguments were supplied
  --> src/main.rs:4:1
   |
4  | / py_class!(class Struct |py| {
5  | |     def __new__(_cls) -> PyResult<Struct> {
6  | |         Struct::create_instance(py)
7  | |     }
8  | | });
   | |  ^
   | |  |
   | |__expected 1 generic argument
   |    help: remove this generic argument
   |
note: type alias defined here, with 1 generic parameter: `T`
  --> nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/error.rs:55:10
   |
55 | pub type Result<T> = result::Result<T, Error>;
   |          ^^^^^^ -
   = note: this error originates in the macro `$crate::py_class_impl` (in Nightly builds, run with -Z macro-backtrace for more info)

dtolnay avatar Jun 17 '22 22:06 dtolnay