//! > Test loop usage
//! > test_runner_name
test_function_usage
//! > function_code
fn foo(mut a: A, ref b: A) {
let c = 5_usize;
loop {
let mut h = 0;
a.b.c = c;
if true {
h = 1;
let mut x = 4;
x = 5;
b = A { b: a.b };
break b;
};
};
}
//! > function_name
foo
//! > module_code
struct A {
b: B,
}
struct B {
c: usize,
}
//! > semantic_diagnostics
//! > usage
Loop 8:4:
Usage: LocalVarId(test::c), ParamId(test::b), ParamId(test::a)::b,
Changes: ParamId(test::a)::b::c, ParamId(test::b),
Snapshot_Usage:
//! > ==========================================================================
//! > Test while loop usage
//! > test_runner_name
test_function_usage
//! > function_code
fn foo(mut a: A, ref b: A) {
let c = 5_usize;
let only_used_in_condition = 5;
while only_used_in_condition != c {
a.b.c = c;
};
}
//! > function_name
foo
//! > module_code
struct A {
b: B,
}
struct B {
c: usize,
}
//! > semantic_diagnostics
//! > usage
While 9:4:
Usage: LocalVarId(test::c), ParamId(test::a)::b::c,
Changes: ParamId(test::a)::b::c,
Snapshot_Usage: LocalVarId(test::only_used_in_condition),
//! > ==========================================================================
//! > Test snap usage
//! > test_runner_name
test_function_usage
//! > function_code
fn foo(mut a: A, ref b: B) {
let c = 5_usize;
let only_used_in_condition = 5;
while only_used_in_condition != c {
{
borrow_B(@b);
borrow_B(@a.b);
}
let _ = c;
consume_B(b);
};
}
//! > function_name
foo
//! > module_code
struct A {
b: B,
}
struct B {
c: usize,
}
fn consume_B(b: B) {}
fn borrow_B(b: @B) {}
//! > semantic_diagnostics
//! > usage
While 11:4:
Usage: LocalVarId(test::c), ParamId(test::b),
Changes:
Snapshot_Usage: LocalVarId(test::only_used_in_condition), ParamId(test::a)::b,
//! > ==========================================================================
//! > Test closure usage
//! > test_runner_name
test_function_usage
//! > function_code
fn foo(a: u32) {
|b: u32| {
|| a + b;
};
}
//! > function_name
foo
//! > semantic_diagnostics
//! > usage
Closure 2:8:
Usage: ParamId(test::a), ParamId(test::b),
Changes:
Snapshot_Usage:
Closure 1:4:
Usage: ParamId(test::a),
Changes:
Snapshot_Usage:
//! > ==========================================================================
//! > Test for usage
//! > test_runner_name
test_function_usage
//! > function_code
fn foo(a: u32) {
let arr = array![1, 2, 3];
for b in arr {
a + b;
};
}
//! > function_name
foo
//! > semantic_diagnostics
//! > usage
For 2:4:
Usage: LocalVarId(test::in), ParamId(test::a),
Changes: LocalVarId(test::in),
Snapshot_Usage:
//! > ==========================================================================
//! > Test inner for usage
//! > test_runner_name
test_function_usage
//! > function_code
fn foo() -> u32 {
let mut counter = 0;
let outer = array![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let inner = array![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
for _i in outer.span() {
for _j in inner.span() {
counter = counter + 1;
};
}
counter
}
//! > function_name
foo
//! > semantic_diagnostics
//! > usage
For 5:8:
Usage: LocalVarId(test::in), LocalVarId(test::counter),
Changes: LocalVarId(test::in), LocalVarId(test::counter),
Snapshot_Usage:
For 4:4:
Usage: LocalVarId(test::in), LocalVarId(test::counter),
Changes: LocalVarId(test::in), LocalVarId(test::counter),
Snapshot_Usage: LocalVarId(test::inner),
//! > ==========================================================================
//! > closure in else block.
//! > test_runner_name
test_function_usage
//! > function_code
fn foo(mut a: Span<u32>, mut b: Span<u32>) -> Option<usize> {
let Some(_) = a.pop_front() else {
return b.pop_front().map(|q| *q);
};
None
}
//! > function_name
foo
//! > semantic_diagnostics
//! > usage
Closure 2:33:
Usage:
Changes:
Snapshot_Usage: