mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-05 21:24:12 +00:00
Add infer array test
This commit is contained in:
parent
d665acbbec
commit
2a3262c757
@ -334,6 +334,29 @@ fn test(x: &str, y: isize) {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_array() {
|
||||
check_inference(
|
||||
r#"
|
||||
fn test(x: &str, y: isize) {
|
||||
let a = [x];
|
||||
let b = [a, a];
|
||||
let c = [b, b];
|
||||
|
||||
let d = [y];
|
||||
let e = [d, d];
|
||||
let f = [e, e];
|
||||
|
||||
// we have not infered these case yet.
|
||||
let g = [1, 2];
|
||||
let h = ["a", "b"];
|
||||
let b = [a, ["b"]];
|
||||
}
|
||||
"#,
|
||||
"array.txt",
|
||||
);
|
||||
}
|
||||
|
||||
fn infer(content: &str) -> String {
|
||||
let (db, _, file_id) = MockDatabase::with_single_file(content);
|
||||
let source_file = db.source_file(file_id);
|
||||
|
38
crates/ra_hir/src/ty/tests/data/array.txt
Normal file
38
crates/ra_hir/src/ty/tests/data/array.txt
Normal file
@ -0,0 +1,38 @@
|
||||
[9; 10) 'x': &str
|
||||
[18; 19) 'y': isize
|
||||
[28; 258) '{ ..."]]; }': ()
|
||||
[38; 39) 'a': [&str,]
|
||||
[42; 45) '[x]': [&str,]
|
||||
[43; 44) 'x': &str
|
||||
[55; 56) 'b': [[&str,], [&str,]]
|
||||
[59; 65) '[a, a]': [[&str,], [&str,]]
|
||||
[60; 61) 'a': [&str,]
|
||||
[63; 64) 'a': [&str,]
|
||||
[75; 76) 'c': [[[&str,], [&str,]], [[&str,], [&str,]]]
|
||||
[79; 85) '[b, b]': [[[&str,], [&str,]], [[&str,], [&str,]]]
|
||||
[80; 81) 'b': [[&str,], [&str,]]
|
||||
[83; 84) 'b': [[&str,], [&str,]]
|
||||
[96; 97) 'd': [isize,]
|
||||
[100; 103) '[y]': [isize,]
|
||||
[101; 102) 'y': isize
|
||||
[113; 114) 'e': [[isize,], [isize,]]
|
||||
[117; 123) '[d, d]': [[isize,], [isize,]]
|
||||
[118; 119) 'd': [isize,]
|
||||
[121; 122) 'd': [isize,]
|
||||
[133; 134) 'f': [[[isize,], [isize,]], [[isize,], [isize,]]]
|
||||
[137; 143) '[e, e]': [[[isize,], [isize,]], [[isize,], [isize,]]]
|
||||
[138; 139) 'e': [[isize,], [isize,]]
|
||||
[141; 142) 'e': [[isize,], [isize,]]
|
||||
[197; 198) 'g': [_, _]
|
||||
[201; 207) '[1, 2]': [_, _]
|
||||
[202; 203) '1': [unknown]
|
||||
[205; 206) '2': [unknown]
|
||||
[217; 218) 'h': [_, _]
|
||||
[221; 231) '["a", "b"]': [_, _]
|
||||
[222; 225) '"a"': [unknown]
|
||||
[227; 230) '"b"': [unknown]
|
||||
[241; 242) 'b': [[&str,], [_,]]
|
||||
[245; 255) '[a, ["b"]]': [[&str,], [_,]]
|
||||
[246; 247) 'a': [&str,]
|
||||
[249; 254) '["b"]': [_,]
|
||||
[250; 253) '"b"': [unknown]
|
Loading…
Reference in New Issue
Block a user