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