Skip to content

Item visibility issue #3

@nguiard

Description

@nguiard

Hi,

If I use lazy_static_include_str in a module, and try to use the result somewhere, I get a compile error with private struct, even though I used pub.

More clearly:

  1. This works:
/// main.rs

use lazy_static_include::lazy_static_include_str;

mod some_mod;

lazy_static_include_str! {
    pub TEST1 => "plain/test1.txt",
}

fn main() {
    some_mod::some_func();
}
/// some_mod.rs

pub(crate) fn some_func() {
    println!("{}", crate::TEST1);
}
  1. But this, unexpectedly, does not:
/// main.rs

mod some_mod;
use some_mod::TEST2;

fn main() {
    println!("{}", TEST2);
}
/// some_mod.rs

use lazy_static_include::lazy_static_include_str;

lazy_static_include_str! {
    pub TEST2 => "plain/test2.txt",
}

On the second case, the full output of the compiler is :

error[E0603]: struct `TEST2` is private
 --> src/main.rs:2:15
  |
2 | use some_mod::TEST2;
  |               ^^^^^ private struct
  |
note: the struct `TEST2` is defined here
 --> src/some_mod.rs:3:1
  |
3 | / lazy_static_include_str! {
4 | |     pub TEST2 => "plain/test2.txt",
5 | | }
  | |_^
  = note: this error originates in the macro `__lazy_static_internal` which comes from the expansion of the macro `lazy_static_include_str` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0603`.
error: could not compile `test-lsi-bug` (bin "test-lsi-bug") due to previous error

Tested on nightly (1.71.0-nightly (b628260df 2023-04-22))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions