Skip to content

Commit 34cd976

Browse files
committed
Rust: Run rustfmt --edition 2024 on the test.
1 parent bfaabab commit 34cd976

File tree

1 file changed

+53
-44
lines changed
  • rust/ql/test/library-tests/type-inference

1 file changed

+53
-44
lines changed

rust/ql/test/library-tests/type-inference/main.rs

Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ mod method_call_type_conversion {
11281128
let t = x7.m1(); // $ method=m1 type=t:& type=t:&T.S2
11291129
println!("{:?}", x7);
11301130

1131-
let x9 : String = "Hello".to_string(); // $ type=x9:String
1131+
let x9: String = "Hello".to_string(); // $ type=x9:String
11321132
// Implicit `String` -> `str` conversion happens via the `Deref` trait:
11331133
// https://doc.rust-lang.org/std/string/struct.String.html#deref.
11341134
let u = x9.parse::<u32>(); // $ method=parse type=u:T.u32
@@ -1865,11 +1865,7 @@ mod method_determined_by_argument_type {
18651865
impl MyAdd<bool> for i64 {
18661866
// MyAdd<bool>::my_add
18671867
fn my_add(&self, value: bool) -> Self {
1868-
if value {
1869-
1
1870-
} else {
1871-
0
1872-
}
1868+
if value { 1 } else { 0 }
18731869
}
18741870
}
18751871

@@ -1882,8 +1878,7 @@ mod method_determined_by_argument_type {
18821878
}
18831879

18841880
mod loops {
1885-
struct MyCallable {
1886-
}
1881+
struct MyCallable {}
18871882

18881883
impl MyCallable {
18891884
fn new() -> Self {
@@ -1898,87 +1893,101 @@ mod loops {
18981893
pub fn f() {
18991894
// for loops with arrays
19001895

1901-
for i in [1, 2, 3] { } // $ type=i:i32
1902-
for i in [1, 2, 3].map(|x| x + 1) { } // $ method=map MISSING: type=i:i32
1903-
for i in [1, 2, 3].into_iter() { } // $ method=into_iter MISSING: type=i:i32
1896+
for i in [1, 2, 3] {} // $ type=i:i32
1897+
for i in [1, 2, 3].map(|x| x + 1) {} // $ method=map MISSING: type=i:i32
1898+
for i in [1, 2, 3].into_iter() {} // $ method=into_iter MISSING: type=i:i32
19041899

19051900
let vals1 = [1u8, 2, 3]; // $ type=vals1:[T;...].u8
1906-
for u in vals1 { } // $ type=u:u8
1901+
for u in vals1 {} // $ type=u:u8
19071902

19081903
let vals2 = [1u16; 3]; // $ type=vals2:[T;...].u16
1909-
for u in vals2 { } // $ type=u:u16
1904+
for u in vals2 {} // $ type=u:u16
19101905

19111906
let vals3: [u32; 3] = [1, 2, 3]; // $ type=vals3:[T;...].u32
1912-
for u in vals3 { } // $ type=u:u32
1907+
for u in vals3 {} // $ type=u:u32
19131908

19141909
let vals4: [u64; 3] = [1; 3]; // $ type=vals4:[T;...].u64
1915-
for u in vals4 { } // $ type=u:u64
1910+
for u in vals4 {} // $ type=u:u64
19161911

19171912
let mut strings1 = ["foo", "bar", "baz"]; // $ type=strings1:[T;...].str
1918-
for s in &strings1 { } // $ MISSING: type=s:&T.str
1919-
for s in &mut strings1 { } // $ MISSING: type=s:&T.str
1920-
for s in strings1 { } // $ type=s:str
1921-
1922-
let strings2 = [String::from("foo"), String::from("bar"), String::from("baz")]; // $ type=strings2:[T;...].String
1923-
for s in strings2 { } // $ type=s:String
1924-
1925-
let strings3 = &[String::from("foo"), String::from("bar"), String::from("baz")]; // $ type=strings3:&T.[T;...].String
1926-
for s in strings3 { } // $ MISSING: type=s:String
1913+
for s in &strings1 {} // $ MISSING: type=s:&T.str
1914+
for s in &mut strings1 {} // $ MISSING: type=s:&T.str
1915+
for s in strings1 {} // $ type=s:str
1916+
1917+
let strings2 = [
1918+
String::from("foo"),
1919+
String::from("bar"),
1920+
String::from("baz"),
1921+
]; // $ type=strings2:[T;...].String
1922+
for s in strings2 {} // $ type=s:String
1923+
1924+
let strings3 = &[
1925+
String::from("foo"),
1926+
String::from("bar"),
1927+
String::from("baz"),
1928+
]; // $ type=strings3:&T.[T;...].String
1929+
for s in strings3 {} // $ MISSING: type=s:String
19271930

19281931
let callables = [MyCallable::new(), MyCallable::new(), MyCallable::new()]; // $ MISSING: type=callables:[T;...].MyCallable; 3
1929-
for c in callables { // $ type=c:MyCallable
1932+
for c in callables {
1933+
// $ type=c:MyCallable
19301934
let result = c.call(); // $ type=result:i64 method=call
19311935
}
19321936

19331937
// for loops with ranges
19341938

1935-
for i in 0..10 { } // $ MISSING: type=i:i32
1936-
for u in [0u8 .. 10] { } // $ MISSING: type=u:u8
1939+
for i in 0..10 {} // $ MISSING: type=i:i32
1940+
for u in [0u8..10] {} // $ MISSING: type=u:u8
19371941
let range = 0..10; // $ MISSING: type=range:Range type=range:Idx.i32
1938-
for i in range { } // $ MISSING: type=i:i32
1942+
for i in range {} // $ MISSING: type=i:i32
19391943

1940-
let range1 = std::ops::Range { start: 0u16, end: 10u16 }; // $ type=range1:Range type=range1:Idx.u16
1941-
for u in range1 { } // $ MISSING: type=u:u16
1944+
let range1 = std::ops::Range {
1945+
start: 0u16,
1946+
end: 10u16,
1947+
}; // $ type=range1:Range type=range1:Idx.u16
1948+
for u in range1 {} // $ MISSING: type=u:u16
19421949

19431950
// for loops with containers
19441951

19451952
let vals3 = vec![1, 2, 3]; // $ MISSING: type=vals3:Vec type=vals3:T.i32
1946-
for i in vals3 { } // $ MISSING: type=i:i32
1953+
for i in vals3 {} // $ MISSING: type=i:i32
19471954

1948-
let vals4a : Vec<u16> = [1u16, 2, 3].to_vec(); // $ type=vals4a:Vec type=vals4a:T.u16
1949-
for u in vals4a { } // $ type=u:u16
1955+
let vals4a: Vec<u16> = [1u16, 2, 3].to_vec(); // $ type=vals4a:Vec type=vals4a:T.u16
1956+
for u in vals4a {} // $ type=u:u16
19501957

19511958
let vals4b = [1u16, 2, 3].to_vec(); // $ MISSING: type=vals4b:Vec type=vals4b:T.u16
1952-
for u in vals4b { } // $ MISSING: type=u:u16
1959+
for u in vals4b {} // $ MISSING: type=u:u16
19531960

19541961
let vals5 = Vec::from([1u32, 2, 3]); // $ type=vals5:Vec MISSING: type=vals5:T.u32
1955-
for u in vals5 { } // $ MISSING: type=u:u32
1962+
for u in vals5 {} // $ MISSING: type=u:u32
19561963

1957-
let vals6 : Vec<&u64> = [1u64, 2, 3].iter().collect(); // $ type=vals6:Vec type=vals6:T.&T.u64
1958-
for u in vals6 { } // $ type=u:&T.u64
1964+
let vals6: Vec<&u64> = [1u64, 2, 3].iter().collect(); // $ type=vals6:Vec type=vals6:T.&T.u64
1965+
for u in vals6 {} // $ type=u:&T.u64
19591966

19601967
let mut vals7 = Vec::new(); // $ type=vals7:Vec MISSING: type=vals7:T.u8
19611968
vals7.push(1u8); // $ method=push
1962-
for u in vals7 { } // $ MISSING: type=u:u8
1969+
for u in vals7 {} // $ MISSING: type=u:u8
19631970

19641971
let matrix1 = vec![vec![1, 2], vec![3, 4]]; // $ MISSING: type=matrix1:Vec type=matrix1:T.Vec type=matrix1:T.T.i32
1965-
for row in matrix1 { // $ MISSING: type=row:Vec type=row:T.i32
1972+
for row in matrix1 {
1973+
// $ MISSING: type=row:Vec type=row:T.i32
19661974
for cell in row { // $ MISSING: type=cell:i32
19671975
}
19681976
}
19691977

19701978
let mut map1 = std::collections::HashMap::new(); // $ MISSING: type=map1:Hashmap type=map1:K.i32 type=map1:V.Box type1=map1:V.T.&T.str
19711979
map1.insert(1, Box::new("one")); // $ method=insert
19721980
map1.insert(2, Box::new("two")); // $ method=insert
1973-
for key in map1.keys() { } // $ method=keys MISSING: type=key:i32
1974-
for value in map1.values() { } // $ method=values MISSING: type=value:Box type=value:T.&T.str
1975-
for (key, value) in map1.iter() { } // $ method=iter MISSING: type=key:i32 type=value:Box type=value:T.&T.str
1976-
for (key, value) in &map1 { } // $ MISSING: type=key:i32 type=value:Box type=value:T.&T.str
1981+
for key in map1.keys() {} // $ method=keys MISSING: type=key:i32
1982+
for value in map1.values() {} // $ method=values MISSING: type=value:Box type=value:T.&T.str
1983+
for (key, value) in map1.iter() {} // $ method=iter MISSING: type=key:i32 type=value:Box type=value:T.&T.str
1984+
for (key, value) in &map1 {} // $ MISSING: type=key:i32 type=value:Box type=value:T.&T.str
19771985

19781986
// while loops
19791987

19801988
let mut a: i64 = 0; // $ type=a:i64
1981-
while a < 10 { // $ method=lt type=a:i64
1989+
while a < 10 {
1990+
// $ method=lt type=a:i64
19821991
a += 1; // $ type=a:i64 method=add_assign
19831992
}
19841993
}

0 commit comments

Comments
 (0)