2014-12-24 14:05:57 -06:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2015-03-22 15:13:15 -05:00
|
|
|
// pretty-expanded FIXME #23616
|
|
|
|
|
2015-01-05 15:16:49 -06:00
|
|
|
pub trait Borrow<Borrowed: ?Sized> {
|
2014-12-24 14:05:57 -06:00
|
|
|
fn borrow(&self) -> &Borrowed;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Sized> Borrow<T> for T {
|
|
|
|
fn borrow(&self) -> &T { self }
|
|
|
|
}
|
|
|
|
|
|
|
|
trait Foo {
|
|
|
|
fn foo(&self, other: &Self);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bar<K, Q>(k: &K, q: &Q) where K: Borrow<Q>, Q: Foo {
|
|
|
|
q.foo(k.borrow())
|
|
|
|
}
|
|
|
|
|
2015-02-12 09:29:52 -06:00
|
|
|
struct MyTree<K>(K);
|
2014-12-24 14:05:57 -06:00
|
|
|
|
|
|
|
impl<K> MyTree<K> {
|
|
|
|
// This caused a failure in #18906
|
|
|
|
fn bar<Q>(k: &K, q: &Q) where K: Borrow<Q>, Q: Foo {
|
|
|
|
q.foo(k.borrow())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|