about summary refs log tree commit diff
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2024-06-11 09:14:35 +0100
committerGitHub <noreply@github.com>2024-06-11 09:14:35 +0100
commit76acf2617cd6e3565747ea4286066c4eb3d8337e (patch)
treef55c41e673dfb28d689ad46f4b69460f18f8a798
parent81ff9b57702b8a7739e8b3839ee66eba52959e44 (diff)
parent040791a9c59d2f604060efb75c81f685ceb5f9db (diff)
downloadrust-76acf2617cd6e3565747ea4286066c4eb3d8337e.tar.gz
rust-76acf2617cd6e3565747ea4286066c4eb3d8337e.zip
Rollup merge of #126234 - Bryanskiy:delegation-no-entry-ice, r=petrochenkov
Delegation: fix ICE on late diagnostics

fixes https://github.com/rust-lang/rust/issues/124342
-rw-r--r--compiler/rustc_resolve/src/late/diagnostics.rs7
-rw-r--r--tests/crashes/124342.rs6
-rw-r--r--tests/ui/delegation/ice-issue-124342.rs12
-rw-r--r--tests/ui/delegation/ice-issue-124342.stderr20
4 files changed, 37 insertions, 8 deletions
diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs
index ec24eac4a9d..9eeb0da7ed2 100644
--- a/compiler/rustc_resolve/src/late/diagnostics.rs
+++ b/compiler/rustc_resolve/src/late/diagnostics.rs
@@ -2041,8 +2041,11 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
                         ast::AssocItemKind::Fn(..) => AssocSuggestion::AssocFn { called },
                         ast::AssocItemKind::Type(..) => AssocSuggestion::AssocType,
                         ast::AssocItemKind::Delegation(..)
-                            if self.r.delegation_fn_sigs[&self.r.local_def_id(assoc_item.id)]
-                                .has_self =>
+                            if self
+                                .r
+                                .delegation_fn_sigs
+                                .get(&self.r.local_def_id(assoc_item.id))
+                                .map_or(false, |sig| sig.has_self) =>
                         {
                             AssocSuggestion::MethodWithSelf { called }
                         }
diff --git a/tests/crashes/124342.rs b/tests/crashes/124342.rs
deleted file mode 100644
index ae51b3db96f..00000000000
--- a/tests/crashes/124342.rs
+++ /dev/null
@@ -1,6 +0,0 @@
-//@ known-bug: #124342
-trait Trait2 : Trait {
-   reuse <() as Trait>::async {
-        (async || {}).await;
-    };
-}
diff --git a/tests/ui/delegation/ice-issue-124342.rs b/tests/ui/delegation/ice-issue-124342.rs
new file mode 100644
index 00000000000..ad62f6bd54a
--- /dev/null
+++ b/tests/ui/delegation/ice-issue-124342.rs
@@ -0,0 +1,12 @@
+#![feature(fn_delegation)]
+#![allow(incomplete_features)]
+
+mod to_reuse {}
+
+trait Trait {
+    reuse to_reuse::foo { foo }
+    //~^ ERROR cannot find function `foo` in module `to_reuse`
+    //~| ERROR cannot find value `foo` in this scope
+}
+
+fn main() {}
diff --git a/tests/ui/delegation/ice-issue-124342.stderr b/tests/ui/delegation/ice-issue-124342.stderr
new file mode 100644
index 00000000000..f9a3684d649
--- /dev/null
+++ b/tests/ui/delegation/ice-issue-124342.stderr
@@ -0,0 +1,20 @@
+error[E0425]: cannot find function `foo` in module `to_reuse`
+  --> $DIR/ice-issue-124342.rs:7:21
+   |
+LL |     reuse to_reuse::foo { foo }
+   |                     ^^^ not found in `to_reuse`
+
+error[E0425]: cannot find value `foo` in this scope
+  --> $DIR/ice-issue-124342.rs:7:27
+   |
+LL |     reuse to_reuse::foo { foo }
+   |                           ^^^
+   |
+help: you might have meant to refer to the associated function
+   |
+LL |     reuse to_reuse::foo { Self::foo }
+   |                           ++++++
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0425`.