fix: clippy warnings in rust 1.83 (#907)

This commit is contained in:
Myriad-Dreamin 2024-11-29 14:50:22 +08:00 committed by GitHub
parent 6d5c353fc0
commit b8f65cf2ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 63 additions and 59 deletions

View file

@ -282,7 +282,7 @@ impl<'de> serde::Deserialize<'de> for Interned<str> {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
struct StrVisitor;
impl<'de> serde::de::Visitor<'de> for StrVisitor {
impl serde::de::Visitor<'_> for StrVisitor {
type Value = Interned<str>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {

View file

@ -460,7 +460,7 @@ mod signature_tests {
struct SignatureSnapshot<'a>(pub Option<&'a Signature>);
impl<'a> fmt::Display for SignatureSnapshot<'a> {
impl fmt::Display for SignatureSnapshot<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Some(sig) = self.0 else {
return write!(f, "<nil>");
@ -547,7 +547,7 @@ mod call_info_tests {
struct CallSnapshot<'a>(pub Option<&'a CallInfo>);
impl<'a> fmt::Display for CallSnapshot<'a> {
impl fmt::Display for CallSnapshot<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Some(ci) = self.0 else {
return write!(f, "<nil>");

View file

@ -24,7 +24,7 @@ struct ColorExprWorker<'a> {
colors: Vec<ColorInformation>,
}
impl<'a> ColorExprWorker<'a> {
impl ColorExprWorker<'_> {
fn collect_colors(&mut self, node: LinkedNode) -> Option<()> {
match node.kind() {
SyntaxKind::FuncCall => {

View file

@ -286,11 +286,13 @@ impl DerefMut for LocalContext {
}
impl LocalContext {
/// Set the files for LSP-based completion.
#[cfg(test)]
pub fn test_completion_files(&mut self, f: impl FnOnce() -> Vec<TypstFileId>) {
self.caches.completion_files.get_or_init(f);
}
/// Set the files for analysis.
#[cfg(test)]
pub fn test_files(&mut self, f: impl FnOnce() -> Vec<TypstFileId>) {
self.caches.root_files.get_or_init(f);
@ -335,7 +337,7 @@ impl LocalContext {
/// Get the module dependencies of the workspace.
pub fn module_dependencies(&mut self) -> &HashMap<TypstFileId, ModuleDependency> {
if self.caches.module_deps.get().is_some() {
return self.caches.module_deps.get().unwrap();
self.caches.module_deps.get().unwrap()
} else {
// may cause multiple times to calculate, but it is okay because we have mutable
// reference to self.

View file

@ -105,7 +105,7 @@ pub(crate) struct PostTypeChecker<'a> {
locals: TypeScheme,
}
impl<'a> TyCtx for PostTypeChecker<'a> {
impl TyCtx for PostTypeChecker<'_> {
fn global_bounds(&self, var: &Interned<TypeVar>, pol: bool) -> Option<TypeBounds> {
self.info.global_bounds(var, pol)
}
@ -115,7 +115,7 @@ impl<'a> TyCtx for PostTypeChecker<'a> {
}
}
impl<'a> TyCtxMut for PostTypeChecker<'a> {
impl TyCtxMut for PostTypeChecker<'_> {
type Snap = <TypeScheme as TyCtxMut>::Snap;
fn start_scope(&mut self) -> Self::Snap {
@ -396,7 +396,7 @@ where
#[bind(0)]
struct PostSigCheckWorker<'x, 'a, T>(&'x mut PostTypeChecker<'a>, &'x mut T);
impl<'x, 'a, T: PostSigChecker> SigChecker for PostSigCheckWorker<'x, 'a, T> {
impl<T: PostSigChecker> SigChecker for PostSigCheckWorker<'_, '_, T> {
fn check(
&mut self,
sig: Sig,

View file

@ -382,7 +382,7 @@ struct AliasStackChecker<'a, 'b> {
checking_with: bool,
}
impl<'a, 'b> BoundChecker for AliasStackChecker<'a, 'b> {
impl BoundChecker for AliasStackChecker<'_, '_> {
fn check_var(&mut self, u: &Interned<TypeVar>, pol: bool) {
log::debug!("collecting var {u:?} {pol:?}");
if self.res.is_some() {
@ -619,7 +619,7 @@ fn analyze_closure_signature(
struct PatternDisplay<'a>(&'a ast::Pattern<'a>);
impl<'a> fmt::Display for PatternDisplay<'a> {
impl fmt::Display for PatternDisplay<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.0 {
ast::Pattern::Normal(ast::Expr::Ident(ident)) => f.write_str(ident.as_str()),

View file

@ -95,7 +95,7 @@ pub(crate) struct TypeChecker<'a> {
env: &'a mut TypeEnv,
}
impl<'a> TyCtx for TypeChecker<'a> {
impl TyCtx for TypeChecker<'_> {
fn global_bounds(&self, var: &Interned<TypeVar>, pol: bool) -> Option<TypeBounds> {
self.info.global_bounds(var, pol)
}
@ -105,7 +105,7 @@ impl<'a> TyCtx for TypeChecker<'a> {
}
}
impl<'a> TyCtxMut for TypeChecker<'a> {
impl TyCtxMut for TypeChecker<'_> {
type Snap = <TypeScheme as TyCtxMut>::Snap;
fn start_scope(&mut self) -> Self::Snap {
@ -147,7 +147,7 @@ impl<'a> TyCtxMut for TypeChecker<'a> {
}
}
impl<'a> TypeChecker<'a> {
impl TypeChecker<'_> {
fn check(&mut self, root: &Expr) -> Ty {
self.check_syntax(root).unwrap_or(Ty::undef())
}

View file

@ -14,7 +14,7 @@ pub struct ApplyTypeChecker<'a, 'b> {
pub resultant: Vec<Ty>,
}
impl<'a, 'b> ApplyChecker for ApplyTypeChecker<'a, 'b> {
impl ApplyChecker for ApplyTypeChecker<'_, '_> {
fn apply(&mut self, sig: Sig, args: &Interned<ArgsTy>, pol: bool) {
let (sig, is_partialize) = match sig {
Sig::Partialize(sig) => (*sig, true),
@ -177,7 +177,7 @@ pub struct TupleChecker<'a, 'b> {
driver: &'a mut dyn TupleCheckDriver,
}
impl<'a, 'b> ApplyChecker for TupleChecker<'a, 'b> {
impl ApplyChecker for TupleChecker<'_, '_> {
fn apply(&mut self, sig: Sig, _args: &Interned<ArgsTy>, pol: bool) {
self.driver.check(self.base, sig, pol);
}

View file

@ -3,7 +3,7 @@ use reflexo::TakeAs;
use super::*;
use crate::syntax::DocString;
impl<'a> TypeChecker<'a> {
impl TypeChecker<'_> {
pub fn check_docstring(&mut self, base_id: &Interned<Decl>) -> Option<Arc<DocString>> {
let docstring = self.ei.docstrings.get(base_id)?.clone();
Some(Arc::new(
@ -53,7 +53,7 @@ struct IdRenamer<'a, 'b> {
base_id: Interned<Decl>,
}
impl<'a, 'b> TyMutator for IdRenamer<'a, 'b> {
impl TyMutator for IdRenamer<'_, '_> {
fn mutate(&mut self, ty: &Ty, pol: bool) -> Option<Ty> {
match ty {
Ty::Var(v) => Some(self.base.copy_doc_vars(

View file

@ -10,7 +10,7 @@ pub struct SelectFieldChecker<'a, 'b> {
pub resultant: Vec<Ty>,
}
impl<'a, 'b> SelectChecker for SelectFieldChecker<'a, 'b> {
impl SelectChecker for SelectFieldChecker<'_, '_> {
fn select(&mut self, iface: Iface, key: &Interned<str>, pol: bool) {
log::debug!("selecting field: {iface:?} {key:?}");
let _ = pol;

View file

@ -9,7 +9,7 @@ use crate::ty::*;
static EMPTY_DOCSTRING: LazyLock<DocString> = LazyLock::new(DocString::default);
static EMPTY_VAR_DOC: LazyLock<VarDoc> = LazyLock::new(VarDoc::default);
impl<'a> TypeChecker<'a> {
impl TypeChecker<'_> {
pub(crate) fn check_syntax(&mut self, root: &Expr) -> Option<Ty> {
Some(match root {
Expr::Block(seq) => self.check_block(seq),

View file

@ -141,7 +141,7 @@ struct DocumentMetricsWorker<'a> {
font_info: HashMap<Font, FontInfoValue>,
}
impl<'a> DocumentMetricsWorker<'a> {
impl DocumentMetricsWorker<'_> {
fn work(&mut self, doc: &Document) -> Option<()> {
for page in &doc.pages {
self.work_frame(&page.frame)?;

View file

@ -79,7 +79,7 @@ struct ReferencesWorker<'a> {
module_path: OnceLock<Interned<str>>,
}
impl<'a> ReferencesWorker<'a> {
impl ReferencesWorker<'_> {
fn label_root(mut self) -> Option<Vec<LspLocation>> {
let mut ids = vec![];

View file

@ -151,7 +151,7 @@ struct RenameFileWorker<'a> {
inserted: FxHashSet<Span>,
}
impl<'a> RenameFileWorker<'a> {
impl RenameFileWorker<'_> {
pub(crate) fn work(&mut self, edits: &mut HashMap<Url, Vec<TextEdit>>) -> Option<()> {
let dep = self.ctx.module_dependencies().get(&self.def_fid).cloned();
if let Some(dep) = dep {

View file

@ -108,7 +108,7 @@ struct DocsChecker<'a> {
static EMPTY_MODULE: LazyLock<Module> =
LazyLock::new(|| Module::new("stub", typst::foundations::Scope::new()));
impl<'a> DocsChecker<'a> {
impl DocsChecker<'_> {
pub fn check_pat_docs(mut self, docs: String) -> Option<DocString> {
let converted =
convert_docs(self.ctx, &docs).and_then(|converted| identify_pat_docs(&converted));

View file

@ -257,7 +257,7 @@ pub(crate) struct ExprWorker<'a> {
comment_matcher: DocCommentMatcher,
}
impl<'a> ExprWorker<'a> {
impl ExprWorker<'_> {
fn with_scope<R>(&mut self, f: impl FnOnce(&mut Self) -> R) -> R {
self.lexical.scopes.push(std::mem::replace(
&mut self.lexical.last,

View file

@ -398,7 +398,7 @@ pub enum DefTarget<'a> {
Import(LinkedNode<'a>),
}
impl<'a> DefTarget<'a> {
impl DefTarget<'_> {
pub fn node(&self) -> &LinkedNode {
match self {
DefTarget::Let(node) => node,
@ -506,7 +506,7 @@ pub enum ParamTarget<'a> {
},
Named(LinkedNode<'a>),
}
impl<'a> ParamTarget<'a> {
impl ParamTarget<'_> {
pub(crate) fn positional_from_before(before: bool) -> Self {
ParamTarget::Positional {
spreads: EcoVec::new(),

View file

@ -30,13 +30,13 @@ impl Ty {
#[bind(0)]
pub struct ApplySigChecker<'a, T: ApplyChecker>(&'a mut T, &'a Interned<ArgsTy>);
impl<'a, T: ApplyChecker> ApplySigChecker<'a, T> {
impl<T: ApplyChecker> ApplySigChecker<'_, T> {
fn ty(&mut self, ty: &Ty, surface: SigSurfaceKind, pol: bool) {
ty.sig_surface(pol, surface, self)
}
}
impl<'a, T: ApplyChecker> SigChecker for ApplySigChecker<'a, T> {
impl<T: ApplyChecker> SigChecker for ApplySigChecker<'_, T> {
fn check(&mut self, cano_sig: Sig, ctx: &mut super::SigCheckContext, pol: bool) -> Option<()> {
let (cano_sig, is_partialize) = match cano_sig {
Sig::Partialize(sig) => (*sig, true),

View file

@ -31,7 +31,7 @@ impl<'a, T: TyCtx, F> BoundPred<'a, T, F> {
}
}
impl<'a, T: TyCtx, F> BoundChecker for BoundPred<'a, T, F>
impl<T: TyCtx, F> BoundChecker for BoundPred<'_, T, F>
where
F: FnMut(&Ty, bool),
{

View file

@ -1344,7 +1344,7 @@ impl_internable!((Ty, Ty),);
struct RefDebug<'a>(&'a Ty);
impl<'a> fmt::Debug for RefDebug<'a> {
impl fmt::Debug for RefDebug<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.0 {
Ty::Var(v) => write!(f, "@v{:?}", v.name()),

View file

@ -29,7 +29,7 @@ pub enum Iface<'a> {
},
}
impl<'a> Iface<'a> {
impl Iface<'_> {
// IfaceShape { iface }
pub fn select(self, ctx: &mut impl TyCtxMut, key: &StrRef) -> Option<Ty> {
log::debug!("iface shape: {self:?}");
@ -87,7 +87,7 @@ impl BoundChecker for IfaceCheckDriver<'_> {
}
}
impl<'a> IfaceCheckDriver<'a> {
impl IfaceCheckDriver<'_> {
fn dict_as_iface(&self) -> bool {
// matches!(
// self.ctx.sig_kind,

View file

@ -16,13 +16,13 @@ impl Ty {
#[bind(0)]
pub struct SelectKeyChecker<'a, T: TyCtx>(&'a mut T, &'a Interned<str>);
impl<'a, T: SelectChecker> SelectKeyChecker<'a, T> {
impl<T: SelectChecker> SelectKeyChecker<'_, T> {
fn ty(&mut self, ty: &Ty, pol: bool) {
ty.iface_surface(pol, self)
}
}
impl<'a, T: SelectChecker> IfaceChecker for SelectKeyChecker<'a, T> {
impl<T: SelectChecker> IfaceChecker for SelectKeyChecker<'_, T> {
fn check(
&mut self,
iface: Iface,

View file

@ -147,7 +147,7 @@ pub struct SigCheckDriver<'a> {
checker: &'a mut dyn SigChecker,
}
impl<'a> SigCheckDriver<'a> {
impl SigCheckDriver<'_> {
fn func_as_sig(&self) -> bool {
matches!(self.ctx.sig_kind, SigSurfaceKind::Call)
}
@ -263,7 +263,7 @@ impl BoundChecker for SigCheckDriver<'_> {
#[bind(0)]
struct MethodDriver<'a, 'b>(&'a mut SigCheckDriver<'b>, &'a StrRef);
impl<'a, 'b> MethodDriver<'a, 'b> {
impl MethodDriver<'_, '_> {
fn is_binder(&self) -> bool {
matches!(self.1.as_ref(), "with" | "where")
}
@ -280,7 +280,7 @@ impl<'a, 'b> MethodDriver<'a, 'b> {
}
}
impl<'a, 'b> BoundChecker for MethodDriver<'a, 'b> {
impl BoundChecker for MethodDriver<'_, '_> {
fn collect(&mut self, ty: &Ty, pol: bool) {
log::debug!("check method: {ty:?}.{}", self.1.as_ref());
match ty {

View file

@ -49,7 +49,7 @@ struct TypeSimplifier<'a, 'b> {
positives: &'b mut FxHashSet<DeclExpr>,
}
impl<'a, 'b> TypeSimplifier<'a, 'b> {
impl TypeSimplifier<'_, '_> {
fn simplify(&mut self, ty: Ty, principal: bool) -> Ty {
if let Some(cano) = self.cano_cache.get(&(ty.clone(), principal)) {
return cano.clone();

View file

@ -1,7 +1,7 @@
use super::{Sig, SigShape, TyMutator};
use crate::ty::prelude::*;
impl<'a> Sig<'a> {
impl Sig<'_> {
pub fn call(&self, args: &Interned<ArgsTy>, pol: bool, ctx: &mut impl TyCtxMut) -> Option<Ty> {
log::debug!("call {self:?} {args:?} {pol:?}");
ctx.with_scope(|ctx| {
@ -34,13 +34,13 @@ struct SubstituteChecker<'a, T: TyCtxMut> {
ctx: &'a mut T,
}
impl<'a, T: TyCtxMut> SubstituteChecker<'a, T> {
impl<T: TyCtxMut> SubstituteChecker<'_, T> {
fn ty(&mut self, body: &Ty, pol: bool) -> Option<Ty> {
body.mutate(pol, self)
}
}
impl<'a, T: TyCtxMut> TyMutator for SubstituteChecker<'a, T> {
impl<T: TyCtxMut> TyMutator for SubstituteChecker<'_, T> {
fn mutate(&mut self, ty: &Ty, pol: bool) -> Option<Ty> {
// todo: extrude the type into a polarized type
let _ = pol;

View file

@ -116,7 +116,7 @@ impl CompletionFeat {
}
}
impl<'a> CompletionContext<'a> {
impl CompletionContext<'_> {
pub fn world(&self) -> &LspWorld {
self.ctx.world()
}
@ -687,7 +687,7 @@ fn analyze_import_source(ctx: &LocalContext, types: &TypeScheme, s: ast::Expr) -
#[bind(0)]
struct ScopeChecker<'a>(&'a mut Defines, &'a mut LocalContext);
impl<'a> IfaceChecker for ScopeChecker<'a> {
impl IfaceChecker for ScopeChecker<'_> {
fn check(
&mut self,
iface: Iface,
@ -1803,7 +1803,6 @@ static DEFAULT_POSTFIX_SNIPPET: LazyLock<Vec<PostfixSnippet>> = LazyLock::new(||
});
#[cfg(test)]
mod tests {
use crate::upstream::complete::slice_at;