Skip to content

Commit

Permalink
fix(table): fix new clippy lint which triggers on table widths tests (#…
Browse files Browse the repository at this point in the history
…630)

* fix(table): new clippy lint in 1.74.0 triggers on table widths tests

https://rust-lang.github.io/rust-clippy/master/index.html\#/needless_borrows_for_generic_args

* fix(clippy): fix beta lint for .get(0) -> .first()

https://rust-lang.github.io/rust-clippy/master/index.html\#/get_first
  • Loading branch information
joshka committed Nov 16, 2023
1 parent 36d8c53 commit 1f88da7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/widgets/chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,12 @@ impl<'a> Chart<'a> {
.map(|l| l.iter().map(Span::width).max().unwrap_or_default() as u16)
.unwrap_or_default();

if let Some(first_x_label) = self.x_axis.labels.as_ref().and_then(|labels| labels.get(0)) {
if let Some(first_x_label) = self
.x_axis
.labels
.as_ref()
.and_then(|labels| labels.first())
{
let first_label_width = first_x_label.content.width() as u16;
let width_left_of_y_axis = match self.x_axis.labels_alignment {
Alignment::Left => {
Expand Down
18 changes: 13 additions & 5 deletions src/widgets/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,17 +678,25 @@ mod tests {

#[test]
fn widths_conversions() {
let table = Table::new(vec![]).widths([Constraint::Percentage(100)]);
let array = [Constraint::Percentage(100)];
let table = Table::new(vec![]).widths(array);
assert_eq!(table.widths, vec![Constraint::Percentage(100)], "array");

#[allow(clippy::needless_borrow)] // for backwards compatibility with existing code
let table = Table::new(vec![]).widths(&[Constraint::Percentage(100)]);
let array_ref = &[Constraint::Percentage(100)];
let table = Table::new(vec![]).widths(array_ref);
assert_eq!(table.widths, vec![Constraint::Percentage(100)], "array ref");

let vec = vec![Constraint::Percentage(100)];
let slice = vec.as_slice();
let table = Table::new(vec![]).widths(slice);
assert_eq!(table.widths, vec![Constraint::Percentage(100)], "slice");

let table = Table::new(vec![]).widths(vec![Constraint::Percentage(100)]);
let vec = vec![Constraint::Percentage(100)];
let table = Table::new(vec![]).widths(vec);
assert_eq!(table.widths, vec![Constraint::Percentage(100)], "vec");

let table = Table::new(vec![]).widths(&vec![Constraint::Percentage(100)]);
let vec_ref = &vec![Constraint::Percentage(100)];
let table = Table::new(vec![]).widths(vec_ref);
assert_eq!(table.widths, vec![Constraint::Percentage(100)], "vec ref");
}

Expand Down

0 comments on commit 1f88da7

Please sign in to comment.