@@ -1248,15 +1248,6 @@ impl<'a> NameBinding<'a> {
1248
1248
}
1249
1249
}
1250
1250
1251
- fn is_renamed_extern_crate ( & self ) -> bool {
1252
- if let NameBindingKind :: Import { directive, ..} = self . kind {
1253
- if let ImportDirectiveSubclass :: ExternCrate ( Some ( _) ) = directive. subclass {
1254
- return true ;
1255
- }
1256
- }
1257
- false
1258
- }
1259
-
1260
1251
fn is_glob_import ( & self ) -> bool {
1261
1252
match self . kind {
1262
1253
NameBindingKind :: Import { directive, .. } => directive. is_glob ( ) ,
@@ -4783,10 +4774,9 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
4783
4774
} ;
4784
4775
4785
4776
let cm = self . session . source_map ( ) ;
4786
- let rename_msg = "You can use `as` to change the binding name of the import" ;
4777
+ let rename_msg = "you can use `as` to change the binding name of the import" ;
4787
4778
4788
- if let ( Ok ( snippet) , false ) = ( cm. span_to_snippet ( binding. span ) ,
4789
- binding. is_renamed_extern_crate ( ) ) {
4779
+ if let Ok ( snippet) = cm. span_to_snippet ( binding. span ) {
4790
4780
let suggested_name = if name. as_str ( ) . chars ( ) . next ( ) . unwrap ( ) . is_uppercase ( ) {
4791
4781
format ! ( "Other{}" , name)
4792
4782
} else {
@@ -4796,20 +4786,22 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
4796
4786
err. span_suggestion_with_applicability (
4797
4787
binding. span ,
4798
4788
rename_msg,
4799
- if snippet. contains ( " as " ) {
4800
- format ! (
4801
- "{} as {}" ,
4789
+ match ( snippet. split_whitespace ( ) . find ( |w| * w == "as" ) , snippet. ends_with ( ";" ) ) {
4790
+ ( Some ( _) , false ) => format ! ( "{} as {}" ,
4802
4791
& snippet[ ..snippet. find( " as " ) . unwrap( ) ] ,
4803
4792
suggested_name,
4804
- )
4805
- } else {
4806
- if snippet. ends_with ( ';' ) {
4807
- format ! ( "{} as {};" , & snippet[ ..snippet. len( ) - 1 ] , suggested_name)
4808
- } else {
4809
- format ! ( "{} as {}" , snippet, suggested_name)
4810
- }
4793
+ ) ,
4794
+ ( Some ( _) , true ) => format ! ( "{} as {};" ,
4795
+ & snippet[ ..snippet. find( " as " ) . unwrap( ) ] ,
4796
+ suggested_name,
4797
+ ) ,
4798
+ ( None , false ) => format ! ( "{} as {}" , snippet, suggested_name) ,
4799
+ ( None , true ) => format ! ( "{} as {};" ,
4800
+ & snippet[ ..snippet. len( ) - 1 ] ,
4801
+ suggested_name
4802
+ ) ,
4811
4803
} ,
4812
- Applicability :: MachineApplicable ,
4804
+ Applicability :: MaybeIncorrect ,
4813
4805
) ;
4814
4806
} else {
4815
4807
err. span_label ( binding. span , rename_msg) ;
0 commit comments