Skip to content

Consistently refer to the right Result in macro expansion#281

Merged
dgrunwald merged 1 commit intodgrunwald:masterfrom
dtolnay-contrib:result
Sep 21, 2022
Merged

Consistently refer to the right Result in macro expansion#281
dgrunwald merged 1 commit intodgrunwald:masterfrom
dtolnay-contrib:result

Conversation

@dtolnay
Copy link
Copy Markdown
Contributor

@dtolnay dtolnay commented Jun 17, 2022

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)

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)
@dgrunwald dgrunwald merged commit 83948b8 into dgrunwald:master Sep 21, 2022
@dtolnay dtolnay deleted the result branch September 21, 2022 21:05
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