Can I avoid eager ambiguity resolution for trait implementations with generics?

后端 未结 2 1616
日久生厌
日久生厌 2020-12-02 02:41

Consider the following Rust code [playground]:

use std::collections::HashMap;
use std::hash::Hash;

trait Foo {
    const FOO: i32;
}

impl

        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 03:05

    Can I avoid eager ambiguity resolution for trait implementations with generics?

    No.

    Is it possible to have [ambiguity resolution to be done at the call site, rather than at the definition site]?

    No.


    There's a (long-delayed) RFC for specialization that will allow overlapping trait implementations, but only when one of them is more specific than the others. I don't believe this is true for your case, so it would not help.

    See also:

    • Conflicting implementations of trait in Rust
    • Why do I get "conflicting implementations of trait" for f32 which does not implement Ord?
    • Why do I get a conflicting implementations error when specializing a trait?
    • How is there a conflicting implementation of `From` when using a generic type?

提交回复
热议问题