@@ -608,7 +608,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
608
608
}
609
609
}
610
610
611
- self . throw_unresolved_import_error ( errors, glob_error) ;
611
+ if !errors. is_empty ( ) {
612
+ self . throw_unresolved_import_error ( errors, glob_error) ;
613
+ }
612
614
}
613
615
614
616
pub ( crate ) fn check_hidden_glob_reexports (
@@ -683,38 +685,54 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
683
685
mut errors : Vec < ( Import < ' _ > , UnresolvedImportError ) > ,
684
686
glob_error : bool ,
685
687
) {
688
+ let span_and_message = |errors : & [ ( Import < ' _ > , UnresolvedImportError ) ] | {
689
+ let span = MultiSpan :: from_spans ( errors. iter ( ) . map ( |( _, err) | err. span ) . collect ( ) ) ;
690
+
691
+ let paths = errors
692
+ . iter ( )
693
+ . map ( |( import, err) | {
694
+ let path = import_path_to_string (
695
+ & import. module_path . iter ( ) . map ( |seg| seg. ident ) . collect :: < Vec < _ > > ( ) ,
696
+ & import. kind ,
697
+ err. span ,
698
+ ) ;
699
+ format ! ( "`{path}`" )
700
+ } )
701
+ . collect :: < Vec < _ > > ( ) ;
702
+ let msg = format ! ( "unresolved import{} {}" , pluralize!( paths. len( ) ) , paths. join( ", " ) , ) ;
703
+ ( span, msg)
704
+ } ;
705
+
706
+ let ( span, msg) = span_and_message ( & errors) ;
707
+
686
708
errors. retain ( |( _import, err) | match err. module {
687
709
// Skip `use` errors for `use foo::Bar;` if `foo.rs` has unrecovered parse errors.
688
710
Some ( def_id) if self . mods_with_parse_errors . contains ( & def_id) => false ,
689
- _ => true ,
711
+ // If we've encountered something like `use _;`, we've already emitted an error stating
712
+ // that `_` is not a valid identifier, so we silence the resolve error.
713
+ _ => err. segment != Some ( kw:: Underscore ) ,
690
714
} ) ;
715
+
691
716
if errors. is_empty ( ) {
717
+ struct_span_code_err ! ( self . dcx( ) , span, E0432 , "{msg}" ) . delay_as_bug ( ) ;
692
718
return ;
693
719
}
694
720
695
- /// Upper limit on the number of `span_label` messages.
696
- const MAX_LABEL_COUNT : usize = 10 ;
697
-
698
- let span = MultiSpan :: from_spans ( errors. iter ( ) . map ( |( _, err) | err. span ) . collect ( ) ) ;
699
- let paths = errors
700
- . iter ( )
701
- . map ( |( import, err) | {
702
- let path = import_path_to_string (
703
- & import. module_path . iter ( ) . map ( |seg| seg. ident ) . collect :: < Vec < _ > > ( ) ,
704
- & import. kind ,
705
- err. span ,
706
- ) ;
707
- format ! ( "`{path}`" )
708
- } )
709
- . collect :: < Vec < _ > > ( ) ;
710
- let msg = format ! ( "unresolved import{} {}" , pluralize!( paths. len( ) ) , paths. join( ", " ) , ) ;
721
+ let ( span, msg) = span_and_message ( & errors) ;
711
722
712
723
let mut diag = struct_span_code_err ! ( self . dcx( ) , span, E0432 , "{msg}" ) ;
724
+ if errors. is_empty ( ) {
725
+ diag. delay_as_bug ( ) ;
726
+ return ;
727
+ }
713
728
714
729
if let Some ( ( _, UnresolvedImportError { note : Some ( note) , .. } ) ) = errors. iter ( ) . last ( ) {
715
730
diag. note ( note. clone ( ) ) ;
716
731
}
717
732
733
+ /// Upper limit on the number of `span_label` messages.
734
+ const MAX_LABEL_COUNT : usize = 10 ;
735
+
718
736
for ( import, err) in errors. into_iter ( ) . take ( MAX_LABEL_COUNT ) {
719
737
if let Some ( label) = err. label {
720
738
diag. span_label ( err. span , label) ;
0 commit comments