Skip to content

Incorrect types shown in an error when using rhai #120416

Open
@Cerber-Ursi

Description

@Cerber-Ursi
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

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Jan 27, 2024
tguichaoua

tguichaoua commented on Jan 27, 2024

@tguichaoua
Contributor

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

clubby789 commented on Jan 27, 2024

@clubby789
Contributor

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

clubby789 commented on Jan 27, 2024

@clubby789
Contributor

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

bvanjoi commented on Jan 30, 2024

@bvanjoi
Contributor

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Cerber-Ursi@clubby789@bvanjoi@tguichaoua

        Issue actions

          Incorrect types shown in an error when using `rhai` · Issue #120416 · rust-lang/rust