mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-10 08:57:36 +00:00
parent
b2e65ee6e4
commit
a329a61b9b
@ -668,6 +668,13 @@ impl<T: fmt::Debug> fmt::Debug for Arc<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl<T> fmt::Pointer for Arc<T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
fmt::Pointer::fmt(&*self._ptr, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T: Default + Sync + Send> Default for Arc<T> {
|
impl<T: Default + Sync + Send> Default for Arc<T> {
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
@ -275,6 +275,16 @@ impl<T: fmt::Debug + ?Sized> fmt::Debug for Box<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl<T> fmt::Pointer for Box<T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
// It's not possible to extract the inner Uniq directly from the Box,
|
||||||
|
// instead we cast it to a *const which aliases the Unique
|
||||||
|
let ptr: *const T = &**self;
|
||||||
|
fmt::Pointer::fmt(&ptr, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T: ?Sized> Deref for Box<T> {
|
impl<T: ?Sized> Deref for Box<T> {
|
||||||
type Target = T;
|
type Target = T;
|
||||||
|
@ -634,6 +634,13 @@ impl<T: fmt::Debug> fmt::Debug for Rc<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl<T> fmt::Pointer for Rc<T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
fmt::Pointer::fmt(&*self._ptr, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A weak version of `Rc<T>`.
|
/// A weak version of `Rc<T>`.
|
||||||
///
|
///
|
||||||
/// Weak references do not count when determining if the inner value should be
|
/// Weak references do not count when determining if the inner value should be
|
||||||
|
@ -94,6 +94,7 @@ use mem;
|
|||||||
use clone::Clone;
|
use clone::Clone;
|
||||||
use intrinsics;
|
use intrinsics;
|
||||||
use ops::Deref;
|
use ops::Deref;
|
||||||
|
use core::fmt;
|
||||||
use option::Option::{self, Some, None};
|
use option::Option::{self, Some, None};
|
||||||
use marker::{PhantomData, Send, Sized, Sync};
|
use marker::{PhantomData, Send, Sized, Sync};
|
||||||
use nonzero::NonZero;
|
use nonzero::NonZero;
|
||||||
@ -570,3 +571,10 @@ impl<T:?Sized> Deref for Unique<T> {
|
|||||||
unsafe { mem::transmute(&*self.pointer) }
|
unsafe { mem::transmute(&*self.pointer) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl<T> fmt::Pointer for Unique<T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
fmt::Pointer::fmt(&*self.pointer, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -111,6 +111,13 @@ impl<T: Display> Display for P<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
impl<T> fmt::Pointer for P<T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
fmt::Pointer::fmt(&self.ptr, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: Hash> Hash for P<T> {
|
impl<T: Hash> Hash for P<T> {
|
||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
(**self).hash(state);
|
(**self).hash(state);
|
||||||
|
28
src/test/run-pass/fmt-pointer-trait.rs
Normal file
28
src/test/run-pass/fmt-pointer-trait.rs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright 2015 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.
|
||||||
|
|
||||||
|
#![feature(libc)]
|
||||||
|
extern crate libc;
|
||||||
|
use std::ptr;
|
||||||
|
use std::rc::Rc;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let p: *const libc::c_void = ptr::null();
|
||||||
|
let rc = Rc::new(1usize);
|
||||||
|
let arc = Arc::new(1usize);
|
||||||
|
let b = Box::new("hi");
|
||||||
|
|
||||||
|
let _ = format!("{:p}{:p}{:p}",
|
||||||
|
rc, arc, b);
|
||||||
|
|
||||||
|
assert_eq!(format!("{:p}", p),
|
||||||
|
"0x0");
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user