@@ -920,20 +920,47 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
920920 & self ,
921921 path : & [ Segment ] ,
922922 ) -> Option < ( Span , & ' static str , String , Applicability ) > {
923- let ident = match path {
924- [ segment] => segment. ident ,
923+ let ( ident, span) = match path {
924+ [ segment] if !segment. has_generic_args => {
925+ ( segment. ident . to_string ( ) , segment. ident . span )
926+ }
925927 _ => return None ,
926928 } ;
927- match (
928- self . diagnostic_metadata . current_item ,
929- self . diagnostic_metadata . currently_processing_generics ,
930- ) {
931- ( Some ( Item { kind : ItemKind :: Fn ( ..) , ident, .. } ) , true ) if ident. name == sym:: main => {
929+ let mut iter = ident. chars ( ) . map ( |c| c. is_uppercase ( ) ) ;
930+ let single_uppercase_char =
931+ matches ! ( iter. next( ) , Some ( true ) ) && matches ! ( iter. next( ) , None ) ;
932+ if !self . diagnostic_metadata . currently_processing_generics && !single_uppercase_char {
933+ return None ;
934+ }
935+ match ( self . diagnostic_metadata . current_item , single_uppercase_char) {
936+ ( Some ( Item { kind : ItemKind :: Fn ( ..) , ident, .. } ) , _) if ident. name == sym:: main => {
932937 // Ignore `fn main()` as we don't want to suggest `fn main<T>()`
933938 }
934- ( Some ( Item { kind, .. } ) , true ) => {
939+ (
940+ Some ( Item {
941+ kind :
942+ kind @ ItemKind :: Fn ( ..)
943+ | kind @ ItemKind :: Enum ( ..)
944+ | kind @ ItemKind :: Struct ( ..)
945+ | kind @ ItemKind :: Union ( ..) ,
946+ ..
947+ } ) ,
948+ true ,
949+ )
950+ | ( Some ( Item { kind, .. } ) , false ) => {
935951 // Likely missing type parameter.
936952 if let Some ( generics) = kind. generics ( ) {
953+ if span. overlaps ( generics. span ) {
954+ // Avoid the following:
955+ // error[E0405]: cannot find trait `A` in this scope
956+ // --> $DIR/typo-suggestion-named-underscore.rs:CC:LL
957+ // |
958+ // L | fn foo<T: A>(x: T) {} // Shouldn't suggest underscore
959+ // | ^- help: you might be missing a type parameter: `, A`
960+ // | |
961+ // | not found in this scope
962+ return None ;
963+ }
937964 let msg = "you might be missing a type parameter" ;
938965 let ( span, sugg) = if let [ .., param] = & generics. params [ ..] {
939966 let span = if let [ .., bound] = & param. bounds [ ..] {
0 commit comments