@@ -206,6 +206,7 @@ pub(crate) fn symbol<'db>(
206
206
name,
207
207
RequiresExplicitReExport :: No ,
208
208
considered_definitions,
209
+ false ,
209
210
)
210
211
}
211
212
@@ -242,6 +243,7 @@ pub(crate) fn class_symbol<'db>(
242
243
place,
243
244
RequiresExplicitReExport :: No ,
244
245
ConsideredDefinitions :: EndOfScope ,
246
+ false ,
245
247
) ;
246
248
247
249
if !place_and_quals. place . is_unbound ( ) {
@@ -257,7 +259,8 @@ pub(crate) fn class_symbol<'db>(
257
259
// Otherwise, we need to check if the symbol has bindings
258
260
let use_def = use_def_map ( db, scope) ;
259
261
let bindings = use_def. end_of_scope_bindings ( place) ;
260
- let inferred = place_from_bindings_impl ( db, bindings, RequiresExplicitReExport :: No ) ;
262
+ let inferred =
263
+ place_from_bindings_impl ( db, bindings, RequiresExplicitReExport :: No , false ) ;
261
264
262
265
// TODO: we should not need to calculate inferred type second time. This is a temporary
263
266
// solution until the notion of Boundness and Declaredness is split. See #16036, #16264
@@ -293,6 +296,7 @@ pub(crate) fn explicit_global_symbol<'db>(
293
296
name,
294
297
RequiresExplicitReExport :: No ,
295
298
ConsideredDefinitions :: AllReachable ,
299
+ false ,
296
300
)
297
301
}
298
302
@@ -352,6 +356,7 @@ pub(crate) fn imported_symbol<'db>(
352
356
name,
353
357
requires_explicit_reexport,
354
358
ConsideredDefinitions :: EndOfScope ,
359
+ true ,
355
360
)
356
361
. or_fall_back_to ( db, || {
357
362
if name == "__getattr__" {
@@ -382,6 +387,7 @@ pub(crate) fn builtins_symbol<'db>(db: &'db dyn Db, symbol: &str) -> PlaceAndQua
382
387
symbol,
383
388
RequiresExplicitReExport :: Yes ,
384
389
ConsideredDefinitions :: EndOfScope ,
390
+ false ,
385
391
)
386
392
. or_fall_back_to ( db, || {
387
393
// We're looking up in the builtins namespace and not the module, so we should
@@ -453,7 +459,12 @@ pub(super) fn place_from_bindings<'db>(
453
459
db : & ' db dyn Db ,
454
460
bindings_with_constraints : BindingWithConstraintsIterator < ' _ , ' db > ,
455
461
) -> Place < ' db > {
456
- place_from_bindings_impl ( db, bindings_with_constraints, RequiresExplicitReExport :: No )
462
+ place_from_bindings_impl (
463
+ db,
464
+ bindings_with_constraints,
465
+ RequiresExplicitReExport :: No ,
466
+ false ,
467
+ )
457
468
}
458
469
459
470
/// Build a declared type from a [`DeclarationsIterator`].
@@ -468,7 +479,7 @@ pub(crate) fn place_from_declarations<'db>(
468
479
db : & ' db dyn Db ,
469
480
declarations : DeclarationsIterator < ' _ , ' db > ,
470
481
) -> PlaceFromDeclarationsResult < ' db > {
471
- place_from_declarations_impl ( db, declarations, RequiresExplicitReExport :: No )
482
+ place_from_declarations_impl ( db, declarations, RequiresExplicitReExport :: No , false )
472
483
}
473
484
474
485
pub ( crate ) type DeclaredTypeAndConflictingTypes < ' db > =
@@ -598,6 +609,7 @@ impl<'db> From<Place<'db>> for PlaceAndQualifiers<'db> {
598
609
}
599
610
}
600
611
612
+ #[ allow( clippy:: too_many_arguments) ]
601
613
fn place_cycle_recover < ' db > (
602
614
_db : & ' db dyn Db ,
603
615
_value : & PlaceAndQualifiers < ' db > ,
@@ -606,6 +618,7 @@ fn place_cycle_recover<'db>(
606
618
_place_id : ScopedPlaceId ,
607
619
_requires_explicit_reexport : RequiresExplicitReExport ,
608
620
_considered_definitions : ConsideredDefinitions ,
621
+ _ignore_never_constraints : bool ,
609
622
) -> salsa:: CycleRecoveryAction < PlaceAndQualifiers < ' db > > {
610
623
salsa:: CycleRecoveryAction :: Iterate
611
624
}
@@ -616,6 +629,7 @@ fn place_cycle_initial<'db>(
616
629
_place_id : ScopedPlaceId ,
617
630
_requires_explicit_reexport : RequiresExplicitReExport ,
618
631
_considered_definitions : ConsideredDefinitions ,
632
+ _ignore_never_constraints : bool ,
619
633
) -> PlaceAndQualifiers < ' db > {
620
634
Place :: bound ( Type :: Never ) . into ( )
621
635
}
@@ -627,6 +641,7 @@ fn place_by_id<'db>(
627
641
place_id : ScopedPlaceId ,
628
642
requires_explicit_reexport : RequiresExplicitReExport ,
629
643
considered_definitions : ConsideredDefinitions ,
644
+ ignore_never_constraints : bool ,
630
645
) -> PlaceAndQualifiers < ' db > {
631
646
let use_def = use_def_map ( db, scope) ;
632
647
@@ -638,7 +653,12 @@ fn place_by_id<'db>(
638
653
ConsideredDefinitions :: AllReachable => use_def. all_reachable_declarations ( place_id) ,
639
654
} ;
640
655
641
- let declared = place_from_declarations_impl ( db, declarations, requires_explicit_reexport) ;
656
+ let declared = place_from_declarations_impl (
657
+ db,
658
+ declarations,
659
+ requires_explicit_reexport,
660
+ ignore_never_constraints,
661
+ ) ;
642
662
643
663
let all_considered_bindings = || match considered_definitions {
644
664
ConsideredDefinitions :: EndOfScope => use_def. end_of_scope_bindings ( place_id) ,
@@ -660,7 +680,12 @@ fn place_by_id<'db>(
660
680
} ) => {
661
681
let bindings = all_considered_bindings ( ) ;
662
682
let boundness_analysis = bindings. boundness_analysis ;
663
- let inferred = place_from_bindings_impl ( db, bindings, requires_explicit_reexport) ;
683
+ let inferred = place_from_bindings_impl (
684
+ db,
685
+ bindings,
686
+ requires_explicit_reexport,
687
+ ignore_never_constraints,
688
+ ) ;
664
689
665
690
let place = match inferred {
666
691
// Place is possibly undeclared and definitely unbound
@@ -690,7 +715,12 @@ fn place_by_id<'db>(
690
715
} ) => {
691
716
let bindings = all_considered_bindings ( ) ;
692
717
let boundness_analysis = bindings. boundness_analysis ;
693
- let mut inferred = place_from_bindings_impl ( db, bindings, requires_explicit_reexport) ;
718
+ let mut inferred = place_from_bindings_impl (
719
+ db,
720
+ bindings,
721
+ requires_explicit_reexport,
722
+ ignore_never_constraints,
723
+ ) ;
694
724
695
725
if boundness_analysis == BoundnessAnalysis :: AssumeBound {
696
726
if let Place :: Type ( ty, Boundness :: PossiblyUnbound ) = inferred {
@@ -756,6 +786,7 @@ fn symbol_impl<'db>(
756
786
name : & str ,
757
787
requires_explicit_reexport : RequiresExplicitReExport ,
758
788
considered_definitions : ConsideredDefinitions ,
789
+ ignore_never_constraints : bool ,
759
790
) -> PlaceAndQualifiers < ' db > {
760
791
let _span = tracing:: trace_span!( "symbol" , ?name) . entered ( ) ;
761
792
@@ -782,6 +813,7 @@ fn symbol_impl<'db>(
782
813
symbol,
783
814
requires_explicit_reexport,
784
815
considered_definitions,
816
+ ignore_never_constraints,
785
817
)
786
818
} )
787
819
. unwrap_or_default ( )
@@ -806,6 +838,7 @@ fn place_impl<'db>(
806
838
place,
807
839
requires_explicit_reexport,
808
840
considered_definitions,
841
+ false ,
809
842
)
810
843
} )
811
844
. unwrap_or_default ( )
@@ -820,6 +853,7 @@ fn place_from_bindings_impl<'db>(
820
853
db : & ' db dyn Db ,
821
854
bindings_with_constraints : BindingWithConstraintsIterator < ' _ , ' db > ,
822
855
requires_explicit_reexport : RequiresExplicitReExport ,
856
+ ignore_never_constraints : bool ,
823
857
) -> Place < ' db > {
824
858
let predicates = bindings_with_constraints. predicates ;
825
859
let reachability_constraints = bindings_with_constraints. reachability_constraints ;
@@ -845,7 +879,12 @@ fn place_from_bindings_impl<'db>(
845
879
// expressions, which is extra work and can lead to cycles.
846
880
let unbound_visibility = || {
847
881
unbound_reachability_constraint. map ( |reachability_constraint| {
848
- reachability_constraints. evaluate ( db, predicates, reachability_constraint)
882
+ reachability_constraints. evaluate (
883
+ db,
884
+ predicates,
885
+ reachability_constraint,
886
+ ignore_never_constraints,
887
+ )
849
888
} )
850
889
} ;
851
890
@@ -861,9 +900,13 @@ fn place_from_bindings_impl<'db>(
861
900
return None ;
862
901
}
863
902
DefinitionState :: Deleted => {
864
- deleted_reachability = deleted_reachability. or (
865
- reachability_constraints. evaluate ( db, predicates, reachability_constraint)
866
- ) ;
903
+ deleted_reachability = deleted_reachability. or ( reachability_constraints
904
+ . evaluate (
905
+ db,
906
+ predicates,
907
+ reachability_constraint,
908
+ ignore_never_constraints,
909
+ ) ) ;
867
910
return None ;
868
911
}
869
912
} ;
@@ -872,8 +915,12 @@ fn place_from_bindings_impl<'db>(
872
915
return None ;
873
916
}
874
917
875
- let static_reachability =
876
- reachability_constraints. evaluate ( db, predicates, reachability_constraint) ;
918
+ let static_reachability = reachability_constraints. evaluate (
919
+ db,
920
+ predicates,
921
+ reachability_constraint,
922
+ ignore_never_constraints,
923
+ ) ;
877
924
878
925
if static_reachability. is_always_false ( ) {
879
926
// If the static reachability evaluates to false, the binding is either not reachable
@@ -1093,6 +1140,7 @@ fn place_from_declarations_impl<'db>(
1093
1140
db : & ' db dyn Db ,
1094
1141
declarations : DeclarationsIterator < ' _ , ' db > ,
1095
1142
requires_explicit_reexport : RequiresExplicitReExport ,
1143
+ ignore_never_constraints : bool ,
1096
1144
) -> PlaceFromDeclarationsResult < ' db > {
1097
1145
let predicates = declarations. predicates ;
1098
1146
let reachability_constraints = declarations. reachability_constraints ;
@@ -1107,9 +1155,12 @@ fn place_from_declarations_impl<'db>(
1107
1155
Some ( DeclarationWithConstraint {
1108
1156
declaration,
1109
1157
reachability_constraint,
1110
- } ) if declaration. is_undefined_or ( is_non_exported) => {
1111
- reachability_constraints. evaluate ( db, predicates, * reachability_constraint)
1112
- }
1158
+ } ) if declaration. is_undefined_or ( is_non_exported) => reachability_constraints. evaluate (
1159
+ db,
1160
+ predicates,
1161
+ * reachability_constraint,
1162
+ ignore_never_constraints,
1163
+ ) ,
1113
1164
_ => Truthiness :: AlwaysFalse ,
1114
1165
} ;
1115
1166
@@ -1128,8 +1179,12 @@ fn place_from_declarations_impl<'db>(
1128
1179
return None ;
1129
1180
}
1130
1181
1131
- let static_reachability =
1132
- reachability_constraints. evaluate ( db, predicates, reachability_constraint) ;
1182
+ let static_reachability = reachability_constraints. evaluate (
1183
+ db,
1184
+ predicates,
1185
+ reachability_constraint,
1186
+ ignore_never_constraints,
1187
+ ) ;
1133
1188
1134
1189
if static_reachability. is_always_false ( ) {
1135
1190
None
@@ -1370,7 +1425,7 @@ impl RequiresExplicitReExport {
1370
1425
/// ```py
1371
1426
/// def _():
1372
1427
/// x = 1
1373
- ///
1428
+ ///
1374
1429
/// x = 2
1375
1430
///
1376
1431
/// if flag():
0 commit comments