Skip to content

Pointer implementation for Rc and Arc should print the address of pointed value  #35384

Closed
@malbarbo

Description

@malbarbo

Consider this example:

#![feature(shared, unique)]

use std::ptr::{Shared, Unique};
use std::rc::Rc;
use std::sync::Arc;

fn main() {
    let x = Box::new(10);
    assert_eq!(format!("{:p}", &*x), format!("{:p}", x));

    let a = &mut 10 as *mut _;
    let x = Shared::new(a).unwrap();
    assert_eq!(format!("{:p}", a), format!("{:p}", x));

    let a = &mut 10 as *mut _;
    let x = Unique::new(a).unwrap();
    assert_eq!(format!("{:p}", a), format!("{:p}", x));

    let x = Rc::new(10);
    println!("rc {:p} {:p}", &*x, x);

    let x = Arc::new(10);
    println!("arc {:p} {:p}", &*x, x);
}

the code runs fine but the printed values are different:

rc 0x7f1eefa1e070 0x7f1eefa1e060
arc 0x7f1eefa1e0d0 0x7f1eefa1e0c0

The Pointer implementation for Rc and Arc prints the address of the inner data (RcBox and ArcInner) instead of the address of the stored value. This seems to be inconsistent with the Pointer implementation for Box, Shared and Unique.

If this is a real issue, I can write a patch to fix it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-acceptedCategory: A feature request that has been accepted pending implementation.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions