@@ -1096,7 +1096,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1096
1096
}
1097
1097
}
1098
1098
Scope :: ExternPrelude => {
1099
- suggestions. extend ( this. extern_prelude . iter ( ) . filter_map ( |( ident, _ ) | {
1099
+ suggestions. extend ( this. extern_prelude . keys ( ) . filter_map ( |ident| {
1100
1100
let res = Res :: Def ( DefKind :: Mod , CRATE_DEF_ID . to_def_id ( ) ) ;
1101
1101
filter_fn ( res) . then_some ( TypoSuggestion :: typo_from_ident ( * ident, res) )
1102
1102
} ) ) ;
@@ -1895,9 +1895,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1895
1895
1896
1896
match binding. kind {
1897
1897
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
+ ) ;
1901
1901
sugg_paths. push ( (
1902
1902
path. iter ( )
1903
1903
. cloned ( )
@@ -1937,25 +1937,23 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1937
1937
} ;
1938
1938
err. subdiagnostic ( note) ;
1939
1939
}
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, _) | {
1947
1945
// A single path segment suggestion is wrong. This happens on circular imports.
1948
1946
// `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) ;
1950
1956
}
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 ;
1959
1957
}
1960
1958
1961
1959
err. emit ( ) ;
@@ -1972,11 +1970,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1972
1970
. map ( |ident| ident. name )
1973
1971
. chain (
1974
1972
self . module_map
1975
- . iter ( )
1976
- . filter ( |( _ , module) | {
1973
+ . values ( )
1974
+ . filter ( |module| {
1977
1975
current_module. is_ancestor_of ( * * module) && current_module != * * module
1978
1976
} )
1979
- . flat_map ( |( _ , module) | module. kind . name ( ) ) ,
1977
+ . flat_map ( |module| module. kind . name ( ) ) ,
1980
1978
)
1981
1979
. filter ( |c| !c. to_string ( ) . is_empty ( ) )
1982
1980
. collect :: < Vec < _ > > ( ) ;
0 commit comments