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

include_dir generates function calls that need promotion, leading to issues with Rust 1.79+ #99

Closed
RalfJung opened this issue Jun 17, 2024 · 2 comments · Fixed by #100
Closed

Comments

@RalfJung
Copy link

RalfJung commented Jun 17, 2024

Apparently, this crate generates code like

Some(include_dir::Dir::new(
        "",
        &[include_dir::DirEntry::File(include_dir::File::new(
            "test_file.txt",
            b"",
        ))],
    ))

It then relies on the part in &[...] to be const-promoted. However, const-promotion of arbitrary function calls is problematic, and in Rust 1.79 it has been limited to only occur in straight-line code, causing compilation failures for some users of this crate.

The intended way to obtain 'static references to things computed by const fn is to make this explicitly const -- either via const { ... } blocks, or (when support for older versions of Rust is required), via explicit const items:

Some(include_dir::Dir::new(
        "",
        {
            const ENTRIES: &'static [DirEntry<'static>] = &[include_dir::DirEntry::File(include_dir::File::new(
                "test_file.txt",
                b"",
            ))];
            ENTRIES
        },
    ))

Would be good to get this crate updated to avoid problems related to promotion of function calls. :)

@Michael-F-Bryan
Copy link
Owner

This was odd. I tried running the crate's tests with 1.79 and nightly, and it built just fine 🤔

I've made the fix anyway. Let's see if it resolves things for other people.

@RalfJung
Copy link
Author

Thanks for the quick fix!

This was odd. I tried running the crate's tests with 1.79 and nightly, and it built just fine 🤔

Yeah, rust-lang/rust#121557 is rather odd, making it tricky to write a good test. This still works fine:

pub static ASSETS_DIR: Option<include_dir::Dir<'_>> = Some(include_dir::include_dir!("$CARGO_MANIFEST_DIR/assets"));

but putting the include_dir! inside an if breaks it. It's kind of a hack but for backcompat reasons it's hard to do better...

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

Successfully merging a pull request may close this issue.

2 participants