Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/tests/method_resolution.rs')
-rw-r--r--crates/hir-ty/src/tests/method_resolution.rs74
1 files changed, 71 insertions, 3 deletions
diff --git a/crates/hir-ty/src/tests/method_resolution.rs b/crates/hir-ty/src/tests/method_resolution.rs
index 378d478336..1e57a4ae29 100644
--- a/crates/hir-ty/src/tests/method_resolution.rs
+++ b/crates/hir-ty/src/tests/method_resolution.rs
@@ -389,6 +389,24 @@ mod bar_test {
}
#[test]
+fn infer_trait_method_multiple_mutable_reference() {
+ check_types(
+ r#"
+trait Trait {
+ fn method(&mut self) -> i32 { 5 }
+}
+struct S;
+impl Trait for &mut &mut S {}
+fn test() {
+ let s = &mut &mut &mut S;
+ s.method();
+ //^^^^^^^^^^ i32
+}
+ "#,
+ );
+}
+
+#[test]
fn infer_trait_method_generic_1() {
// the trait implementation is intentionally incomplete -- it shouldn't matter
check_types(
@@ -1255,7 +1273,6 @@ fn foo<T: Trait>(a: &T) {
#[test]
fn autoderef_visibility_field() {
- // FIXME: We should know mutability in overloaded deref
check(
r#"
//- minicore: deref
@@ -1277,7 +1294,7 @@ mod a {
mod b {
fn foo() {
let x = super::a::Bar::new().0;
- // ^^^^^^^^^^^^^^^^^^^^ adjustments: Deref(Some(OverloadedDeref(None)))
+ // ^^^^^^^^^^^^^^^^^^^^ adjustments: Deref(Some(OverloadedDeref(Some(Not))))
// ^^^^^^^^^^^^^^^^^^^^^^ type: char
}
}
@@ -1723,7 +1740,7 @@ fn test() {
Foo.foo();
//^^^ adjustments: Borrow(Ref(Not))
(&Foo).foo();
- // ^^^^ adjustments: ,
+ // ^^^^ adjustments: Deref(None), Borrow(Ref(Not))
}
"#,
);
@@ -1922,3 +1939,54 @@ fn foo() {
"#,
);
}
+
+#[test]
+fn box_deref_is_builtin() {
+ check(
+ r#"
+//- minicore: deref
+use core::ops::Deref;
+
+#[lang = "owned_box"]
+struct Box<T>(*mut T);
+
+impl<T> Box<T> {
+ fn new(t: T) -> Self {
+ loop {}
+ }
+}
+
+impl<T> Deref for Box<T> {
+ type Target = T;
+ fn deref(&self) -> &Self::Target;
+}
+
+struct Foo;
+impl Foo {
+ fn foo(&self) {}
+}
+fn test() {
+ Box::new(Foo).foo();
+ //^^^^^^^^^^^^^ adjustments: Deref(None), Borrow(Ref(Not))
+}
+"#,
+ );
+}
+
+#[test]
+fn manually_drop_deref_is_not_builtin() {
+ check(
+ r#"
+//- minicore: manually_drop, deref
+struct Foo;
+impl Foo {
+ fn foo(&self) {}
+}
+use core::mem::ManuallyDrop;
+fn test() {
+ ManuallyDrop::new(Foo).foo();
+ //^^^^^^^^^^^^^^^^^^^^^^ adjustments: Deref(Some(OverloadedDeref(Some(Not)))), Borrow(Ref(Not))
+}
+"#,
+ );
+}