@@ -1234,7 +1234,7 @@ impl<'a> NameBinding<'a> {
12341234 match self . kind {
12351235 NameBindingKind :: Import {
12361236 directive : & ImportDirective {
1237- subclass : ImportDirectiveSubclass :: ExternCrate ( _ ) , ..
1237+ subclass : ImportDirectiveSubclass :: ExternCrate { .. } , ..
12381238 } , ..
12391239 } => true ,
12401240 _ => false ,
@@ -3794,7 +3794,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
37943794 if let NameBindingKind :: Import { directive : d, .. } = binding. kind {
37953795 // Careful: we still want to rewrite paths from
37963796 // renamed extern crates.
3797- if let ImportDirectiveSubclass :: ExternCrate ( None ) = d. subclass {
3797+ if let ImportDirectiveSubclass :: ExternCrate { source : None , .. } = d. subclass {
37983798 return
37993799 }
38003800 }
@@ -4776,7 +4776,15 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
47764776 let cm = self . session . source_map ( ) ;
47774777 let rename_msg = "you can use `as` to change the binding name of the import" ;
47784778
4779- if let Ok ( snippet) = cm. span_to_snippet ( binding. span ) {
4779+ if let (
4780+ Ok ( snippet) ,
4781+ NameBindingKind :: Import { directive, ..} ,
4782+ _x @ 1 ... std:: u32:: MAX ,
4783+ ) = (
4784+ cm. span_to_snippet ( binding. span ) ,
4785+ binding. kind . clone ( ) ,
4786+ binding. span . hi ( ) . 0 ,
4787+ ) {
47804788 let suggested_name = if name. as_str ( ) . chars ( ) . next ( ) . unwrap ( ) . is_uppercase ( ) {
47814789 format ! ( "Other{}" , name)
47824790 } else {
@@ -4785,24 +4793,29 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
47854793
47864794 err. span_suggestion_with_applicability (
47874795 binding. span ,
4788- rename_msg,
4789- match (
4790- snippet. split_whitespace ( ) . find ( |w| * w == "as" ) ,
4791- snippet. ends_with ( ";" )
4792- ) {
4793- ( Some ( _) , false ) => format ! ( "{} as {}" ,
4794- & snippet[ ..snippet. find( " as " ) . unwrap( ) ] ,
4795- suggested_name,
4796- ) ,
4797- ( Some ( _) , true ) => format ! ( "{} as {};" ,
4798- & snippet[ ..snippet. find( " as " ) . unwrap( ) ] ,
4799- suggested_name,
4800- ) ,
4801- ( None , false ) => format ! ( "{} as {}" , snippet, suggested_name) ,
4802- ( None , true ) => format ! ( "{} as {};" ,
4803- & snippet[ ..snippet. len( ) - 1 ] ,
4804- suggested_name
4805- ) ,
4796+ & rename_msg,
4797+ match ( & directive. subclass , snippet. ends_with ( ";" ) , snippet. as_ref ( ) ) {
4798+ ( ImportDirectiveSubclass :: SingleImport { .. } , false , "self" ) =>
4799+ format ! ( "self as {}" , suggested_name) ,
4800+ ( ImportDirectiveSubclass :: SingleImport { source, .. } , false , _) =>
4801+ format ! (
4802+ "{} as {}" ,
4803+ & snippet[ ..( ( source. span. hi( ) . 0 - binding. span. lo( ) . 0 ) as usize ) ] ,
4804+ suggested_name,
4805+ ) ,
4806+ ( ImportDirectiveSubclass :: SingleImport { source, .. } , true , _) =>
4807+ format ! (
4808+ "{} as {};" ,
4809+ & snippet[ ..( ( source. span. hi( ) . 0 - binding. span. lo( ) . 0 ) as usize ) ] ,
4810+ suggested_name,
4811+ ) ,
4812+ ( ImportDirectiveSubclass :: ExternCrate { source, target, .. } , _, _) =>
4813+ format ! (
4814+ "extern crate {} as {};" ,
4815+ source. unwrap_or( target. name) ,
4816+ suggested_name,
4817+ ) ,
4818+ ( _, _, _) => unreachable ! ( ) ,
48064819 } ,
48074820 Applicability :: MaybeIncorrect ,
48084821 ) ;
0 commit comments