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

Rustc fails to compile code with "source trait is inaccessible", when the source trait is re-exported to be public. #32145

Closed
TyOverby opened this issue Mar 9, 2016 · 5 comments

Comments

@TyOverby
Copy link
Contributor

TyOverby commented Mar 9, 2016

I have a module structure that looks like this:

lib.rs
glyph_packer/
   mod.rs
   buffer2d.rs
rasterize
    mod.rs

The glyph_packer module publicly re-exports a Buffer2d trait from the buffer2d module, which is then used by rasterize/mod.rs.

However, when I attempt to implement the Buffer2d trait, I get this error:

$ rustc -V
rustc 1.8.0-nightly (3623797eb 2016-02-07)
$ cargo build
   Compiling font-atlas v0.1.2 (file:///C:/Users/Ty/workspace/rust/font-atlas)
src\rasterize/mod.rs:59:29: 59:41 error: source trait is inaccessible
src\rasterize/mod.rs:59         self.bytes.get((x + self.width() * y) as usize).cloned()
                                                    ^~~~~~~~~~~~
src\rasterize/mod.rs:59:29: 59:41 note: module `buffer2d` is private
src\rasterize/mod.rs:59         self.bytes.get((x + self.width() * y) as usize).cloned()
                                                    ^~~~~~~~~~~~
src\rasterize/mod.rs:63:17: 63:29 error: source trait is inaccessible
src\rasterize/mod.rs:63         let w = self.width();
                                        ^~~~~~~~~~~~
src\rasterize/mod.rs:63:17: 63:29 note: module `buffer2d` is private
src\rasterize/mod.rs:63         let w = self.width();
                                        ^~~~~~~~~~~~
src\rasterize/mod.rs:73:17: 73:29 error: source trait is inaccessible
src\rasterize/mod.rs:73         assert!(self.width() <= width && self.height() <= height,
                                        ^~~~~~~~~~~~
src\rasterize/mod.rs:73:9: 74:55 note: in this expansion of assert! (defined in <std macros>)
src\rasterize/mod.rs:73:17: 73:29 note: module `buffer2d` is private
src\rasterize/mod.rs:73         assert!(self.width() <= width && self.height() <= height,
                                        ^~~~~~~~~~~~
src\rasterize/mod.rs:73:9: 74:55 note: in this expansion of assert! (defined in <std macros>)
src\rasterize/mod.rs:73:42: 73:55 error: source trait is inaccessible
src\rasterize/mod.rs:73         assert!(self.width() <= width && self.height() <= height,
                                                                 ^~~~~~~~~~~~~
src\rasterize/mod.rs:73:9: 74:55 note: in this expansion of assert! (defined in <std macros>)
src\rasterize/mod.rs:73:42: 73:55 note: module `buffer2d` is private
src\rasterize/mod.rs:73         assert!(self.width() <= width && self.height() <= height,
                                                                 ^~~~~~~~~~~~~
src\rasterize/mod.rs:73:9: 74:55 note: in this expansion of assert! (defined in <std macros>)
src\rasterize/mod.rs:76:9: 76:32 error: source trait is inaccessible
src\rasterize/mod.rs:76         o_new.patch(0, 0, self);
                                ^~~~~~~~~~~~~~~~~~~~~~~
src\rasterize/mod.rs:76:9: 76:32 note: module `buffer2d` is private
src\rasterize/mod.rs:76         o_new.patch(0, 0, self);
                                ^~~~~~~~~~~~~~~~~~~~~~~
src\rasterize/mod.rs:96:13: 96:45 error: source trait is inaccessible
src\rasterize/mod.rs:96             out.set(x, y, (v * 255.0) as u8);
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src\rasterize/mod.rs:96:13: 96:45 note: module `buffer2d` is private
src\rasterize/mod.rs:96             out.set(x, y, (v * 255.0) as u8);
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src\rasterize/mod.rs:104:9: 104:34 error: source trait is inaccessible
src\rasterize/mod.rs:104         packer.set_margin(margin);
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~
src\rasterize/mod.rs:104:9: 104:34 note: module `packer` is private
src\rasterize/mod.rs:104         packer.set_margin(margin);
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~
src\rasterize/mod.rs:106:13: 106:64 error: source trait is inaccessible
src\rasterize/mod.rs:106             packer.pack_resize(&c, |(ow, oh)| (ow * 2, oh * 2));
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src\rasterize/mod.rs:106:13: 106:64 note: module `packer` is private
src\rasterize/mod.rs:106             packer.pack_resize(&c, |(ow, oh)| (ow * 2, oh * 2));
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src\rasterize/mod.rs:108:9: 108:26 error: source trait is inaccessible
src\rasterize/mod.rs:108         packer.into_buf()
                                 ^~~~~~~~~~~~~~~~~
src\rasterize/mod.rs:108:9: 108:26 note: module `packer` is private
src\rasterize/mod.rs:108         packer.into_buf()
                                 ^~~~~~~~~~~~~~~~~
error: aborting due to 9 previous errors
Could not compile `font-atlas`.

By making the glyph_packer module pub mod buffer2d; pub use buffer2d::Buffer2d; instead of just mod buffer2d; pub use buffer2d::Buffer2d; the error goes away.

@TyOverby TyOverby changed the title Rustc fails to compile code with "source trait is inaccessible", when the source trait is public. Rustc fails to compile code with "source trait is inaccessible", when the source trait is re-exported to be public. Mar 9, 2016
@TyOverby
Copy link
Contributor Author

TyOverby commented Mar 9, 2016

@alexcrichton
Copy link
Member

cc @jseyfried, @petrochenkov

@jseyfried
Copy link
Contributor

This is due to #18241, which was fixed by #31920 (merged three days ago).

@TyOverby I checked that your repo compiles on the most recent nighties.

@alexcrichton
Copy link
Member

Oh awesome, thanks @jseyfried!

@TyOverby
Copy link
Contributor Author

TyOverby commented Mar 9, 2016

Thanks @jseyfried!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants