about summary refs log tree commit diff
path: root/src/test/ui/suggestions
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2018-01-17 20:15:13 -0800
committerEsteban Küber <esteban@kuber.com.ar>2018-01-22 08:29:24 -0800
commit4121ddb041aaa20769c8b31bc6496906c6330170 (patch)
tree1e1b0a47a0bd43a8456ac885078888a561f0a3bd /src/test/ui/suggestions
parentfdc18b3067b5bad257ccbe7400e3c4fb617e9e18 (diff)
downloadrust-4121ddb041aaa20769c8b31bc6496906c6330170.tar.gz
rust-4121ddb041aaa20769c8b31bc6496906c6330170.zip
Do not suggest private traits that have missing method
When encountering a method call for an ADT that doesn't have any
implementation of it, we search for traits that could be implemented
that do have that method. Filter out private non-local traits that would
not be able to be implemented.

This doesn't account for public traits that are in a private scope, but
works as a first approximation and is a more correct behavior than the
current one.
Diffstat (limited to 'src/test/ui/suggestions')
-rw-r--r--src/test/ui/suggestions/dont-suggest-private-trait-method.rs16
-rw-r--r--src/test/ui/suggestions/dont-suggest-private-trait-method.stderr11
2 files changed, 27 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/dont-suggest-private-trait-method.rs b/src/test/ui/suggestions/dont-suggest-private-trait-method.rs
new file mode 100644
index 00000000000..99bee0d3c59
--- /dev/null
+++ b/src/test/ui/suggestions/dont-suggest-private-trait-method.rs
@@ -0,0 +1,16 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+struct T;
+
+fn main() {
+    T::new();
+    //~^ ERROR no function or associated item named `new` found for type `T` in the current scope
+}
diff --git a/src/test/ui/suggestions/dont-suggest-private-trait-method.stderr b/src/test/ui/suggestions/dont-suggest-private-trait-method.stderr
new file mode 100644
index 00000000000..97f424f9fbf
--- /dev/null
+++ b/src/test/ui/suggestions/dont-suggest-private-trait-method.stderr
@@ -0,0 +1,11 @@
+error[E0599]: no function or associated item named `new` found for type `T` in the current scope
+  --> $DIR/dont-suggest-private-trait-method.rs:14:5
+   |
+11 | struct T;
+   | --------- function or associated item `new` not found for this
+...
+14 |     T::new();
+   |     ^^^^^^ function or associated item not found in `T`
+
+error: aborting due to previous error
+