about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-04-17 05:44:53 +0200
committerGitHub <noreply@github.com>2024-04-17 05:44:53 +0200
commit90af17ddcbd39ff80ee4264e908eda2e2c57de98 (patch)
tree7420aa12af8259bfdb38dd10429f547d9ee5a490 /tests
parent8229a34102540924347b8a0fd81cba895f623473 (diff)
parent6288a721f5ea59a59b4304a7b70c92d7755e8aa8 (diff)
downloadrust-90af17ddcbd39ff80ee4264e908eda2e2c57de98.tar.gz
rust-90af17ddcbd39ff80ee4264e908eda2e2c57de98.zip
Rollup merge of #123997 - compiler-errors:self-res, r=fmease
Delay span bug when `Self` kw resolves to `DefKind::{Mod,Trait}`

Catch the case where `kw::Self` is recovered in the parser and causes us to subsequently resolve `&self`'s implicit type to something that's not a type.

This check could be made more accurate, though I'm not sure how hard we have to try here.

Fixes #123988
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/resolve/incorrect-self-res.rs17
-rw-r--r--tests/ui/resolve/incorrect-self-res.stderr30
2 files changed, 47 insertions, 0 deletions
diff --git a/tests/ui/resolve/incorrect-self-res.rs b/tests/ui/resolve/incorrect-self-res.rs
new file mode 100644
index 00000000000..ca97e698994
--- /dev/null
+++ b/tests/ui/resolve/incorrect-self-res.rs
@@ -0,0 +1,17 @@
+fn module() {
+    fn test(&mut self) {
+    //~^ ERROR `self` parameter is only allowed in associated functions
+    }
+    mod Self {}
+    //~^ ERROR expected identifier, found keyword `Self`
+}
+
+fn trait_() {
+    fn test(&mut self) {
+    //~^ ERROR `self` parameter is only allowed in associated functions
+    }
+    trait Self {}
+    //~^ ERROR expected identifier, found keyword `Self`
+}
+
+fn main() {}
diff --git a/tests/ui/resolve/incorrect-self-res.stderr b/tests/ui/resolve/incorrect-self-res.stderr
new file mode 100644
index 00000000000..406bfb98011
--- /dev/null
+++ b/tests/ui/resolve/incorrect-self-res.stderr
@@ -0,0 +1,30 @@
+error: expected identifier, found keyword `Self`
+  --> $DIR/incorrect-self-res.rs:5:9
+   |
+LL |     mod Self {}
+   |         ^^^^ expected identifier, found keyword
+
+error: expected identifier, found keyword `Self`
+  --> $DIR/incorrect-self-res.rs:13:11
+   |
+LL |     trait Self {}
+   |           ^^^^ expected identifier, found keyword
+
+error: `self` parameter is only allowed in associated functions
+  --> $DIR/incorrect-self-res.rs:2:13
+   |
+LL |     fn test(&mut self) {
+   |             ^^^^^^^^^ not semantically valid as function parameter
+   |
+   = note: associated functions are those in `impl` or `trait` definitions
+
+error: `self` parameter is only allowed in associated functions
+  --> $DIR/incorrect-self-res.rs:10:13
+   |
+LL |     fn test(&mut self) {
+   |             ^^^^^^^^^ not semantically valid as function parameter
+   |
+   = note: associated functions are those in `impl` or `trait` definitions
+
+error: aborting due to 4 previous errors
+