Change:
Given the following code: %20%7B%0A%20%20%20%20let%20%20%3D%20MyIterator%3A%3Anext%3B%0A%20%20%20%20%2F%2Flet%20%20%3D%20MyIterator%3CItem%3D()%3E%3A%3Anext%3B%0A%7D) The current output is: But when when I write , it gets interpreted as comparison expressions like and it fails to compile with a lot of "cannot find value in this scope" and "cannot find crate in the list of imported crates". The suggestion is confusing because it is unclear how to apply it. The error goes away if you use directly: produces the error one would expect: <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
I think it gets evaluated as an expression because you are missing a . If you add them, then you get a new error message ():
I see, let me rephrase the issue: The suggestion is "help: specify the associated type: " where "help: specify the associated type: " with a double colon would be correct.
Triage: Suggestion is correct for code using (which all code written in Rust =2021 uses). For code written without in Rust <2021: No change. As mentioned, the suggestion should use an expression-style path (i.e., one with turbofishes).
claim
Working on tests before creating a PR. Multiple tests exist already that have an odd hardcoded expectation for error output, so I'll be double checking those make sense with these changes, and adding a few tests of my own. Otherwise, this really does seem like it was a simple two character fix, unless I missed something somewhere.
Yeah, it's a pretty easy one. Adding before is always correct — not only in expression contexts but also in type contexts since turbofish is also possible in type positions (e.g., ) — albeit redundant. Omitting before in type contexts would be a possible "optimization". However, it really isn't worth doing here. Consider the following code which is ill-formed even after specifying the assoc ty. () would only be well-formed if we defined an inherent associated type () on which doesn't work yet anyway () and is pretty niche) or once we support arbitrary shorthand projections ().

Discussion:
use rustc_errors::{ codes::*, pluralize, struct_span_code_err, Applicability, Diag, ErrorGuaranteed, }; <del> use rustc_hir as hir; </del> use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId}; <ins> use rustc_hir::{self as hir, Node}; </ins> use rustc_middle::bug; use rustc_middle::query::Key; use rustc_middle::ty::print::{PrintPolyTraitRefExt as _, PrintTraitRefExt as _};

if object_safety_violations { return; } <ins> // related to issue #91997, turbofishes added only when in an expr or pat let mut in_expr_or_pat = false; </ins> if let ([], [bound]) = (&potential_assoc_types[..], &trait_bounds) { <ins> let grandparent = tcx.parent_hir_node(tcx.parent_hir_id(bound.trait_ref.hir_ref_id)); in_expr_or_pat = match grandparent { Node::Expr(_) | Node::Pat(_) => true, _ => false, }; </ins> match bound.trait_ref.path.segments { // FIXME: `trait_ref.path.span` can point to a full path with multiple // segments, even though `trait_ref.path.segments` is of length `1`. Work

// `Trait<'a, Item = Type>` while accounting for the `<'a>` in the // suggestion. format!("{}, {}>", &snippet[..snippet.len() - 1], types.join(", ")) <ins> } else if in_expr_or_pat { // The user wrote `Iterator`, so we don't have a type we can suggest, but at // least we can clue them to the correct syntax `Iterator::<Item = Type>`. format!("{}::<{}>", snippet, types.join(", ")) </ins> } else { // The user wrote `Iterator`, so we don't have a type we can suggest, but at // least we can clue them to the correct syntax `Iterator<Item = Type>`.

<ins> trait MyIterator : Iterator {} fn main() { let _ = MyIterator::next; } //~^^ ERROR the value of the associated type `Item` in `Iterator` must be specified [E0191] //~| WARN trait objects without an explicit `dyn` are deprecated [bare_trait_objects] //~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! </ins>

<ins> warning: trait objects without an explicit `dyn` are deprecated --> $DIR/dynless-turbofish-e0191-issue-91997.rs:4:13 | LL |     let _ = MyIterator::next; |             ^^^^^^^^^^ | = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> = note: `#[warn(bare_trait_objects)]` on by default help: if this is an object-safe trait, use `dyn` | LL |     let _ = <dyn MyIterator>::next; |             ++++           + error[E0191]: the value of the associated type `Item` in `Iterator` must be specified --> $DIR/dynless-turbofish-e0191-issue-91997.rs:4:13 | LL |     let _ = MyIterator::next; |             ^^^^^^^^^^ help: specify the associated type: `MyIterator::<Item = Type>` error: aborting due to 1 previous error; 1 warning emitted For more information about this error, try `rustc --explain E0191`. </ins>

--> $DIR/issue-23024.rs:8:39 | LL |     println!("{:?}",(vfnfer[0] as dyn Fn)(3)); <del> |                                       ^^ help: specify the associated type: `Fn<Output = Type>` </del> <ins> |                                       ^^ help: specify the associated type: `Fn::<Output = Type>` </ins> error: aborting due to 3 previous errors

--> $DIR/issue-28344.rs:4:17 | LL |     let x: u8 = BitXor::bitor(0 as u8, 0 as u8); <del> |                 ^^^^^^ help: specify the associated type: `BitXor<Output = Type>` </del> <ins> |                 ^^^^^^ help: specify the associated type: `BitXor::<Output = Type>` </ins> error[E0599]: no function or associated item named `bitor` found for trait object `dyn BitXor<_>` in the current scope --> $DIR/issue-28344.rs:4:25

--> $DIR/issue-28344.rs:10:13 | LL |     let g = BitXor::bitor; <del> |             ^^^^^^ help: specify the associated type: `BitXor<Output = Type>` </del> <ins> |             ^^^^^^ help: specify the associated type: `BitXor::<Output = Type>` </ins> error[E0599]: no function or associated item named `bitor` found for trait object `dyn BitXor<_>` in the current scope --> $DIR/issue-28344.rs:10:21