chore: clean up clippy lints (#11377)

Using clippy 1.80.0. Also cleans up some that were windows only.
This commit is contained in:
RoloEdits 2024-07-31 14:39:46 -07:00 committed by GitHub
parent 3fcf168c33
commit 86aecc96a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 46 additions and 41 deletions

View File

@ -75,9 +75,9 @@ fn from((open, close): (&char, &char)) -> Self {
impl AutoPairs {
/// Make a new AutoPairs set with the given pairs and default conditions.
pub fn new<'a, V: 'a, A>(pairs: V) -> Self
pub fn new<'a, V, A>(pairs: V) -> Self
where
V: IntoIterator<Item = A>,
V: IntoIterator<Item = A> + 'a,
A: Into<Pair>,
{
let mut auto_pairs = HashMap::new();

View File

@ -457,7 +457,7 @@ fn query_indents<'a>(
// Skip matches where not all custom predicates are fulfilled
if !query.general_predicates(m.pattern_index).iter().all(|pred| {
match pred.operator.as_ref() {
"not-kind-eq?" => match (pred.args.get(0), pred.args.get(1)) {
"not-kind-eq?" => match (pred.args.first(), pred.args.get(1)) {
(
Some(QueryPredicateArg::Capture(capture_idx)),
Some(QueryPredicateArg::String(kind)),
@ -473,7 +473,7 @@ fn query_indents<'a>(
}
},
"same-line?" | "not-same-line?" => {
match (pred.args.get(0), pred.args.get(1)) {
match (pred.args.first(), pred.args.get(1)) {
(
Some(QueryPredicateArg::Capture(capt1)),
Some(QueryPredicateArg::Capture(capt2))
@ -495,7 +495,7 @@ fn query_indents<'a>(
}
}
}
"one-line?" | "not-one-line?" => match pred.args.get(0) {
"one-line?" | "not-one-line?" => match pred.args.first() {
Some(QueryPredicateArg::Capture(capture_idx)) => {
let node = m.nodes_for_capture_index(*capture_idx).next();
@ -786,6 +786,7 @@ fn init_indent_query<'a, 'b>(
/// - The line after the node. This is defined by:
/// - The scope `tail`.
/// - The scope `all` if this node is not the first node on its line.
///
/// Intuitively, `all` applies to everything contained in this node while `tail` applies to everything except for the first line of the node.
/// The indents from different nodes for the same line are then combined.
/// The result [Indentation] is simply the sum of the [Indentation] for all lines.

View File

@ -1431,8 +1431,11 @@ pub fn highlight_iter<'a>(
// The `captures` iterator borrows the `Tree` and the `QueryCursor`, which
// prevents them from being moved. But both of these values are really just
// pointers, so it's actually ok to move them.
let cursor_ref =
unsafe { mem::transmute::<_, &'static mut QueryCursor>(&mut cursor) };
let cursor_ref = unsafe {
mem::transmute::<&mut tree_sitter::QueryCursor, &mut tree_sitter::QueryCursor>(
&mut cursor,
)
};
// if reusing cursors & no range this resets to whole range
cursor_ref.set_byte_range(range.clone().unwrap_or(0..usize::MAX));
@ -1737,7 +1740,7 @@ fn traverse(point: Point, text: &Tendril) -> Point {
}
use std::sync::atomic::{AtomicUsize, Ordering};
use std::{iter, mem, ops, str, usize};
use std::{iter, mem, ops, str};
use tree_sitter::{
Language as Grammar, Node, Parser, Point, Query, QueryCaptures, QueryCursor, QueryError,
QueryMatch, Range, TextProvider, Tree,

View File

@ -295,21 +295,21 @@ fn eaccess(p: &Path, mut mode: FILE_ACCESS_RIGHTS) -> io::Result<()> {
let mut privileges_length = std::mem::size_of::<PRIVILEGE_SET>() as u32;
let mut result = 0;
let mut mapping = GENERIC_MAPPING {
let mapping = GENERIC_MAPPING {
GenericRead: FILE_GENERIC_READ,
GenericWrite: FILE_GENERIC_WRITE,
GenericExecute: FILE_GENERIC_EXECUTE,
GenericAll: FILE_ALL_ACCESS,
};
unsafe { MapGenericMask(&mut mode, &mut mapping) };
unsafe { MapGenericMask(&mut mode, &mapping) };
if unsafe {
AccessCheck(
*sd.descriptor(),
*token.as_handle(),
mode,
&mut mapping,
&mapping,
&mut privileges,
&mut privileges_length,
&mut granted_access,

View File

@ -66,18 +66,16 @@ fn find_rc_exe() -> io::Result<PathBuf> {
.output();
match find_reg_key {
Err(find_reg_key) => {
return Err(io::Error::new(
Err(find_reg_key) => Err(io::Error::new(
io::ErrorKind::Other,
format!("Failed to run registry query: {}", find_reg_key),
))
}
)),
Ok(find_reg_key) => {
if find_reg_key.status.code().unwrap() != 0 {
return Err(io::Error::new(
Err(io::Error::new(
io::ErrorKind::Other,
"Can not find Windows SDK",
));
))
} else {
let lines = String::from_utf8(find_reg_key.stdout)
.expect("Should be able to parse the output");

View File

@ -35,7 +35,9 @@
use std::io::stdout;
use std::{collections::btree_map::Entry, io::stdin, path::Path, sync::Arc};
use anyhow::{Context, Error};
#[cfg(not(windows))]
use anyhow::Context;
use anyhow::Error;
use crossterm::{event::Event as CrosstermEvent, tty::IsTty};
#[cfg(not(windows))]

View File

@ -34,7 +34,7 @@
use std::{
cmp::Ordering,
collections::{BTreeMap, HashSet},
fmt::Write,
fmt::{Display, Write},
future::Future,
path::Path,
};
@ -832,13 +832,13 @@ pub enum ApplyEditErrorKind {
// InvalidEdit,
}
impl ToString for ApplyEditErrorKind {
fn to_string(&self) -> String {
impl Display for ApplyEditErrorKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ApplyEditErrorKind::DocumentChanged => "document has changed".to_string(),
ApplyEditErrorKind::FileNotFound => "file not found".to_string(),
ApplyEditErrorKind::UnknownURISchema => "URI schema not supported".to_string(),
ApplyEditErrorKind::IoError(err) => err.to_string(),
ApplyEditErrorKind::DocumentChanged => f.write_str("document has changed"),
ApplyEditErrorKind::FileNotFound => f.write_str("file not found"),
ApplyEditErrorKind::UnknownURISchema => f.write_str("URI schema not supported"),
ApplyEditErrorKind::IoError(err) => f.write_str(&format!("{err}")),
}
}
}

View File

@ -2498,7 +2498,7 @@ fn read(cx: &mut compositor::Context, args: &[Cow<str>], event: PromptEvent) ->
ensure!(!args.is_empty(), "file name is expected");
ensure!(args.len() == 1, "only the file name is expected");
let filename = args.get(0).unwrap();
let filename = args.first().unwrap();
let path = PathBuf::from(filename.to_string());
ensure!(
path.exists() && path.is_file(),

View File

@ -117,10 +117,9 @@ async fn main_impl() -> Result<i32> {
setup_logging(args.verbosity).context("failed to initialize logging")?;
// Before setting the working directory, resolve all the paths in args.files
for (path, _) in args.files.iter_mut() {
*path = helix_stdx::path::canonicalize(&path);
for (path, _) in &mut args.files {
*path = helix_stdx::path::canonicalize(&*path);
}
// NOTE: Set the working directory early so the correct configuration is loaded. Be aware that
// Application::new() depends on this logic so it must be updated if this changes.
if let Some(path) = &args.working_directory {

View File

@ -1245,7 +1245,7 @@ pub fn reset_selection(&mut self, view_id: ViewId) {
/// Initializes a new selection and view_data for the given view
/// if it does not already have them.
pub fn ensure_view_init(&mut self, view_id: ViewId) {
if self.selections.get(&view_id).is_none() {
if !self.selections.contains_key(&view_id) {
self.reset_selection(view_id);
}

View File

@ -37,7 +37,7 @@ pub async fn select_thread_id(editor: &mut Editor, thread_id: ThreadId, force: b
debugger.thread_id = Some(thread_id);
fetch_stack_trace(debugger, thread_id).await;
let frame = debugger.stack_frames[&thread_id].get(0).cloned();
let frame = debugger.stack_frames[&thread_id].first().cloned();
if let Some(frame) = &frame {
jump_to_stack_frame(editor, frame);
}

View File

@ -1,3 +1,5 @@
use std::fmt::Display;
use crate::editor::Action;
use crate::Editor;
use crate::{DocumentId, ViewId};
@ -73,13 +75,13 @@ fn from(err: helix_core::uri::UrlConversionError) -> Self {
}
}
impl ToString for ApplyEditErrorKind {
fn to_string(&self) -> String {
impl Display for ApplyEditErrorKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ApplyEditErrorKind::DocumentChanged => "document has changed".to_string(),
ApplyEditErrorKind::FileNotFound => "file not found".to_string(),
ApplyEditErrorKind::InvalidUrl(err) => err.to_string(),
ApplyEditErrorKind::IoError(err) => err.to_string(),
ApplyEditErrorKind::DocumentChanged => f.write_str("document has changed"),
ApplyEditErrorKind::FileNotFound => f.write_str("file not found"),
ApplyEditErrorKind::InvalidUrl(err) => f.write_str(&format!("{err}")),
ApplyEditErrorKind::IoError(err) => f.write_str(&format!("{err}")),
}
}
}