@@ -12,9 +12,9 @@ use rustc_errors::MultiSpan;
1212use rustc_errors:: {
1313 codes:: * , pluralize, struct_span_code_err, Applicability , Diag , ErrorGuaranteed ,
1414} ;
15- use rustc_hir as hir;
1615use rustc_hir:: def:: { DefKind , Res } ;
1716use rustc_hir:: def_id:: { DefId , LocalDefId } ;
17+ use rustc_hir:: { self as hir, Node } ;
1818use rustc_middle:: bug;
1919use rustc_middle:: query:: Key ;
2020use rustc_middle:: ty:: print:: { PrintPolyTraitRefExt as _, PrintTraitRefExt as _} ;
@@ -745,7 +745,18 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
745745 if object_safety_violations {
746746 return ;
747747 }
748+
749+ // related to issue #91997, turbofishes added only when in an expr or pat
750+ let mut in_expr_or_pat = false ;
748751 if let ( [ ] , [ bound] ) = ( & potential_assoc_types[ ..] , & trait_bounds) {
752+ in_expr_or_pat = match tcx. parent_hir_node ( bound. trait_ref . hir_ref_id ) {
753+ Node :: Expr ( _) | Node :: Pat ( _) => true ,
754+ _ => false ,
755+ } ;
756+ println ! (
757+ "(!!!!!!) parent node: {:#?}" ,
758+ tcx. parent_hir_node( bound. trait_ref. hir_ref_id)
759+ ) ;
749760 match bound. trait_ref . path . segments {
750761 // FIXME: `trait_ref.path.span` can point to a full path with multiple
751762 // segments, even though `trait_ref.path.segments` is of length `1`. Work
@@ -901,10 +912,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
901912 // `Trait<'a, Item = Type>` while accounting for the `<'a>` in the
902913 // suggestion.
903914 format ! ( "{}, {}>" , & snippet[ ..snippet. len( ) - 1 ] , types. join( ", " ) )
904- } else {
915+ } else if in_expr_or_pat {
905916 // The user wrote `Iterator`, so we don't have a type we can suggest, but at
906917 // least we can clue them to the correct syntax `Iterator::<Item = Type>`.
907918 format ! ( "{}::<{}>" , snippet, types. join( ", " ) )
919+ } else {
920+ // The user wrote `Iterator`, so we don't have a type we can suggest, but at
921+ // least we can clue them to the correct syntax `Iterator<Item = Type>`.
922+ format ! ( "{}<{}>" , snippet, types. join( ", " ) )
908923 } ;
909924 suggestions. push ( ( * span, code) ) ;
910925 } else if dupes {
0 commit comments