Semver question: Is the non-qualified call to `.as_dyn_error()` intentional?

Đang mở
#452 0 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ó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
rust
Lĩnh vực
tooling

Hướng nghiên cứu

Đọc phần xung quanh lời gọi .as_dyn_error() được sinh ra trong impl/src/expand.rs và trait AsDynError ẩn trong src/aserror.rs. Tái hiện hành vi phân giải phương thức được mô tả trong issue, sau đó xác định liệu các phương thức bên ngoài có được hỗ trợ hay không. Hoàn thành khi hợp đồng đó được ghi lại hoặc quyết định sử dụng một lời gọi đủ điều kiện, đồng thời xử lý ảnh hưởng đến tính tương thích.

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

Mô tả

Right now the thiserror macro will generate code that invokes the hidden AsDynError trait. However it doesn't use a fully qualified path, but instead uses method-call resolution, where an inherent method on the field type shadows the trait method.

Is this an intentional choice to allow external implementations of the method?

Context: In rootcause we got a feature request to support placing a rootcause report inside enums with thiserror impls using #[error(transparent)].

While we don't recommend this way of combining thiserror and rootcause, we do consider it a helpful feature to make migrations of large codebases easier.

We added the feature using a Deref impl, but we had to roll back the change.

However after rolling back the change, I noticed that the #[error(transparent)] code still worked. It turns out, this is because we also named our method .as_dyn_error(), so everything happened to still work.

This makes me a bit worried, as "internal" changes in thiserror can now cause accidental breakage in consumers that use both thiserror and rootcause.

It'd be good to know where you land on this. If external as_dyn_error() impls are fair game, then we will document that this is a supported (but non-recommended) way to combine rootcause with thiserror. Otherwise we'd rather you make the call fully-qualified so the behavior breaks now instead of by accident later.

Ngôn ngữ chính
Rust
Star
5.6k
Fork
220
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

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 dtolnay/thiserror

Tất cả issue của dtolnay/thiserror

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.