@@ -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,18 @@ 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
+ 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
+ ) ;
749
760
match bound. trait_ref . path . segments {
750
761
// FIXME: `trait_ref.path.span` can point to a full path with multiple
751
762
// segments, even though `trait_ref.path.segments` is of length `1`. Work
@@ -901,10 +912,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
901
912
// `Trait<'a, Item = Type>` while accounting for the `<'a>` in the
902
913
// suggestion.
903
914
format ! ( "{}, {}>" , & snippet[ ..snippet. len( ) - 1 ] , types. join( ", " ) )
904
- } else {
915
+ } else if in_expr_or_pat {
905
916
// The user wrote `Iterator`, so we don't have a type we can suggest, but at
906
917
// least we can clue them to the correct syntax `Iterator::<Item = Type>`.
907
918
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( ", " ) )
908
923
} ;
909
924
suggestions. push ( ( * span, code) ) ;
910
925
} else if dupes {
0 commit comments