Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pnkfelix opened this issue Jan 26, 2015 · 4 comments · Fixed by #32073
Closed

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

pnkfelix opened this issue Jan 26, 2015 · 4 comments · Fixed by #32073
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name resolution

Comments

@pnkfelix
Copy link
Member

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
@pnkfelix pnkfelix changed the title "error: source trait is private" fixed by adding use of *struct* "error: source trait is private" (fixed by adding use of *struct*) Jan 26, 2015
@arielb1
Copy link
Contributor

arielb1 commented Jan 27, 2015

importing std::any::Any also works (as get_type_id comes from it). I think this is an error message problem - it should at least talk about the relevant trait.

@pnkfelix
Copy link
Member Author

@arielb1 but should we be worried that importing a struct fixed things here? I am used to needing to import traits in order to be able to call their methods. I'm not clear on why importing a struct fixed things here.

@pnkfelix pnkfelix added A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name resolution labels Jan 27, 2015
@steveklabnik
Copy link
Member

Triage: updated code, made minimal:

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

fn main() {
    let child = thread::spawn(|| {
    });
    child.join().unwrap_err().get_type_id();
}

@jseyfried
Copy link
Contributor

This happens because resolve only loads the items in an external module if this is needed for name resolution (i.e. if the module appears as a non-final segment in a path). Since we build the set of external exports while loading external modules, unused external modules are not counted as exported, leading the privacy checker to incorrectly consider them to be private.

jseyfried added a commit to jseyfried/rust that referenced this issue Mar 6, 2016
bors added a commit that referenced this issue Mar 9, 2016
…ikomatsakis

Fix incorrect trait privacy error

This PR fixes #21670 by using the crate metadata instead of `ExternalExports` to determine if an external item is public.

r? @nikomatsakis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name resolution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants