Skip to content

Clippy and const and &'static references #1612

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

Closed
martinthomson opened this issue Aug 19, 2019 · 5 comments · Fixed by #2099
Closed

Clippy and const and &'static references #1612

martinthomson opened this issue Aug 19, 2019 · 5 comments · Fixed by #2099

Comments

@martinthomson
Copy link

Input C/C++ Header

#define X "string"

Bindgen Invocation

I don't think that I've tweaked anything here.

Actual Results

pub const X: &'static [u8; 2usize] = b"string\0";

This results in warnings from clippy when compiled with #![deny(warnings)]. The use of &'static trips clippy::redundant_static_lifetimes.

Expected Results

As explained in the lint, the use of &'static is redundant and can be removed.

@Lokathor
Copy link
Contributor

I was just about to open this issue myself <3

@emilio
Copy link
Contributor

emilio commented Aug 31, 2019

Is it redundant in all the rust versions that bindgen supports? I'm not sure we intentionally keep our generated code clippy-warning-free, but improvements are welcome of course.

@Lokathor
Copy link
Contributor

Clearly the generated module should simply insert

#![allow(clippy::redundant_static_lifetimes)]

If you're targeting a rust version that allows tool attributes :P

But more seriously, the 'static can probably be skipped if the target rust version is new enough.

looking through the releases file, seems like 1.17 made the change here https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1170-2017-04-27

@emilio
Copy link
Contributor

emilio commented Aug 31, 2019

Ok, we could add a rust-target for 1.17 and just not emit the &'static if the rust target version is greater than that.

@wucke13
Copy link

wucke13 commented Feb 16, 2021

I was about to open this issue and then found it already here. Is this still considered a TODO?

aplanas added a commit to aplanas/rust-bindgen that referenced this issue Sep 17, 2021
Constant and static declaration have a 'static live time by default,
that is already elided since 1.17.

Clippy complains on this kind of strings that are present in the
generated code.

This patch remove the 'static live time for those strings.

Fix rust-lang#1612

Signed-off-by: Alberto Planas <[email protected]>
aplanas added a commit to aplanas/rust-bindgen that referenced this issue Sep 17, 2021
Constant and static declaration have a 'static live time by default,
that is already elided since 1.17.

Clippy complains on this kind of strings that are present in the
generated code.

This patch remove the 'static live time for those strings.

Fix rust-lang#1612

Signed-off-by: Alberto Planas <[email protected]>
aplanas added a commit to aplanas/rust-bindgen that referenced this issue Oct 14, 2021
Constant and static declaration have a 'static live time by default,
that is already elided since 1.17.

Clippy complains on this kind of strings that are present in the
generated code.

This patch remove the 'static live time for those strings.

Fix rust-lang#1612

Signed-off-by: Alberto Planas <[email protected]>
aplanas added a commit to aplanas/rust-bindgen that referenced this issue Nov 8, 2021
Constant and static declaration have a 'static live time by default,
that is already elided since 1.17.

Clippy complains on this kind of strings that are present in the
generated code.

This patch remove the 'static live time for those strings when rustc >
1.17 via a new added RustFeature.

Fix rust-lang#1612

Signed-off-by: Alberto Planas <[email protected]>
aplanas added a commit to aplanas/rust-bindgen that referenced this issue Nov 8, 2021
Constant and static declaration have a 'static live time by default,
that is already elided since 1.17.

Clippy complains on this kind of strings that are present in the
generated code.

This patch remove the 'static live time for those strings when rustc >
1.17 via a new added RustFeature.

Fix rust-lang#1612

Signed-off-by: Alberto Planas <[email protected]>
aplanas added a commit to aplanas/rust-bindgen that referenced this issue Nov 8, 2021
Constant and static declaration have a 'static live time by default,
that is already elided since 1.17.

Clippy complains on this kind of strings that are present in the
generated code.

This patch remove the 'static live time for those strings when rustc >
1.17 via a new added RustFeature.

Fix rust-lang#1612

Signed-off-by: Alberto Planas <[email protected]>
aplanas added a commit to aplanas/rust-bindgen that referenced this issue Nov 8, 2021
Constant and static declaration have a 'static live time by default,
that is already elided since 1.17.

Clippy complains on this kind of strings that are present in the
generated code.

This patch remove the 'static live time for those strings when rustc >
1.17 via a new added RustFeature.

Fix rust-lang#1612

Signed-off-by: Alberto Planas <[email protected]>
emilio pushed a commit that referenced this issue Nov 26, 2021
Constant and static declaration have a 'static live time by default,
that is already elided since 1.17.

Clippy complains on this kind of strings that are present in the
generated code.

This patch remove the 'static live time for those strings when rustc >
1.17 via a new added RustFeature.

Fix #1612

Signed-off-by: Alberto Planas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants