about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-06-30 10:19:21 +0000
committerbors <bors@rust-lang.org>2022-06-30 10:19:21 +0000
commit7f9c054686fb3e1af7acb7292e05462afc138981 (patch)
tree823eedad16c38e1568b0d8147f35b247b0e24760
parent2ff505ab48faf3f5d3c4174449e3a53ece19141e (diff)
parente0c17e8777f0b56f399c359a16b1b0295ce45173 (diff)
downloadrust-7f9c054686fb3e1af7acb7292e05462afc138981.tar.gz
rust-7f9c054686fb3e1af7acb7292e05462afc138981.zip
Auto merge of #12626 - CuriousCorrelation:fix/empty-reasons, r=flodiebold
fix: trailing ':' on empty inactive reasons

## Description
Fixes trailing ':' even when there is no explanation. e.g.
``` sh
code is inactive due to #[cfg] directives:
```
## Issue
Fixes: #12615
-rw-r--r--crates/ide-diagnostics/src/handlers/inactive_code.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/crates/ide-diagnostics/src/handlers/inactive_code.rs b/crates/ide-diagnostics/src/handlers/inactive_code.rs
index 155bbc569d0..17243d612a4 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
 "#,
         );
     }