Skip to content

Commit 5d15f4f

Browse files
committed
Fix remaining lints by hand
1 parent 3ea4cf1 commit 5d15f4f

File tree

12 files changed

+95
-51
lines changed

12 files changed

+95
-51
lines changed

gl/examples/basic.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ fn main() {
3434
*control_flow = ControlFlow::Wait;
3535
match event {
3636
Event::LoopDestroyed => (),
37-
Event::WindowEvent { event, .. } => if event == WindowEvent::CloseRequested { *control_flow = ControlFlow::Exit },
37+
Event::WindowEvent { event, .. } => {
38+
if event == WindowEvent::CloseRequested {
39+
*control_flow = ControlFlow::Exit
40+
}
41+
},
3842
Event::RedrawRequested(_) => {
3943
unsafe {
4044
gl::ClearColor(0.3, 0.3, 0.3, 1.0);

gl/examples/triangle.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ extern crate glutin;
1717

1818
use gl::types::*;
1919
use std::ffi::CString;
20-
use std::mem;
2120
use std::ptr;
2221
use std::str;
2322

@@ -57,20 +56,19 @@ fn compile_shader(src: &str, ty: GLenum) -> GLuint {
5756
// Fail on error
5857
if status != (gl::TRUE as GLint) {
5958
let mut len = 0;
59+
let mut outlen = 0;
6060
gl::GetShaderiv(shader, gl::INFO_LOG_LENGTH, &mut len);
6161
let mut buf = Vec::with_capacity(len as usize);
62-
buf.set_len((len as usize) - 1); // subtract 1 to skip the trailing null character
6362
gl::GetShaderInfoLog(
6463
shader,
6564
len,
66-
ptr::null_mut(),
65+
&mut outlen, // Number of characters written excluding null terminator
6766
buf.as_mut_ptr() as *mut GLchar,
6867
);
68+
buf.set_len(outlen as usize);
6969
panic!(
7070
"{}",
71-
str::from_utf8(&buf)
72-
.ok()
73-
.expect("ShaderInfoLog not valid utf8")
71+
str::from_utf8(&buf).expect("ShaderInfoLog not valid utf8")
7472
);
7573
}
7674
}
@@ -89,21 +87,20 @@ fn link_program(vs: GLuint, fs: GLuint) -> GLuint {
8987

9088
// Fail on error
9189
if status != (gl::TRUE as GLint) {
92-
let mut len: GLint = 0;
90+
let mut len = 0;
91+
let mut outlen = 0;
9392
gl::GetProgramiv(program, gl::INFO_LOG_LENGTH, &mut len);
9493
let mut buf = Vec::with_capacity(len as usize);
95-
buf.set_len((len as usize) - 1); // subtract 1 to skip the trailing null character
9694
gl::GetProgramInfoLog(
9795
program,
9896
len,
99-
ptr::null_mut(),
97+
&mut outlen, // Number of characters written excluding null terminator
10098
buf.as_mut_ptr() as *mut GLchar,
10199
);
100+
buf.set_len(outlen as usize);
102101
panic!(
103102
"{}",
104-
str::from_utf8(&buf)
105-
.ok()
106-
.expect("ProgramInfoLog not valid utf8")
103+
str::from_utf8(&buf).expect("ProgramInfoLog not valid utf8")
107104
);
108105
}
109106
program
@@ -141,8 +138,8 @@ fn main() {
141138
gl::BindBuffer(gl::ARRAY_BUFFER, vbo);
142139
gl::BufferData(
143140
gl::ARRAY_BUFFER,
144-
(VERTEX_DATA.len() * mem::size_of::<GLfloat>()) as GLsizeiptr,
145-
mem::transmute(&VERTEX_DATA[0]),
141+
size_of_val(&VERTEX_DATA) as GLsizeiptr,
142+
VERTEX_DATA.as_ptr().cast(),
146143
gl::STATIC_DRAW,
147144
);
148145

@@ -169,16 +166,18 @@ fn main() {
169166
*control_flow = ControlFlow::Wait;
170167
match event {
171168
Event::LoopDestroyed => (),
172-
Event::WindowEvent { event, .. } => if event == WindowEvent::CloseRequested {
173-
// Cleanup
174-
unsafe {
175-
gl::DeleteProgram(program);
176-
gl::DeleteShader(fs);
177-
gl::DeleteShader(vs);
178-
gl::DeleteBuffers(1, &vbo);
179-
gl::DeleteVertexArrays(1, &vao);
169+
Event::WindowEvent { event, .. } => {
170+
if event == WindowEvent::CloseRequested {
171+
// Cleanup
172+
unsafe {
173+
gl::DeleteProgram(program);
174+
gl::DeleteShader(fs);
175+
gl::DeleteShader(vs);
176+
gl::DeleteBuffers(1, &vbo);
177+
gl::DeleteVertexArrays(1, &vao);
178+
}
179+
*control_flow = ControlFlow::Exit
180180
}
181-
*control_flow = ControlFlow::Exit
182181
},
183182
Event::RedrawRequested(_) => {
184183
unsafe {

gl/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,16 @@
7272
7373
#![crate_name = "gl"]
7474
#![crate_type = "lib"]
75+
#![allow(
76+
clippy::missing_safety_doc,
77+
clippy::missing_transmute_annotations,
78+
clippy::too_many_arguments,
79+
clippy::unused_unit
80+
)]
7581

7682
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
83+
84+
// #[test]
85+
// fn x() {
86+
// ActiveShaderProgram()
87+
// }

gl_generator/generators/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ where
5353
writeln!(dest,
5454
"#[allow(dead_code, non_upper_case_globals)] pub const {ident}: {types_prefix}{ty} = {value}{cast_suffix};",
5555
ident = enm.ident,
56-
types_prefix = if enm.ty == "&'static str" { "" } else { types_prefix },
56+
types_prefix = if enm.ty == "&str" { "" } else { types_prefix },
5757
ty = enm.ty,
5858
value = enm.value,
5959
cast_suffix = match enm.cast {

gl_generator/registry/parse.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,7 @@ fn underscore_keyword(ident: String) -> String {
126126
}
127127

128128
fn trim_str<'a>(s: &'a str, trim: &str) -> &'a str {
129-
if s.starts_with(trim) {
130-
&s[trim.len()..]
131-
} else {
132-
s
133-
}
129+
s.strip_prefix(trim).unwrap_or(s)
134130
}
135131

136132
fn trim_enum_prefix(ident: &str, api: Api) -> String {
@@ -164,7 +160,7 @@ fn make_enum(ident: String, ty: Option<String>, value: String, alias: Option<Str
164160
Some(ref ty) if ty == "u" => "GLuint",
165161
Some(ref ty) if ty == "ull" => "GLuint64",
166162
Some(ty) => panic!("Unhandled enum type: {}", ty),
167-
None if value.starts_with("\"") => "&'static str",
163+
None if value.starts_with("\"") => "&str",
168164
None if ident == "TRUE" || ident == "FALSE" => "GLboolean",
169165
None => "GLenum",
170166
};
@@ -246,7 +242,7 @@ fn merge_map(a: &mut BTreeMap<String, Vec<String>>, b: BTreeMap<String, Vec<Stri
246242
#[derive(Clone)]
247243
struct Feature {
248244
pub api: Api,
249-
pub name: String,
245+
pub _name: String,
250246
pub number: String,
251247
pub requires: Vec<Require>,
252248
pub removes: Vec<Remove>,
@@ -713,10 +709,7 @@ impl FromXml for Require {
713709
fn convert<P: Parse>(parser: &mut P, _: &[Attribute]) -> Require {
714710
debug!("Doing a FromXml on Require");
715711
let (enums, commands) = parser.consume_two("enum", "command", "require");
716-
Require {
717-
enums,
718-
commands,
719-
}
712+
Require { enums, commands }
720713
}
721714
}
722715

@@ -749,7 +742,7 @@ impl FromXml for Feature {
749742

750743
Feature {
751744
api,
752-
name,
745+
_name: name,
753746
number,
754747
requires: require,
755748
removes: remove,

khronos_api/build.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ fn main() {
3838
// The slice will have one entry for each WebGL extension. To find the
3939
// extensions we mirror the behaviour of the `api_webgl/extensions/find-exts`
4040
// shell script.
41-
let mut paths: Vec<_> = root.read_dir().unwrap().map(|e| e.unwrap().path()).collect();
41+
let mut paths: Vec<_> = root
42+
.read_dir()
43+
.unwrap()
44+
.map(|e| e.unwrap().path())
45+
.collect();
4246
// Sort the list of paths in order for the webgl_exts.rs file to be created
4347
// deterministically.
4448
paths.sort();

khronos_api/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ pub const GLX_XML: &[u8] = include_bytes!("../api/xml/glx.xml");
3333
pub const GL_ANGLE_EXT_XML: &[u8] = include_bytes!("../api_angle/scripts/gl_angle_ext.xml");
3434

3535
/// The contents of [`egl_angle_ext.xml`](https://github.com/google/angle/blob/master/scripts/egl_angle_ext.xml)
36-
pub const EGL_ANGLE_EXT_XML: &[u8] =
37-
include_bytes!("../api_angle/scripts/egl_angle_ext.xml");
36+
pub const EGL_ANGLE_EXT_XML: &[u8] = include_bytes!("../api_angle/scripts/egl_angle_ext.xml");
3837

3938
/// The contents of [`webgl.idl`](https://github.com/KhronosGroup/WebGL/blob/master/specs/latest/1.0/webgl.idl)
4039
pub const WEBGL_IDL: &[u8] = include_bytes!("../api_webgl/specs/latest/1.0/webgl.idl");
@@ -44,5 +43,4 @@ pub const WEBGL2_IDL: &[u8] = include_bytes!("../api_webgl/specs/latest/2.0/webg
4443

4544
/// The contents of the WebGL extension XML files
4645
/// These are discovered via a build script to avoid having to list each extension by name.
47-
pub const WEBGL_EXT_XML: &[&[u8]] =
48-
include!(concat!(env!("OUT_DIR"), "/webgl_exts.rs"));
46+
pub const WEBGL_EXT_XML: &[&[u8]] = include!(concat!(env!("OUT_DIR"), "/webgl_exts.rs"));

tests/test_add_registries/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,11 @@
1313
// limitations under the License.
1414

1515
pub mod gl {
16+
#![allow(
17+
clippy::missing_safety_doc,
18+
clippy::missing_transmute_annotations,
19+
clippy::too_many_arguments,
20+
clippy::unused_unit
21+
)]
1622
include!(concat!(env!("OUT_DIR"), "/test_add_registries.rs"));
1723
}

tests/test_gen_symbols/lib.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#![allow(
16+
clippy::missing_transmute_annotations,
17+
clippy::too_many_arguments,
18+
clippy::unused_unit,
19+
clippy::upper_case_acronyms
20+
)]
21+
1522
use std::os::raw;
1623

1724
include!(concat!(env!("OUT_DIR"), "/test_gen_symbols.rs"));
@@ -54,18 +61,14 @@ pub fn compile_test_glsc2() {
5461

5562
pub fn compile_test_glx() {
5663
unsafe {
57-
let _ = glx::GetProcAddress(std::mem::MaybeUninit::uninit().assume_init());
58-
glx::SwapBuffers(
59-
std::mem::MaybeUninit::uninit().assume_init(),
60-
std::mem::MaybeUninit::uninit().assume_init(),
61-
);
64+
let _ = glx::GetProcAddress(std::ptr::null());
65+
glx::SwapBuffers(std::ptr::null_mut(), 0);
6266
}
6367
}
6468

6569
pub fn compile_test_wgl() {
6670
unsafe {
67-
let _: wgl::types::HGLRC =
68-
wgl::CreateContext(std::mem::MaybeUninit::uninit().assume_init());
71+
let _: wgl::types::HGLRC = wgl::CreateContext(std::ptr::null());
6972
}
7073
}
7174

@@ -84,6 +87,6 @@ pub fn compile_test_egl() {
8487
];
8588

8689
let _ = egl::GetDisplay(egl::DEFAULT_DISPLAY);
87-
egl::Terminate(std::mem::MaybeUninit::uninit().assume_init());
90+
egl::Terminate(std::ptr::null());
8891
}
8992
}

tests/test_no_warnings/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,18 @@
1414

1515
//! Making sure that no warning is generated by code from generate_gl_bindings!
1616
#![deny(warnings)]
17+
#![allow(
18+
// Allow clashing definitions because we're pasting and testing all APIs at once (with
19+
// references to different types).
20+
clashing_extern_declarations,
21+
22+
unused_imports,
23+
clippy::let_and_return,
24+
clippy::let_unit_value,
25+
clippy::missing_transmute_annotations,
26+
clippy::too_many_arguments,
27+
clippy::unused_unit,
28+
clippy::upper_case_acronyms,
29+
)]
1730

1831
include!(concat!(env!("OUT_DIR"), "/test_no_warnings.rs"));

0 commit comments

Comments
 (0)