@@ -617,14 +617,12 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
617617 _ => format ! ( "{}" , ident) ,
618618 } ;
619619
620- // Assume this is the easy case of `use issue_59764::foo::makro;` and just remove
621- // intermediate segments.
622- let ( mut span, mut correction) = ( directive. span ,
623- format ! ( "{}::{}" , module_name, import) ) ;
624-
625- if directive. is_nested ( ) {
626- span = directive. use_span ;
627-
620+ let mut corrections: Vec < ( Span , String ) > = Vec :: new ( ) ;
621+ if !directive. is_nested ( ) {
622+ // Assume this is the easy case of `use issue_59764::foo::makro;` and just remove
623+ // intermediate segments.
624+ corrections. push ( ( directive. span , format ! ( "{}::{}" , module_name, import) ) ) ;
625+ } else {
628626 // Find the binding span (and any trailing commas and spaces).
629627 // ie. `use a::b::{c, d, e};`
630628 // ^^^
@@ -652,6 +650,9 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
652650 }
653651 debug ! ( "check_for_module_export_macro: removal_span={:?}" , removal_span) ;
654652
653+ // Remove the `removal_span`.
654+ corrections. push ( ( removal_span, "" . to_string ( ) ) ) ;
655+
655656 // Find the span after the crate name and if it has nested imports immediatately
656657 // after the crate name already.
657658 // ie. `use a::b::{c, d};`
@@ -666,34 +667,32 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
666667
667668 let source_map = self . resolver . session . source_map ( ) ;
668669
669- // Remove two bytes at the end to keep all but the `};` characters.
670- // ie. `{b::{c, d}, e::{f, g}};`
671- // ^^^^^^^^^^^^^^^^^^^^^
672- let end_bytes = BytePos ( if has_nested { 2 } else { 1 } ) ;
673- let mut remaining_span = after_crate_name. with_hi (
674- after_crate_name. hi ( ) - end_bytes) ;
675- if has_nested {
676- // Remove two bytes at the start to keep all but the initial `{` character.
677- // ie. `{b::{c, d}, e::{f, g}`
678- // ^^^^^^^^^^^^^^^^^^^^
679- remaining_span = remaining_span. with_lo ( after_crate_name. lo ( ) + BytePos ( 1 ) ) ;
670+ // Add the import to the start, with a `{` if required.
671+ let start_point = source_map. start_point ( after_crate_name) ;
672+ if let Ok ( start_snippet) = source_map. span_to_snippet ( start_point) {
673+ corrections. push ( (
674+ start_point,
675+ if has_nested {
676+ // In this case, `start_snippet` must equal '{'.
677+ format ! ( "{}{}, " , start_snippet, import)
678+ } else {
679+ // In this case, add a `{`, then the moved import, then whatever
680+ // was there before.
681+ format ! ( "{{{}, {}" , import, start_snippet)
682+ }
683+ ) ) ;
680684 }
681685
682- // Calculate the number of characters into a snippet to remove the removal
683- // span.
684- let lo = removal_span. lo ( ) - remaining_span. lo ( ) ;
685- let hi = lo + ( removal_span. hi ( ) - removal_span. lo ( ) ) ;
686- if let Ok ( mut remaining) = source_map. span_to_snippet ( remaining_span) {
687- // Remove the original location of the binding.
688- remaining. replace_range ( ( lo. 0 as usize ) ..( hi. 0 as usize ) , "" ) ;
689- correction = format ! ( "use {}::{{{}, {}}};" , module_name, import, remaining) ;
686+ // Add a `};` to the end if nested, matching the `{` added at the start.
687+ if !has_nested {
688+ corrections. push ( ( source_map. end_point ( after_crate_name) ,
689+ "};" . to_string ( ) ) ) ;
690690 }
691691 }
692692
693693 let suggestion = Some ( (
694- span ,
694+ corrections ,
695695 String :: from ( "a macro with this name exists at the root of the crate" ) ,
696- correction,
697696 Applicability :: MaybeIncorrect ,
698697 ) ) ;
699698 let note = vec ! [
0 commit comments