Skip to content

Commit

Permalink
Auto merge of rust-lang#13053 - lowr:fix/pat-sole-Self, r=Veykril
Browse files Browse the repository at this point in the history
fix: resolve path `Self` alone in value namespace

Fixes rust-lang#12968
  • Loading branch information
bors committed Aug 18, 2022
2 parents 5543dd8 + dac2767 commit 0a33d04
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/hir-ty/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
36 changes: 36 additions & 0 deletions crates/hir-ty/src/tests/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,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(
Expand Down

0 comments on commit 0a33d04

Please sign in to comment.