From 6ea132708c27922ca6bd1db9bbb17f6a17bda765 Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Wed, 28 May 2025 13:01:55 +0200 Subject: [PATCH] vmm: use Error trait directly with Note for compiler bug While working on this, I found a subtle but severe compiler bug [0]. To fight the bug with explicitness rather than implicitness (to prevent weird stuff in the future), this change is beneficial. The bug is at least in Rust stable 1.34..1.87. [0]: https://github.com/rust-lang/rust/issues/141673 Signed-off-by: Philipp Schuster On-behalf-of: SAP philipp.schuster@sap.com --- src/lib.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ec941ea52..94d5a7b48 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,12 +1,13 @@ // Copyright © 2025 Cyberus Technology GmbH // // SPDX-License-Identifier: Apache-2.0 -// + +use std::error::Error; /// Prints a chain of errors to the user in a consistent manner. /// The user will see a clear chain of errors, followed by debug output /// for opening issues. -pub fn cli_print_error_chain(top_error: &dyn std::error::Error, component: &str) { +pub fn cli_print_error_chain(top_error: &dyn Error, component: &str) { eprint!("Error: {component} exited with the following "); if top_error.source().is_none() { eprintln!("error:"); @@ -14,7 +15,9 @@ pub fn cli_print_error_chain(top_error: &dyn std::error::Error, component: &str) } else { eprintln!("chain of errors:"); std::iter::successors(Some(top_error), |sub_error| { - sub_error.source() + // Dereference necessary to mitigate rustc compiler bug. + // See + (*sub_error).source() }) .enumerate() .for_each(|(level, error)| {