@@ -442,32 +442,38 @@ impl NameDerivation {
442442
443443impl PartialOrd for NameDerivation {
444444 fn partial_cmp ( & self , other : & Self ) -> Option < cmp:: Ordering > {
445+ Some ( self . cmp ( other) )
446+ }
447+ }
448+
449+ impl Ord for NameDerivation {
450+ fn cmp ( & self , other : & Self ) -> cmp:: Ordering {
445451 match ( self , other) {
446- ( NameDerivation :: Def , NameDerivation :: Def ) => Some ( cmp:: Ordering :: Equal ) ,
447- ( NameDerivation :: Def , _) => Some ( cmp:: Ordering :: Greater ) ,
448- ( _, NameDerivation :: Def ) => Some ( cmp:: Ordering :: Less ) ,
452+ ( NameDerivation :: Def , NameDerivation :: Def ) => cmp:: Ordering :: Equal ,
453+ ( NameDerivation :: Def , _) => cmp:: Ordering :: Greater ,
454+ ( _, NameDerivation :: Def ) => cmp:: Ordering :: Less ,
449455
450456 ( NameDerivation :: NamedImported ( _) , NameDerivation :: NamedImported ( _) ) => {
451- Some ( cmp:: Ordering :: Equal )
457+ cmp:: Ordering :: Equal
452458 }
453- ( NameDerivation :: NamedImported ( _) , _) => Some ( cmp:: Ordering :: Greater ) ,
454- ( _, NameDerivation :: NamedImported ( _) ) => Some ( cmp:: Ordering :: Less ) ,
459+ ( NameDerivation :: NamedImported ( _) , _) => cmp:: Ordering :: Greater ,
460+ ( _, NameDerivation :: NamedImported ( _) ) => cmp:: Ordering :: Less ,
455461
456462 ( NameDerivation :: GlobImported ( _) , NameDerivation :: GlobImported ( _) ) => {
457- Some ( cmp:: Ordering :: Equal )
463+ cmp:: Ordering :: Equal
458464 }
459- ( NameDerivation :: GlobImported ( _) , _) => Some ( cmp:: Ordering :: Greater ) ,
460- ( _, NameDerivation :: GlobImported ( _) ) => Some ( cmp:: Ordering :: Less ) ,
465+ ( NameDerivation :: GlobImported ( _) , _) => cmp:: Ordering :: Greater ,
466+ ( _, NameDerivation :: GlobImported ( _) ) => cmp:: Ordering :: Less ,
461467
462- ( NameDerivation :: Lex ( lhs) , NameDerivation :: Lex ( rhs) ) => lhs. partial_cmp ( rhs) ,
463- ( NameDerivation :: Lex ( _) , _) => Some ( cmp:: Ordering :: Greater ) ,
464- ( _, NameDerivation :: Lex ( _) ) => Some ( cmp:: Ordering :: Less ) ,
468+ ( NameDerivation :: Lex ( lhs) , NameDerivation :: Lex ( rhs) ) => lhs. cmp ( rhs) ,
469+ ( NameDerivation :: Lex ( _) , _) => cmp:: Ordering :: Greater ,
470+ ( _, NameDerivation :: Lex ( _) ) => cmp:: Ordering :: Less ,
465471
466- ( NameDerivation :: External , NameDerivation :: External ) => Some ( cmp:: Ordering :: Equal ) ,
467- ( NameDerivation :: External , _) => Some ( cmp:: Ordering :: Greater ) ,
468- ( _, NameDerivation :: External ) => Some ( cmp:: Ordering :: Less ) ,
472+ ( NameDerivation :: External , NameDerivation :: External ) => cmp:: Ordering :: Equal ,
473+ ( NameDerivation :: External , _) => cmp:: Ordering :: Greater ,
474+ ( _, NameDerivation :: External ) => cmp:: Ordering :: Less ,
469475
470- ( NameDerivation :: Prim , NameDerivation :: Prim ) => Some ( cmp:: Ordering :: Equal ) ,
476+ ( NameDerivation :: Prim , NameDerivation :: Prim ) => cmp:: Ordering :: Equal ,
471477 }
472478 }
473479}
@@ -504,6 +510,7 @@ impl<'db, 'a> NameResolver<'db, 'a> {
504510 }
505511
506512 pub ( crate ) fn resolve_query ( & mut self , query : NameQuery ) -> NameResBucket {
513+ let hir_db = self . db . as_hir_db ( ) ;
507514 // If the query is already resolved, return the cached result.
508515 if let Some ( resolved) = self . cache_store . get ( query) {
509516 return resolved. clone ( ) ;
@@ -519,7 +526,7 @@ impl<'db, 'a> NameResolver<'db, 'a> {
519526
520527 // 1. Look for the name in the current scope.
521528 let mut found_scopes = FxHashSet :: default ( ) ;
522- for edge in query. scope . edges ( self . db . as_hir_db ( ) ) {
529+ for edge in query. scope . edges ( hir_db ) {
523530 match edge. kind . propagate ( & query) {
524531 PropagationResult :: Terminated => {
525532 if found_scopes. insert ( edge. dest ) {
@@ -577,16 +584,16 @@ impl<'db, 'a> NameResolver<'db, 'a> {
577584 // 5. Look for the name in the external ingots.
578585 query
579586 . scope
580- . top_mod ( self . db . as_hir_db ( ) )
581- . ingot ( self . db . as_hir_db ( ) )
582- . external_ingots ( self . db . as_hir_db ( ) )
587+ . top_mod ( hir_db )
588+ . ingot ( hir_db )
589+ . external_ingots ( hir_db )
583590 . iter ( )
584- . for_each ( |( name, root_mod ) | {
591+ . for_each ( |( name, ingot ) | {
585592 if * name == query. name {
586593 // We don't care about the result of `push` because we assume ingots are
587594 // guaranteed to be unique.
588595 bucket. push ( & NameRes :: new_from_scope (
589- ScopeId :: from_item ( ( * root_mod) . into ( ) ) ,
596+ ScopeId :: from_item ( ( ingot . root_mod ( hir_db ) ) . into ( ) ) ,
590597 NameDomain :: Type ,
591598 NameDerivation :: External ,
592599 ) )
@@ -735,12 +742,6 @@ impl<'db, 'a> NameResolver<'db, 'a> {
735742 }
736743}
737744
738- impl Ord for NameDerivation {
739- fn cmp ( & self , other : & Self ) -> cmp:: Ordering {
740- self . partial_cmp ( other) . unwrap ( )
741- }
742- }
743-
744745#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
745746pub enum NameResolutionError {
746747 /// The name is not found.
0 commit comments