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

Incorrect types shown in an error when using rhai #120416

Open
Cerber-Ursi opened this issue Jan 27, 2024 · 4 comments
Open

Incorrect types shown in an error when using rhai #120416

Cerber-Ursi opened this issue Jan 27, 2024 · 4 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Cerber-Ursi
Copy link
Contributor

Code

use std::{cell::RefCell, rc::Rc};

struct Wrapper {
    // this part is important - if this field is commented out, error disappears
    engine: rhai::Engine,
    // this is what actually triggers the diagnostic
    ctx: Rc<RefCell<()>>,
}

fn main() {
    let _ = Wrapper {
        engine: rhai::Engine::new_raw(),
        ctx: (),
    };
}

Current output

error[E0308]: mismatched types
  --> src/main.rs:13:14
   |
13 |         ctx: (),
   |              ^^ expected `Shared<Locked<()>>`, found `()`
   |
   = note: expected struct `Rc<Locked<()>>`
           found unit type `()`

Desired output

error[E0308]: mismatched types
  --> src/main.rs:13:14
   |
13 |         ctx: (),
   |              ^^ expected `Rc<RefCell<()>>`, found `()`
   |
   = note: expected struct `Rc<RefCell<()>>`
           found unit type `()`

Rationale and extra context

No response

Other cases

No response

Rust Version

rustc 1.75.0 (82e1608df 2023-12-21)
binary: rustc
commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112
commit-date: 2023-12-21
host: x86_64-unknown-linux-gnu
release: 1.75.0
LLVM version: 17.0.6

Anything else?

No response

@Cerber-Ursi Cerber-Ursi added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 27, 2024
@tguichaoua
Copy link
Contributor

tguichaoua commented Jan 27, 2024

For context, Shared and Locked are re-exports of Rc and RefCell (or Arc and RwLock, based on a feature flag) in the rhai crate.

https://github.com/rhaiscript/rhai/blob/8b0a62e6b172abffadea4a5cb404c75c01c3aba9/src/func/native.rs#L31-L53

@clubby789
Copy link
Contributor

clubby789 commented Jan 27, 2024

Reproduction (doesn't happen if the alias is in the same crate)

// dep.rs
pub use std::option::Option as DepOption;
pub struct Engine;
// poc.rs
struct Wrapper {
    engine: dep::Engine,
    ctx: Option<()>,
}

fn main() {
    let _ = Wrapper {
        engine: dep::Engine,
        ctx: (),
    };
}

rustc dep.rs --crate-type=lib && rustc poc.rs --extern dep=./libdep.rlib:

error[E0308]: mismatched types
 --> poc.rs:9:14
  |
9 |         ctx: (),
  |              ^^ expected `DepOption<()>`, found `()`
  |
  = note:   expected enum `DepOption<()>`
          found unit type `()`
...

@clubby789
Copy link
Contributor

clubby789 commented Jan 27, 2024

Bisects to

  commit[0] 2020-07-05: Auto merge of #73879 - ecstatic-morse:discr-switch-uninit, r=oli-obk
  commit[1] 2020-07-05: Auto merge of #74073 - Manishearth:rollup-faqo9lx, r=Manishearth

#74073 seems more likely, #73834 #73871 seem relevant (the second in particular)

@bvanjoi
Copy link
Contributor

bvanjoi commented Jan 30, 2024

I believe this issue was regressed by #105411. More precisely, it was caused by the changes found at https://github.com/rust-lang/rust/pull/105411/files#diff-b56d8c5fa3d7803c5b0e19e1a8854d85c302974484c4c20bf51c76a19556f4a7R376-R382.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants