@@ -672,7 +672,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
672
672
} ;
673
673
674
674
let has_explicit_self =
675
- import. module_path . len ( ) > 0 &&
675
+ ! import. module_path . is_empty ( ) &&
676
676
import. module_path [ 0 ] . name == keywords:: SelfValue . name ( ) ;
677
677
678
678
self . per_ns ( |_, ns| {
@@ -703,9 +703,8 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
703
703
if let SingleImport { source, ref result, .. } = import. subclass {
704
704
if source. name == "self" {
705
705
// Silence `unresolved import` error if E0429 is already emitted
706
- match result. value_ns . get ( ) {
707
- Err ( Determined ) => continue ,
708
- _ => { } ,
706
+ if let Err ( Determined ) = result. value_ns . get ( ) {
707
+ continue ;
709
708
}
710
709
}
711
710
}
@@ -822,20 +821,19 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
822
821
fn throw_unresolved_import_error ( & self , error_vec : Vec < ( Span , String , String ) > ,
823
822
span : Option < MultiSpan > ) {
824
823
let max_span_label_msg_count = 10 ; // upper limit on number of span_label message.
825
- let ( span, msg) = match error_vec. is_empty ( ) {
826
- true => ( span. unwrap ( ) , "unresolved import" . to_string ( ) ) ,
827
- false => {
828
- let span = MultiSpan :: from_spans ( error_vec. clone ( ) . into_iter ( )
829
- . map ( |elem : ( Span , String , String ) | { elem. 0 }
830
- ) . collect ( ) ) ;
831
- let path_vec: Vec < String > = error_vec. clone ( ) . into_iter ( )
832
- . map ( |elem : ( Span , String , String ) | { format ! ( "`{}`" , elem. 1 ) }
833
- ) . collect ( ) ;
834
- let path = path_vec. join ( ", " ) ;
835
- let msg = format ! ( "unresolved import{} {}" ,
836
- if path_vec. len( ) > 1 { "s" } else { "" } , path) ;
837
- ( span, msg)
838
- }
824
+ let ( span, msg) = if error_vec. is_empty ( ) {
825
+ ( span. unwrap ( ) , "unresolved import" . to_string ( ) )
826
+ } else {
827
+ let span = MultiSpan :: from_spans ( error_vec. clone ( ) . into_iter ( )
828
+ . map ( |elem : ( Span , String , String ) | { elem. 0 } )
829
+ . collect ( ) ) ;
830
+ let path_vec: Vec < String > = error_vec. clone ( ) . into_iter ( )
831
+ . map ( |elem : ( Span , String , String ) | { format ! ( "`{}`" , elem. 1 ) } )
832
+ . collect ( ) ;
833
+ let path = path_vec. join ( ", " ) ;
834
+ let msg = format ! ( "unresolved import{} {}" ,
835
+ if path_vec. len( ) > 1 { "s" } else { "" } , path) ;
836
+ ( span, msg)
839
837
} ;
840
838
let mut err = struct_span_err ! ( self . resolver. session, span, E0432 , "{}" , & msg) ;
841
839
for span_error in error_vec. into_iter ( ) . take ( max_span_label_msg_count) {
@@ -1026,9 +1024,8 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
1026
1024
if all_ns_err {
1027
1025
let mut all_ns_failed = true ;
1028
1026
self . per_ns ( |this, ns| if !type_ns_only || ns == TypeNS {
1029
- match this. resolve_ident_in_module ( module, ident, ns, record_used, span) {
1030
- Ok ( _) => all_ns_failed = false ,
1031
- _ => { }
1027
+ if this. resolve_ident_in_module ( module, ident, ns, record_used, span) . is_ok ( ) {
1028
+ all_ns_failed = false ;
1032
1029
}
1033
1030
} ) ;
1034
1031
@@ -1247,65 +1244,62 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
1247
1244
}
1248
1245
}
1249
1246
1250
- match binding. kind {
1251
- NameBindingKind :: Import { binding : orig_binding, directive, .. } => {
1252
- if ns == TypeNS && orig_binding. is_variant ( ) &&
1253
- !orig_binding. vis . is_at_least ( binding. vis , & * self ) {
1254
- let msg = match directive. subclass {
1255
- ImportDirectiveSubclass :: SingleImport { .. } => {
1256
- format ! ( "variant `{}` is private and cannot be re-exported" ,
1257
- ident)
1258
- } ,
1259
- ImportDirectiveSubclass :: GlobImport { .. } => {
1260
- let msg = "enum is private and its variants \
1261
- cannot be re-exported". to_owned ( ) ;
1262
- let error_id = ( DiagnosticMessageId :: ErrorId ( 0 ) , // no code?!
1263
- Some ( binding. span ) ,
1264
- msg. clone ( ) ) ;
1265
- let fresh = self . session . one_time_diagnostics
1266
- . borrow_mut ( ) . insert ( error_id) ;
1267
- if !fresh {
1268
- continue ;
1269
- }
1270
- msg
1271
- } ,
1272
- ref s @ _ => bug ! ( "unexpected import subclass {:?}" , s)
1273
- } ;
1274
- let mut err = self . session . struct_span_err ( binding. span , & msg) ;
1275
-
1276
- let imported_module = match directive. imported_module . get ( ) {
1277
- Some ( ModuleOrUniformRoot :: Module ( module) ) => module,
1278
- _ => bug ! ( "module should exist" ) ,
1279
- } ;
1280
- let resolutions = imported_module. parent . expect ( "parent should exist" )
1281
- . resolutions . borrow ( ) ;
1282
- let enum_path_segment_index = directive. module_path . len ( ) - 1 ;
1283
- let enum_ident = directive. module_path [ enum_path_segment_index] ;
1284
-
1285
- let enum_resolution = resolutions. get ( & ( enum_ident, TypeNS ) )
1286
- . expect ( "resolution should exist" ) ;
1287
- let enum_span = enum_resolution. borrow ( )
1288
- . binding . expect ( "binding should exist" )
1289
- . span ;
1290
- let enum_def_span = self . session . source_map ( ) . def_span ( enum_span) ;
1291
- let enum_def_snippet = self . session . source_map ( )
1292
- . span_to_snippet ( enum_def_span) . expect ( "snippet should exist" ) ;
1293
- // potentially need to strip extant `crate`/`pub(path)` for suggestion
1294
- let after_vis_index = enum_def_snippet. find ( "enum" )
1295
- . expect ( "`enum` keyword should exist in snippet" ) ;
1296
- let suggestion = format ! ( "pub {}" ,
1297
- & enum_def_snippet[ after_vis_index..] ) ;
1298
-
1299
- self . session
1300
- . diag_span_suggestion_once ( & mut err,
1301
- DiagnosticMessageId :: ErrorId ( 0 ) ,
1302
- enum_def_span,
1303
- "consider making the enum public" ,
1304
- suggestion) ;
1305
- err. emit ( ) ;
1306
- }
1247
+ if let NameBindingKind :: Import { binding : orig_binding, directive, .. } = binding. kind {
1248
+ if ns == TypeNS && orig_binding. is_variant ( ) &&
1249
+ !orig_binding. vis . is_at_least ( binding. vis , & * self ) {
1250
+ let msg = match directive. subclass {
1251
+ ImportDirectiveSubclass :: SingleImport { .. } => {
1252
+ format ! ( "variant `{}` is private and cannot be re-exported" ,
1253
+ ident)
1254
+ } ,
1255
+ ImportDirectiveSubclass :: GlobImport { .. } => {
1256
+ let msg = "enum is private and its variants \
1257
+ cannot be re-exported". to_owned ( ) ;
1258
+ let error_id = ( DiagnosticMessageId :: ErrorId ( 0 ) , // no code?!
1259
+ Some ( binding. span ) ,
1260
+ msg. clone ( ) ) ;
1261
+ let fresh = self . session . one_time_diagnostics
1262
+ . borrow_mut ( ) . insert ( error_id) ;
1263
+ if !fresh {
1264
+ continue ;
1265
+ }
1266
+ msg
1267
+ } ,
1268
+ ref s @ _ => bug ! ( "unexpected import subclass {:?}" , s)
1269
+ } ;
1270
+ let mut err = self . session . struct_span_err ( binding. span , & msg) ;
1271
+
1272
+ let imported_module = match directive. imported_module . get ( ) {
1273
+ Some ( ModuleOrUniformRoot :: Module ( module) ) => module,
1274
+ _ => bug ! ( "module should exist" ) ,
1275
+ } ;
1276
+ let resolutions = imported_module. parent . expect ( "parent should exist" )
1277
+ . resolutions . borrow ( ) ;
1278
+ let enum_path_segment_index = directive. module_path . len ( ) - 1 ;
1279
+ let enum_ident = directive. module_path [ enum_path_segment_index] ;
1280
+
1281
+ let enum_resolution = resolutions. get ( & ( enum_ident, TypeNS ) )
1282
+ . expect ( "resolution should exist" ) ;
1283
+ let enum_span = enum_resolution. borrow ( )
1284
+ . binding . expect ( "binding should exist" )
1285
+ . span ;
1286
+ let enum_def_span = self . session . source_map ( ) . def_span ( enum_span) ;
1287
+ let enum_def_snippet = self . session . source_map ( )
1288
+ . span_to_snippet ( enum_def_span) . expect ( "snippet should exist" ) ;
1289
+ // potentially need to strip extant `crate`/`pub(path)` for suggestion
1290
+ let after_vis_index = enum_def_snippet. find ( "enum" )
1291
+ . expect ( "`enum` keyword should exist in snippet" ) ;
1292
+ let suggestion = format ! ( "pub {}" ,
1293
+ & enum_def_snippet[ after_vis_index..] ) ;
1294
+
1295
+ self . session
1296
+ . diag_span_suggestion_once ( & mut err,
1297
+ DiagnosticMessageId :: ErrorId ( 0 ) ,
1298
+ enum_def_span,
1299
+ "consider making the enum public" ,
1300
+ suggestion) ;
1301
+ err. emit ( ) ;
1307
1302
}
1308
- _ => { }
1309
1303
}
1310
1304
}
1311
1305
0 commit comments