diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
commit | dc0db358abe19481e475e10c32149b53370f1a1c (patch) | |
tree | ab8ce99c4b255ce46f99ef402c27916055b899ee /src/tools/rust-analyzer/crates/hir-ty/src/tests/method_resolution.rs | |
parent | Releasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip |
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/rust-analyzer/crates/hir-ty/src/tests/method_resolution.rs')
-rw-r--r-- | src/tools/rust-analyzer/crates/hir-ty/src/tests/method_resolution.rs | 74 |
1 files changed, 71 insertions, 3 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/method_resolution.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/method_resolution.rs index 378d47833..1e57a4ae2 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/method_resolution.rs +++ b/src/tools/rust-analyzer/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)) +} +"#, + ); +} |