@@ -34,7 +34,7 @@ impl<'tcx> SelectionCache<'tcx> {
3434/// clauses, and so forth that might resolve an obligation. Sometimes
3535/// we'll be able to say definitively that (e.g.) an impl does not
3636/// 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
3838/// list. But the other cases are considered *candidates*.
3939///
4040/// For selection to succeed, there must be exactly one matching
@@ -54,12 +54,14 @@ impl<'tcx> SelectionCache<'tcx> {
5454/// will always be satisfied) picking the blanket impl will be wrong
5555/// for at least *some* substitutions. To make this concrete, if we have
5656///
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+ /// ```
6365///
6466/// we can't just use the impl to resolve the `<T as AsDebug>` obligation
6567/// -- a type from another crate (that doesn't implement `fmt::Debug`) could
@@ -79,14 +81,16 @@ impl<'tcx> SelectionCache<'tcx> {
7981/// inference variables. The can lead to inference making "leaps of logic",
8082/// for example in this situation:
8183///
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 } }
8588///
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+ /// ```
9094///
9195/// Here the obligation `<T as Foo<$0>>` can be matched by both the blanket
9296/// impl and the where-clause. We select the where-clause and unify `$0=bool`,
0 commit comments