@@ -1248,15 +1248,6 @@ impl<'a> NameBinding<'a> {
12481248 }
12491249 }
12501250
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-
12601251 fn is_glob_import ( & self ) -> bool {
12611252 match self . kind {
12621253 NameBindingKind :: Import { directive, .. } => directive. is_glob ( ) ,
@@ -4783,10 +4774,9 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
47834774 } ;
47844775
47854776 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" ;
47874778
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 ) {
47904780 let suggested_name = if name. as_str ( ) . chars ( ) . next ( ) . unwrap ( ) . is_uppercase ( ) {
47914781 format ! ( "Other{}" , name)
47924782 } else {
@@ -4796,20 +4786,22 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
47964786 err. span_suggestion_with_applicability (
47974787 binding. span ,
47984788 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 {}" ,
48024791 & snippet[ ..snippet. find( " as " ) . unwrap( ) ] ,
48034792 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+ ) ,
48114803 } ,
4812- Applicability :: MachineApplicable ,
4804+ Applicability :: MaybeIncorrect ,
48134805 ) ;
48144806 } else {
48154807 err. span_label ( binding. span , rename_msg) ;
0 commit comments