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