Skip to content

Commit 8583ec1

Browse files
fix: resolve Clippy issues
1 parent fb92ba8 commit 8583ec1

12 files changed

Lines changed: 273 additions & 290 deletions

File tree

packages/core/src/compute_position.rs

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -86,42 +86,40 @@ pub fn compute_position<Element: Clone, Window: Clone>(
8686
middleware_data.set(middleware.name(), new_data);
8787
}
8888

89-
if let Some(reset) = reset {
90-
if reset_count <= 50 {
91-
reset_count += 1;
92-
93-
match reset {
94-
Reset::True => {}
95-
Reset::Value(value) => {
96-
if let Some(reset_placement) = value.placement {
97-
stateful_placement = reset_placement;
98-
}
89+
if let Some(reset) = reset
90+
&& reset_count <= 50
91+
{
92+
reset_count += 1;
9993

100-
if let Some(reset_rects) = value.rects {
101-
rects = match reset_rects {
102-
ResetRects::True => {
103-
platform.get_element_rects(GetElementRectsArgs {
104-
reference: reference.clone(),
105-
floating,
106-
strategy,
107-
})
108-
}
109-
ResetRects::Value(element_rects) => element_rects,
110-
}
111-
}
94+
match reset {
95+
Reset::True => {}
96+
Reset::Value(value) => {
97+
if let Some(reset_placement) = value.placement {
98+
stateful_placement = reset_placement;
99+
}
112100

113-
let Coords {
114-
x: next_x,
115-
y: next_y,
116-
} = compute_coords_from_placement(&rects, stateful_placement, rtl);
117-
x = next_x;
118-
y = next_y;
101+
if let Some(reset_rects) = value.rects {
102+
rects = match reset_rects {
103+
ResetRects::True => platform.get_element_rects(GetElementRectsArgs {
104+
reference: reference.clone(),
105+
floating,
106+
strategy,
107+
}),
108+
ResetRects::Value(element_rects) => element_rects,
109+
}
119110
}
120-
}
121111

122-
i = 0;
123-
continue;
112+
let Coords {
113+
x: next_x,
114+
y: next_y,
115+
} = compute_coords_from_placement(&rects, stateful_placement, rtl);
116+
x = next_x;
117+
y = next_y;
118+
}
124119
}
120+
121+
i = 0;
122+
continue;
125123
}
126124

127125
i += 1;

packages/core/src/middleware/inline.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,21 +186,21 @@ impl<Element: Clone + PartialEq + 'static, Window: Clone + PartialEq + 'static>
186186

187187
let get_bounding_client_rect = move || {
188188
// There are two rects and they are disjoined.
189-
if client_rects.len() == 2 && client_rects[0].left > client_rects[1].right {
190-
if let Some(x) = options.x {
191-
if let Some(y) = options.y {
192-
return client_rects
193-
.clone()
194-
.into_iter()
195-
.find(|rect| {
196-
x > rect.left - padding_object.left
197-
&& x < rect.right + padding_object.right
198-
&& y > rect.top - padding_object.top
199-
&& rect.y < rect.bottom + padding_object.bottom
200-
})
201-
.unwrap_or(fallback.clone());
202-
}
203-
}
189+
if client_rects.len() == 2
190+
&& client_rects[0].left > client_rects[1].right
191+
&& let Some(x) = options.x
192+
&& let Some(y) = options.y
193+
{
194+
return client_rects
195+
.clone()
196+
.into_iter()
197+
.find(|rect| {
198+
x > rect.left - padding_object.left
199+
&& x < rect.right + padding_object.right
200+
&& y > rect.top - padding_object.top
201+
&& rect.y < rect.bottom + padding_object.bottom
202+
})
203+
.unwrap_or(fallback.clone());
204204
}
205205

206206
// There are 2 or more connected rects.

packages/core/src/middleware/offset.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ fn convert_value_to_coords<Element: Clone, Window: Clone>(
4141
),
4242
};
4343

44-
if let Some(alignment) = alignment {
45-
if let Some(alignment_axis) = alignment_axis {
46-
cross_axis = match alignment {
47-
Alignment::Start => alignment_axis,
48-
Alignment::End => -alignment_axis,
49-
};
50-
}
44+
if let Some(alignment) = alignment
45+
&& let Some(alignment_axis) = alignment_axis
46+
{
47+
cross_axis = match alignment {
48+
Alignment::Start => alignment_axis,
49+
Alignment::End => -alignment_axis,
50+
};
5151
}
5252

5353
if is_vertical {
@@ -192,20 +192,20 @@ impl<Element: Clone + PartialEq, Window: Clone + PartialEq> Middleware<Element,
192192
let diff_coords = convert_value_to_coords(state, &options);
193193

194194
// If the placement is the same and the arrow caused an alignment offset then we don't need to change the positioning coordinates.
195-
if let Some(data_placement) = data.map(|data| data.placement) {
196-
if placement == data_placement {
197-
let arrow_data: Option<ArrowData> = middleware_data.get_as(ARROW_NAME);
198-
if arrow_data
199-
.and_then(|arrow_data| arrow_data.alignment_offset)
200-
.is_some()
201-
{
202-
return MiddlewareReturn {
203-
x: None,
204-
y: None,
205-
data: None,
206-
reset: None,
207-
};
208-
}
195+
if let Some(data_placement) = data.map(|data| data.placement)
196+
&& placement == data_placement
197+
{
198+
let arrow_data: Option<ArrowData> = middleware_data.get_as(ARROW_NAME);
199+
if arrow_data
200+
.and_then(|arrow_data| arrow_data.alignment_offset)
201+
.is_some()
202+
{
203+
return MiddlewareReturn {
204+
x: None,
205+
y: None,
206+
data: None,
207+
reset: None,
208+
};
209209
}
210210
}
211211

packages/dioxus/src/use_floating.rs

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,28 @@ pub fn use_floating(
6565
});
6666

6767
let update = use_callback(move |_| {
68-
if let Some(reference_element) = reference().map(|reference| reference.as_web_event()) {
69-
if let Some(floating_element) = floating().map(|floating| floating.as_web_event()) {
70-
let config = ComputePositionConfig {
71-
placement: Some(placement_option()),
72-
strategy: Some(strategy_option()),
73-
middleware: Some(middleware_option()),
74-
};
75-
76-
let open = open_option();
77-
78-
let position =
79-
compute_position((&reference_element).into(), &floating_element, config);
80-
x.set(position.x);
81-
y.set(position.y);
82-
strategy.set(position.strategy);
83-
placement.set(position.placement);
84-
middleware_data.set(position.middleware_data);
85-
// The floating element's position may be recomputed while it's closed
86-
// but still mounted (such as when transitioning out). To ensure
87-
// `is_positioned` will be `false` initially on the next open,
88-
// avoid setting it to `true` when `open === false` (must be specified).
89-
is_positioned.set(open);
90-
}
68+
if let Some(reference_element) = reference().map(|reference| reference.as_web_event())
69+
&& let Some(floating_element) = floating().map(|floating| floating.as_web_event())
70+
{
71+
let config = ComputePositionConfig {
72+
placement: Some(placement_option()),
73+
strategy: Some(strategy_option()),
74+
middleware: Some(middleware_option()),
75+
};
76+
77+
let open = open_option();
78+
79+
let position = compute_position((&reference_element).into(), &floating_element, config);
80+
x.set(position.x);
81+
y.set(position.y);
82+
strategy.set(position.strategy);
83+
placement.set(position.placement);
84+
middleware_data.set(position.middleware_data);
85+
// The floating element's position may be recomputed while it's closed
86+
// but still mounted (such as when transitioning out). To ensure
87+
// `is_positioned` will be `false` initially on the next open,
88+
// avoid setting it to `true` when `open === false` (must be specified).
89+
is_positioned.set(open);
9190
}
9291
});
9392

@@ -109,18 +108,16 @@ pub fn use_floating(
109108
cleanup.call(());
110109

111110
if let Some(while_elements_mounted) = &while_elements_mounted_option {
112-
if let Some(reference_element) = reference().map(|reference| reference.as_web_event()) {
113-
if let Some(floating_element) = floating().map(|floating| floating.as_web_event()) {
114-
while_elements_mounted_cleanup.replace(Some(Rc::new(
115-
(*while_elements_mounted)(
116-
(&reference_element).into(),
117-
&floating_element,
118-
Rc::new(move || {
119-
update.call(());
120-
}),
121-
),
122-
)));
123-
}
111+
if let Some(reference_element) = reference().map(|reference| reference.as_web_event())
112+
&& let Some(floating_element) = floating().map(|floating| floating.as_web_event())
113+
{
114+
while_elements_mounted_cleanup.replace(Some(Rc::new((*while_elements_mounted)(
115+
(&reference_element).into(),
116+
&floating_element,
117+
Rc::new(move || {
118+
update.call(());
119+
}),
120+
))));
124121
}
125122
} else {
126123
update.call(());

packages/dom/src/auto_update.rs

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -346,18 +346,17 @@ pub fn auto_update(
346346
let update = update.clone();
347347

348348
move |entries: Vec<ResizeObserverEntry>| {
349-
if let Some(first_entry) = entries.first() {
350-
if resize_reference_element
349+
if let Some(first_entry) = entries.first()
350+
&& resize_reference_element
351351
.as_ref()
352352
.is_some_and(|reference_element| first_entry.target() == *reference_element)
353-
{
354-
if let Some(reobserve_frame) = reobserve_frame.take() {
355-
cancel_animation_frame(reobserve_frame);
356-
}
357-
358-
reobserve_frame
359-
.replace(Some(request_animation_frame(reobserve_closure.as_ref())));
353+
{
354+
if let Some(reobserve_frame) = reobserve_frame.take() {
355+
cancel_animation_frame(reobserve_frame);
360356
}
357+
358+
reobserve_frame
359+
.replace(Some(request_animation_frame(reobserve_closure.as_ref())));
361360
}
362361

363362
update();
@@ -369,14 +368,14 @@ pub fn auto_update(
369368
.expect("Resize observer should be created."),
370369
));
371370

372-
if let Some(reference) = reference_element.as_ref() {
373-
if !animation_frame {
374-
resize_observer
375-
.borrow()
376-
.as_ref()
377-
.expect("Resize observer should exist.")
378-
.observe(reference);
379-
}
371+
if let Some(reference) = reference_element.as_ref()
372+
&& !animation_frame
373+
{
374+
resize_observer
375+
.borrow()
376+
.as_ref()
377+
.expect("Resize observer should exist.")
378+
.observe(reference);
380379
}
381380

382381
resize_observer
@@ -406,10 +405,10 @@ pub fn auto_update(
406405
let next_ref_rect =
407406
get_bounding_client_rect((&owned_reference).into(), false, false, None);
408407

409-
if let Some(prev_ref_rect) = prev_ref_rect.borrow().as_ref() {
410-
if !rects_are_equal(prev_ref_rect, &next_ref_rect) {
411-
update();
412-
}
408+
if let Some(prev_ref_rect) = prev_ref_rect.borrow().as_ref()
409+
&& !rects_are_equal(prev_ref_rect, &next_ref_rect)
410+
{
411+
update();
413412
}
414413

415414
prev_ref_rect.replace(Some(next_ref_rect));
@@ -427,14 +426,13 @@ pub fn auto_update(
427426

428427
let next_ref_rect = get_bounding_client_rect((&owned_reference).into(), false, false, None);
429428

430-
if let Some(prev_ref_rect) = prev_ref_rect.borrow().as_ref() {
431-
if next_ref_rect.x != prev_ref_rect.x
429+
if let Some(prev_ref_rect) = prev_ref_rect.borrow().as_ref()
430+
&& (next_ref_rect.x != prev_ref_rect.x
432431
|| next_ref_rect.y != prev_ref_rect.y
433432
|| next_ref_rect.width != prev_ref_rect.width
434-
|| next_ref_rect.height != prev_ref_rect.height
435-
{
436-
update();
437-
}
433+
|| next_ref_rect.height != prev_ref_rect.height)
434+
{
435+
update();
438436
}
439437

440438
prev_ref_rect.replace(Some(next_ref_rect));

packages/dom/src/platform/convert_offset_parent_relative_rect_to_viewport_relative_rect.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,11 @@ pub fn convert_offset_parent_relative_rect_to_viewport_relative_rect(
5353

5454
#[allow(clippy::nonminimal_bool)]
5555
if is_offset_parent_an_element || (!is_offset_parent_an_element && !is_fixed) {
56-
if let Some(offset_parent) = offset_parent.as_ref() {
57-
if get_node_name(offset_parent.into()) != "body"
58-
|| is_overflow_element(&document_element)
59-
{
60-
scroll = get_node_scroll(offset_parent.into());
61-
}
56+
if let Some(offset_parent) = offset_parent.as_ref()
57+
&& (get_node_name(offset_parent.into()) != "body"
58+
|| is_overflow_element(&document_element))
59+
{
60+
scroll = get_node_scroll(offset_parent.into());
6261
}
6362

6463
if let Some(ElementOrWindow::Element(offset_parent)) = offset_parent {

packages/dom/src/platform/get_offset_parent.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,18 @@ pub fn get_true_offset_parent(element: &Element, polyfill: &Option<Polyfill>) ->
2929

3030
// Firefox returns the <html> element as the offsetParent if it's non-static, while Chrome and Safari return the <body> element.
3131
// The <body> element must be used to perform the correct calculations even if the <html> element is non-static.
32-
if let Some(raw_offset_parent) = raw_offset_parent.as_ref() {
33-
if get_document_element(Some(DomNodeOrWindow::Node(raw_offset_parent)))
32+
if let Some(raw_offset_parent) = raw_offset_parent.as_ref()
33+
&& get_document_element(Some(DomNodeOrWindow::Node(raw_offset_parent)))
3434
== *raw_offset_parent
35-
{
36-
return Some(
37-
raw_offset_parent
38-
.owner_document()
39-
.expect("Element should have owner document.")
40-
.body()
41-
.expect("Document should have body.")
42-
.unchecked_into::<Element>(),
43-
);
44-
}
35+
{
36+
return Some(
37+
raw_offset_parent
38+
.owner_document()
39+
.expect("Element should have owner document.")
40+
.body()
41+
.expect("Document should have body.")
42+
.unchecked_into::<Element>(),
43+
);
4544
}
4645

4746
raw_offset_parent
@@ -88,13 +87,12 @@ pub fn get_offset_parent(
8887
}
8988
}
9089

91-
if let Some(parent) = offset_parent.as_ref() {
92-
if is_last_traversable_node(parent)
93-
&& is_static_positioned(parent)
94-
&& !is_containing_block(parent.into())
95-
{
96-
return OwnedElementOrWindow::Window(window);
97-
}
90+
if let Some(parent) = offset_parent.as_ref()
91+
&& is_last_traversable_node(parent)
92+
&& is_static_positioned(parent)
93+
&& !is_containing_block(parent.into())
94+
{
95+
return OwnedElementOrWindow::Window(window);
9896
}
9997

10098
offset_parent

0 commit comments

Comments
 (0)