Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings from clippy #7013

Merged
merged 2 commits into from
May 11, 2023
Merged

Fix warnings from clippy #7013

merged 2 commits into from
May 11, 2023

Conversation

zjp-CN
Copy link
Contributor

@zjp-CN zjp-CN commented May 10, 2023

I found clippy complained a lot and thus fix them.

cargo clippy --workspace --all-targets
helix $ cargo clippy --workspace --all-targets
warning: items were found after the testing module
   --> helix-loader\src\lib.rs:213:1
    |
213 | / mod merge_toml_tests {
214 | |     use std::str;
215 | |
216 | |     use super::merge_toml_values;
...   |
300 | |     (current_dir, true)
301 | | }
    | |_^
    |
    = help: move the items to before the testing module was defined
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#items_after_test_module
    = note: `#[warn(clippy::items_after_test_module)]` on by default

    Checking helix-core v0.6.0 (E:\Rust\helix\helix-core)
warning: `helix-loader` (lib test) generated 1 warning
   Compiling helix-term v0.6.0 (E:\Rust\helix\helix-term)
warning: taking a reference on `std::path::MAIN_SEPARATOR` conversion to `String`
   --> helix-core\src\syntax.rs:191:45
    |
191 |                         suffix.replace('/', &std::path::MAIN_SEPARATOR.to_string()),
    |                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `std::path::MAIN_SEPARATOR_STR`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_main_separator_str
    = note: `#[warn(clippy::manual_main_separator_str)]` on by default

warning: `helix-core` (lib) generated 1 warning (run `cargo clippy --fix --lib -p helix-core` to apply 1 suggestion)
    Checking helix-lsp v0.6.0 (E:\Rust\helix\helix-lsp)
    Checking helix-vcs v0.6.0 (E:\Rust\helix\helix-vcs)
    Checking helix-dap v0.6.0 (E:\Rust\helix\helix-dap)
warning: useless conversion to the same type: `std::str::MatchIndices<'_, char>`
   --> helix-core\src\surround.rs:398:48
    |
398 |           let selections: SmallVec<[Range; 1]> = spec
    |  ________________________________________________^
399 | |             .match_indices('^')
400 | |             .into_iter()
    | |________________________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
    = note: `#[warn(clippy::useless_conversion)]` on by default
help: consider removing `.into_iter()`
    |
398 ~         let selections: SmallVec<[Range; 1]> = spec
399 +             .match_indices('^')
    |

warning: useless conversion to the same type: `std::str::MatchIndices<'_, char>`
   --> helix-core\src\surround.rs:404:40
    |
404 |           let expectations: Vec<usize> = spec
    |  ________________________________________^
405 | |             .match_indices('_')
406 | |             .into_iter()
    | |________________________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
help: consider removing `.into_iter()`
    |
404 ~         let expectations: Vec<usize> = spec
405 +             .match_indices('_')
    |

warning: `helix-core` (lib test) generated 3 warnings (1 duplicate) (run `cargo clippy --fix --lib -p helix-core --tests` to apply 2 suggestions)
    Checking helix-view v0.6.0 (E:\Rust\helix\helix-view)
warning: `Box::new(_)` of default value
  --> helix-view\src\clipboard.rs:71:5
   |
71 |     Box::new(provider::WindowsProvider::default())
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<WindowsProvider>::default()`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#box_default
   = note: `#[warn(clippy::box_default)]` on by default

warning: use of `default` to create a unit struct
  --> helix-view\src\clipboard.rs:71:39
   |
71 |     Box::new(provider::WindowsProvider::default())
   |                                       ^^^^^^^^^^^ help: remove this call to `default`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#default_constructed_unit_structs
   = note: `#[warn(clippy::default_constructed_unit_structs)]` on by default

warning: `helix-view` (lib) generated 2 warnings (run `cargo clippy --fix --lib -p helix-view` to apply 2 suggestions)
    Checking helix-tui v0.6.0 (E:\Rust\helix\helix-tui)
warning: casting to the same type is unnecessary (`u16` -> `u16`)
   --> helix-tui\src\buffer.rs:445:39
    |
445 |         let mut index = self.index_of(max_offset as u16, y);
    |                                       ^^^^^^^^^^^^^^^^^ help: try: `max_offset`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
    = note: `#[warn(clippy::unnecessary_cast)]` on by default

