@@ -1234,7 +1234,7 @@ impl<'a> NameBinding<'a> {
1234
1234
match self . kind {
1235
1235
NameBindingKind :: Import {
1236
1236
directive : & ImportDirective {
1237
- subclass : ImportDirectiveSubclass :: ExternCrate ( _ ) , ..
1237
+ subclass : ImportDirectiveSubclass :: ExternCrate { .. } , ..
1238
1238
} , ..
1239
1239
} => true ,
1240
1240
_ => false ,
@@ -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 ( ) ,
@@ -3812,7 +3803,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
3812
3803
if let NameBindingKind :: Import { directive : d, .. } = binding. kind {
3813
3804
// Careful: we still want to rewrite paths from
3814
3805
// renamed extern crates.
3815
- if let ImportDirectiveSubclass :: ExternCrate ( None ) = d. subclass {
3806
+ if let ImportDirectiveSubclass :: ExternCrate { source : None , .. } = d. subclass {
3816
3807
return
3817
3808
}
3818
3809
}
@@ -4782,10 +4773,17 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
4782
4773
} ;
4783
4774
4784
4775
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
+ ) {
4789
4787
let suggested_name = if name. as_str ( ) . chars ( ) . next ( ) . unwrap ( ) . is_uppercase ( ) {
4790
4788
format ! ( "Other{}" , name)
4791
4789
} else {
@@ -4794,13 +4792,30 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
4794
4792
4795
4793
err. span_suggestion_with_applicability (
4796
4794
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 ! ( ) ,
4802
4817
} ,
4803
- Applicability :: MachineApplicable ,
4818
+ Applicability :: MaybeIncorrect ,
4804
4819
) ;
4805
4820
} else {
4806
4821
err. span_label ( binding. span , rename_msg) ;
0 commit comments