Skip to content

Commit 0a33d04

Browse files
committed
Auto merge of rust-lang#13053 - lowr:fix/pat-sole-Self, r=Veykril
fix: resolve path `Self` alone in value namespace Fixes rust-lang#12968
2 parents 5543dd8 + dac2767 commit 0a33d04

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

crates/hir-ty/src/infer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ impl<'a> InferenceContext<'a> {
734734
let ty = self.insert_type_vars(ty.substitute(Interner, &substs));
735735
return (ty, Some(strukt.into()));
736736
}
737+
ValueNs::ImplSelf(impl_id) => (TypeNs::SelfType(impl_id), None),
737738
_ => return (self.err_ty(), None),
738739
},
739740
Some(ResolveValueResult::Partial(typens, unresolved)) => (typens, Some(unresolved)),

crates/hir-ty/src/tests/patterns.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,42 @@ fn infer_adt_pattern() {
488488
);
489489
}
490490

491+
#[test]
492+
fn tuple_struct_destructured_with_self() {
493+
check_infer(
494+
r#"
495+
struct Foo(usize,);
496+
impl Foo {
497+
fn f() {
498+
let Self(s,) = &Foo(0,);
499+
let Self(s,) = &mut Foo(0,);
500+
let Self(s,) = Foo(0,);
501+
}
502+
}
503+
"#,
504+
expect![[r#"
505+
42..151 '{ ... }': ()
506+
56..64 'Self(s,)': Foo
507+
61..62 's': &usize
508+
67..75 '&Foo(0,)': &Foo
509+
68..71 'Foo': Foo(usize) -> Foo
510+
68..75 'Foo(0,)': Foo
511+
72..73 '0': usize
512+
89..97 'Self(s,)': Foo
513+
94..95 's': &mut usize
514+
100..112 '&mut Foo(0,)': &mut Foo
515+
105..108 'Foo': Foo(usize) -> Foo
516+
105..112 'Foo(0,)': Foo
517+
109..110 '0': usize
518+
126..134 'Self(s,)': Foo
519+
131..132 's': usize
520+
137..140 'Foo': Foo(usize) -> Foo
521+
137..144 'Foo(0,)': Foo
522+
141..142 '0': usize
523+
"#]],
524+
);
525+
}
526+
491527
#[test]
492528
fn enum_variant_through_self_in_pattern() {
493529
check_infer(

0 commit comments

Comments
 (0)