warning: `helix-tui` (lib) generated 1 warning (run `cargo clippy --fix --lib -p helix-tui` to apply 1 suggestion)
warning: `helix-tui` (lib test) generated 1 warning (1 duplicate)
error: this looks like you are trying to swap `l2` and `tree.focus`
   --> helix-view\src\tree.rs:731:9
    |
731 | /         let l2 = tree.focus;
732 | |
733 | |         // Tree in test
734 | |         // | L0  | L2 |    |
735 | |         // |    L1    | R0 |
736 | |         tree.focus = l2;
    | |_______________________^ help: try: `std::mem::swap(&mut l2, &mut tree.focus)`
    |
    = note: or maybe you should use `std::mem::replace`?
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#almost_swapped
    = note: `#[deny(clippy::almost_swapped)]` on by default

warning: `helix-view` (lib test) generated 2 warnings (2 duplicates)
error: could not compile `helix-view` (lib test) due to previous error; 2 warnings emitted
warning: build failed, waiting for other jobs to finish...
warning: casting to the same type is unnecessary (`usize` -> `usize`)
   --> helix-term\src\ui\editor.rs:106:28
    |
106 |             let dap_line = frame.line.saturating_sub(1) as usize;
    |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `frame.line.saturating_sub(1)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
    = note: `#[warn(clippy::unnecessary_cast)]` on by default

warning: `helix-term` (lib) generated 1 warning (run `cargo clippy --fix --lib -p helix-term` to apply 1 suggestion)
warning: `helix-term` (lib test) generated 1 warning (1 duplicate)

@zjp-CN
Copy link
Contributor Author

zjp-CN commented May 10, 2023

std::path::MAIN_SEPARATOR_STR isn't stable on 1.65 and stable from 1.68

I'll update the PR by using the project toolchain instead of my local nightly rustc.

Comment on lines -284 to -301

/// Finds the current workspace folder.
/// Used as a ceiling dir for LSP root resolution, the filepicker and potentially as a future filewatching root
///
/// This function starts searching the FS upward from the CWD
/// and returns the first directory that contains either `.git` or `.helix`.
/// If no workspace was found returns (CWD, true).
/// Otherwise (workspace, false) is returned
pub fn find_workspace() -> (PathBuf, bool) {
let current_dir = std::env::current_dir().expect("unable to determine current directory");
for ancestor in current_dir.ancestors() {
if ancestor.join(".git").exists() || ancestor.join(".helix").exists() {
return (ancestor.to_owned(), false);
}
}

(current_dir, true)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change here?

Copy link
Contributor Author

@zjp-CN zjp-CN May 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clippy says the normal items should avoid being declared after testing mod: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_test_module

So I just move the testing mod down, but git diff shows the changes on find_workspace instead.

warning: items were found after the testing module
   --> helix-loader\src\lib.rs:213:1
    |
213 | / mod merge_toml_tests {
214 | |     use std::str;
215 | |
216 | |     use super::merge_toml_values;
...   |
300 | |     (current_dir, true)
301 | | }
    | |_^
    |
    = help: move the items to before the testing module was defined
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#items_after_test_module
    = note: `#[warn(clippy::items_after_test_module)]` on by default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I think the reason why I meet clippy complaints is that I use a rustc/cargo in a higher verion.

items_after_test_module hasn't been in clippy1.65 yet.

So the Github action doesn't catch them for now.

If this PR is not appropriate for now, feel free to close.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah all these are future lints that don't trigger in current version yet but it's good to fix them ahead of time 👍🏻

@archseer archseer merged commit 3b8c156 into helix-editor:master May 11, 2023
Triton171 pushed a commit to Triton171/helix that referenced this pull request Jun 18, 2023
* Fix warnings from clippy

* revert MAIN_SEPARATOR_STR
wes-adams pushed a commit to wes-adams/helix that referenced this pull request Jul 4, 2023
* Fix warnings from clippy

* revert MAIN_SEPARATOR_STR
smortime pushed a commit to smortime/helix that referenced this pull request Jul 10, 2024
* Fix warnings from clippy

* revert MAIN_SEPARATOR_STR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants