@@ -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 ,
@@ -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 ( ) ,
@@ -3812,7 +3803,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
38123803 if let NameBindingKind :: Import { directive : d, .. } = binding. kind {
38133804 // Careful: we still want to rewrite paths from
38143805 // renamed extern crates.
3815- if let ImportDirectiveSubclass :: ExternCrate ( None ) = d. subclass {
3806+ if let ImportDirectiveSubclass :: ExternCrate { source : None , .. } = d. subclass {
38163807 return
38173808 }
38183809 }
@@ -4782,10 +4773,17 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
47824773 } ;
47834774
47844775 let cm = self . session . source_map ( ) ;
4785- let rename_msg = "You can use `as` to change the binding name of the import" ;
4786-
4787- if let ( Ok ( snippet) , false ) = ( cm. span_to_snippet ( binding. span ) ,
4788- binding. is_renamed_extern_crate ( ) ) {
4776+ let rename_msg = "you can use `as` to change the binding name of the import" ;
4777+
4778+ if let (
4779+ Ok ( snippet) ,
4780+ NameBindingKind :: Import { directive, ..} ,
4781+ _dummy @ false ,
4782+ ) = (
4783+ cm. span_to_snippet ( binding. span ) ,
4784+ binding. kind . clone ( ) ,
4785+ binding. span . is_dummy ( ) ,
4786+ ) {
47894787 let suggested_name = if name. as_str ( ) . chars ( ) . next ( ) . unwrap ( ) . is_uppercase ( ) {
47904788 format ! ( "Other{}" , name)
47914789 } else {
@@ -4794,13 +4792,30 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
47944792
47954793 err. span_suggestion_with_applicability (
47964794 binding. span ,
4797- rename_msg,
4798- if snippet. ends_with ( ';' ) {
4799- format ! ( "{} as {};" , & snippet[ ..snippet. len( ) - 1 ] , suggested_name)
4800- } else {
4801- format ! ( "{} as {}" , snippet, suggested_name)
4795+ & rename_msg,
4796+ match ( & directive. subclass , snippet. as_ref ( ) ) {
4797+ ( ImportDirectiveSubclass :: SingleImport { .. } , "self" ) =>
4798+ format ! ( "self as {}" , suggested_name) ,
4799+ ( ImportDirectiveSubclass :: SingleImport { source, .. } , _) =>
4800+ format ! (
4801+ "{} as {}{}" ,
4802+ & snippet[ ..( ( source. span. hi( ) . 0 - binding. span. lo( ) . 0 ) as usize ) ] ,
4803+ suggested_name,
4804+ if snippet. ends_with( ";" ) {
4805+ ";"
4806+ } else {
4807+ ""
4808+ }
4809+ ) ,
4810+ ( ImportDirectiveSubclass :: ExternCrate { source, target, .. } , _) =>
4811+ format ! (
4812+ "extern crate {} as {};" ,
4813+ source. unwrap_or( target. name) ,
4814+ suggested_name,
4815+ ) ,
4816+ ( _, _) => unreachable ! ( ) ,
48024817 } ,
4803- Applicability :: MachineApplicable ,
4818+ Applicability :: MaybeIncorrect ,
48044819 ) ;
48054820 } else {
48064821 err. span_label ( binding. span , rename_msg) ;
0 commit comments