Skip to content

"error: source trait is private" (fixed by adding use of *struct*) #21670

Closed
@pnkfelix

Description

@pnkfelix

My attempt to call Any::get_type_id() and use its return value of as an instance of fmt::Debug does not work without import of std::any::TypeId struct: http://doc.rust-lang.org/std/any/struct.TypeId.html

Example code:

use std::thread;
// use std::any::TypeId; // uncomment this line to make the compile work

fn main() {
    let b1 = Box::new(3u64);
    println!("hello world, b1: {:?}", b1);
    let child = thread::Thread::scoped(|| {
        let b2 = Box::new(4u64);
        println!("other thread b2: {:?}", b2);
    });
    match child.join() {
        Ok(()) => {}
        Err(ref panic_arg) => {
            if let Some(s) = panic_arg.downcast_ref::<&str>() {
                println!("whoops child died with str: {}", s);
            } else if let Some(s) = panic_arg.downcast_ref::<String>() {
                println!("whoops child died with String: {}", s);
            } else {
                let id = panic_arg.get_type_id();
                println!("whoops child died with unknown panic arg, id: {:?}", id);
            }
        }
    }
}

Transcript of attempt to compile:

<anon>:19:26: 19:49 error: source trait is private
<anon>:19                 let id = panic_arg.get_type_id();
                                   ^~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
playpen: application terminated with error code 101

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions