[gnome-builder] rust-analyzer: be more defensive
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] rust-analyzer: be more defensive
- Date: Thu, 4 Mar 2021 05:50:07 +0000 (UTC)
commit 73f0844ca57102b517017fba3a06c082dc091cad
Author: Christian Hergert <chergert redhat com>
Date: Wed Mar 3 21:49:57 2021 -0800
rust-analyzer: be more defensive
Squash some potential runtime warnings.
.../rust-analyzer/rust-analyzer-pipeline-addin.c | 26 ++++++++++++----------
1 file changed, 14 insertions(+), 12 deletions(-)
---
diff --git a/src/plugins/rust-analyzer/rust-analyzer-pipeline-addin.c
b/src/plugins/rust-analyzer/rust-analyzer-pipeline-addin.c
index b0b412498..8bb26ba22 100644
--- a/src/plugins/rust-analyzer/rust-analyzer-pipeline-addin.c
+++ b/src/plugins/rust-analyzer/rust-analyzer-pipeline-addin.c
@@ -70,18 +70,21 @@ is_meson_project (RustAnalyzerPipelineAddin *self)
static GFile *
find_cargo_toml_from_file (GFile *file)
{
- g_autoptr(GFile) parent = g_file_get_parent (file);
- g_autoptr(GFile) cargo_toml = g_file_get_child (parent, "Cargo.toml");
- g_autofree gchar *name = g_file_get_basename (file);
+ if (file != NULL)
+ {
+ g_autoptr(GFile) parent = g_file_get_parent (file);
+ g_autoptr(GFile) cargo_toml = g_file_get_child (parent, "Cargo.toml");
+ g_autofree gchar *name = g_file_get_basename (file);
- if (g_strcmp0 (name, "Cargo.toml") == 0)
- return g_steal_pointer (&parent);
+ if (g_strcmp0 (name, "Cargo.toml") == 0)
+ return g_steal_pointer (&parent);
- if (g_file_query_exists (cargo_toml, NULL))
- return g_steal_pointer (&cargo_toml);
+ if (g_file_query_exists (cargo_toml, NULL))
+ return g_steal_pointer (&cargo_toml);
- if (parent != NULL)
- return find_cargo_toml_from_file (parent);
+ if (parent != NULL)
+ return find_cargo_toml_from_file (parent);
+ }
return NULL;
}
@@ -132,15 +135,14 @@ rust_analyzer_pipeline_addin_discover_workdir (RustAnalyzerPipelineAddin *self,
g_assert (RUST_IS_ANALYZER_PIPELINE_ADDIN (self));
if (!(context = ide_object_ref_context (IDE_OBJECT (self))) ||
- !(workbench = ide_workbench_from_context (context)))
+ !(workbench = ide_workbench_from_context (context)) ||
+ !(project_workdir = ide_context_ref_workdir (context)))
{
*src_workdir = NULL;
*build_workdir = NULL;
IDE_EXIT;
}
- project_workdir = ide_context_ref_workdir (context);
-
/* Use project root as workdir if it contains Cargo.toml, otherwise
* try to look at open files and locate a workdir from the topmost
* directory containing a Cargo.toml.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]