about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-10-15 05:11:39 +0200
committerGitHub <noreply@github.com>2024-10-15 05:11:39 +0200
commit2e2c433be4da62f723a06ce90e3a2dfabc8f2885 (patch)
treecc702ba3b7a17b3263a82aa0e61b600e01357c42 /tests
parent258c17741b998b7b068593759935d374e8af7d13 (diff)
parentc3b696dec99e7646b84d8b43c05a113acf7d249c (diff)
downloadrust-2e2c433be4da62f723a06ce90e3a2dfabc8f2885.tar.gz
rust-2e2c433be4da62f723a06ce90e3a2dfabc8f2885.zip
Rollup merge of #131702 - compiler-errors:method-lookup-trait-warning, r=jieyouxu
Suppress import errors for traits that couldve applied for method lookup error

Self-explanatory. I hit this quite often when refactoring in rustc, so even though this isn't really showing up as significant in the UI test suite, it probably will matter more for multi-module projects.
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/use/unused-trait-with-method-err.rs17
-rw-r--r--tests/ui/use/unused-trait-with-method-err.stderr19
2 files changed, 36 insertions, 0 deletions
diff --git a/tests/ui/use/unused-trait-with-method-err.rs b/tests/ui/use/unused-trait-with-method-err.rs
new file mode 100644
index 00000000000..37684e1bf81
--- /dev/null
+++ b/tests/ui/use/unused-trait-with-method-err.rs
@@ -0,0 +1,17 @@
+// Test that we don't issue an unused import warning when there's
+// a method lookup error and that trait was possibly applicable.
+
+use foo::Bar;
+
+mod foo {
+    pub trait Bar {
+        fn uwu(&self) {}
+    }
+}
+
+struct Foo;
+
+fn main() {
+    Foo.uwu();
+    //~^ ERROR no method named `uwu` found for struct `Foo` in the current scope
+}
diff --git a/tests/ui/use/unused-trait-with-method-err.stderr b/tests/ui/use/unused-trait-with-method-err.stderr
new file mode 100644
index 00000000000..7ca4563673b
--- /dev/null
+++ b/tests/ui/use/unused-trait-with-method-err.stderr
@@ -0,0 +1,19 @@
+error[E0599]: no method named `uwu` found for struct `Foo` in the current scope
+  --> $DIR/unused-trait-with-method-err.rs:15:9
+   |
+LL | struct Foo;
+   | ---------- method `uwu` not found for this struct
+...
+LL |     Foo.uwu();
+   |         ^^^ method not found in `Foo`
+   |
+   = help: items from traits can only be used if the trait is implemented and in scope
+note: `Bar` defines an item `uwu`, perhaps you need to implement it
+  --> $DIR/unused-trait-with-method-err.rs:7:5
+   |
+LL |     pub trait Bar {
+   |     ^^^^^^^^^^^^^
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0599`.