@@ -127,8 +127,11 @@ impl PartialResolvedImport {
127
127
}
128
128
129
129
#[ 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 ,
132
135
}
133
136
134
137
#[ derive( Debug , Eq , PartialEq ) ]
@@ -154,7 +157,7 @@ impl Import {
154
157
path,
155
158
alias,
156
159
visibility : visibility. clone ( ) ,
157
- source : ImportSource :: Use { use_tree : idx, id, is_prelude, kind } ,
160
+ source : ImportSource { use_tree : idx, id, is_prelude, kind } ,
158
161
} ) ;
159
162
} ) ;
160
163
}
@@ -780,35 +783,31 @@ impl DefCollector<'_> {
780
783
let _p = tracing:: info_span!( "resolve_import" , import_path = %import. path. display( self . db. upcast( ) , Edition :: LATEST ) )
781
784
. entered ( ) ;
782
785
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
+ ) ;
793
794
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
+ }
798
799
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
+ }
804
805
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)
812
811
}
813
812
}
814
813
@@ -824,7 +823,12 @@ impl DefCollector<'_> {
824
823
. unwrap_or ( Visibility :: Public ) ;
825
824
826
825
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
+ } => {
828
832
let name = match & import. alias {
829
833
Some ( ImportAlias :: Alias ( name) ) => Some ( name) ,
830
834
Some ( ImportAlias :: Underscore ) => None ,
@@ -837,24 +841,20 @@ impl DefCollector<'_> {
837
841
} ,
838
842
} ;
839
843
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 } ) ;
849
849
tracing:: debug!( "resolved import {:?} ({:?}) to {:?}" , name, import, def) ;
850
850
851
851
self . update ( module_id, & [ ( name. cloned ( ) , def) ] , vis, Some ( imp) ) ;
852
852
}
853
- ImportSource :: Use { kind : ImportKind :: Glob , id, .. } => {
853
+ ImportSource { kind : ImportKind :: Glob , id, is_prelude , .. } => {
854
854
tracing:: debug!( "glob import: {:?}" , import) ;
855
855
match def. take_types ( ) {
856
856
Some ( ModuleDefId :: ModuleId ( m) ) => {
857
- if let ImportSource :: Use { id , is_prelude : true , .. } = import . source {
857
+ if is_prelude {
858
858
// Note: This dodgily overrides the injected prelude. The rustc
859
859
// implementation seems to work the same though.
860
860
cov_mark:: hit!( std_prelude) ;
@@ -1509,18 +1509,26 @@ impl DefCollector<'_> {
1509
1509
}
1510
1510
1511
1511
// 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;
1515
1523
if matches ! (
1516
- ( directive . import . path. segments( ) . first( ) , & directive . import . path. kind) ,
1524
+ ( path. segments( ) . first( ) , & path. kind) ,
1517
1525
( Some ( krate) , PathKind :: Plain | PathKind :: Abs ) if self . unresolved_extern_crates. contains( krate)
1518
1526
) {
1519
1527
continue ;
1520
1528
}
1521
1529
let item_tree_id = id. lookup ( self . db ) . id ;
1522
1530
self . def_map . diagnostics . push ( DefDiagnostic :: unresolved_import (
1523
- directive . module_id ,
1531
+ module_id,
1524
1532
item_tree_id,
1525
1533
use_tree,
1526
1534
) ) ;
0 commit comments