@@ -43,6 +43,10 @@ impl AstIds {
4343 fn use_id ( & self , key : impl Into < ExpressionNodeKey > ) -> ScopedUseId {
4444 self . uses_map [ & key. into ( ) ]
4545 }
46+
47+ fn try_use_id ( & self , key : impl Into < ExpressionNodeKey > ) -> Option < ScopedUseId > {
48+ self . uses_map . get ( & key. into ( ) ) . copied ( )
49+ }
4650}
4751
4852fn ast_ids < ' db > ( db : & ' db dyn Db , scope : ScopeId ) -> & ' db AstIds {
@@ -56,27 +60,43 @@ pub struct ScopedUseId;
5660pub trait HasScopedUseId {
5761 /// Returns the ID that uniquely identifies the use in `scope`.
5862 fn scoped_use_id ( & self , db : & dyn Db , scope : ScopeId ) -> ScopedUseId ;
63+ fn try_scoped_use_id ( & self , db : & dyn Db , scope : ScopeId ) -> Option < ScopedUseId > ;
5964}
6065
6166impl HasScopedUseId for ast:: Identifier {
6267 fn scoped_use_id ( & self , db : & dyn Db , scope : ScopeId ) -> ScopedUseId {
6368 let ast_ids = ast_ids ( db, scope) ;
6469 ast_ids. use_id ( self )
6570 }
71+
72+ fn try_scoped_use_id ( & self , db : & dyn Db , scope : ScopeId ) -> Option < ScopedUseId > {
73+ let ast_ids = ast_ids ( db, scope) ;
74+ ast_ids. try_use_id ( self )
75+ }
6676}
6777
6878impl HasScopedUseId for ast:: ExprName {
6979 fn scoped_use_id ( & self , db : & dyn Db , scope : ScopeId ) -> ScopedUseId {
7080 let expression_ref = ExprRef :: from ( self ) ;
7181 expression_ref. scoped_use_id ( db, scope)
7282 }
83+
84+ fn try_scoped_use_id ( & self , db : & dyn Db , scope : ScopeId ) -> Option < ScopedUseId > {
85+ let expression_ref = ExprRef :: from ( self ) ;
86+ expression_ref. try_scoped_use_id ( db, scope)
87+ }
7388}
7489
7590impl HasScopedUseId for ast:: ExprRef < ' _ > {
7691 fn scoped_use_id ( & self , db : & dyn Db , scope : ScopeId ) -> ScopedUseId {
7792 let ast_ids = ast_ids ( db, scope) ;
7893 ast_ids. use_id ( * self )
7994 }
95+
96+ fn try_scoped_use_id ( & self , db : & dyn Db , scope : ScopeId ) -> Option < ScopedUseId > {
97+ let ast_ids = ast_ids ( db, scope) ;
98+ ast_ids. try_use_id ( * self )
99+ }
80100}
81101
82102/// Uniquely identifies an [`ast::Expr`] in a [`crate::semantic_index::symbol::FileScopeId`].
0 commit comments