mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-11-24 13:10:07 +00:00
fix: eliminate clippy warnings (#2036)
using clippy 0.1.91 (898aff704d 2025-08-14), but some warnings already
exist in the latest stable version
mostly about elided lifetime and if-chain
only remaining warnings:
```
warning: struct `HashRepr` is never constructed
--> crates\tinymist-query\src\tests.rs:462:12
|
462 | pub struct HashRepr<T>(pub T);
| ^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: a method with this name may be added to the standard library in the future
--> crates\tinymist\src\actor\editor.rs:103:30
|
103 | ... .map_or_default(|fid| unix_slash(fid.vpath().as_rooted_path()));
| ^^^^^^^^^^^^^^
|
= warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
= note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
= help: call with fully qualified syntax `typst::typst_utils::OptionExt::map_or_default(...)` to keep using the current method
= note: `#[warn(unstable_name_collisions)]` on by default
help: add `#![feature(result_option_map_or_default)]` to the crate attributes to enable `std::option::Option::<T>::map_or_default`
--> crates\tinymist\src\lib.rs:3:1
|
3 + #![feature(result_option_map_or_default)]
|
```
This commit is contained in:
parent
c73e7f5863
commit
3a51577b28
9 changed files with 32 additions and 31 deletions
|
|
@ -394,7 +394,7 @@ pub enum DefClass<'a> {
|
||||||
|
|
||||||
impl DefClass<'_> {
|
impl DefClass<'_> {
|
||||||
/// Gets the node of the def class.
|
/// Gets the node of the def class.
|
||||||
pub fn node(&self) -> &LinkedNode {
|
pub fn node(&self) -> &LinkedNode<'_> {
|
||||||
match self {
|
match self {
|
||||||
DefClass::Let(node) => node,
|
DefClass::Let(node) => node,
|
||||||
DefClass::Import(node) => node,
|
DefClass::Import(node) => node,
|
||||||
|
|
@ -402,7 +402,7 @@ impl DefClass<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the name node of the def class.
|
/// Gets the name node of the def class.
|
||||||
pub fn name(&self) -> Option<LinkedNode> {
|
pub fn name(&self) -> Option<LinkedNode<'_>> {
|
||||||
match self {
|
match self {
|
||||||
DefClass::Let(node) => {
|
DefClass::Let(node) => {
|
||||||
let lb: ast::LetBinding<'_> = node.cast()?;
|
let lb: ast::LetBinding<'_> = node.cast()?;
|
||||||
|
|
@ -433,17 +433,17 @@ impl DefClass<'_> {
|
||||||
|
|
||||||
// todo: whether we should distinguish between strict and loose def classes
|
// todo: whether we should distinguish between strict and loose def classes
|
||||||
/// Classifies a definition loosely.
|
/// Classifies a definition loosely.
|
||||||
pub fn classify_def_loosely(node: LinkedNode) -> Option<DefClass<'_>> {
|
pub fn classify_def_loosely(node: LinkedNode<'_>) -> Option<DefClass<'_>> {
|
||||||
classify_def_(node, false)
|
classify_def_(node, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Classifies a definition strictly.
|
/// Classifies a definition strictly.
|
||||||
pub fn classify_def(node: LinkedNode) -> Option<DefClass<'_>> {
|
pub fn classify_def(node: LinkedNode<'_>) -> Option<DefClass<'_>> {
|
||||||
classify_def_(node, true)
|
classify_def_(node, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The internal implementation of classifying a definition.
|
/// The internal implementation of classifying a definition.
|
||||||
fn classify_def_(node: LinkedNode, strict: bool) -> Option<DefClass<'_>> {
|
fn classify_def_(node: LinkedNode<'_>, strict: bool) -> Option<DefClass<'_>> {
|
||||||
let mut ancestor = node;
|
let mut ancestor = node;
|
||||||
if ancestor.kind().is_trivia() || is_mark(ancestor.kind()) {
|
if ancestor.kind().is_trivia() || is_mark(ancestor.kind()) {
|
||||||
ancestor = ancestor.prev_sibling()?;
|
ancestor = ancestor.prev_sibling()?;
|
||||||
|
|
@ -715,7 +715,7 @@ impl<'a> SyntaxClass<'a> {
|
||||||
|
|
||||||
/// Classifies node's syntax (inner syntax) that can be operated on by IDE
|
/// Classifies node's syntax (inner syntax) that can be operated on by IDE
|
||||||
/// functionality.
|
/// functionality.
|
||||||
pub fn classify_syntax(node: LinkedNode, cursor: usize) -> Option<SyntaxClass<'_>> {
|
pub fn classify_syntax(node: LinkedNode<'_>, cursor: usize) -> Option<SyntaxClass<'_>> {
|
||||||
if matches!(node.kind(), SyntaxKind::Error) && node.text().starts_with('<') {
|
if matches!(node.kind(), SyntaxKind::Error) && node.text().starts_with('<') {
|
||||||
return Some(SyntaxClass::error_as_label(node));
|
return Some(SyntaxClass::error_as_label(node));
|
||||||
}
|
}
|
||||||
|
|
@ -1233,7 +1233,7 @@ pub fn classify_context_outer<'a>(
|
||||||
|
|
||||||
/// Classifies node's context (outer syntax) that can be operated on by IDE
|
/// Classifies node's context (outer syntax) that can be operated on by IDE
|
||||||
/// functionality.
|
/// functionality.
|
||||||
pub fn classify_context(node: LinkedNode, cursor: Option<usize>) -> Option<SyntaxContext<'_>> {
|
pub fn classify_context(node: LinkedNode<'_>, cursor: Option<usize>) -> Option<SyntaxContext<'_>> {
|
||||||
let mut node = node;
|
let mut node = node;
|
||||||
if node.kind().is_trivia() && node.parent_kind().is_some_and(possible_in_code_trivia) {
|
if node.kind().is_trivia() && node.parent_kind().is_some_and(possible_in_code_trivia) {
|
||||||
loop {
|
loop {
|
||||||
|
|
|
||||||
|
|
@ -72,11 +72,11 @@ pub trait PackFs: fmt::Debug {
|
||||||
f: &mut (dyn FnMut(&str, PackFile) -> PackageResult<()> + Send + Sync),
|
f: &mut (dyn FnMut(&str, PackFile) -> PackageResult<()> + Send + Sync),
|
||||||
) -> PackageResult<()>;
|
) -> PackageResult<()>;
|
||||||
/// Read a file from the package.
|
/// Read a file from the package.
|
||||||
fn read(&self, _path: &str) -> io::Result<PackFile> {
|
fn read(&self, _path: &str) -> io::Result<PackFile<'_>> {
|
||||||
Err(unsupported())
|
Err(unsupported())
|
||||||
}
|
}
|
||||||
/// Read entries from the package.
|
/// Read entries from the package.
|
||||||
fn entries(&self) -> io::Result<PackEntries> {
|
fn entries(&self) -> io::Result<PackEntries<'_>> {
|
||||||
Err(unsupported())
|
Err(unsupported())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -420,7 +420,7 @@ impl LocalContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fork a new context for searching in the workspace.
|
/// Fork a new context for searching in the workspace.
|
||||||
pub fn fork_for_search(&mut self) -> SearchCtx {
|
pub fn fork_for_search(&mut self) -> SearchCtx<'_> {
|
||||||
SearchCtx {
|
SearchCtx {
|
||||||
ctx: self,
|
ctx: self,
|
||||||
searched: Default::default(),
|
searched: Default::default(),
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,8 @@ impl PeriscopeRenderer {
|
||||||
let mut doc = UsingExporter::svg_doc(paged_doc);
|
let mut doc = UsingExporter::svg_doc(paged_doc);
|
||||||
doc.module.prepare_glyphs();
|
doc.module.prepare_glyphs();
|
||||||
let page0 = doc.pages.get(pos.page.get() - 1)?.clone();
|
let page0 = doc.pages.get(pos.page.get() - 1)?.clone();
|
||||||
let mut svg_text = UsingExporter::render(&doc.module, &[page0.clone()], None);
|
let mut svg_text =
|
||||||
|
UsingExporter::render(&doc.module, std::slice::from_ref(&page0), None);
|
||||||
|
|
||||||
// todo: let typst.ts expose it
|
// todo: let typst.ts expose it
|
||||||
let svg_header = svg_text.get_mut(0)?;
|
let svg_header = svg_text.get_mut(0)?;
|
||||||
|
|
|
||||||
|
|
@ -102,12 +102,12 @@ impl Write for FileLock {
|
||||||
|
|
||||||
impl Drop for FileLock {
|
impl Drop for FileLock {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if let Some(f) = self.f.take() {
|
if let Some(f) = self.f.take()
|
||||||
if let Err(e) = unlock(&f) {
|
&& let Err(e) = unlock(&f)
|
||||||
|
{
|
||||||
log::warn!("failed to release lock: {e:?}");
|
log::warn!("failed to release lock: {e:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A "filesystem" is intended to be a globally shared, hence locked, resource
|
/// A "filesystem" is intended to be a globally shared, hence locked, resource
|
||||||
|
|
|
||||||
|
|
@ -360,11 +360,11 @@ impl<'a> Iterator for PathAncestors<'a> {
|
||||||
if let Some(path) = self.current {
|
if let Some(path) = self.current {
|
||||||
self.current = path.parent();
|
self.current = path.parent();
|
||||||
|
|
||||||
if let Some(ref stop_at) = self.stop_at {
|
if let Some(ref stop_at) = self.stop_at
|
||||||
if path == stop_at {
|
&& path == stop_at
|
||||||
|
{
|
||||||
self.current = None;
|
self.current = None;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Some(path)
|
Some(path)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -668,12 +668,12 @@ pub fn create_dir_all_excluded_from_backups_atomic(p: impl AsRef<Path>) -> Resul
|
||||||
// existing behavior. If we get an error at rename() and suddenly the
|
// existing behavior. If we get an error at rename() and suddenly the
|
||||||
// directory (which didn't exist a moment earlier) exists we can infer from
|
// directory (which didn't exist a moment earlier) exists we can infer from
|
||||||
// it's another cargo process doing work.
|
// it's another cargo process doing work.
|
||||||
if let Err(e) = fs::rename(tempdir.path(), path) {
|
if let Err(e) = fs::rename(tempdir.path(), path)
|
||||||
if !path.exists() {
|
&& !path.exists()
|
||||||
|
{
|
||||||
return Err(anyhow::Error::from(e))
|
return Err(anyhow::Error::from(e))
|
||||||
.with_context(|| format!("failed to create directory `{}`", path.display()));
|
.with_context(|| format!("failed to create directory `{}`", path.display()));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -324,7 +324,7 @@ impl<M: PathAccessModel + Sized> Vfs<M> {
|
||||||
|
|
||||||
/// Obtains an object to revise. The object will update the original vfs
|
/// Obtains an object to revise. The object will update the original vfs
|
||||||
/// when it is dropped.
|
/// when it is dropped.
|
||||||
pub fn revise(&mut self) -> RevisingVfs<M> {
|
pub fn revise(&mut self) -> RevisingVfs<'_, M> {
|
||||||
let managed = self.managed.lock().clone();
|
let managed = self.managed.lock().clone();
|
||||||
let paths = self.paths.lock().clone();
|
let paths = self.paths.lock().clone();
|
||||||
let goal_revision = self.revision.checked_add(1).expect("revision overflowed");
|
let goal_revision = self.revision.checked_add(1).expect("revision overflowed");
|
||||||
|
|
@ -339,7 +339,7 @@ impl<M: PathAccessModel + Sized> Vfs<M> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Obtains an object to display.
|
/// Obtains an object to display.
|
||||||
pub fn display(&self) -> DisplayVfs<M> {
|
pub fn display(&self) -> DisplayVfs<'_, M> {
|
||||||
DisplayVfs { inner: self }
|
DisplayVfs { inner: self }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -604,7 +604,7 @@ impl EntryMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display(&self) -> DisplayEntryMap {
|
fn display(&self) -> DisplayEntryMap<'_> {
|
||||||
DisplayEntryMap { map: self }
|
DisplayEntryMap { map: self }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -660,7 +660,7 @@ impl PathMap {
|
||||||
self.paths.get(path)
|
self.paths.get(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display(&self) -> DisplayPathMap {
|
fn display(&self) -> DisplayPathMap<'_> {
|
||||||
DisplayPathMap { map: self }
|
DisplayPathMap { map: self }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,7 @@ impl ExportTask {
|
||||||
pub(crate) fn signal(
|
pub(crate) fn signal(
|
||||||
&self,
|
&self,
|
||||||
snap: &LspCompiledArtifact,
|
snap: &LspCompiledArtifact,
|
||||||
client: &std::sync::Arc<(dyn ProjectClient + 'static)>,
|
client: &std::sync::Arc<dyn ProjectClient + 'static>,
|
||||||
) {
|
) {
|
||||||
let config = self.factory.task();
|
let config = self.factory.task();
|
||||||
|
|
||||||
|
|
@ -153,7 +153,7 @@ impl ExportTask {
|
||||||
&self,
|
&self,
|
||||||
artifact: &LspCompiledArtifact,
|
artifact: &LspCompiledArtifact,
|
||||||
config: &Arc<ExportUserConfig>,
|
config: &Arc<ExportUserConfig>,
|
||||||
client: &std::sync::Arc<(dyn ProjectClient + 'static)>,
|
client: &std::sync::Arc<dyn ProjectClient + 'static>,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
let doc = artifact.doc.as_ref()?;
|
let doc = artifact.doc.as_ref()?;
|
||||||
let s = artifact.snap.signal;
|
let s = artifact.snap.signal;
|
||||||
|
|
|
||||||
|
|
@ -325,7 +325,7 @@ impl ServerState {
|
||||||
self.preview
|
self.preview
|
||||||
.start(cli_args, previewer, id, false, is_background)
|
.start(cli_args, previewer, id, false, is_background)
|
||||||
} else {
|
} else {
|
||||||
return Err(internal_error("entry file must be provided"));
|
Err(internal_error("entry file must be provided"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue