Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7f9c054

Browse files
committed
Auto merge of rust-lang#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: rust-lang#12615
2 parents 2ff505a + e0c17e8 commit 7f9c054

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

crates/ide-diagnostics/src/handlers/inactive_code.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ pub(crate) fn inactive_code(
1919
let mut message = "code is inactive due to #[cfg] directives".to_string();
2020

2121
if let Some(inactive) = inactive {
22-
format_to!(message, ": {}", inactive);
22+
let inactive_reasons = inactive.to_string();
23+
24+
if inactive_reasons.is_empty() {
25+
format_to!(message);
26+
} else {
27+
format_to!(message, ": {}", inactive);
28+
}
2329
}
2430

2531
let res = Diagnostic::new(
@@ -91,6 +97,9 @@ fn f() {
9197
9298
#[cfg(feature = "std")] use std;
9399
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives: feature = "std" is disabled
100+
101+
#[cfg(any())] pub fn f() {}
102+
//^^^^^^^^^^^^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives
94103
"#,
95104
);
96105
}

0 commit comments

Comments
 (0)