Rust: False positive for unused variable names

Đang mở
#22,342 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
38/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Ít trao đổi
Công nghệ
rust
Lĩnh vực
security

Hướng nghiên cứu

Bắt đầu với cảnh báo quét mã được liên kết và đoạn mã Rust, sau đó lần theo cách truy vấn biến không được sử dụng của CodeQL Rust xử lý phép nội suy format!. Hoàn tất khi truy vấn không còn báo cáo name là không được sử dụng, nhưng vẫn phát hiện các biến thực sự không được sử dụng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

false-positive

Description of the false positive

CodeQL seems to produce false positives for Rust variables in format strings.

Code samples or links to source code

On 2026-08-13, the folllowing Rust snippet got flagged by CodeQL on https://github.com/alltheplaces/osm-diffs/pull/660. CodeQL posted a notice, claiming Variable 'name' is not used. However, the variable does get used in this snippet, via a format! macro. We also check for unused variables with clippy, which does not flag an unused variable for this code. So, this looks like a false positive from CodeQL.

        let producers: Vec<_> = sources
            .into_iter()
            .map(|(name, reader)| {
                let tx = tx.clone();
                s.spawn(move || -> Result<()> {
                    for record in reader.iter()? {
                        let bytes = record?;
                        let fti = FeatureToIndex::decode(bytes.as_slice()).with_context(|| {
                            format!("failed to decode a FeatureToIndex record from {name}")
                        })?;
                        tx.send(fti)?;
                        progress_bar.inc(1);
                    }
                    Ok(())
                })
            })
            .collect();

URL to the alert on GitHub code scanning (optional)

https://github.com/alltheplaces/osm-diffs/security/code-scanning/30

Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 11 giờ
Pull request đã merge (30 ngày)
129

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của github/codeql

Tất cả issue của github/codeql

Issue tương tự

Thêm issue về Security

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.