fix: clippy error in rust 1.84 and deny warnings in CI (#1178)

* fix: clippy error in 1.84

* fix: deny warnings

* fix: clippy warnings and doc errors

* fix: warnings

* fix: warnings

* fix: warnings

* fix: compile error
This commit is contained in:
Myriad-Dreamin 2025-01-15 20:26:34 +08:00 committed by GitHub
parent 31b22d9333
commit 448ce484d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 30 additions and 30 deletions

View file

@ -15,6 +15,7 @@ on:
workflow_dispatch: workflow_dispatch:
env: env:
RUSTFLAGS: '-Dwarnings'
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER: arm-linux-gnueabihf-gcc CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER: arm-linux-gnueabihf-gcc
@ -311,7 +312,7 @@ jobs:
env: env:
target: alpine-x64 target: alpine-x64
RUST_TARGET: x86_64-unknown-linux-musl RUST_TARGET: x86_64-unknown-linux-musl
RUSTFLAGS: "-C link-arg=-fuse-ld=lld -C target-feature=-crt-static" RUSTFLAGS: "-Dwarnings -C link-arg=-fuse-ld=lld -C target-feature=-crt-static"
isRelease: ${{ (startsWith(github.ref, 'refs/tags/') && (!contains(github.ref, 'rc') && (endsWith(github.ref, '0') || endsWith(github.ref, '2') || endsWith(github.ref, '4') || endsWith(github.ref, '6') || endsWith(github.ref, '8')))) }} isRelease: ${{ (startsWith(github.ref, 'refs/tags/') && (!contains(github.ref, 'rc') && (endsWith(github.ref, '0') || endsWith(github.ref, '2') || endsWith(github.ref, '4') || endsWith(github.ref, '6') || endsWith(github.ref, '8')))) }}
isNightly: ${{ ((startsWith(github.ref, 'refs/tags/') && !((!contains(github.ref, 'rc') && (endsWith(github.ref, '0') || endsWith(github.ref, '2') || endsWith(github.ref, '4') || endsWith(github.ref, '6') || endsWith(github.ref, '8'))))) || (!startsWith(github.ref, 'refs/tags/') && matrix.regular_build == 'true')) }} isNightly: ${{ ((startsWith(github.ref, 'refs/tags/') && !((!contains(github.ref, 'rc') && (endsWith(github.ref, '0') || endsWith(github.ref, '2') || endsWith(github.ref, '4') || endsWith(github.ref, '6') || endsWith(github.ref, '8'))))) || (!startsWith(github.ref, 'refs/tags/') && matrix.regular_build == 'true')) }}
steps: steps:

View file

@ -199,7 +199,7 @@ impl Filesystem {
/// This function will create a file at `path` if it doesn't already exist /// This function will create a file at `path` if it doesn't already exist
/// (including intermediate directories), and then it will acquire an /// (including intermediate directories), and then it will acquire an
/// exclusive lock on `path`. If the process must block waiting for the /// exclusive lock on `path`. If the process must block waiting for the
/// lock, the `msg` is printed to [`GlobalContext`]. /// lock, the `msg` is printed to stderr.
/// ///
/// The returned file can be accessed to look at the path and also has /// The returned file can be accessed to look at the path and also has
/// read/write access to the underlying file. /// read/write access to the underlying file.
@ -239,7 +239,7 @@ impl Filesystem {
/// ///
/// This function will fail if `path` doesn't already exist, but if it does /// This function will fail if `path` doesn't already exist, but if it does
/// then it will acquire a shared lock on `path`. If the process must block /// then it will acquire a shared lock on `path`. If the process must block
/// waiting for the lock, the `msg` is printed to [`GlobalContext`]. /// waiting for the lock, the `msg` is printed to stderr.
/// ///
/// The returned file can be accessed to look at the path and also has read /// The returned file can be accessed to look at the path and also has read
/// access to the underlying file. Any writes to the file will return an /// access to the underlying file. Any writes to the file will return an
@ -389,6 +389,7 @@ fn is_on_nfs_mount(path: &Path) -> bool {
return false; return false;
}; };
// SAFETY: this is implemented by the cargo
unsafe { unsafe {
let mut buf: libc::statfs = mem::zeroed(); let mut buf: libc::statfs = mem::zeroed();
let r = libc::statfs(path.as_ptr(), &mut buf); let r = libc::statfs(path.as_ptr(), &mut buf);
@ -429,7 +430,7 @@ mod sys {
} }
pub(super) fn error_contended(err: &Error) -> bool { pub(super) fn error_contended(err: &Error) -> bool {
err.raw_os_error().map_or(false, |x| x == libc::EWOULDBLOCK) err.raw_os_error() == Some(libc::EWOULDBLOCK)
} }
pub(super) fn error_unsupported(err: &Error) -> bool { pub(super) fn error_unsupported(err: &Error) -> bool {
@ -445,6 +446,7 @@ mod sys {
#[cfg(not(target_os = "solaris"))] #[cfg(not(target_os = "solaris"))]
fn flock(file: &File, flag: libc::c_int) -> Result<()> { fn flock(file: &File, flag: libc::c_int) -> Result<()> {
// SAFETY: this is implemented by the cargo
let ret = unsafe { libc::flock(file.as_raw_fd(), flag) }; let ret = unsafe { libc::flock(file.as_raw_fd(), flag) };
if ret < 0 { if ret < 0 {
Err(Error::last_os_error()) Err(Error::last_os_error())
@ -520,13 +522,11 @@ mod sys {
} }
pub(super) fn error_contended(err: &Error) -> bool { pub(super) fn error_contended(err: &Error) -> bool {
err.raw_os_error() err.raw_os_error() == Some(ERROR_LOCK_VIOLATION as i32)
.map_or(false, |x| x == ERROR_LOCK_VIOLATION as i32)
} }
pub(super) fn error_unsupported(err: &Error) -> bool { pub(super) fn error_unsupported(err: &Error) -> bool {
err.raw_os_error() err.raw_os_error() == Some(ERROR_INVALID_FUNCTION as i32)
.map_or(false, |x| x == ERROR_INVALID_FUNCTION as i32)
} }
pub(super) fn unlock(file: &File) -> Result<()> { pub(super) fn unlock(file: &File) -> Result<()> {

View file

@ -195,6 +195,7 @@ pub fn write_atomic<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Res
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
// these constants are u16 on macOS // these constants are u16 on macOS
#[allow(clippy::useless_conversion)]
let mask = u32::from(libc::S_IRWXU | libc::S_IRWXG | libc::S_IRWXO); let mask = u32::from(libc::S_IRWXU | libc::S_IRWXG | libc::S_IRWXO);
let mode = meta.permissions().mode() & mask; let mode = meta.permissions().mode() & mask;
@ -782,9 +783,9 @@ mod tests {
fn write_atomic_permissions() { fn write_atomic_permissions() {
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
let original_perms = std::fs::Permissions::from_mode(u32::from( #[allow(clippy::useless_conversion)]
libc::S_IRWXU | libc::S_IRGRP | libc::S_IWGRP | libc::S_IROTH, let perms = u32::from(libc::S_IRWXU | libc::S_IRGRP | libc::S_IWGRP | libc::S_IROTH);
)); let original_perms = std::fs::Permissions::from_mode(perms);
let tmp = tempfile::Builder::new().tempfile().unwrap(); let tmp = tempfile::Builder::new().tempfile().unwrap();
@ -800,6 +801,7 @@ mod tests {
let new_perms = std::fs::metadata(tmp.path()).unwrap().permissions(); let new_perms = std::fs::metadata(tmp.path()).unwrap().permissions();
#[allow(clippy::useless_conversion)]
let mask = u32::from(libc::S_IRWXU | libc::S_IRWXG | libc::S_IRWXO); let mask = u32::from(libc::S_IRWXU | libc::S_IRWXG | libc::S_IRWXO);
assert_eq!(original_perms.mode(), new_perms.mode() & mask); assert_eq!(original_perms.mode(), new_perms.mode() & mask);
} }

View file

@ -35,7 +35,7 @@ pub enum TaskWhen {
OnSave, OnSave,
/// Run task on type. /// Run task on type.
OnType, OnType,
/// [DEPRECATED] Run task when a document has a title and on saved, which is /// *DEPRECATED* Run task when a document has a title and on saved, which is
/// useful to filter out template files. /// useful to filter out template files.
/// ///
/// Note: this is deprecating. /// Note: this is deprecating.
@ -86,7 +86,7 @@ display_possible_values!(PdfStandard);
/// `CompileCommand.pages` argument, through the `FromStr` trait instead of a /// `CompileCommand.pages` argument, through the `FromStr` trait instead of a
/// value parser, in order to generate better errors. /// value parser, in order to generate better errors.
/// ///
/// See also: https://github.com/clap-rs/clap/issues/5065 /// See also: <https://github.com/clap-rs/clap/issues/5065>
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Pages(pub RangeInclusive<Option<NonZeroUsize>>); pub struct Pages(pub RangeInclusive<Option<NonZeroUsize>>);

View file

@ -205,7 +205,7 @@ impl FnCompletionFeat {
let pos_size = sig.positional_params().len(); let pos_size = sig.positional_params().len();
self.has_rest = self.has_rest || sig.rest_param().is_some(); self.has_rest = self.has_rest || sig.rest_param().is_some();
self.next_arg_is_content = self.next_arg_is_content =
self.next_arg_is_content || sig.pos(idx).map_or(false, |ty| ty.is_content(&())); self.next_arg_is_content || sig.pos(idx).is_some_and(|ty| ty.is_content(&()));
let name_size = sig.named_params().len(); let name_size = sig.named_params().len();
let left_pos = pos_size.saturating_sub(idx); let left_pos = pos_size.saturating_sub(idx);
self.min_pos = self self.min_pos = self

View file

@ -617,7 +617,7 @@ fn token_from_ident(ei: &ExprInfo, ident: &LinkedNode, modifier: &mut ModifierSe
let next = ident.next_leaf(); let next = ident.next_leaf();
let next_is_adjacent = next let next_is_adjacent = next
.as_ref() .as_ref()
.map_or(false, |n| n.range().start == ident.range().end); .is_some_and(|n| n.range().start == ident.range().end);
let next_parent = next.as_ref().and_then(|n| n.parent_kind()); let next_parent = next.as_ref().and_then(|n| n.parent_kind());
let next_kind = next.map(|n| n.kind()); let next_kind = next.map(|n| n.kind());
let lexical_function_call = next_is_adjacent let lexical_function_call = next_is_adjacent
@ -699,7 +699,7 @@ fn ns(modifier: &mut ModifierSet) -> TokenType {
fn get_expr_following_hashtag<'a>(hashtag: &LinkedNode<'a>) -> Option<LinkedNode<'a>> { fn get_expr_following_hashtag<'a>(hashtag: &LinkedNode<'a>) -> Option<LinkedNode<'a>> {
hashtag hashtag
.next_sibling() .next_sibling()
.filter(|next| next.cast::<ast::Expr>().map_or(false, |expr| expr.hash())) .filter(|next| next.cast::<ast::Expr>().is_some_and(|expr| expr.hash()))
.and_then(|node| node.leftmost_leaf()) .and_then(|node| node.leftmost_leaf())
} }

View file

@ -238,7 +238,7 @@ impl RenameFileWorker<'_> {
fn rename_module_path(&mut self, span: Span, r: &RefExpr, src: &Source) -> Option<TextEdit> { fn rename_module_path(&mut self, span: Span, r: &RefExpr, src: &Source) -> Option<TextEdit> {
let importing = r.root.as_ref()?.file_id(); let importing = r.root.as_ref()?.file_id();
if importing.map_or(true, |fid| fid != self.def_fid) { if importing != Some(self.def_fid) {
return None; return None;
} }
crate::log_debug_ct!("import: {span:?} -> {importing:?} v.s. {:?}", self.def_fid); crate::log_debug_ct!("import: {span:?} -> {importing:?} v.s. {:?}", self.def_fid);

View file

@ -188,7 +188,7 @@ impl ExprInfo {
let of = Expr::Decl(decl.clone()); let of = Expr::Decl(decl.clone());
self.exports self.exports
.get(decl.name()) .get(decl.name())
.map_or(false, |export| match export { .is_some_and(|export| match export {
Expr::Ref(ref_expr) => ref_expr.root == Some(of), Expr::Ref(ref_expr) => ref_expr.root == Some(of),
exprt => *exprt == of, exprt => *exprt == of,
}) })

View file

@ -279,8 +279,7 @@ pub fn interpret_mode_at(mut leaf: Option<&LinkedNode>) -> InterpretMode {
if !t.kind().is_trivia() && { if !t.kind().is_trivia() && {
// Previous leaf is hash // Previous leaf is hash
t.prev_leaf() t.prev_leaf().is_some_and(|n| n.kind() == SyntaxKind::Hash)
.map_or(false, |n| n.kind() == SyntaxKind::Hash)
} { } {
return InterpretMode::Code; return InterpretMode::Code;
} }

View file

@ -1,7 +1,7 @@
use core::fmt; use core::fmt;
use std::borrow::Cow; use std::borrow::Cow;
use std::str::FromStr; use std::str::FromStr;
use std::sync::{Arc, OnceLock}; use std::sync::{Arc, LazyLock};
use std::{ use std::{
collections::{HashMap, HashSet}, collections::{HashMap, HashSet},
ops::Range, ops::Range,
@ -397,6 +397,8 @@ fn pos(v: &Value) -> String {
impl Redact for RedactFields { impl Redact for RedactFields {
fn redact(&self, json_val: Value) -> Value { fn redact(&self, json_val: Value) -> Value {
static REG: LazyLock<regex::Regex> =
LazyLock::new(|| regex::Regex::new(r#"data:image/svg\+xml;base64,([^"]+)"#).unwrap());
match json_val { match json_val {
Value::Object(mut map) => { Value::Object(mut map) => {
for (_, val) in map.iter_mut() { for (_, val) in map.iter_mut() {
@ -432,11 +434,7 @@ impl Redact for RedactFields {
} }
"contents" => { "contents" => {
let res = t.as_str().unwrap(); let res = t.as_str().unwrap();
static REG: OnceLock<regex::Regex> = OnceLock::new(); let res = REG.replace_all(res, |_captures: &regex::Captures| {
let reg = REG.get_or_init(|| {
regex::Regex::new(r#"data:image/svg\+xml;base64,([^"]+)"#).unwrap()
});
let res = reg.replace_all(res, |_captures: &regex::Captures| {
"data:image-hash/svg+xml;base64,redacted" "data:image-hash/svg+xml;base64,redacted"
}); });

View file

@ -93,7 +93,7 @@ impl PathPreference {
pub fn is_match(&self, path: &Path) -> bool { pub fn is_match(&self, path: &Path) -> bool {
let ext = path.extension().and_then(|ext| ext.to_str()); let ext = path.extension().and_then(|ext| ext.to_str());
ext.map_or(false, |ext| self.ext_matcher().is_match(ext)) ext.is_some_and(|ext| self.ext_matcher().is_match(ext))
} }
pub fn from_ext(path: &str) -> Option<Self> { pub fn from_ext(path: &str) -> Option<Self> {

View file

@ -765,9 +765,9 @@ impl LanguageState {
fn completion(&mut self, req_id: RequestId, params: CompletionParams) -> ScheduledResult { fn completion(&mut self, req_id: RequestId, params: CompletionParams) -> ScheduledResult {
let (path, position) = as_path_pos(params.text_document_position); let (path, position) = as_path_pos(params.text_document_position);
let explicit = params.context.as_ref().map_or(false, |context| { let context = params.context.as_ref();
context.trigger_kind == CompletionTriggerKind::INVOKED let explicit =
}); context.is_some_and(|context| context.trigger_kind == CompletionTriggerKind::INVOKED);
let trigger_character = params let trigger_character = params
.context .context
.and_then(|c| c.trigger_character) .and_then(|c| c.trigger_character)