Skip to content

Use non-global interner in test_string_interning in bootstrap #143325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/bootstrap/src/utils/cache/tests.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
use std::path::PathBuf;

use crate::utils::cache::{INTERNER, Internable, TyIntern};
use crate::utils::cache::{INTERNER, Internable, Interner, TyIntern};

#[test]
fn test_string_interning() {
let s1 = INTERNER.intern_str("Hello");
let s2 = INTERNER.intern_str("Hello");
let s3 = INTERNER.intern_str("world");
let interner = Interner::default();
let s1 = interner.intern_str("Hello");
let s2 = interner.intern_str("Hello");
let s3 = interner.intern_str("world");

assert_eq!(s1, s2, "Same strings should be interned to the same instance");
assert_ne!(s1, s3, "Different strings should have different interned values");
}

#[test]
fn test_interned_equality() {
// Because we compare with &str, and the Deref impl accesses the global
// INTERNER variable, we cannot use a local Interner variable here.
let s1 = INTERNER.intern_str("test");
let s2 = INTERNER.intern_str("test");

Expand Down
Loading