@@ -3105,60 +3105,65 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
3105
3105
owned_sugg = true ;
3106
3106
}
3107
3107
if let Some ( ty) = lt_finder. found {
3108
- if let TyKind :: Path ( None , path @ Path { segments, .. } ) = & ty. kind
3109
- && segments. len ( ) == 1
3110
- {
3111
- if segments[ 0 ] . ident . name == sym:: str {
3112
- // Don't suggest `-> str`, suggest `-> String`.
3113
- sugg = vec ! [
3114
- ( lt. span. with_hi( ty. span. hi( ) ) , "String" . to_string( ) ) ,
3115
- ] ;
3116
- } else {
3117
- // Check if the path being borrowed is likely to be owned.
3118
- let path: Vec < _ > = Segment :: from_path ( path) ;
3119
- match self . resolve_path ( & path, Some ( TypeNS ) , None ) {
3120
- PathResult :: Module (
3121
- ModuleOrUniformRoot :: Module ( module) ,
3122
- ) => {
3123
- match module. res ( ) {
3124
- Some ( Res :: PrimTy ( ..) ) => { }
3125
- Some ( Res :: Def (
3126
- DefKind :: Struct
3127
- | DefKind :: Union
3128
- | DefKind :: Enum
3129
- | DefKind :: ForeignTy
3130
- | DefKind :: AssocTy
3131
- | DefKind :: OpaqueTy
3132
- | DefKind :: TyParam ,
3133
- _,
3134
- ) ) => { }
3135
- _ => { // Do not suggest in all other cases.
3136
- owned_sugg = false ;
3137
- }
3108
+ if let TyKind :: Path ( None , path) = & ty. kind {
3109
+ // Check if the path being borrowed is likely to be owned.
3110
+ let path: Vec < _ > = Segment :: from_path ( path) ;
3111
+ match self . resolve_path ( & path, Some ( TypeNS ) , None ) {
3112
+ PathResult :: Module (
3113
+ ModuleOrUniformRoot :: Module ( module) ,
3114
+ ) => {
3115
+ match module. res ( ) {
3116
+ Some ( Res :: PrimTy ( PrimTy :: Str ) ) => {
3117
+ // Don't suggest `-> str`, suggest `-> String`.
3118
+ sugg = vec ! [ (
3119
+ lt. span. with_hi( ty. span. hi( ) ) ,
3120
+ "String" . to_string( ) ,
3121
+ ) ] ;
3138
3122
}
3139
- }
3140
- PathResult :: NonModule ( res) => {
3141
- match res. base_res ( ) {
3142
- Res :: PrimTy ( ..) => { }
3143
- Res :: Def (
3144
- DefKind :: Struct
3145
- | DefKind :: Union
3146
- | DefKind :: Enum
3147
- | DefKind :: ForeignTy
3148
- | DefKind :: AssocTy
3149
- | DefKind :: OpaqueTy
3150
- | DefKind :: TyParam ,
3151
- _,
3152
- ) => { }
3153
- _ => { // Do not suggest in all other cases.
3154
- owned_sugg = false ;
3155
- }
3123
+ Some ( Res :: PrimTy ( ..) ) => { }
3124
+ Some ( Res :: Def (
3125
+ DefKind :: Struct
3126
+ | DefKind :: Union
3127
+ | DefKind :: Enum
3128
+ | DefKind :: ForeignTy
3129
+ | DefKind :: AssocTy
3130
+ | DefKind :: OpaqueTy
3131
+ | DefKind :: TyParam ,
3132
+ _,
3133
+ ) ) => { }
3134
+ _ => { // Do not suggest in all other cases.
3135
+ owned_sugg = false ;
3156
3136
}
3157
3137
}
3158
- _ => { // Do not suggest in all other cases.
3159
- owned_sugg = false ;
3138
+ }
3139
+ PathResult :: NonModule ( res) => {
3140
+ match res. base_res ( ) {
3141
+ Res :: PrimTy ( PrimTy :: Str ) => {
3142
+ // Don't suggest `-> str`, suggest `-> String`.
3143
+ sugg = vec ! [ (
3144
+ lt. span. with_hi( ty. span. hi( ) ) ,
3145
+ "String" . to_string( ) ,
3146
+ ) ] ;
3147
+ }
3148
+ Res :: PrimTy ( ..) => { }
3149
+ Res :: Def (
3150
+ DefKind :: Struct
3151
+ | DefKind :: Union
3152
+ | DefKind :: Enum
3153
+ | DefKind :: ForeignTy
3154
+ | DefKind :: AssocTy
3155
+ | DefKind :: OpaqueTy
3156
+ | DefKind :: TyParam ,
3157
+ _,
3158
+ ) => { }
3159
+ _ => { // Do not suggest in all other cases.
3160
+ owned_sugg = false ;
3161
+ }
3160
3162
}
3161
3163
}
3164
+ _ => { // Do not suggest in all other cases.
3165
+ owned_sugg = false ;
3166
+ }
3162
3167
}
3163
3168
}
3164
3169
if let TyKind :: Slice ( inner_ty) = & ty. kind {
0 commit comments