about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-02-15 21:30:58 +0100
committerGitHub <noreply@github.com>2023-02-15 21:30:58 +0100
commit897f56ed28ec072b0839032c67f3121111e8a550 (patch)
treed272c4c4d1bf1c374f54d6a0e18717c73288c253
parent31d7e514ab194349736075dac6c86fae13e1eb32 (diff)
parentf4de121951edc326f605c7e3109d98bbc7897a8e (diff)
downloadrust-897f56ed28ec072b0839032c67f3121111e8a550.tar.gz
rust-897f56ed28ec072b0839032c67f3121111e8a550.zip
Rollup merge of #108049 - clubby789:dont-suggest-unstable, r=compiler-errors
Don't suggest `#[doc(hidden)]` trait methods with matching return type

Fixes #107983, addressing the bad suggestion.
The test can probably be made more specific to this  case, but I'm unsure how.

`@rustbot` label +A-diagnostics
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs4
-rw-r--r--tests/ui/suggestions/trait-hidden-method.rs11
-rw-r--r--tests/ui/suggestions/trait-hidden-method.stderr24
3 files changed, 38 insertions, 1 deletions
diff --git a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs
index c3fe4158618..b6337d6853f 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs
@@ -504,7 +504,9 @@ fn foo(&self) -> Self::T { String::new() }
         let methods: Vec<(Span, String)> = items
             .in_definition_order()
             .filter(|item| {
-                ty::AssocKind::Fn == item.kind && Some(item.name) != current_method_ident
+                ty::AssocKind::Fn == item.kind
+                    && Some(item.name) != current_method_ident
+                    && !tcx.is_doc_hidden(item.def_id)
             })
             .filter_map(|item| {
                 let method = tcx.fn_sig(item.def_id).subst_identity();
diff --git a/tests/ui/suggestions/trait-hidden-method.rs b/tests/ui/suggestions/trait-hidden-method.rs
new file mode 100644
index 00000000000..ae7ef47e1d4
--- /dev/null
+++ b/tests/ui/suggestions/trait-hidden-method.rs
@@ -0,0 +1,11 @@
+// #107983 - testing that `__iterator_get_unchecked` isn't suggested
+// HELP included so that compiletest errors on the bad suggestion
+pub fn i_can_has_iterator() -> impl Iterator<Item = u32> {
+    //~^ ERROR expected `Box<dyn Iterator>`
+    //~| HELP consider constraining the associated type
+    Box::new(1..=10) as Box<dyn Iterator>
+    //~^ ERROR the value of the associated type `Item`
+    //~| HELP specify the associated type
+}
+
+fn main() {}
diff --git a/tests/ui/suggestions/trait-hidden-method.stderr b/tests/ui/suggestions/trait-hidden-method.stderr
new file mode 100644
index 00000000000..a5a65d193db
--- /dev/null
+++ b/tests/ui/suggestions/trait-hidden-method.stderr
@@ -0,0 +1,24 @@
+error[E0191]: the value of the associated type `Item` (from trait `Iterator`) must be specified
+  --> $DIR/trait-hidden-method.rs:6:33
+   |
+LL |     Box::new(1..=10) as Box<dyn Iterator>
+   |                                 ^^^^^^^^ help: specify the associated type: `Iterator<Item = Type>`
+
+error[E0271]: expected `Box<dyn Iterator>` to be an iterator that yields `u32`, but it yields `<dyn Iterator as Iterator>::Item`
+  --> $DIR/trait-hidden-method.rs:3:32
+   |
+LL | pub fn i_can_has_iterator() -> impl Iterator<Item = u32> {
+   |                                ^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found `u32`
+...
+LL |     Box::new(1..=10) as Box<dyn Iterator>
+   |     ------------------------------------- return type was inferred to be `Box<dyn Iterator>` here
+   |
+   = note: expected associated type `<dyn Iterator as Iterator>::Item`
+                         found type `u32`
+   = help: consider constraining the associated type `<dyn Iterator as Iterator>::Item` to `u32` or calling a method that returns `<dyn Iterator as Iterator>::Item`
+   = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0191, E0271.
+For more information about an error, try `rustc --explain E0191`.