about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2022-11-04 22:40:06 +0100
committerLukas Wirth <lukastw97@gmail.com>2022-11-04 22:40:06 +0100
commit95d20fccd77869a98ed8db1e8b0d45d4d909f26b (patch)
treecb9172c182fed2dba87c742a9857b175cdd25706
parentc98fc537e6d2c0d3c9a19582962a3db8bf2c1827 (diff)
downloadrust-95d20fccd77869a98ed8db1e8b0d45d4d909f26b.tar.gz
rust-95d20fccd77869a98ed8db1e8b0d45d4d909f26b.zip
Add adjustment hint tests
-rw-r--r--crates/ide/src/inlay_hints.rs121
1 files changed, 78 insertions, 43 deletions
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs
index a26ff1893c7..9eef5aaeed0 100644
--- a/crates/ide/src/inlay_hints.rs
+++ b/crates/ide/src/inlay_hints.rs
@@ -635,7 +635,12 @@ fn adjustment_hints(
     expr: &ast::Expr,
 ) -> Option<()> {
     if config.adjustment_hints == AdjustmentHints::Never {
-        // return None;
+        return None;
+    }
+
+    if let ast::Expr::ParenExpr(_) = expr {
+        // These inherit from the inner expression which would result in duplicate hints
+        return None;
     }
 
     let parent = expr.syntax().parent().and_then(ast::Expr::cast);
@@ -2910,48 +2915,6 @@ impl () {
     }
 
     #[test]
-    fn hints_implicit_reborrow() {
-        check_with_config(
-            InlayHintsConfig {
-                adjustment_hints: AdjustmentHints::Always,
-                parameter_hints: true,
-                ..DISABLED_CONFIG
-            },
-            r#"
-fn __() {
-    let unique = &mut ();
-    let r_mov = unique;
-    let foo: &mut _ = unique;
-                    //^^^^^^ &mut *
-    ref_mut_id(unique);
-             //^^^^^^ mut_ref
-             //^^^^^^ &mut *
-    let shared = ref_id(unique);
-                      //^^^^^^ shared_ref
-                      //^^^^^^ &*
-    let mov = shared;
-    let r_mov: &_ = shared;
-    ref_id(shared);
-         //^^^^^^ shared_ref
-
-    identity(unique);
-    identity(shared);
-}
-fn identity<T>(t: T) -> T {
-    t
-}
-fn ref_mut_id(mut_ref: &mut ()) -> &mut () {
-    mut_ref
-  //^^^^^^^ &mut *
-}
-fn ref_id(shared_ref: &()) -> &() {
-    shared_ref
-}
-"#,
-        );
-    }
-
-    #[test]
     fn hints_binding_modes() {
         check_with_config(
             InlayHintsConfig { binding_mode_hints: true, ..DISABLED_CONFIG },
@@ -3058,4 +3021,76 @@ fn f() {
 "#,
         );
     }
+
+    #[test]
+    fn adjustment_hints() {
+        check_with_config(
+            InlayHintsConfig { adjustment_hints: AdjustmentHints::Always, ..DISABLED_CONFIG },
+            r#"
+//- minicore: coerce_unsized
+fn main() {
+    let _: u32         = loop {};
+                       //^^^^^^^<never-to-any>
+    let _: &u32        = &mut 0;
+                       //^^^^^^&
+                       //^^^^^^*
+    let _: &mut u32    = &mut 0;
+                       //^^^^^^&mut $
+                       //^^^^^^*
+    let _: *const u32  = &mut 0;
+                       //^^^^^^&raw const $
+                       //^^^^^^*
+    let _: *mut u32    = &mut 0;
+                       //^^^^^^&raw mut $
+                       //^^^^^^*
+    let _: fn()        = main;
+                       //^^^^<fn-item-to-fn-pointer>
+    let _: unsafe fn() = main;
+                       //^^^^<safe-fn-pointer-to-unsafe-fn-pointer>
+                       //^^^^<fn-item-to-fn-pointer>
+    let _: unsafe fn() = main as fn();
+                       //^^^^^^^^^^^^<safe-fn-pointer-to-unsafe-fn-pointer>
+    let _: fn()        = || {};
+                       //^^^^^<closure-to-fn-pointer>
+    let _: unsafe fn() = || {};
+                       //^^^^^<closure-to-unsafe-fn-pointer>
+    let _: *const u32  = &mut 0u32 as *mut u32;
+                       //^^^^^^^^^^^^^^^^^^^^^<mut-ptr-to-const-ptr>
+    let _: &mut [_]    = &mut [0; 0];
+                       //^^^^^^^^^^^<unsize>
+                       //^^^^^^^^^^^&mut $
+                       //^^^^^^^^^^^*
+
+    Struct.consume();
+    Struct.by_ref();
+  //^^^^^^(
+  //^^^^^^&
+  //^^^^^^)
+    Struct.by_ref_mut();
+  //^^^^^^(
+  //^^^^^^&mut $
+  //^^^^^^)
+
+    (&Struct).consume();
+   //^^^^^^^*
+    (&Struct).by_ref();
+
+    (&mut Struct).consume();
+   //^^^^^^^^^^^*
+    (&mut Struct).by_ref();
+   //^^^^^^^^^^^&
+   //^^^^^^^^^^^*
+    (&mut Struct).by_ref_mut();
+}
+
+#[derive(Copy, Clone)]
+struct Struct;
+impl Struct {
+    fn consume(self) {}
+    fn by_ref(&self) {}
+    fn by_ref_mut(&mut self) {}
+}
+"#,
+        )
+    }
 }