Skip to content

Commit

Permalink
misc clippy fixes from 1.60.0
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Apr 7, 2022
1 parent dffab1c commit 7cd285e
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 45 deletions.
1 change: 0 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ rustflags = [
"-Wclippy::missing_enforced_import_renames",
"-Wclippy::missing_errors_doc",
"-Wclippy::missing_safety_doc",
# "-Wclippy::mod_module_files", // Enable when we update MSRV
"-Wclippy::mut_mut",
"-Wclippy::mutex_integer",
"-Wclippy::needless_borrow",
Expand Down
4 changes: 1 addition & 3 deletions egui/src/input_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ impl Default for InputState {
impl InputState {
#[must_use]
pub fn begin_frame(mut self, new: RawInput) -> InputState {
let time = new
.time
.unwrap_or_else(|| self.time + new.predicted_dt as f64);
let time = new.time.unwrap_or(self.time + new.predicted_dt as f64);
let unstable_dt = (time - self.time) as f32;
let screen_rect = new.screen_rect.unwrap_or(self.screen_rect);
self.create_touch_states_for_new_devices(&new.events);
Expand Down
14 changes: 6 additions & 8 deletions egui/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,32 +772,30 @@ impl Layout {
let cursor = region.cursor;
let next_pos = self.next_widget_position(region);

let align;

let l = 64.0;

match self.main_dir {
let align = match self.main_dir {
Direction::LeftToRight => {
painter.line_segment([cursor.left_top(), cursor.left_bottom()], stroke);
painter.arrow(next_pos, vec2(l, 0.0), stroke);
align = Align2([Align::LEFT, self.vertical_align()]);
Align2([Align::LEFT, self.vertical_align()])
}
Direction::RightToLeft => {
painter.line_segment([cursor.right_top(), cursor.right_bottom()], stroke);
painter.arrow(next_pos, vec2(-l, 0.0), stroke);
align = Align2([Align::RIGHT, self.vertical_align()]);
Align2([Align::RIGHT, self.vertical_align()])
}
Direction::TopDown => {
painter.line_segment([cursor.left_top(), cursor.right_top()], stroke);
painter.arrow(next_pos, vec2(0.0, l), stroke);
align = Align2([self.horizontal_align(), Align::TOP]);
Align2([self.horizontal_align(), Align::TOP])
}
Direction::BottomUp => {
painter.line_segment([cursor.left_bottom(), cursor.right_bottom()], stroke);
painter.arrow(next_pos, vec2(0.0, -l), stroke);
align = Align2([self.horizontal_align(), Align::BOTTOM]);
Align2([self.horizontal_align(), Align::BOTTOM])
}
}
};

painter.debug_text(next_pos, align, stroke.color, text);
}
Expand Down
2 changes: 1 addition & 1 deletion egui/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl MenuRootManager {
) -> Option<InnerResponse<R>> {
if let Some(root) = self.inner.as_mut() {
let (menu_response, inner_response) = root.show(response, add_contents);
if let MenuResponse::Close = menu_response {
if MenuResponse::Close == menu_response {
self.inner = None;
}
inner_response
Expand Down
1 change: 1 addition & 0 deletions egui_demo_lib/src/apps/demo/password.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/// ``` ignore
/// password_ui(ui, &mut my_password);
/// ```
#[allow(clippy::ptr_arg)] // false positive
pub fn password_ui(ui: &mut egui::Ui, password: &mut String) -> egui::Response {
// This widget has its own state — show or hide password characters (`show_plaintext`).
// In this case we use a simple `bool`, but you can also declare your own type.
Expand Down
13 changes: 1 addition & 12 deletions egui_demo_lib/src/backend_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl Default for RunMode {

// ----------------------------------------------------------------------------

#[derive(Default)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde", serde(default))]
pub struct BackendPanel {
Expand All @@ -60,18 +61,6 @@ pub struct BackendPanel {
egui_windows: EguiWindows,
}

impl Default for BackendPanel {
fn default() -> Self {
Self {
open: false,
run_mode: Default::default(),
pixels_per_point: Default::default(),
frame_history: Default::default(),
egui_windows: Default::default(),
}
}
}

impl BackendPanel {
pub fn update(&mut self, ctx: &egui::Context, frame: &mut epi::Frame) {
self.frame_history
Expand Down
8 changes: 4 additions & 4 deletions egui_demo_lib/src/easy_mark/easy_mark_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl<'a> Parser<'a> {
self.s = rest;
self.start_of_line = false;
self.style.code = true;
let rest_of_line = &self.s[..self.s.find('\n').unwrap_or_else(|| self.s.len())];
let rest_of_line = &self.s[..self.s.find('\n').unwrap_or(self.s.len())];
if let Some(end) = rest_of_line.find('`') {
let item = Item::Text(self.style, &self.s[..end]);
self.s = &self.s[end + 1..];
Expand All @@ -153,7 +153,7 @@ impl<'a> Parser<'a> {
/// `<url>` or `[link](url)`
fn url(&mut self) -> Option<Item<'a>> {
if self.s.starts_with('<') {
let this_line = &self.s[..self.s.find('\n').unwrap_or_else(|| self.s.len())];
let this_line = &self.s[..self.s.find('\n').unwrap_or(self.s.len())];
if let Some(url_end) = this_line.find('>') {
let url = &self.s[1..url_end];
self.s = &self.s[url_end + 1..];
Expand All @@ -164,7 +164,7 @@ impl<'a> Parser<'a> {

// [text](url)
if self.s.starts_with('[') {
let this_line = &self.s[..self.s.find('\n').unwrap_or_else(|| self.s.len())];
let this_line = &self.s[..self.s.find('\n').unwrap_or(self.s.len())];
if let Some(bracket_end) = this_line.find(']') {
let text = &this_line[1..bracket_end];
if this_line[bracket_end + 1..].starts_with('(') {
Expand Down Expand Up @@ -217,7 +217,7 @@ impl<'a> Iterator for Parser<'a> {
if self.start_of_line {
// leading space (indentation)
if self.s.starts_with(' ') {
let length = self.s.find(|c| c != ' ').unwrap_or_else(|| self.s.len());
let length = self.s.find(|c| c != ' ').unwrap_or(self.s.len());
self.s = &self.s[length..];
self.start_of_line = true; // indentation doesn't count
return Some(Item::Indentation(length));
Expand Down
4 changes: 2 additions & 2 deletions egui_demo_lib/src/syntax_highlighting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,15 @@ impl Highlighter {

while !text.is_empty() {
if text.starts_with("//") {
let end = text.find('\n').unwrap_or_else(|| text.len());
let end = text.find('\n').unwrap_or(text.len());
job.append(&text[..end], 0.0, theme.formats[TokenType::Comment].clone());
text = &text[end..];
} else if text.starts_with('"') {
let end = text[1..]
.find('"')
.map(|i| i + 2)
.or_else(|| text.find('\n'))
.unwrap_or_else(|| text.len());
.unwrap_or(text.len());
job.append(
&text[..end],
0.0,
Expand Down
4 changes: 3 additions & 1 deletion egui_glow/src/shader_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ impl ShaderVersion {
pub(crate) fn parse(glsl_ver: &str) -> Self {
let start = glsl_ver.find(|c| char::is_ascii_digit(&c)).unwrap();
let es = glsl_ver[..start].contains(" ES ");
let ver = glsl_ver[start..].splitn(2, ' ').next().unwrap();
let ver = glsl_ver[start..]
.split_once(' ')
.map_or(&glsl_ver[start..], |x| x.0);
let [maj, min]: [u8; 2] = ver
.splitn(3, '.')
.take(2)
Expand Down
11 changes: 5 additions & 6 deletions egui_web/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@ pub fn pos_from_touch_event(
event: &web_sys::TouchEvent,
touch_id_for_pos: &mut Option<egui::TouchId>,
) -> egui::Pos2 {
let touch_for_pos;
if let Some(touch_id_for_pos) = touch_id_for_pos {
let touch_for_pos = if let Some(touch_id_for_pos) = touch_id_for_pos {
// search for the touch we previously used for the position
// (unfortunately, `event.touches()` is not a rust collection):
touch_for_pos = (0..event.touches().length())
(0..event.touches().length())
.into_iter()
.map(|i| event.touches().get(i).unwrap())
.find(|touch| egui::TouchId::from(touch.identifier()) == *touch_id_for_pos);
.find(|touch| egui::TouchId::from(touch.identifier()) == *touch_id_for_pos)
} else {
touch_for_pos = None;
}
None
};
// Use the touch found above or pick the first, or return a default position if there is no
// touch at all. (The latter is not expected as the current method is only called when there is
// at least one touch.)
Expand Down
11 changes: 4 additions & 7 deletions epaint/src/text/text_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ fn line_break(

if row_start_idx < paragraph.glyphs.len() {
if non_empty_rows == job.wrap.max_rows {
replace_last_glyph_with_overflow_character(fonts, job, out_rows);
if let Some(last_row) = out_rows.last_mut() {
replace_last_glyph_with_overflow_character(fonts, job, last_row);
}
} else {
let glyphs: Vec<Glyph> = paragraph.glyphs[row_start_idx..]
.iter()
Expand All @@ -277,18 +279,13 @@ fn line_break(
fn replace_last_glyph_with_overflow_character(
fonts: &mut FontsImpl,
job: &LayoutJob,
out_rows: &mut Vec<Row>,
row: &mut Row,
) {
let overflow_character = match job.wrap.overflow_character {
Some(c) => c,
None => return,
};

let row = match out_rows.last_mut() {
Some(r) => r,
None => return,
};

loop {
let (prev_glyph, last_glyph) = match row.glyphs.as_mut_slice() {
[.., prev, last] => (Some(prev), last),
Expand Down
2 changes: 2 additions & 0 deletions sh/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,5 @@ cargo deny check

# what compiles slowly?
# cargo llvm-lines --lib -p egui | head -20

echo "All checks passed."

0 comments on commit 7cd285e

Please sign in to comment.