From e0c17e8777f0b56f399c359a16b1b0295ce45173 Mon Sep 17 00:00:00 2001 From: CuriousCorrelation Date: Thu, 23 Jun 2022 22:10:27 +0530 Subject: [PATCH] fix: trailing ':' on empty inactive reasons Fixes: #12615 --- crates/ide-diagnostics/src/handlers/inactive_code.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/ide-diagnostics/src/handlers/inactive_code.rs b/crates/ide-diagnostics/src/handlers/inactive_code.rs index 155bbc569d..17243d612a 100644 --- a/crates/ide-diagnostics/src/handlers/inactive_code.rs +++ b/crates/ide-diagnostics/src/handlers/inactive_code.rs @@ -19,7 +19,13 @@ pub(crate) fn inactive_code( let mut message = "code is inactive due to #[cfg] directives".to_string(); if let Some(inactive) = inactive { - format_to!(message, ": {}", inactive); + let inactive_reasons = inactive.to_string(); + + if inactive_reasons.is_empty() { + format_to!(message); + } else { + format_to!(message, ": {}", inactive); + } } let res = Diagnostic::new( @@ -91,6 +97,9 @@ fn f() { #[cfg(feature = "std")] use std; //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives: feature = "std" is disabled + + #[cfg(any())] pub fn f() {} + //^^^^^^^^^^^^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives "#, ); }