Auto merge of #26727 - remram44:coerceunsized-weak, r=eddyb

This is a simple addition, shouldn't change behavior.

Fixes #26704

I don't know if the coercion for `Rc` is tested, if it is this probably needs the same test with `Weak`.
This commit is contained in:
bors 2015-07-02 09:19:27 +00:00
commit c4b4f07592
3 changed files with 10 additions and 2 deletions

View file

@ -145,6 +145,8 @@ pub struct Weak<T: ?Sized> {
unsafe impl<T: ?Sized + Sync + Send> Send for Weak<T> { }
unsafe impl<T: ?Sized + Sync + Send> Sync for Weak<T> { }
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Weak<U>> for Weak<T> {}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized + fmt::Debug> fmt::Debug for Weak<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

View file

@ -734,6 +734,8 @@ pub struct Weak<T: ?Sized> {
impl<T: ?Sized> !marker::Send for Weak<T> {}
impl<T: ?Sized> !marker::Sync for Weak<T> {}
impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<Weak<U>> for Weak<T> {}
#[unstable(feature = "rc_weak",
reason = "Weak pointers may not belong in this module.")]
impl<T: ?Sized> Weak<T> {

View file

@ -10,10 +10,10 @@
// Test a very simple custom DST coercion.
#![feature(core)]
#![feature(core, rc_weak)]
use std::cell::RefCell;
use std::rc::Rc;
use std::rc::{Rc, Weak};
trait Baz {
fn get(&self) -> i32;
@ -36,9 +36,13 @@ fn main() {
let b: Rc<Baz> = a.clone();
assert_eq!(b.get(), 42);
let c: Weak<i32> = a.downgrade();
let d: Weak<Baz> = c.clone();
let _c = b.clone();
let a: Rc<RefCell<i32>> = Rc::new(RefCell::new(42));
let b: Rc<RefCell<Baz>> = a.clone();
assert_eq!(b.borrow().get(), 42);
let c: Weak<RefCell<Baz>> = a.downgrade();
}