Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/inlay_hints/adjustment.rs')
-rw-r--r--crates/ide/src/inlay_hints/adjustment.rs97
1 files changed, 96 insertions, 1 deletions
diff --git a/crates/ide/src/inlay_hints/adjustment.rs b/crates/ide/src/inlay_hints/adjustment.rs
index b2bec10d05..1c13f31cf2 100644
--- a/crates/ide/src/inlay_hints/adjustment.rs
+++ b/crates/ide/src/inlay_hints/adjustment.rs
@@ -5,7 +5,6 @@
//! ```
use hir::{Adjust, AutoBorrow, Mutability, OverloadedDeref, PointerCast, Safety, Semantics};
use ide_db::RootDatabase;
-
use syntax::ast::{self, AstNode};
use crate::{AdjustmentHints, InlayHint, InlayHintsConfig, InlayKind};
@@ -16,6 +15,10 @@ pub(super) fn hints(
config: &InlayHintsConfig,
expr: &ast::Expr,
) -> Option<()> {
+ if config.adjustment_hints_hide_outside_unsafe && !sema.is_inside_unsafe(expr) {
+ return None;
+ }
+
if config.adjustment_hints == AdjustmentHints::Never {
return None;
}
@@ -233,4 +236,96 @@ fn or_else() {
"#,
)
}
+
+ #[test]
+ fn adjustment_hints_unsafe_only() {
+ check_with_config(
+ InlayHintsConfig {
+ adjustment_hints: AdjustmentHints::Always,
+ adjustment_hints_hide_outside_unsafe: true,
+ ..DISABLED_CONFIG
+ },
+ r#"
+unsafe fn enabled() {
+ f(&&());
+ //^^^^&
+ //^^^^*
+ //^^^^*
+}
+
+fn disabled() {
+ f(&&());
+}
+
+fn mixed() {
+ f(&&());
+
+ unsafe {
+ f(&&());
+ //^^^^&
+ //^^^^*
+ //^^^^*
+ }
+}
+
+const _: () = {
+ f(&&());
+
+ unsafe {
+ f(&&());
+ //^^^^&
+ //^^^^*
+ //^^^^*
+ }
+};
+
+static STATIC: () = {
+ f(&&());
+
+ unsafe {
+ f(&&());
+ //^^^^&
+ //^^^^*
+ //^^^^*
+ }
+};
+
+enum E {
+ Disable = { f(&&()); 0 },
+ Enable = unsafe { f(&&()); 1 },
+ //^^^^&
+ //^^^^*
+ //^^^^*
+}
+
+const fn f(_: &()) {}
+ "#,
+ )
+ }
+
+ #[test]
+ fn adjustment_hints_unsafe_only_with_item() {
+ check_with_config(
+ InlayHintsConfig {
+ adjustment_hints: AdjustmentHints::Always,
+ adjustment_hints_hide_outside_unsafe: true,
+ ..DISABLED_CONFIG
+ },
+ r#"
+fn a() {
+ struct Struct;
+ impl Struct {
+ fn by_ref(&self) {}
+ }
+
+ _ = Struct.by_ref();
+
+ _ = unsafe { Struct.by_ref() };
+ //^^^^^^(
+ //^^^^^^&
+ //^^^^^^)
+}
+ "#,
+ );
+ }
}