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

gl_generator: clippy warnings in generated code #523

Open
iceiix opened this issue Jun 29, 2020 · 2 comments
Open

gl_generator: clippy warnings in generated code #523

iceiix opened this issue Jun 29, 2020 · 2 comments

Comments

@iceiix
Copy link

iceiix commented Jun 29, 2020

Hello, I'm using gl-generator in my project and it works great, but I'm looking to enable clippy, and it is reporting many warnings in gl-generator's generated code. Any ideas how to best solve this?

Complete output (619 warnings): https://gist.github.com/iceiix/60cdb5a3e1aae1550fec21690e18cd86

My build script is nothing special, generating bindings for OpenGL 3.2 core:

use gl_generator::{Api, Fallbacks, GlobalGenerator, Profile, Registry};
use std::env;
use std::fs::File;
use std::io::BufWriter;
use std::path::Path;

fn main() {
    let out_dir = env::var("OUT_DIR").unwrap();
    let dest = Path::new(&out_dir);

    let mut file = BufWriter::new(File::create(&dest.join("bindings.rs")).unwrap());
    Registry::new(Api::Gl, (3, 2), Profile::Core, Fallbacks::All, [])
        .write_bindings(GlobalGenerator, &mut file)
        .unwrap();
}

Breakdown of the warnings:

  • 13 warning: this function has too many arguments (clippy::too_many_arguments)
  • 290 warning: unneeded unit return type (clippy::unused_unit)
  • 316 warning: unsafe function's docs miss # Safety section (clippy::missing_safety_doc)

These warnings might not make sense for generated code, so I tried to suppress them by writing #![allow(clippy::all)] at the top of the bindings.rs file (generated above). However this fails because #![] cannot be applied at this position. It may have be emitted before each module, or a more targeted fix with #[allow(clippy::too_many_arguments)] attached to the generated functions, etc. Or is there a better way to address these warnings systematically?

@Lokathor
Copy link

The best way to use gl generator is to generate some bindings and then manually edit the file after the fact, so just edit the file by hand.

You should not be making the bindings during the main build, that's very inefficient.

@therocode
Copy link

The best way to use gl generator is to generate some bindings and then manually edit the file after the fact, so just edit the file by hand.

And then re-run it when you change some parameters just to have to re-apply all hand-edited changes? That's just madness. Would be more reasonable IMO to fix the warnings at the source (i.e. the generator).
clippy::too_many_arguments might be hard to fix, but that one can at least be configured in a clippy.toml file on a project level. I don't see a reason to not fix the others though.

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