μλ ν λ‘ : https://users.rust-lang.org/t/unexpected-behaviors-of-trait-bounds/12286/10
μ΄ μ€λλ λ¬Έμ μ κ΄λ ¨λ κ² κ°μ΅λλ€ : https://github.com/rust-lang/rust/issues/29859
κΈ°λ³Έμ κ°λ trait Complete
νμ trait Partial
λ° trait Partial
νμ trait PartialEq
(λλ λ€λ₯Έ νΉμ±), μ ν ( struct TypeB
ν¬ν¨) impl Complete
λ λ²κ·Έμ²λΌ 보μ΄λ impl PartialEq
μ μΆ©μ‘± ν νμκ° μμ΅λλ€.
ν₯λ―Έλ‘κ²λ <TypeB as Partial>
μ΄ λ³΄μΌ λλ§λ€ κ²μ¬κ° μνλκ³ μ μ ν μ€λ₯κ° λ°μν©λλ€.
λ€μμ μ¬νμ λλ€.
pub trait Partial: PartialEq {
fn foo() -> Option<bool>;
}
pub trait Complete: Partial {
fn foo() -> bool;
}
impl<T> Partial for T
where
T: Complete,
{
fn foo() -> Option<bool> {
Some(<Self as Complete>::foo())
}
}
// ----
#[derive(PartialEq)]
pub struct TypeA {}
impl Partial for TypeA {
fn foo() -> Option<bool> {
None
}
}
// ----
// BUG: No compile warning about `PartialEq` not being implemented
// #[derive(PartialEq)]
pub struct TypeB {}
impl Complete for TypeB {
fn foo() -> bool {
true
}
}
// ----
pub fn main() {
println!("{:?}", TypeA::foo());
// This works, but shouldn't!
println!("{:?}", <TypeB as Complete>::foo());
// This would trigger the issue, though.
//println!("{:?}", <TypeB as Partial>::foo());
/* Result in:
error[E0277]: the trait bound `TypeB: std::cmp::PartialEq` is not satisfied
--> src/bin/cyclic_traits.rs:48:22
|
48 | println!("{:?}", <TypeB as Partial>::foo());
| ^^^^^^^^^^^^^^^^^^^^^^^ can't compare `TypeB` with `TypeB`
|
= help: the trait `std::cmp::PartialEq` is not implemented for `TypeB`
= note: required by `Partial::foo`
*/
}
λ€μμ ICE νμμ μ΅μν λ μ¬νμ λλ€.
trait Base {
fn base() {}
}
trait Partial: Base {}
trait Complete: Partial {}
impl<T: Complete> Partial for T {}
struct TypeB;
impl Complete for TypeB {}
fn main() {
ice::<TypeB>();
}
fn ice<P: Partial>() {
P::base();
}
error: internal compiler error: /checkout/src/librustc/traits/trans/mod.rs:75: Encountered error `Unimplemented` selecting `Binder(<TypeB as Base>)` during trans
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: rustc 1.21.0-nightly (cbbe17aa7 2017-08-07) running on x86_64-unknown-linux-gnu
@ arielb1 λ μ΄μ λν΄ μμ μ λ¬Έμ (# 43784)λ₯Ό μ° κ² κ°μ΅λλ€. μ΄μ¨λ μ΄κ²μ # 43786μ μν΄ μμ λμμ΅λλ€.
λλ μ΄κ²μ΄ # 43784μ 볡μ λΌκ³ λ―Ώμ΅λλ€.
κ°μ₯ μ μ©ν λκΈ
λ€μμ ICE νμμ μ΅μν λ μ¬νμ λλ€.