@@ -1096,7 +1096,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10961096 }
10971097 }
10981098 Scope :: ExternPrelude => {
1099- suggestions. extend ( this. extern_prelude . iter ( ) . filter_map ( |( ident, _ ) | {
1099+ suggestions. extend ( this. extern_prelude . keys ( ) . filter_map ( |ident| {
11001100 let res = Res :: Def ( DefKind :: Mod , CRATE_DEF_ID . to_def_id ( ) ) ;
11011101 filter_fn ( res) . then_some ( TypoSuggestion :: typo_from_ident ( * ident, res) )
11021102 } ) ) ;
@@ -1895,9 +1895,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
18951895
18961896 match binding. kind {
18971897 NameBindingKind :: Import { import, .. } => {
1898- for segment in import . module_path . iter ( ) . skip ( 1 ) {
1899- path . push ( segment. ident . to_string ( ) ) ;
1900- }
1898+ path . extend (
1899+ import . module_path . iter ( ) . skip ( 1 ) . map ( | segment| segment . ident . to_string ( ) ) ,
1900+ ) ;
19011901 sugg_paths. push ( (
19021902 path. iter ( )
19031903 . cloned ( )
@@ -1937,25 +1937,23 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
19371937 } ;
19381938 err. subdiagnostic ( note) ;
19391939 }
1940- // We prioritize shorter paths, non-core imports and direct imports over the alternatives.
1941- sugg_paths. sort_by_key ( |( p, reexport) | ( p. len ( ) , p[ 0 ] == "core" , * reexport) ) ;
1942- for ( sugg, reexport) in sugg_paths {
1943- if not_publicly_reexported {
1944- break ;
1945- }
1946- if sugg. len ( ) <= 1 {
1940+ if !not_publicly_reexported {
1941+ // We prioritize shorter paths, non-core imports and direct imports over the alternatives.
1942+ sugg_paths. sort_by_key ( |( p, reexport) | ( p. len ( ) , p[ 0 ] == "core" , * reexport) ) ;
1943+
1944+ if let Some ( ( sugg, reexport) ) = sugg_paths. into_iter ( ) . find ( |( sugg, _) | {
19471945 // A single path segment suggestion is wrong. This happens on circular imports.
19481946 // `tests/ui/imports/issue-55884-2.rs`
1949- continue ;
1947+ sugg. len ( ) > 1
1948+ } ) {
1949+ let path = sugg. join ( "::" ) ;
1950+ let sugg = if reexport {
1951+ errors:: ImportIdent :: ThroughReExport { span : dedup_span, ident, path }
1952+ } else {
1953+ errors:: ImportIdent :: Directly { span : dedup_span, ident, path }
1954+ } ;
1955+ err. subdiagnostic ( sugg) ;
19501956 }
1951- let path = sugg. join ( "::" ) ;
1952- let sugg = if reexport {
1953- errors:: ImportIdent :: ThroughReExport { span : dedup_span, ident, path }
1954- } else {
1955- errors:: ImportIdent :: Directly { span : dedup_span, ident, path }
1956- } ;
1957- err. subdiagnostic ( sugg) ;
1958- break ;
19591957 }
19601958
19611959 err. emit ( ) ;
@@ -1972,11 +1970,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
19721970 . map ( |ident| ident. name )
19731971 . chain (
19741972 self . module_map
1975- . iter ( )
1976- . filter ( |( _ , module) | {
1973+ . values ( )
1974+ . filter ( |module| {
19771975 current_module. is_ancestor_of ( * * module) && current_module != * * module
19781976 } )
1979- . flat_map ( |( _ , module) | module. kind . name ( ) ) ,
1977+ . flat_map ( |module| module. kind . name ( ) ) ,
19801978 )
19811979 . filter ( |c| !c. to_string ( ) . is_empty ( ) )
19821980 . collect :: < Vec < _ > > ( ) ;
0 commit comments