@@ -127,8 +127,11 @@ impl PartialResolvedImport {
127127}
128128
129129#[ derive( Clone , Debug , Eq , PartialEq ) ]
130- enum ImportSource {
131- Use { use_tree : Idx < ast:: UseTree > , id : UseId , is_prelude : bool , kind : ImportKind } ,
130+ struct ImportSource {
131+ use_tree : Idx < ast:: UseTree > ,
132+ id : UseId ,
133+ is_prelude : bool ,
134+ kind : ImportKind ,
132135}
133136
134137#[ derive( Debug , Eq , PartialEq ) ]
@@ -154,7 +157,7 @@ impl Import {
154157 path,
155158 alias,
156159 visibility : visibility. clone ( ) ,
157- source : ImportSource :: Use { use_tree : idx, id, is_prelude, kind } ,
160+ source : ImportSource { use_tree : idx, id, is_prelude, kind } ,
158161 } ) ;
159162 } ) ;
160163 }
@@ -780,35 +783,31 @@ impl DefCollector<'_> {
780783 let _p = tracing:: info_span!( "resolve_import" , import_path = %import. path. display( self . db. upcast( ) , Edition :: LATEST ) )
781784 . entered ( ) ;
782785 tracing:: debug!( "resolving import: {:?} ({:?})" , import, self . def_map. data. edition) ;
783- match import. source {
784- ImportSource :: Use { .. } => {
785- let res = self . def_map . resolve_path_fp_with_macro (
786- self . db ,
787- ResolveMode :: Import ,
788- module_id,
789- & import. path ,
790- BuiltinShadowMode :: Module ,
791- None , // An import may resolve to any kind of macro.
792- ) ;
786+ let res = self . def_map . resolve_path_fp_with_macro (
787+ self . db ,
788+ ResolveMode :: Import ,
789+ module_id,
790+ & import. path ,
791+ BuiltinShadowMode :: Module ,
792+ None , // An import may resolve to any kind of macro.
793+ ) ;
793794
794- let def = res. resolved_def ;
795- if res. reached_fixedpoint == ReachedFixedPoint :: No || def. is_none ( ) {
796- return PartialResolvedImport :: Unresolved ;
797- }
795+ let def = res. resolved_def ;
796+ if res. reached_fixedpoint == ReachedFixedPoint :: No || def. is_none ( ) {
797+ return PartialResolvedImport :: Unresolved ;
798+ }
798799
799- if res. from_differing_crate {
800- return PartialResolvedImport :: Resolved (
801- def. filter_visibility ( |v| matches ! ( v, Visibility :: Public ) ) ,
802- ) ;
803- }
800+ if res. from_differing_crate {
801+ return PartialResolvedImport :: Resolved (
802+ def. filter_visibility ( |v| matches ! ( v, Visibility :: Public ) ) ,
803+ ) ;
804+ }
804805
805- // Check whether all namespaces are resolved.
806- if def. is_full ( ) {
807- PartialResolvedImport :: Resolved ( def)
808- } else {
809- PartialResolvedImport :: Indeterminate ( def)
810- }
811- }
806+ // Check whether all namespaces are resolved.
807+ if def. is_full ( ) {
808+ PartialResolvedImport :: Resolved ( def)
809+ } else {
810+ PartialResolvedImport :: Indeterminate ( def)
812811 }
813812 }
814813
@@ -824,7 +823,12 @@ impl DefCollector<'_> {
824823 . unwrap_or ( Visibility :: Public ) ;
825824
826825 match import. source {
827- ImportSource :: Use { kind : ImportKind :: Plain | ImportKind :: TypeOnly , .. } => {
826+ ImportSource {
827+ kind : kind @ ( ImportKind :: Plain | ImportKind :: TypeOnly ) ,
828+ id,
829+ use_tree,
830+ ..
831+ } => {
828832 let name = match & import. alias {
829833 Some ( ImportAlias :: Alias ( name) ) => Some ( name) ,
830834 Some ( ImportAlias :: Underscore ) => None ,
@@ -837,24 +841,20 @@ impl DefCollector<'_> {
837841 } ,
838842 } ;
839843
840- let imp = match import. source {
841- ImportSource :: Use { kind, id, use_tree, .. } => {
842- if kind == ImportKind :: TypeOnly {
843- def. values = None ;
844- def. macros = None ;
845- }
846- ImportType :: Import ( ImportId { import : id, idx : use_tree } )
847- }
848- } ;
844+ if kind == ImportKind :: TypeOnly {
845+ def. values = None ;
846+ def. macros = None ;
847+ }
848+ let imp = ImportType :: Import ( ImportId { import : id, idx : use_tree } ) ;
849849 tracing:: debug!( "resolved import {:?} ({:?}) to {:?}" , name, import, def) ;
850850
851851 self . update ( module_id, & [ ( name. cloned ( ) , def) ] , vis, Some ( imp) ) ;
852852 }
853- ImportSource :: Use { kind : ImportKind :: Glob , id, .. } => {
853+ ImportSource { kind : ImportKind :: Glob , id, is_prelude , .. } => {
854854 tracing:: debug!( "glob import: {:?}" , import) ;
855855 match def. take_types ( ) {
856856 Some ( ModuleDefId :: ModuleId ( m) ) => {
857- if let ImportSource :: Use { id , is_prelude : true , .. } = import . source {
857+ if is_prelude {
858858 // Note: This dodgily overrides the injected prelude. The rustc
859859 // implementation seems to work the same though.
860860 cov_mark:: hit!( std_prelude) ;
@@ -1509,18 +1509,26 @@ impl DefCollector<'_> {
15091509 }
15101510
15111511 // Emit diagnostics for all remaining unresolved imports.
1512- for directive in & self . unresolved_imports {
1513- let ImportSource :: Use { use_tree, id, is_prelude : _, kind : _ } =
1514- directive. import . source ;
1512+ for import in & self . unresolved_imports {
1513+ let & ImportDirective {
1514+ module_id,
1515+ import :
1516+ Import {
1517+ ref path,
1518+ source : ImportSource { use_tree, id, is_prelude : _, kind : _ } ,
1519+ ..
1520+ } ,
1521+ ..
1522+ } = import;
15151523 if matches ! (
1516- ( directive . import . path. segments( ) . first( ) , & directive . import . path. kind) ,
1524+ ( path. segments( ) . first( ) , & path. kind) ,
15171525 ( Some ( krate) , PathKind :: Plain | PathKind :: Abs ) if self . unresolved_extern_crates. contains( krate)
15181526 ) {
15191527 continue ;
15201528 }
15211529 let item_tree_id = id. lookup ( self . db ) . id ;
15221530 self . def_map . diagnostics . push ( DefDiagnostic :: unresolved_import (
1523- directive . module_id ,
1531+ module_id,
15241532 item_tree_id,
15251533 use_tree,
15261534 ) ) ;
0 commit comments