From 0b2716415f1bd26e80887c2d8459fd436fc8e9b3 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Wed, 19 Oct 2022 11:17:46 +0900 Subject: [PATCH 1/2] fix `SelfVisitor::is_self_ty` ICE --- compiler/rustc_resolve/src/late.rs | 6 +++--- src/test/ui/resolve/issue-103202.rs | 7 +++++++ src/test/ui/resolve/issue-103202.stderr | 9 +++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/resolve/issue-103202.rs create mode 100644 src/test/ui/resolve/issue-103202.stderr diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index cc877e2fd30ca..5b99cd1e26436 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -1928,11 +1928,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { match ty.kind { TyKind::ImplicitSelf => true, TyKind::Path(None, _) => { - let path_res = self.r.partial_res_map[&ty.id].expect_full_res(); - if let Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } = path_res { + let path_res = self.r.partial_res_map[&ty.id].full_res(); + if let Some(Res::SelfTyParam { .. } | Res::SelfTyAlias { .. }) = path_res { return true; } - Some(path_res) == self.impl_self + path_res == self.impl_self } _ => false, } diff --git a/src/test/ui/resolve/issue-103202.rs b/src/test/ui/resolve/issue-103202.rs new file mode 100644 index 0000000000000..469d9d7c860ca --- /dev/null +++ b/src/test/ui/resolve/issue-103202.rs @@ -0,0 +1,7 @@ +struct S {} + +impl S { + fn f(self: &S::x) {} //~ ERROR ambiguous associated type +} + +fn main() {} diff --git a/src/test/ui/resolve/issue-103202.stderr b/src/test/ui/resolve/issue-103202.stderr new file mode 100644 index 0000000000000..880389371ef70 --- /dev/null +++ b/src/test/ui/resolve/issue-103202.stderr @@ -0,0 +1,9 @@ +error[E0223]: ambiguous associated type + --> $DIR/issue-103202.rs:4:17 + | +LL | fn f(self: &S::x) {} + | ^^^^ help: use fully-qualified syntax: `::x` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0223`. From 9a9e2fe15fd0a730e929db88fcf73b0cb3a99ddc Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Thu, 20 Oct 2022 14:10:52 +0900 Subject: [PATCH 2/2] check if impl_self is `Some` --- compiler/rustc_resolve/src/late.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 5b99cd1e26436..c6607eff90dcc 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -1932,7 +1932,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { if let Some(Res::SelfTyParam { .. } | Res::SelfTyAlias { .. }) = path_res { return true; } - path_res == self.impl_self + self.impl_self.is_some() && path_res == self.impl_self } _ => false, }