if 和 else 在 Polars-arrow 0.37.0 中具有不兼容的类型

CAB*_*314 6 rust rust-polars

我在使用 Polars 版本 0.37.0 并运行 Cargo Clippy 进行代码检查时遇到问题。该错误出现在 Polars-arrow-0.37.0 箱中,特别是 utf8_to.rs 文件中。以下是详细的错误消息:

error[E0308]: `if` and `else` have incompatible types
   --> /Users/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-arrow-0.37.0/src/compute/cast/utf8_to.rs:101:9
    |
98  |       let buffers = if uses_buffer {
    |  ___________________-
99  | |         Arc::from([arr.values().clone()])
    | |         --------------------------------- expected because of this
100 | |     } else {
101 | |         Arc::from([])
    | |         ^^^^^^^^^^^^^ expected an array with a fixed size of 1 element, found one with 0 elements
102 | |     };
    | |_____- `if` and `else` have incompatible types
    |
    = note: expected struct `Arc<[buffer::immutable::Buffer<u8>; 1]>`
               found struct `Arc<[_; 0]>`

Run Code Online (Sandbox Code Playgroud)

任何有关如何解决此问题的指导或建议将不胜感激。如果需要更多信息,我很乐意提供。

[我添加了最小的可重现示例!]

最小可重现示例:

主要.rs:

fn main() {}
Run Code Online (Sandbox Code Playgroud)

货物.toml:

[package] 
name = "polars-test-me" 
version = "0.1.0" 
edition = "2021"

[dependencies]
polars = "0.37.0"
Run Code Online (Sandbox Code Playgroud)

货物命令:

error[E0308]: `if` and `else` have incompatible types
   --> /Users/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-arrow-0.37.0/src/compute/cast/utf8_to.rs:101:9
    |
98  |       let buffers = if uses_buffer {
    |  ___________________-
99  | |         Arc::from([arr.values().clone()])
    | |         --------------------------------- expected because of this
100 | |     } else {
101 | |         Arc::from([])
    | |         ^^^^^^^^^^^^^ expected an array with a fixed size of 1 element, found one with 0 elements
102 | |     };
    | |_____- `if` and `else` have incompatible types
    |
    = note: expected struct `Arc<[buffer::immutable::Buffer<u8>; 1]>`
               found struct `Arc<[_; 0]>`

Run Code Online (Sandbox Code Playgroud)

Rust 版本信息:

$ rustc -V
rustc 1.72.0 (5680fa18f 2023-08-23)
Run Code Online (Sandbox Code Playgroud)
$ cargo --version
cargo 1.72.0 (103a7ff2e 2023-08-15)
Run Code Online (Sandbox Code Playgroud)
$ cargo clippy -V
clippy 0.1.72 (5680fa18 2023-08-23)
Run Code Online (Sandbox Code Playgroud)

小智 1

我刚刚遇到了这个完全相同的问题,并通过简单地执行来解决它rustup update