Polars 0.37.0中cargo clippy检测报if/else类型不兼容错误
Polars 0.37.0 执行
cargo clippy时的类型不兼容错误解决 问题描述
使用Polars 0.37.0版本时,执行cargo clippy代码检查遇到类型不兼容错误,错误位于polars-arrow-0.37.0 crate的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]>`
最小复现示例
main.rs
fn main() {}
Cargo.toml
[package] name = "polars-test-me" version = "0.1.0" edition = "2021" [dependencies] polars = "0.37.0"
执行命令
$ cargo clippy
Rust版本信息
$ rustc -V rustc 1.72.0 (5680fa18f 2023-08-23)
$ cargo --version cargo 1.72.0 (103a7ff2e 2023-08-15)
$ cargo clippy -V clippy 0.1.72 (5680fa18 2023-08-23)
解决建议
- 升级Polars版本:该错误是Polars 0.37.0的已知bug,官方在后续小版本(如0.37.1及以上)中已修复。只需将Cargo.toml中的
polars依赖版本更新至0.37.1或更高即可解决问题。 - 临时规避方案:若暂时无法升级依赖,可通过添加
patch字段强制替换polars-arrow为修复后的版本,或者执行cargo clippy --allow E0308跳过该错误检查(不推荐长期使用)。
内容的提问来源于stack exchange,提问作者CAB314
相关产品推荐
相关产品推荐

