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

Improve span of errors on implicitly generated shim impls #786

Merged
merged 7 commits into from
Mar 27, 2021

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Mar 27, 2021

Repro:

pub struct MyBuilder<'a> {
    _s: &'a str,
}

type OptBuilder<'a> = Option<MyBuilder<'a>>;

#[cxx::bridge]
mod ffi {
    extern "Rust" {
        type OptBuilder<'a>;
    }

    struct MyBuilder<'a> {
        rs: Box<OptBuilder<'a>>,
    }
}

Diagnostic before:

Arrows everywhere, completely confused spans.

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
  --> $DIR/nonlocal_rust_type.rs:7:1
   |
7  |   #[cxx::bridge]
   |   ^^^^^^^^^^^^^^ impl doesn't use only types from inside the current crate
...
10 |           type OptBuilder<'a>;
   |  ___________________________-
11 | |     }
12 | |
13 | |     struct MyBuilder<'a> {
14 | |         rs: Box<OptBuilder<'a>>,
   | |__________________________- `Option` is not defined in the current crate
   |
   = note: define and implement a trait or new type instead
   = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

Diagnostic after

error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
  --> $DIR/nonlocal_rust_type.rs:14:13
   |
14 |         rs: Box<OptBuilder<'a>>,
   |             ^^^^---------------
   |             |   |
   |             |   `Option` is not defined in the current crate
   |             impl doesn't use only types from inside the current crate
   |
   = note: define and implement a trait or new type instead

@dtolnay dtolnay merged commit b1efdae into master Mar 27, 2021
@dtolnay dtolnay deleted the spanimplicit branch March 27, 2021 06:10
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.

1 participant