@@ -12,9 +12,9 @@ use rustc_errors::MultiSpan;
12
12
use rustc_errors:: {
13
13
codes:: * , pluralize, struct_span_code_err, Applicability , Diag , ErrorGuaranteed ,
14
14
} ;
15
- use rustc_hir as hir;
16
15
use rustc_hir:: def:: { DefKind , Res } ;
17
16
use rustc_hir:: def_id:: { DefId , LocalDefId } ;
17
+ use rustc_hir:: { self as hir, Node } ;
18
18
use rustc_middle:: bug;
19
19
use rustc_middle:: query:: Key ;
20
20
use rustc_middle:: ty:: print:: { PrintPolyTraitRefExt as _, PrintTraitRefExt as _} ;
@@ -745,7 +745,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
745
745
if object_safety_violations {
746
746
return ;
747
747
}
748
+
749
+ // related to issue #91997, turbofishes added only when in an expr or pat
750
+ let mut in_expr_or_pat = false ;
748
751
if let ( [ ] , [ bound] ) = ( & potential_assoc_types[ ..] , & trait_bounds) {
752
+ let grandparent = tcx. parent_hir_node ( tcx. parent_hir_id ( bound. trait_ref . hir_ref_id ) ) ;
753
+ in_expr_or_pat = match grandparent {
754
+ Node :: Expr ( _) | Node :: Pat ( _) => true ,
755
+ _ => false ,
756
+ } ;
749
757
match bound. trait_ref . path . segments {
750
758
// FIXME: `trait_ref.path.span` can point to a full path with multiple
751
759
// segments, even though `trait_ref.path.segments` is of length `1`. Work
@@ -901,6 +909,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
901
909
// `Trait<'a, Item = Type>` while accounting for the `<'a>` in the
902
910
// suggestion.
903
911
format ! ( "{}, {}>" , & snippet[ ..snippet. len( ) - 1 ] , types. join( ", " ) )
912
+ } else if in_expr_or_pat {
913
+ // The user wrote `Iterator`, so we don't have a type we can suggest, but at
914
+ // least we can clue them to the correct syntax `Iterator::<Item = Type>`.
915
+ format ! ( "{}::<{}>" , snippet, types. join( ", " ) )
904
916
} else {
905
917
// The user wrote `Iterator`, so we don't have a type we can suggest, but at
906
918
// least we can clue them to the correct syntax `Iterator<Item = Type>`.
0 commit comments