@@ -4858,16 +4858,16 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
48584858 let db = self . db ( ) ;
48594859 let scope = self . scope ( ) ;
48604860 let file_scope_id = scope. file_scope_id ( db) ;
4861- let current_file = self . file ( ) ;
4861+
48624862 ' names: for name in names {
48634863 // Walk up parent scopes looking for a possible enclosing scope that may have a
48644864 // definition of this name visible to us. Note that we skip the scope containing the
48654865 // use that we are resolving, since we already looked for the place there up above.
48664866 for ( enclosing_scope_file_id, _) in self . index . ancestor_scopes ( file_scope_id) . skip ( 1 ) {
48674867 // Class scopes are not visible to nested scopes, and `nonlocal` cannot refer to
48684868 // globals, so check only function-like scopes.
4869- let enclosing_scope_id = enclosing_scope_file_id . to_scope_id ( db , current_file ) ;
4870- if !enclosing_scope_id . is_function_like ( db ) {
4869+ let enclosing_scope = self . index . scope ( enclosing_scope_file_id ) ;
4870+ if !enclosing_scope . kind ( ) . is_function_like ( ) {
48714871 continue ;
48724872 }
48734873 let enclosing_place_table = self . index . place_table ( enclosing_scope_file_id) ;
@@ -6348,7 +6348,6 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
63486348 }
63496349
63506350 let place = PlaceAndQualifiers :: from ( local_scope_place) . or_fall_back_to ( db, || {
6351- let current_file = self . file ( ) ;
63526351 let mut symbol_resolves_locally = false ;
63536352 if let Some ( symbol) = place_expr. as_symbol ( ) {
63546353 if let Some ( symbol_id) = place_table. symbol_id ( symbol. name ( ) ) {
@@ -6414,7 +6413,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
64146413 // check only function-like scopes.
64156414 // There is one exception to this rule: annotation scopes can see
64166415 // names defined in an immediately-enclosing class scope.
6417- let enclosing_scope_id = enclosing_scope_file_id . to_scope_id ( db , current_file ) ;
6416+ let enclosing_scope = self . index . scope ( enclosing_scope_file_id ) ;
64186417
64196418 let is_immediately_enclosing_scope = scope. is_annotation ( db)
64206419 && scope
@@ -6481,7 +6480,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
64816480 }
64826481 }
64836482
6484- if !enclosing_scope_id . is_function_like ( db ) && !is_immediately_enclosing_scope {
6483+ if !enclosing_scope . kind ( ) . is_function_like ( ) && !is_immediately_enclosing_scope {
64856484 continue ;
64866485 }
64876486
@@ -6502,6 +6501,8 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
65026501 break ;
65036502 }
65046503
6504+ let enclosing_scope_id = enclosing_scope_file_id. to_scope_id ( db, self . file ( ) ) ;
6505+
65056506 // If the name is declared or bound in this scope, figure out its type. This might
65066507 // resolve the name and end the walk. But if the name is declared `nonlocal` in
65076508 // this scope, we'll keep walking enclosing scopes and union this type with the
0 commit comments