Skip to content

Commit 897f56e

Browse files
authored
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
2 parents 31d7e51 + f4de121 commit 897f56e

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,9 @@ fn foo(&self) -> Self::T { String::new() }
504504
let methods: Vec<(Span, String)> = items
505505
.in_definition_order()
506506
.filter(|item| {
507-
ty::AssocKind::Fn == item.kind && Some(item.name) != current_method_ident
507+
ty::AssocKind::Fn == item.kind
508+
&& Some(item.name) != current_method_ident
509+
&& !tcx.is_doc_hidden(item.def_id)
508510
})
509511
.filter_map(|item| {
510512
let method = tcx.fn_sig(item.def_id).subst_identity();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// #107983 - testing that `__iterator_get_unchecked` isn't suggested
2+
// HELP included so that compiletest errors on the bad suggestion
3+
pub fn i_can_has_iterator() -> impl Iterator<Item = u32> {
4+
//~^ ERROR expected `Box<dyn Iterator>`
5+
//~| HELP consider constraining the associated type
6+
Box::new(1..=10) as Box<dyn Iterator>
7+
//~^ ERROR the value of the associated type `Item`
8+
//~| HELP specify the associated type
9+
}
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0191]: the value of the associated type `Item` (from trait `Iterator`) must be specified
2+
--> $DIR/trait-hidden-method.rs:6:33
3+
|
4+
LL | Box::new(1..=10) as Box<dyn Iterator>
5+
| ^^^^^^^^ help: specify the associated type: `Iterator<Item = Type>`
6+
7+
error[E0271]: expected `Box<dyn Iterator>` to be an iterator that yields `u32`, but it yields `<dyn Iterator as Iterator>::Item`
8+
--> $DIR/trait-hidden-method.rs:3:32
9+
|
10+
LL | pub fn i_can_has_iterator() -> impl Iterator<Item = u32> {
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found `u32`
12+
...
13+
LL | Box::new(1..=10) as Box<dyn Iterator>
14+
| ------------------------------------- return type was inferred to be `Box<dyn Iterator>` here
15+
|
16+
= note: expected associated type `<dyn Iterator as Iterator>::Item`
17+
found type `u32`
18+
= help: consider constraining the associated type `<dyn Iterator as Iterator>::Item` to `u32` or calling a method that returns `<dyn Iterator as Iterator>::Item`
19+
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
20+
21+
error: aborting due to 2 previous errors
22+
23+
Some errors have detailed explanations: E0191, E0271.
24+
For more information about an error, try `rustc --explain E0191`.

0 commit comments

Comments
 (0)