Fixes recommended by clippy

This commit is contained in:
Joonas Javanainen 2018-08-12 19:20:04 +03:00
parent 130ebfc931
commit da9ee9302b
No known key found for this signature in database
GPG Key ID: D39CCA5CB19B9179
17 changed files with 74 additions and 73 deletions

View File

@ -46,6 +46,7 @@ HIDPI are calculated. Depending on your needs, you may want to set HIDPI to 1
by setting the environment variable `WINIT_HIDPI_FACTOR=1` if you use X11.
- `frame()` now takes a single `FrameSize` argument
- Bump minimum Rust version to 1.24
- `set_mouse_down` takes button states by value, not by reference
### Deprecated

View File

@ -204,7 +204,7 @@ fn configure_keys(imgui: &mut ImGui) {
fn update_mouse(imgui: &mut ImGui, mouse_state: &mut MouseState) {
imgui.set_mouse_pos(mouse_state.pos.0 as f32, mouse_state.pos.1 as f32);
imgui.set_mouse_down(&[
imgui.set_mouse_down([
mouse_state.pressed.0,
mouse_state.pressed.1,
mouse_state.pressed.2,

View File

@ -242,7 +242,7 @@ fn configure_keys(imgui: &mut ImGui) {
fn update_mouse(imgui: &mut ImGui, mouse_state: &mut MouseState) {
imgui.set_mouse_pos(mouse_state.pos.0 as f32, mouse_state.pos.1 as f32);
imgui.set_mouse_down(&[
imgui.set_mouse_down([
mouse_state.pressed.0,
mouse_state.pressed.1,
mouse_state.pressed.2,

View File

@ -13,7 +13,6 @@ extern crate gfx;
extern crate glium;
use std::convert::From;
use std::mem;
use std::os::raw::{c_char, c_float, c_int, c_short, c_uchar, c_uint, c_ushort, c_void};
use std::slice;
@ -902,7 +901,7 @@ pub struct ImDrawData {
impl ImDrawData {
pub unsafe fn cmd_lists(&self) -> &[*const ImDrawList] {
let cmd_lists: *const *const ImDrawList = mem::transmute(self.cmd_lists);
let cmd_lists = self.cmd_lists as *const *const ImDrawList;
slice::from_raw_parts(cmd_lists, self.cmd_lists_count as usize)
}
}

View File

@ -15,7 +15,7 @@ pub struct ChildFrame<'ui, 'p> {
impl<'ui, 'p> ChildFrame<'ui, 'p> {
pub fn new<S: Into<ImVec2>>(_: &Ui<'ui>, name: &'p ImStr, size: S) -> ChildFrame<'ui, 'p> {
ChildFrame {
name: name,
name,
size: size.into(),
border: false,
flags: ImGuiWindowFlags::empty(),

View File

@ -65,8 +65,8 @@ pub struct DragFloat<'ui, 'p> {
impl<'ui, 'p> DragFloat<'ui, 'p> {
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut f32) -> Self {
DragFloat {
label: label,
value: value,
label,
value,
speed: 1.0,
min: 0.0,
max: 0.0,
@ -113,8 +113,8 @@ macro_rules! impl_drag_floatn {
impl<'ui, 'p> $DragFloatN<'ui, 'p> {
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [f32; $N]) -> Self {
$DragFloatN {
label: label,
value: value,
label,
value,
speed: 1.0,
min: 0.0,
max: 0.0,
@ -172,9 +172,9 @@ impl<'ui, 'p> DragFloatRange2<'ui, 'p> {
current_max: &'p mut f32,
) -> Self {
DragFloatRange2 {
label: label,
current_min: current_min,
current_max: current_max,
label,
current_min,
current_max,
speed: 1.0,
min: 0.0,
max: 0.0,
@ -227,8 +227,8 @@ pub struct DragInt<'ui, 'p> {
impl<'ui, 'p> DragInt<'ui, 'p> {
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut i32) -> Self {
DragInt {
label: label,
value: value,
label,
value,
speed: 1.0,
min: 0,
max: 0,
@ -271,8 +271,8 @@ macro_rules! impl_drag_intn {
impl<'ui, 'p> $DragIntN<'ui, 'p> {
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [i32; $N]) -> Self {
$DragIntN {
label: label,
value: value,
label,
value,
speed: 1.0,
min: 0,
max: 0,
@ -326,9 +326,9 @@ impl<'ui, 'p> DragIntRange2<'ui, 'p> {
current_max: &'p mut i32,
) -> Self {
DragIntRange2 {
label: label,
current_min: current_min,
current_max: current_max,
label,
current_min,
current_max,
speed: 1.0,
min: 0,
max: 0,

View File

@ -68,9 +68,9 @@ impl FontGlyphRange {
"A glyph range must be zero-terminated."
);
for i in 0..slice.len() - 1 {
for (i, &glyph) in slice.iter().enumerate().take(slice.len() - 1) {
assert_ne!(
slice[i], 0,
glyph, 0,
"A glyph in a range cannot be zero. \
(Glyph is zero at index {})",
i
@ -122,14 +122,14 @@ impl FontGlyphRange {
unsafe fn to_ptr(&self, atlas: *mut sys::ImFontAtlas) -> *const sys::ImWchar {
match &self.0 {
&FontGlyphRangeData::Chinese => sys::ImFontAtlas_GetGlyphRangesChinese(atlas),
&FontGlyphRangeData::Cyrillic => sys::ImFontAtlas_GetGlyphRangesCyrillic(atlas),
&FontGlyphRangeData::Default => sys::ImFontAtlas_GetGlyphRangesDefault(atlas),
&FontGlyphRangeData::Japanese => sys::ImFontAtlas_GetGlyphRangesJapanese(atlas),
&FontGlyphRangeData::Korean => sys::ImFontAtlas_GetGlyphRangesKorean(atlas),
&FontGlyphRangeData::Thai => sys::ImFontAtlas_GetGlyphRangesThai(atlas),
FontGlyphRangeData::Chinese => sys::ImFontAtlas_GetGlyphRangesChinese(atlas),
FontGlyphRangeData::Cyrillic => sys::ImFontAtlas_GetGlyphRangesCyrillic(atlas),
FontGlyphRangeData::Default => sys::ImFontAtlas_GetGlyphRangesDefault(atlas),
FontGlyphRangeData::Japanese => sys::ImFontAtlas_GetGlyphRangesJapanese(atlas),
FontGlyphRangeData::Korean => sys::ImFontAtlas_GetGlyphRangesKorean(atlas),
FontGlyphRangeData::Thai => sys::ImFontAtlas_GetGlyphRangesThai(atlas),
&FontGlyphRangeData::Custom(ptr) => ptr,
FontGlyphRangeData::Custom(ptr) => *ptr,
}
}
}

View File

@ -147,8 +147,8 @@ pub struct InputText<'ui, 'p> {
impl<'ui, 'p> InputText<'ui, 'p> {
pub fn new(_: &Ui<'ui>, label: &'p ImStr, buf: &'p mut ImString) -> Self {
InputText {
label: label,
buf: buf,
label,
buf,
flags: ImGuiInputTextFlags::empty(),
_phantom: PhantomData,
}
@ -185,10 +185,10 @@ pub struct InputTextMultiline<'ui, 'p> {
impl<'ui, 'p> InputTextMultiline<'ui, 'p> {
pub fn new(_: &Ui<'ui>, label: &'p ImStr, buf: &'p mut ImString, size: sys::ImVec2) -> Self {
InputTextMultiline {
label: label,
buf: buf,
label,
buf,
flags: ImGuiInputTextFlags::empty(),
size: size,
size,
_phantom: PhantomData,
}
}
@ -226,8 +226,8 @@ pub struct InputInt<'ui, 'p> {
impl<'ui, 'p> InputInt<'ui, 'p> {
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut i32) -> Self {
InputInt {
label: label,
value: value,
label,
value,
step: 1,
step_fast: 100,
flags: ImGuiInputTextFlags::empty(),
@ -265,8 +265,8 @@ pub struct InputFloat<'ui, 'p> {
impl<'ui, 'p> InputFloat<'ui, 'p> {
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut f32) -> Self {
InputFloat {
label: label,
value: value,
label,
value,
step: 0.0,
step_fast: 0.0,
decimal_precision: -1,
@ -307,8 +307,8 @@ macro_rules! impl_input_floatn {
impl<'ui, 'p> $InputFloatN<'ui, 'p> {
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [f32; $N]) -> Self {
$InputFloatN {
label: label,
value: value,
label,
value,
decimal_precision: -1,
flags: ImGuiInputTextFlags::empty(),
_phantom: PhantomData,
@ -349,8 +349,8 @@ macro_rules! impl_input_intn {
impl<'ui, 'p> $InputIntN<'ui, 'p> {
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut [i32; $N]) -> Self {
$InputIntN {
label: label,
value: value,
label,
value,
flags: ImGuiInputTextFlags::empty(),
_phantom: PhantomData,
}

View File

@ -246,9 +246,9 @@ impl ImGui {
let io = self.io();
(io.mouse_delta.x, io.mouse_delta.y)
}
pub fn set_mouse_down(&mut self, states: &[bool; 5]) {
pub fn set_mouse_down(&mut self, states: [bool; 5]) {
let io = self.io_mut();
io.mouse_down = *states;
io.mouse_down = states;
}
pub fn set_mouse_wheel(&mut self, value: f32) {
let io = self.io_mut();
@ -337,7 +337,7 @@ impl ImGui {
}
pub fn set_imgui_key(&mut self, key: ImGuiKey, mapping: u8) {
let io = self.io_mut();
io.key_map[key as usize] = mapping as i32;
io.key_map[key as usize] = i32::from(mapping);
}
/// Map [`ImGuiKey`] values into user's key index
pub fn get_key_index(&self, key: ImGuiKey) -> usize {

View File

@ -14,7 +14,7 @@ pub struct Menu<'ui, 'p> {
impl<'ui, 'p> Menu<'ui, 'p> {
pub fn new(_: &Ui<'ui>, label: &'p ImStr) -> Self {
Menu {
label: label,
label,
enabled: true,
_phantom: PhantomData,
}
@ -45,7 +45,7 @@ pub struct MenuItem<'ui, 'p> {
impl<'ui, 'p> MenuItem<'ui, 'p> {
pub fn new(_: &Ui<'ui>, label: &'p ImStr) -> Self {
MenuItem {
label: label,
label,
shortcut: None,
selected: None,
enabled: true,

View File

@ -20,8 +20,8 @@ pub struct PlotHistogram<'ui, 'p> {
impl<'ui, 'p> PlotHistogram<'ui, 'p> {
pub fn new(_: &Ui<'ui>, label: &'p ImStr, values: &'p [f32]) -> Self {
PlotHistogram {
label: label,
values: values,
label,
values,
values_offset: 0usize,
overlay_text: None,
scale_min: f32::MAX,

View File

@ -20,8 +20,8 @@ pub struct PlotLines<'ui, 'p> {
impl<'ui, 'p> PlotLines<'ui, 'p> {
pub fn new(_: &Ui<'ui>, label: &'p ImStr, values: &'p [f32]) -> Self {
PlotLines {
label: label,
values: values,
label,
values,
values_offset: 0usize,
overlay_text: None,
scale_min: f32::MAX,

View File

@ -22,7 +22,7 @@ impl<'ui, 'p> ProgressBar<'ui, 'p> {
/// specified.
pub fn new(_: &Ui<'ui>, fraction: f32) -> Self {
ProgressBar {
fraction: fraction,
fraction,
size: ImVec2::new(-1.0, 0.0),
overlay_text: None,
_phantom: PhantomData,

View File

@ -18,10 +18,10 @@ pub struct SliderInt<'ui, 'p> {
impl<'ui, 'p> SliderInt<'ui, 'p> {
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut i32, min: i32, max: i32) -> Self {
SliderInt {
label: label,
value: value,
min: min,
max: max,
label,
value,
min,
max,
display_format: unsafe { ImStr::from_utf8_with_nul_unchecked(b"%.0f\0") },
_phantom: PhantomData,
}
@ -65,10 +65,10 @@ macro_rules! impl_slider_intn {
max: i32,
) -> Self {
$SliderIntN {
label: label,
value: value,
min: min,
max: max,
label,
value,
min,
max,
display_format: unsafe { ImStr::from_utf8_with_nul_unchecked(b"%.0f\0") },
_phantom: PhantomData,
}
@ -111,10 +111,10 @@ pub struct SliderFloat<'ui, 'p> {
impl<'ui, 'p> SliderFloat<'ui, 'p> {
pub fn new(_: &Ui<'ui>, label: &'p ImStr, value: &'p mut f32, min: f32, max: f32) -> Self {
SliderFloat {
label: label,
value: value,
min: min,
max: max,
label,
value,
min,
max,
display_format: unsafe { ImStr::from_utf8_with_nul_unchecked(b"%.3f\0") },
power: 1.0,
_phantom: PhantomData,
@ -166,10 +166,10 @@ macro_rules! impl_slider_floatn {
max: f32,
) -> Self {
$SliderFloatN {
label: label,
value: value,
min: min,
max: max,
label,
value,
min,
max,
display_format: unsafe { ImStr::from_utf8_with_nul_unchecked(b"%.3f\0") },
power: 1.0,
_phantom: PhantomData,

View File

@ -1,7 +1,6 @@
use std::borrow::Borrow;
use std::ffi::CStr;
use std::fmt;
use std::mem;
use std::ops::{Deref, Index, RangeFull};
use std::os::raw::c_char;
use std::str;
@ -130,7 +129,9 @@ impl Deref for ImString {
fn deref(&self) -> &ImStr {
// as_ptr() is used, because we need to look at the bytes to figure out the length
// self.0.len() is incorrect, because there might be more than one nul byte in the end
unsafe { mem::transmute(CStr::from_ptr(self.0.as_ptr() as *const c_char)) }
unsafe {
&*(CStr::from_ptr(self.0.as_ptr() as *const c_char) as *const CStr as *const ImStr)
}
}
}
@ -155,7 +156,7 @@ impl ImStr {
s.as_ref()
}
pub unsafe fn from_utf8_with_nul_unchecked(bytes: &[u8]) -> &ImStr {
mem::transmute(bytes)
&*(bytes as *const [u8] as *const ImStr)
}
pub fn as_ptr(&self) -> *const c_char {
self.0.as_ptr()

View File

@ -16,7 +16,7 @@ pub struct TreeNode<'ui, 'p> {
impl<'ui, 'p> TreeNode<'ui, 'p> {
pub fn new(_: &Ui<'ui>, id: &'p ImStr) -> Self {
TreeNode {
id: id,
id,
label: None,
opened: false,
opened_cond: ImGuiCond::empty(),
@ -126,7 +126,7 @@ pub struct CollapsingHeader<'ui, 'p> {
impl<'ui, 'p> CollapsingHeader<'ui, 'p> {
pub fn new(_: &Ui<'ui>, label: &'p ImStr) -> Self {
CollapsingHeader {
label: label,
label,
flags: ImGuiTreeNodeFlags::empty(),
_phantom: PhantomData,
}

View File

@ -25,7 +25,7 @@ impl<'ui, 'p> Window<'ui, 'p> {
pos_cond: ImGuiCond::empty(),
size: (0.0, 0.0),
size_cond: ImGuiCond::empty(),
name: name,
name,
opened: None,
flags: ImGuiWindowFlags::empty(),
border: false,