Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/inlay_hints.rs')
-rw-r--r--crates/ide/src/inlay_hints.rs40
1 files changed, 34 insertions, 6 deletions
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs
index 3689bd5a42..910aee7b05 100644
--- a/crates/ide/src/inlay_hints.rs
+++ b/crates/ide/src/inlay_hints.rs
@@ -21,7 +21,7 @@ pub struct InlayHintsConfig {
pub parameter_hints: bool,
pub chaining_hints: bool,
pub reborrow_hints: ReborrowHints,
- pub closure_return_type_hints: bool,
+ pub closure_return_type_hints: ClosureReturnTypeHints,
pub binding_mode_hints: bool,
pub lifetime_elision_hints: LifetimeElisionHints,
pub param_names_for_lifetime_elision_hints: bool,
@@ -32,6 +32,13 @@ pub struct InlayHintsConfig {
}
#[derive(Clone, Debug, PartialEq, Eq)]
+pub enum ClosureReturnTypeHints {
+ Always,
+ WithBlock,
+ Never,
+}
+
+#[derive(Clone, Debug, PartialEq, Eq)]
pub enum LifetimeElisionHints {
Always,
SkipTrivial,
@@ -86,7 +93,7 @@ pub enum InlayTooltip {
//
// Optionally, one can enable additional hints for
//
-// * return types of closure expressions with blocks
+// * return types of closure expressions
// * elided lifetimes
// * compiler inserted reborrows
//
@@ -460,7 +467,7 @@ fn closure_ret_hints(
file_id: FileId,
closure: ast::ClosureExpr,
) -> Option<()> {
- if !config.closure_return_type_hints {
+ if config.closure_return_type_hints == ClosureReturnTypeHints::Never {
return None;
}
@@ -468,7 +475,9 @@ fn closure_ret_hints(
return None;
}
- if !closure_has_block_body(&closure) {
+ if !closure_has_block_body(&closure)
+ && config.closure_return_type_hints == ClosureReturnTypeHints::WithBlock
+ {
return None;
}
@@ -1092,13 +1101,15 @@ mod tests {
use crate::inlay_hints::ReborrowHints;
use crate::{fixture, inlay_hints::InlayHintsConfig, LifetimeElisionHints};
+ use super::ClosureReturnTypeHints;
+
const DISABLED_CONFIG: InlayHintsConfig = InlayHintsConfig {
render_colons: false,
type_hints: false,
parameter_hints: false,
chaining_hints: false,
lifetime_elision_hints: LifetimeElisionHints::Never,
- closure_return_type_hints: false,
+ closure_return_type_hints: ClosureReturnTypeHints::Never,
reborrow_hints: ReborrowHints::Always,
binding_mode_hints: false,
hide_named_constructor_hints: false,
@@ -1112,7 +1123,7 @@ mod tests {
parameter_hints: true,
chaining_hints: true,
reborrow_hints: ReborrowHints::Always,
- closure_return_type_hints: true,
+ closure_return_type_hints: ClosureReturnTypeHints::WithBlock,
binding_mode_hints: true,
lifetime_elision_hints: LifetimeElisionHints::Always,
..DISABLED_CONFIG
@@ -2055,6 +2066,23 @@ fn main() {
}
#[test]
+ fn return_type_hints_for_closure_without_block() {
+ check_with_config(
+ InlayHintsConfig {
+ closure_return_type_hints: ClosureReturnTypeHints::Always,
+ ..DISABLED_CONFIG
+ },
+ r#"
+fn main() {
+ let a = || { 0 };
+ //^^ i32
+ let b = || 0;
+ //^^ i32
+}"#,
+ );
+ }
+
+ #[test]
fn skip_closure_type_hints() {
check_with_config(
InlayHintsConfig {