@@ -34,7 +34,7 @@ impl<'tcx> SelectionCache<'tcx> {
34
34
/// clauses, and so forth that might resolve an obligation. Sometimes
35
35
/// we'll be able to say definitively that (e.g.) an impl does not
36
36
/// apply to the obligation: perhaps it is defined for `usize` but the
37
- /// obligation is for `int `. In that case, we drop the impl out of the
37
+ /// obligation is for `i32 `. In that case, we drop the impl out of the
38
38
/// list. But the other cases are considered *candidates*.
39
39
///
40
40
/// For selection to succeed, there must be exactly one matching
@@ -54,12 +54,14 @@ impl<'tcx> SelectionCache<'tcx> {
54
54
/// will always be satisfied) picking the blanket impl will be wrong
55
55
/// for at least *some* substitutions. To make this concrete, if we have
56
56
///
57
- /// trait AsDebug { type Out : fmt::Debug; fn debug(self) -> Self::Out; }
58
- /// impl<T: fmt::Debug> AsDebug for T {
59
- /// type Out = T;
60
- /// fn debug(self) -> fmt::Debug { self }
61
- /// }
62
- /// fn foo<T: AsDebug>(t: T) { println!("{:?}", <T as AsDebug>::debug(t)); }
57
+ /// ```rust, ignore
58
+ /// trait AsDebug { type Out: fmt::Debug; fn debug(self) -> Self::Out; }
59
+ /// impl<T: fmt::Debug> AsDebug for T {
60
+ /// type Out = T;
61
+ /// fn debug(self) -> fmt::Debug { self }
62
+ /// }
63
+ /// fn foo<T: AsDebug>(t: T) { println!("{:?}", <T as AsDebug>::debug(t)); }
64
+ /// ```
63
65
///
64
66
/// we can't just use the impl to resolve the `<T as AsDebug>` obligation
65
67
/// -- a type from another crate (that doesn't implement `fmt::Debug`) could
@@ -79,14 +81,16 @@ impl<'tcx> SelectionCache<'tcx> {
79
81
/// inference variables. The can lead to inference making "leaps of logic",
80
82
/// for example in this situation:
81
83
///
82
- /// pub trait Foo<T> { fn foo(&self) -> T; }
83
- /// impl<T> Foo<()> for T { fn foo(&self) { } }
84
- /// impl Foo<bool> for bool { fn foo(&self) -> bool { *self } }
84
+ /// ```rust, ignore
85
+ /// pub trait Foo<T> { fn foo(&self) -> T; }
86
+ /// impl<T> Foo<()> for T { fn foo(&self) { } }
87
+ /// impl Foo<bool> for bool { fn foo(&self) -> bool { *self } }
85
88
///
86
- /// pub fn foo<T>(t: T) where T: Foo<bool> {
87
- /// println!("{:?}", <T as Foo<_>>::foo(&t));
88
- /// }
89
- /// fn main() { foo(false); }
89
+ /// pub fn foo<T>(t: T) where T: Foo<bool> {
90
+ /// println!("{:?}", <T as Foo<_>>::foo(&t));
91
+ /// }
92
+ /// fn main() { foo(false); }
93
+ /// ```
90
94
///
91
95
/// Here the obligation `<T as Foo<$0>>` can be matched by both the blanket
92
96
/// impl and the where-clause. We select the where-clause and unify `$0=bool`,
0 commit comments