Infer range types

This commit is contained in:
oxalica 2019-11-29 03:10:16 +08:00
parent 8b278b1ab6
commit 4992d2bf79
No known key found for this signature in database
GPG key ID: CED392DE0C483D00
7 changed files with 209 additions and 4 deletions

View file

@ -221,6 +221,56 @@ mod collections {
assert_eq!("&str", type_at_pos(&db, pos));
}
#[test]
fn infer_ranges() {
let (db, pos) = TestDB::with_position(
r#"
//- /main.rs crate:main deps:std
fn test() {
let a = ..;
let b = 1..;
let c = ..2u32;
let d = 1..2usize;
let e = ..=10;
let f = 'a'..='z';
let t = (a, b, c, d, e, f);
t<|>;
}
//- /std.rs crate:std
#[prelude_import] use prelude::*;
mod prelude {}
pub mod ops {
pub struct Range<Idx> {
pub start: Idx,
pub end: Idx,
}
pub struct RangeFrom<Idx> {
pub start: Idx,
}
struct RangeFull;
pub struct RangeInclusive<Idx> {
start: Idx,
end: Idx,
is_empty: u8,
}
pub struct RangeTo<Idx> {
pub end: Idx,
}
pub struct RangeToInclusive<Idx> {
pub end: Idx,
}
}
"#,
);
assert_eq!(
"(RangeFull, RangeFrom<i32>, RangeTo<u32>, Range<usize>, RangeToInclusive<i32>, RangeInclusive<char>)",
type_at_pos(&db, pos),
);
}
#[test]
fn infer_while_let() {
let (db, pos) = TestDB::with_position(