diff options
| author | bors <bors@rust-lang.org> | 2022-08-18 11:17:40 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-08-18 11:17:40 +0000 |
| commit | 0a33d04a3d06ce41fa4e876ef3e3dc6475fe84d2 (patch) | |
| tree | 537a36d8953080137d369b9578c32e50e3f7711a | |
| parent | 5543dd88c98eca686d63fc032ae927a0565565b8 (diff) | |
| parent | dac27679f75725c8a3e8ff5fc009f3bc59ce3523 (diff) | |
| download | rust-0a33d04a3d06ce41fa4e876ef3e3dc6475fe84d2.tar.gz rust-0a33d04a3d06ce41fa4e876ef3e3dc6475fe84d2.zip | |
Auto merge of #13053 - lowr:fix/pat-sole-Self, r=Veykril
fix: resolve path `Self` alone in value namespace Fixes #12968
| -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 95a7229e879..5df48e5fdcb 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#" |
