Skip to content
This repository has been archived by the owner on May 12, 2022. It is now read-only.

Commit

Permalink
feat(tcw3): address clippy lints
Browse files Browse the repository at this point in the history
- `clone_on_copy`
- `type_complexity` (threshold adjusted)
- `collapsible_if`
- `option_map_unit_fn`
- `identity_conversion`
- `iter_nth_zero`
- `eval_order_dependence` (ignored)
- `new_without_default` (adds `impl Default` for a public type)

Unaddressed:
- `len_zero` - This is a bug in clippy:
  <rust-lang/rust-clippy#3807>
  • Loading branch information
yvt committed May 29, 2020
1 parent 69a5459 commit 179598e
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 15 deletions.
1 change: 1 addition & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type-complexity-threshold = 500
12 changes: 9 additions & 3 deletions tcw3/src/ui/editing/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,22 @@ impl<T: ?Sized + CoalescingCb<Text>, Text> CoalescingCb<Text> for &'_ mut T {
}
}

impl<Text: TextTrait> CoalescingState<Text> {
/// Construct a `CoalescingState`.
pub fn new() -> Self {
impl<Text> Default for CoalescingState<Text> {
fn default() -> Self {
Self {
composition_active: false,
has_edit: false,
num_coalescable_edits: 0,
_phantom: std::marker::PhantomData,
}
}
}

impl<Text: TextTrait> CoalescingState<Text> {
/// Construct a `CoalescingState`.
pub fn new() -> Self {
Self::default()
}

/// Resets the state of the algorithm.
///
Expand Down
2 changes: 1 addition & 1 deletion tcw3/src/ui/scrolling/lineset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ impl Lineset {
let (mut iter, range) = self
.line_grs
.range(range_by_key(LineOff::index, Floor(range.start)..));
(*iter.nth(0).unwrap(), range.start)
(*iter.next().unwrap(), range.start)
};

// Endpoints of the line group (pre-insertion)
Expand Down
5 changes: 4 additions & 1 deletion tcw3/src/ui/theming/stylesheet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,10 @@ macro_rules! rule {
}
) => {{
let start = $i;
$i += $crate::prop_count! { $($props)* };
// This lint misfires for `$i`
#[allow(clippy::eval_order_dependence)] {
$i += $crate::prop_count! { $($props)* };
}
let end = $i;

$crate::ui::theming::Rule {
Expand Down
6 changes: 4 additions & 2 deletions tcw3/src/ui/theming/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,15 @@ impl StyledBox {
let mut subelems = self.shared.subelems.borrow_mut();

if let Some(i) = subelems.iter().position(|&(r, _)| r == role) {
// There's already a subelement with `role`. Replace or remove it
self.shared.style_elem.remove_child(subelems[i].1);
if let Some(helem) = helem {
subelems[i].1 = helem;
} else {
subelems.swap_remove(i);
}
} else {
// There's no subelement with `role`
if let Some(helem) = helem {
subelems.push((role, helem));
}
Expand Down Expand Up @@ -452,7 +454,7 @@ impl AbsInnerLayout {
Self {
subview_layout: subviews
.clone()
.map(|&(role, _)| (role, (*props.subview_metrics(role)).clone()))
.map(|&(role, _)| (role, *props.subview_metrics(role)))
.collect(),
subviews: subviews.map(|x| x.1.clone()).collect(),
overrider,
Expand Down Expand Up @@ -522,7 +524,7 @@ impl Layout for AbsInnerLayout {
fn arrange(&self, ctx: &mut LayoutCtx<'_>, size: Vector2<f32>) {
for (&(role, ref metrics), sv) in self.subview_layout.iter().zip(self.subviews.iter()) {
let sv_traits = ctx.subview_size_traits(sv.as_ref());
let container = box2! {top_left: [0.0, 0.0].into(), size: size.into()};
let container = box2! {top_left: [0.0, 0.0].into(), size: size};

let mut frame = metrics.arrange(container, sv_traits.preferred);

Expand Down
6 changes: 4 additions & 2 deletions tcw3/src/ui/views/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ impl ViewListener for EntryCoreListener {
.update_layer(wm, view, ctx.hwnd(), visual_bounds, |draw_ctx| {
let c = &mut draw_ctx.canvas;

let mut sel_range = sel_range.clone();
let mut sel_range = *sel_range;
let text_layout = &text_layout_info.text_layout;

c.save();
Expand Down Expand Up @@ -1313,7 +1313,9 @@ impl pal::iface::TextInputCtxEdit<pal::Wm> for Edit<'_> {
}

fn set_composition_range(&mut self, range: Option<Range<usize>>) {
range.as_ref().map(|r| self.check_range(r));
if let Some(r) = &range {
self.check_range(r)
}

let range = range.map(|r| [r.start, r.end]);
if range == self.state.comp_range {
Expand Down
3 changes: 2 additions & 1 deletion tcw3/src/ui/views/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ impl SliderRaw {

for &(role, label) in children.iter() {
if let Some((new_value, new_widget)) = label {
// Assign a label
let new_value = new_value as f32;
let wrap_view =
if let Some(label) = labels.iter_mut().find(|label| label.role == role) {
Expand All @@ -339,8 +340,8 @@ impl SliderRaw {
FillLayout::new(new_widget.view_ref().cloned()).with_margin(wrap_view_margin),
);
} else {
// Remove a label if there's one for `role`
if let Some(i) = labels.iter().position(|label| label.role == role) {
// Remove the label
let label = labels.swap_remove(i);
debug_assert_eq!(label.role, role);
labels_wrapper.set_subview(role, None);
Expand Down
2 changes: 1 addition & 1 deletion tcw3/src/ui/views/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ impl Layout for SplitLayout {
);

// Arrange the panels
let mut frame1 = box2! { top_left: [0.0, 0.0].into(), size: size.into() };
let mut frame1 = box2! { top_left: [0.0, 0.0].into(), size: size };
let mut frame2 = frame1;
let mut spl_frame = frame1;

Expand Down
6 changes: 2 additions & 4 deletions tcw3/src/uicore/keybd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,8 @@ impl HWndRef<'_> {
// Does this window recognize the action?
let listener = self.wnd.listener.borrow();
let status = listener.validate_action(wm, self, action);
if status.contains(ActionStatus::VALID) {
if perform && status.contains(ActionStatus::ENABLED) {
listener.perform_action(wm, self, action);
}
if perform && status.contains(ActionStatus::VALID | ActionStatus::ENABLED) {
listener.perform_action(wm, self, action);
}
status
}
Expand Down

0 comments on commit 179598e

Please sign in to comment.