Spaceship operator always returns strong_ordering

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

Maintainer thường phản hồi trong vòng 1 ngày

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
30/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp, rust
Lĩnh vực
compilers

Hướng nghiên cứu

The spaceship operator is currently lowered to Ord::cmp in the C++-to-Rust translation pass, so start by finding where binary <=> is handled in the Clang AST visitor and the matching Rust emission code. The issue asks for a ThreeWayComparable-style trait so the result category follows the operand types, including partial_ordering for floats and the weakest-member rule for std::pair. Done means 1.0 <=> 2.0 and pair{NAN, 1} < pair{NAN, 2} translate with the correct ordering semantics and have tests covering them.

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

Mô tả

a <=> b is translated as Ord::cmp, which always gives Ordering (strong_ordering). In C++ the result depends on the operands:

1 <=> 2        // strong_ordering
1.0 <=> NAN    // partial_ordering (unordered)
w1 <=> w2      // weak_ordering, if W's operator<=> returns it

So 1.0 <=> 2.0 does not compile, and a weak ordering becomes strong.

std::pair's operator<=> returns the weakest category of its members (pair<double, int> gives partial_ordering). Its rule is generic, so without a trait for <=> it can only compare the members with < and return Ordering, and pair{NAN, 1} < pair{NAN, 2} is true instead of false.

We need to translate spaceship operator to a ThreeWayComparable trait.

Ngôn ngữ chính
Rust
Star
310
Fork
18
Merge trung bình
9 giờ 46 phút
Pull request đã merge (30 ngày)
82

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

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 Cpp2Rust/cpp2rust

Tất cả issue của Cpp2Rust/cpp2rust

Issue tương tự

Thêm issue về Rust

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.