]> git.lizzy.rs Git - rust.git/blobdiff - crates/hir_ty/src/tests/simple.rs
Refactor & improve handling of overloaded binary operators
[rust.git] / crates / hir_ty / src / tests / simple.rs
index 68776f3c0b56b7301b1991c770f4781b98b4bd44..a409c453b0edfe39f425e66a534e12d4c87e9270 100644 (file)
@@ -60,7 +60,7 @@ enum Nat { Succ(Self), Demo(Nat), Zero }
 fn test() {
     let foo: Nat = Nat::Zero;
     if let Nat::Succ(x) = foo {
-        x
+        x;
     } //^ Nat
 }
 "#,
@@ -138,7 +138,7 @@ enum Option<T> { Some(T), None }
 fn test() {
     let foo: Option<f32> = None;
     while let Option::Some(x) = foo {
-        x
+        x;
     } //^ f32
 }
 "#,
@@ -1745,7 +1745,7 @@ impl i32 { fn foo(&self) -> Foo { Foo } }
 fn main() {
     let x: i32 = i32;
     x.foo();
-        //^ Foo
+  //^^^^^^^ Foo
 }"#,
     );
 }
@@ -1763,7 +1763,7 @@ fn main() {
     fn inner() {}
     let x: i32 = i32;
     x.foo();
-        //^ Foo
+  //^^^^^^^ Foo
 }"#,
     );
 }
@@ -1781,7 +1781,7 @@ fn foo() -> &'static str { "" }
 
 fn main() {
     foo();
-      //^ &str
+  //^^^^^ &str
 }"#,
     );
 }
@@ -1799,7 +1799,7 @@ fn foo() -> &'static str { "" }
 
 fn main() {
     str::foo();
-           //^ u32
+  //^^^^^^^^^^ u32
 }"#,
     );
 }
@@ -1825,9 +1825,9 @@ mod d {
 
 fn main() {
     d::foo();
-         //^ u8
+  //^^^^^^^^ u8
     d::foo{a:0};
-           //^ u8
+  //^^^^^^^^^^^ foo
 }"#,
     );
 }
@@ -1917,6 +1917,7 @@ fn main() {
 fn effects_smoke_test() {
     check_infer(
         r#"
+        //- minicore: future
         async fn main() {
             let x = unsafe { 92 };
             let y = async { async { () }.await };
@@ -1924,13 +1925,6 @@ async fn main() {
             let w = const { 92 };
             let t = 'a: { 92 };
         }
-
-        #[prelude_import] use future::*;
-
-        mod future {
-            #[lang = "future_trait"]
-            pub trait Future { type Output; }
-        }
         "#,
         expect![[r#"
             16..162 '{     ...2 }; }': ()
@@ -2317,89 +2311,24 @@ fn test(t1: Thing) {
 
 #[test]
 fn infer_operator_overload() {
-    cov_mark::check!(infer_expr_inner_binary_operator_overload);
-
-    check_infer(
+    check_types(
         r#"
-        struct V2([f32; 2]);
-
-        #[lang = "add"]
-        pub trait Add<Rhs = Self> {
-            /// The resulting type after applying the `+` operator.
-            type Output;
-
-            /// Performs the `+` operation.
-            #[must_use]
-            fn add(self, rhs: Rhs) -> Self::Output;
-        }
-
-        impl Add<V2> for V2 {
-            type Output = V2;
+//- minicore: add
+struct V2([f32; 2]);
 
-            fn add(self, rhs: V2) -> V2 {
-                let x = self.0[0] + rhs.0[0];
-                let y = self.0[1] + rhs.0[1];
-                V2([x, y])
-            }
-        }
+impl core::ops::Add<V2> for V2 {
+    type Output = V2;
+}
 
-        fn test() {
-            let va = V2([0.0, 1.0]);
-            let vb = V2([0.0, 1.0]);
+fn test() {
+    let va = V2([0.0, 1.0]);
+    let vb = V2([0.0, 1.0]);
 
-            let r = va + vb;
-        }
+    let r = va + vb;
+    //      ^^^^^^^ V2
+}
 
         "#,
-        expect![[r#"
-            207..211 'self': Self
-            213..216 'rhs': Rhs
-            299..303 'self': V2
-            305..308 'rhs': V2
-            320..422 '{     ...     }': V2
-            334..335 'x': f32
-            338..342 'self': V2
-            338..344 'self.0': [f32; 2]
-            338..347 'self.0[0]': {unknown}
-            338..358 'self.0...s.0[0]': f32
-            345..346 '0': i32
-            350..353 'rhs': V2
-            350..355 'rhs.0': [f32; 2]
-            350..358 'rhs.0[0]': {unknown}
-            356..357 '0': i32
-            372..373 'y': f32
-            376..380 'self': V2
-            376..382 'self.0': [f32; 2]
-            376..385 'self.0[1]': {unknown}
-            376..396 'self.0...s.0[1]': f32
-            383..384 '1': i32
-            388..391 'rhs': V2
-            388..393 'rhs.0': [f32; 2]
-            388..396 'rhs.0[1]': {unknown}
-            394..395 '1': i32
-            406..408 'V2': V2([f32; 2]) -> V2
-            406..416 'V2([x, y])': V2
-            409..415 '[x, y]': [f32; 2]
-            410..411 'x': f32
-            413..414 'y': f32
-            436..519 '{     ... vb; }': ()
-            446..448 'va': V2
-            451..453 'V2': V2([f32; 2]) -> V2
-            451..465 'V2([0.0, 1.0])': V2
-            454..464 '[0.0, 1.0]': [f32; 2]
-            455..458 '0.0': f32
-            460..463 '1.0': f32
-            475..477 'vb': V2
-            480..482 'V2': V2([f32; 2]) -> V2
-            480..494 'V2([0.0, 1.0])': V2
-            483..493 '[0.0, 1.0]': [f32; 2]
-            484..487 '0.0': f32
-            489..492 '1.0': f32
-            505..506 'r': V2
-            509..511 'va': V2
-            509..516 'va + vb': V2
-            514..516 'vb': V2
-        "#]],
     );
 }
 
@@ -2683,7 +2612,7 @@ fn prelude_2015() {
 //- /main.rs edition:2015 crate:main deps:core
 fn f() {
     Rust;
-     //^ Rust
+  //^^^^ Rust
 }
 
 //- /core.rs crate:core