diff --git a/crates/mun_codegen/src/code_gen/symbols.rs b/crates/mun_codegen/src/code_gen/symbols.rs index 3a6eb5bc8..850471b1e 100644 --- a/crates/mun_codegen/src/code_gen/symbols.rs +++ b/crates/mun_codegen/src/code_gen/symbols.rs @@ -158,7 +158,7 @@ fn get_function_definition_array<'ink, 'a>( ), } }) - .as_value(context) + .into_value(context) .into_const_private_global("fn.get_info.functions", context) } diff --git a/crates/mun_codegen/src/ir/body.rs b/crates/mun_codegen/src/ir/body.rs index 869be6e8e..6ec830f09 100644 --- a/crates/mun_codegen/src/ir/body.rs +++ b/crates/mun_codegen/src/ir/body.rs @@ -721,13 +721,11 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> { ) -> Option> { let lhs: IntValue = self .gen_expr(lhs_expr) - .map(|value| self.opt_deref_value(lhs_expr, value)) - .expect("no lhs value") + .map(|value| self.opt_deref_value(lhs_expr, value))? .into_int_value(); let rhs: IntValue = self .gen_expr(rhs_expr) - .map(|value| self.opt_deref_value(rhs_expr, value)) - .expect("no rhs value") + .map(|value| self.opt_deref_value(rhs_expr, value))? .into_int_value(); match op { BinaryOp::ArithOp(op) => Some(self.gen_arith_bin_op_bool(lhs, rhs, op).into()), diff --git a/crates/mun_codegen/src/ir/type_table.rs b/crates/mun_codegen/src/ir/type_table.rs index cca360a5d..044a325a0 100644 --- a/crates/mun_codegen/src/ir/type_table.rs +++ b/crates/mun_codegen/src/ir/type_table.rs @@ -342,7 +342,7 @@ impl<'db, 'ink, 't> TypeTableBuilder<'db, 'ink, 't> { type_info_to_index.insert(type_info, index); ptr }) - .as_value(self.value_context); + .into_value(self.value_context); // If there are types, introduce a special global that contains all the TypeInfos if !type_info_ptrs.is_empty() { diff --git a/crates/mun_codegen/src/value/array_value.rs b/crates/mun_codegen/src/value/array_value.rs index 1bf9ec7fb..2e924283e 100644 --- a/crates/mun_codegen/src/value/array_value.rs +++ b/crates/mun_codegen/src/value/array_value.rs @@ -115,7 +115,7 @@ pub trait IterAsIrValue<'ink, E: SizedValueType<'ink>, T: AsValue<'ink, E>>: IntoIterator { /// Returns a `Value<[E]>` that contains all values converted to `Value`. - fn as_value(self, context: &IrValueContext<'ink, '_, '_>) -> Value<'ink, [E]>; + fn into_value(self, context: &IrValueContext<'ink, '_, '_>) -> Value<'ink, [E]>; /// Constructs a const private global and returns a pointer to it. fn into_const_private_pointer>( @@ -129,7 +129,7 @@ pub trait IterAsIrValue<'ink, E: SizedValueType<'ink>, T: AsValue<'ink, E>>: E: PointerValueType<'ink>, Self: Sized, { - self.as_value(context) + self.into_value(context) .into_const_private_global(name, context) .as_value(context) } @@ -150,7 +150,7 @@ pub trait IterAsIrValue<'ink, E: SizedValueType<'ink>, T: AsValue<'ink, E>>: { let mut iter = self.into_iter().peekable(); if iter.peek().is_some() { - iter.as_value(context) + iter.into_value(context) .into_const_private_global(name, context) .as_value(context) } else { @@ -164,7 +164,7 @@ impl<'ink, E: SizedValueType<'ink>, T: AsValue<'ink, E>, I: IntoIterator, { - fn as_value(self, context: &IrValueContext<'ink, '_, '_>) -> Value<'ink, [E]> { + fn into_value(self, context: &IrValueContext<'ink, '_, '_>) -> Value<'ink, [E]> { let element_type = E::get_ir_type(context.type_context); // eprintln!("constructing array of type {:?}", element_type); let elements: Vec = self diff --git a/crates/mun_hir/src/package_defs/collector.rs b/crates/mun_hir/src/package_defs/collector.rs index 7d136b4a0..c1bf622b0 100644 --- a/crates/mun_hir/src/package_defs/collector.rs +++ b/crates/mun_hir/src/package_defs/collector.rs @@ -494,48 +494,48 @@ struct ModCollectorContext<'a, 'db> { impl<'a> ModCollectorContext<'a, '_> { fn collect(&mut self, items: &[ModItem]) { for &item in items { - let definition = match item { + let DefData { + id, + name, + visibility, + has_constructor, + } = match item { ModItem::Function(id) => self.collect_function(id), ModItem::Struct(id) => self.collect_struct(id), ModItem::TypeAlias(id) => self.collect_type_alias(id), - ModItem::Import(id) => self.collect_import(id), + ModItem::Import(id) => { + self.collect_import(id); + continue; + } }; - if let Some(DefData { - id, - name, - visibility, - has_constructor, - }) = definition - { - self.def_collector.package_defs.modules[self.module_id].add_definition(id); - let visibility = self - .def_collector - .package_defs - .module_tree - .resolve_visibility(self.def_collector.db, self.module_id, visibility); - self.def_collector.package_defs.modules[self.module_id].add_resolution( - name.clone(), - PerNs::from_definition(id, visibility, has_constructor), - ); - } + self.def_collector.package_defs.modules[self.module_id].add_definition(id); + let visibility = self + .def_collector + .package_defs + .module_tree + .resolve_visibility(self.def_collector.db, self.module_id, visibility); + self.def_collector.package_defs.modules[self.module_id].add_resolution( + name.clone(), + PerNs::from_definition(id, visibility, has_constructor), + ); } } /// Collects the definition data from an import statement. - fn collect_import(&mut self, id: LocalItemTreeId) -> Option> { + fn collect_import(&mut self, id: LocalItemTreeId) { self.def_collector.unresolved_imports.push(ImportDirective { module_id: self.module_id, import: Import::from_use(&self.item_tree, InFile::new(self.file_id, id)), status: PartiallyResolvedImport::Unresolved, }); - None } /// Collects the definition data from a `Function` - fn collect_function(&self, id: LocalItemTreeId) -> Option> { + #[warn(clippy::unnecessary_wraps)] + fn collect_function(&self, id: LocalItemTreeId) -> DefData<'a> { let func = &self.item_tree[id]; - Some(DefData { + DefData { id: FunctionLoc { module: ModuleId { package: self.def_collector.package_id, @@ -548,13 +548,13 @@ impl<'a> ModCollectorContext<'a, '_> { name: &func.name, visibility: &self.item_tree[func.visibility], has_constructor: false, - }) + } } /// Collects the definition data from a `Struct` - fn collect_struct(&self, id: LocalItemTreeId) -> Option> { + fn collect_struct(&self, id: LocalItemTreeId) -> DefData<'a> { let adt = &self.item_tree[id]; - Some(DefData { + DefData { id: StructLoc { module: ModuleId { package: self.def_collector.package_id, @@ -567,13 +567,13 @@ impl<'a> ModCollectorContext<'a, '_> { name: &adt.name, visibility: &self.item_tree[adt.visibility], has_constructor: adt.kind != StructDefKind::Record, - }) + } } /// Collects the definition data from a `TypeAlias` - fn collect_type_alias(&self, id: LocalItemTreeId) -> Option> { + fn collect_type_alias(&self, id: LocalItemTreeId) -> DefData<'a> { let type_alias = &self.item_tree[id]; - Some(DefData { + DefData { id: TypeAliasLoc { module: ModuleId { package: self.def_collector.package_id, @@ -586,7 +586,7 @@ impl<'a> ModCollectorContext<'a, '_> { name: &type_alias.name, visibility: &self.item_tree[type_alias.visibility], has_constructor: false, - }) + } } } diff --git a/crates/mun_hir/src/ty/infer.rs b/crates/mun_hir/src/ty/infer.rs index 9c2e5a983..2e41bf440 100644 --- a/crates/mun_hir/src/ty/infer.rs +++ b/crates/mun_hir/src/ty/infer.rs @@ -37,10 +37,7 @@ macro_rules! ty_app { }) }; ($ctor:pat) => { - $crate::Ty::Apply($crate::ApplicationTy { - ctor: $ctor, - .. - }) + $crate::Ty::Apply($crate::ApplicationTy { ctor: $ctor, .. }) }; } diff --git a/crates/mun_language_server/src/state.rs b/crates/mun_language_server/src/state.rs index 5a6ff863f..08759483a 100644 --- a/crates/mun_language_server/src/state.rs +++ b/crates/mun_language_server/src/state.rs @@ -187,6 +187,7 @@ impl LanguageServerState { } /// Handles a task sent by another async task + #[allow(clippy::unnecessary_wraps)] fn handle_task(&mut self, task: Task) -> anyhow::Result<()> { match task { Task::Notify(notification) => { @@ -198,6 +199,7 @@ impl LanguageServerState { } /// Handles a change to the underlying virtual file system. + #[allow(clippy::unnecessary_wraps)] fn handle_vfs_task(&mut self, mut task: vfs::MonitorMessage) -> anyhow::Result<()> { loop { match task { diff --git a/crates/mun_language_server/src/state/protocol.rs b/crates/mun_language_server/src/state/protocol.rs index d3666764d..ca8cf8c2c 100644 --- a/crates/mun_language_server/src/state/protocol.rs +++ b/crates/mun_language_server/src/state/protocol.rs @@ -14,12 +14,11 @@ impl LanguageServerState { &mut self, params: lsp_types::DidOpenTextDocumentParams, ) -> anyhow::Result<()> { - if let Ok(path) = from_lsp::abs_path(¶ms.text_document.uri) { - self.open_docs.insert(path.clone()); - self.vfs - .write() - .set_file_contents(&path, Some(params.text_document.text.into_bytes())); - } + let path = from_lsp::abs_path(¶ms.text_document.uri)?; + self.open_docs.insert(path.clone()); + self.vfs + .write() + .set_file_contents(&path, Some(params.text_document.text.into_bytes())); Ok(()) } @@ -32,18 +31,17 @@ impl LanguageServerState { text_document, content_changes, } = params; - if let Ok(path) = from_lsp::abs_path(&text_document.uri) { - let vfs = &mut *self.vfs.write(); - let file_id = vfs - .file_id(&path) - .expect("we already checked that the file_id exists!"); - let mut text = vfs - .file_contents(file_id) - .and_then(|contents| String::from_utf8(contents.to_vec()).ok()) - .expect("if the file_id exists it must be valid utf8"); - apply_document_changes(&mut text, content_changes); - vfs.set_file_contents(&path, Some(text.into_bytes())); - } + let path = from_lsp::abs_path(&text_document.uri)?; + let vfs = &mut *self.vfs.write(); + let file_id = vfs + .file_id(&path) + .expect("we already checked that the file_id exists!"); + let mut text = vfs + .file_contents(file_id) + .and_then(|contents| String::from_utf8(contents.to_vec()).ok()) + .expect("if the file_id exists it must be valid utf8"); + apply_document_changes(&mut text, content_changes); + vfs.set_file_contents(&path, Some(text.into_bytes())); Ok(()) } @@ -52,10 +50,9 @@ impl LanguageServerState { &mut self, params: lsp_types::DidCloseTextDocumentParams, ) -> anyhow::Result<()> { - if let Ok(path) = from_lsp::abs_path(¶ms.text_document.uri) { - self.open_docs.remove(&path); - self.vfs_monitor.reload(&path); - } + let path = from_lsp::abs_path(¶ms.text_document.uri)?; + self.open_docs.remove(&path); + self.vfs_monitor.reload(&path); Ok(()) } @@ -65,9 +62,8 @@ impl LanguageServerState { params: lsp_types::DidChangeWatchedFilesParams, ) -> anyhow::Result<()> { for change in params.changes { - if let Ok(path) = from_lsp::abs_path(&change.uri) { - self.vfs_monitor.reload(&path); - } + let path = from_lsp::abs_path(&change.uri)?; + self.vfs_monitor.reload(&path); } Ok(()) } diff --git a/crates/mun_memory/src/diff/myers.rs b/crates/mun_memory/src/diff/myers.rs index c947f706e..4f0b6e364 100644 --- a/crates/mun_memory/src/diff/myers.rs +++ b/crates/mun_memory/src/diff/myers.rs @@ -168,10 +168,14 @@ pub fn diff_length(old: &[T], new: &[T]) -> usize { v[idx - 1] + 1 }; let mut y = (x as isize - k) as usize; - while x < num_old && y < num_new && old[x] == new[y] { - x += 1; - y += 1; - } + let shortest_equal = old + .iter() + .skip(x) + .zip(new.iter().skip(y)) + .take_while(|(a, b)| a == b) + .count(); + x += shortest_equal; + y += shortest_equal; v[idx] = x; if x == num_old && y == num_new { return d as usize; diff --git a/crates/mun_syntax/src/parsing/grammar/expressions.rs b/crates/mun_syntax/src/parsing/grammar/expressions.rs index 38a38f5be..9e309a113 100644 --- a/crates/mun_syntax/src/parsing/grammar/expressions.rs +++ b/crates/mun_syntax/src/parsing/grammar/expressions.rs @@ -211,13 +211,7 @@ fn postfix_expr( loop { lhs = match p.current() { T!['('] => call_expr(p, lhs), - T![.] => match postfix_dot_expr(p, lhs) { - Ok(it) => it, - Err(it) => { - lhs = it; - break; - } - }, + T![.] => postfix_dot_expr(p, lhs), INDEX => field_expr(p, lhs), _ => break, } @@ -251,16 +245,13 @@ fn arg_list(p: &mut Parser) { m.complete(p, ARG_LIST); } -fn postfix_dot_expr( - p: &mut Parser, - lhs: CompletedMarker, -) -> Result { +fn postfix_dot_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { assert!(p.at(T![.])); if p.nth(1) == IDENT && p.nth(2) == T!['('] { unimplemented!("Method calls are not supported yet."); } - Ok(field_expr(p, lhs)) + field_expr(p, lhs) } fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker { diff --git a/rust-toolchain b/rust-toolchain index 7f3a46a84..5a5c7211d 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.49.0 +1.50.0