Skip to content

Commit

Permalink
More minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkdp committed Dec 20, 2024
1 parent b85a56d commit f0e9cce
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ impl Default for UseDefMapBuilder<'_> {
Self {
all_definitions: IndexVec::from_iter([None]),
all_constraints: IndexVec::new(),
visibility_constraints: VisibilityConstraints::new(),
visibility_constraints: VisibilityConstraints::default(),
scope_start_visibility: ScopedVisibilityConstraintId::ALWAYS_TRUE,
bindings_by_use: IndexVec::new(),
definitions_by_definition: FxHashMap::default(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ mod tests {

#[test]
fn merge() {
let mut visibility_constraints = VisibilityConstraints::new();
let mut visibility_constraints = VisibilityConstraints::default();

// merging the same definition with the same constraint keeps the constraint
let mut sym1a = SymbolState::undefined(ScopedVisibilityConstraintId::ALWAYS_TRUE);
Expand Down Expand Up @@ -717,7 +717,7 @@ mod tests {

#[test]
fn record_declaration_merge() {
let mut visibility_constraints = VisibilityConstraints::new();
let mut visibility_constraints = VisibilityConstraints::default();
let mut sym = SymbolState::undefined(ScopedVisibilityConstraintId::ALWAYS_TRUE);
sym.record_declaration(ScopedDefinitionId::from_u32(1));

Expand All @@ -731,7 +731,7 @@ mod tests {

#[test]
fn record_declaration_merge_partial_undeclared() {
let mut visibility_constraints = VisibilityConstraints::new();
let mut visibility_constraints = VisibilityConstraints::default();
let mut sym = SymbolState::undefined(ScopedVisibilityConstraintId::ALWAYS_TRUE);
sym.record_declaration(ScopedDefinitionId::from_u32(1));

Expand Down
8 changes: 3 additions & 5 deletions crates/red_knot_python_semantic/src/types/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6361,15 +6361,13 @@ mod tests {
}

// Incremental inference tests

#[track_caller]
fn first_public_binding<'db>(db: &'db TestDb, file: File, name: &str) -> Definition<'db> {
let scope = global_scope(db, file);
use_def_map(db, scope)
.public_bindings(symbol_table(db, scope).symbol_id_by_name(name).unwrap())
.map(|b| b.binding)
.find(Option::is_some)
.unwrap()
.unwrap()
.find_map(|b| b.binding)
.expect("no binding found")
}

#[test]
Expand Down
6 changes: 4 additions & 2 deletions crates/red_knot_python_semantic/src/visibility_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ pub(crate) struct VisibilityConstraints<'db> {
constraints: IndexVec<ScopedVisibilityConstraintId, VisibilityConstraint<'db>>,
}

impl<'db> VisibilityConstraints<'db> {
pub(crate) fn new() -> Self {
impl Default for VisibilityConstraints<'_> {
fn default() -> Self {
Self {
constraints: IndexVec::from_iter([VisibilityConstraint::AlwaysTrue]),
}
}
}

impl<'db> VisibilityConstraints<'db> {
pub(crate) fn add(
&mut self,
constraint: VisibilityConstraint<'db>,
Expand Down

0 comments on commit f0e9cce

Please sign in to comment.