@@ -672,7 +672,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
672672 } ;
673673
674674 let has_explicit_self =
675- import. module_path . len ( ) > 0 &&
675+ ! import. module_path . is_empty ( ) &&
676676 import. module_path [ 0 ] . name == keywords:: SelfValue . name ( ) ;
677677
678678 self . per_ns ( |_, ns| {
@@ -703,9 +703,8 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
703703 if let SingleImport { source, ref result, .. } = import. subclass {
704704 if source. name == "self" {
705705 // 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 ;
709708 }
710709 }
711710 }
@@ -822,20 +821,19 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
822821 fn throw_unresolved_import_error ( & self , error_vec : Vec < ( Span , String , String ) > ,
823822 span : Option < MultiSpan > ) {
824823 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)
839837 } ;
840838 let mut err = struct_span_err ! ( self . resolver. session, span, E0432 , "{}" , & msg) ;
841839 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> {
10261024 if all_ns_err {
10271025 let mut all_ns_failed = true ;
10281026 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 ;
10321029 }
10331030 } ) ;
10341031
@@ -1247,65 +1244,62 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
12471244 }
12481245 }
12491246
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 ( ) ;
13071302 }
1308- _ => { }
13091303 }
13101304 }
13111305
0 commit comments