diff options
| author | Ryo Yoshida <low.ryoshida@gmail.com> | 2022-08-18 08:46:06 +0900 |
|---|---|---|
| committer | Ryo Yoshida <low.ryoshida@gmail.com> | 2022-08-18 20:12:59 +0900 |
| commit | dac27679f75725c8a3e8ff5fc009f3bc59ce3523 (patch) | |
| tree | b0bf99b1046d34184d20faa5dd9271697ffa7aa0 | |
| parent | d6412b58666ee399bdc56a868a79ed322d6a3fcd (diff) | |
| download | rust-dac27679f75725c8a3e8ff5fc009f3bc59ce3523.tar.gz rust-dac27679f75725c8a3e8ff5fc009f3bc59ce3523.zip | |
fix: resolve path `Self` alone in value namespace
| -rw-r--r-- | crates/hir-ty/src/infer.rs | 1 | ||||
| -rw-r--r-- | crates/hir-ty/src/tests/patterns.rs | 36 |
2 files changed, 37 insertions, 0 deletions
diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs index 46eeea0e6fc..7440439522e 100644 --- a/crates/hir-ty/src/infer.rs +++ b/crates/hir-ty/src/infer.rs @@ -734,6 +734,7 @@ impl<'a> InferenceContext<'a> { let ty = self.insert_type_vars(ty.substitute(Interner, &substs)); return (ty, Some(strukt.into())); } + ValueNs::ImplSelf(impl_id) => (TypeNs::SelfType(impl_id), None), _ => return (self.err_ty(), None), }, Some(ResolveValueResult::Partial(typens, unresolved)) => (typens, Some(unresolved)), diff --git a/crates/hir-ty/src/tests/patterns.rs b/crates/hir-ty/src/tests/patterns.rs index 94efe7bc11a..eb04bf87783 100644 --- a/crates/hir-ty/src/tests/patterns.rs +++ b/crates/hir-ty/src/tests/patterns.rs @@ -489,6 +489,42 @@ fn infer_adt_pattern() { } #[test] +fn tuple_struct_destructured_with_self() { + check_infer( + r#" +struct Foo(usize,); +impl Foo { + fn f() { + let Self(s,) = &Foo(0,); + let Self(s,) = &mut Foo(0,); + let Self(s,) = Foo(0,); + } +} + "#, + expect![[r#" + 42..151 '{ ... }': () + 56..64 'Self(s,)': Foo + 61..62 's': &usize + 67..75 '&Foo(0,)': &Foo + 68..71 'Foo': Foo(usize) -> Foo + 68..75 'Foo(0,)': Foo + 72..73 '0': usize + 89..97 'Self(s,)': Foo + 94..95 's': &mut usize + 100..112 '&mut Foo(0,)': &mut Foo + 105..108 'Foo': Foo(usize) -> Foo + 105..112 'Foo(0,)': Foo + 109..110 '0': usize + 126..134 'Self(s,)': Foo + 131..132 's': usize + 137..140 'Foo': Foo(usize) -> Foo + 137..144 'Foo(0,)': Foo + 141..142 '0': usize + "#]], + ); +} + +#[test] fn enum_variant_through_self_in_pattern() { check_infer( r#" |
